Ejemplo n.º 1
0
    unsigned int    ReadEepromWord(unsigned char Arg6)
	
    {
    unsigned int Arg7;
    Arg7=ReadEeprom(Arg6+1);		 	
    Arg7=Arg7<<8;
    Arg7=Arg7 | ReadEeprom(Arg6);   	
   	return Arg7;
    }
Ejemplo n.º 2
0
	void	ChangeUNom(void)
	{
	unsigned char R0;					
	if(!CtDeltaU)
		{
	if(RegS & 0x100)//MU
			{
	if(RegS & 0x10)
				{ 
	++UNom;
	CtDeltaU=10;
				}
	else if(RegS & 0x20)
				{ 
	--UNom;
	CtDeltaU=10;
				}
			}
	else//DU
			{
	if(RomReceive[2] & 0x40)
				{ 
	++UNom;
	CtDeltaU=10;
				}
	else if(RomReceive[2] & 0x80)
				{ 
	--UNom;
	CtDeltaU=10;
				}
			}
	if(UNom>UMax)
	UNom=UMax;
	if(UNom<UMin)
	UNom=UMin;


	R0= ReadEeprom(1);
	
	if(R0 !=UNom)
	WriteEeprom(1,UNom);

		}

	RegSOld=RegS;		
	}																		        
Ejemplo n.º 3
0
	int main(void)
    {
	unsigned char Arg0;


//if DDRX,X=1 PORTX,X=OUT
    DDRA=0xff;


    DDRB=0x1f;
	PORTB = 0xff;

    DDRC=0xfc;
    PORTC =0xff;

    DDRD=0xea;

    PORTD=0xff;
	RegTransmitRS[7]=ReadEeprom(4);
//INIT TWI;
    TWBR=0x7f;//F TWI


    TCCR1B=0x2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
    TWAR=(NumberLink<<1)+4;   
   TWCR =(1<<TWEA)|(1<<TWEN);

   _SEI();
    RegimTime =0;

		
	for(Arg0=1;Arg0<=10;++Arg0)
		RomReceive[Arg0]=0;




	RegimWork=0;
	CtErrorLink=CtErrorLink0;

	CtKn=5;

	Regim=1;//Gashenie=on;

	InitUsart();  
			
	CtUsart=1;	
	CtEnableKn=3;
	InitStarter();

	CtErrorRS=9;
	NumberRegim=1;// hand MShU
	NNom=1500;
	CtBegin=50;
	RegS=0x1200;
	RegSTemp=0x1200;
	RegS1=0;
	RegSTemp1=0;
	CtErrorRSMin=255;
	NumberRegim=2;
	ClearPZA=0;
	CtPZA=CtPZA0;
	ErrorPZA=0;
	RezervDiz2=0;
//WORK	
	           
      while(1)
    {


	_WDR();

	ControlNU();
	PORTB &=0xef;
	if(RegimWork<=2)
		{
		ReadEeprom(4);
		if(ReadEeprom(4)!=RegTransmitRS[7])
			WriteEeprom(4,RegTransmitRS[7]);
		}






	if((!RegimWork)||(RegimWork & 0x8))
	PORTD |=0x60;
	else if((RegimWork & 1)||(RegimWork & 0x80))
		{
	PORTD &=0xbf;

		}
	else
		{
	PORTD &=0xdf;
	PORTD |=0x40;
		}


	ControlZapravkaTopliva();
	ControlZapravkaMasla();
	ControlPodogrev();
//	ControlAvarStop();
	ControlLampError();
	TOG=RomReceiveRS[6][(NumberBlok-1)];


	if(CtBegin)
		
	ClearError();
	else if(RegS1 & 8)
		{
	ClearError();


		}
	if(!(RegTransmit[1] & 6))
	ClearPZA=0;
	if(RegS1 & 0x20)
		{
	ClearPZA=0;

		}
	if(RomReceive[3] & 1) 
	NumberBlok=6;//SHU 2
	else
	NumberBlok=3;//SHU 1



		


	if(PORTC & 8)
	ChangeNumberRegim();

	ChangeNNom();
	AccountNDiz();
	LoadRegTransmitRS();

	SetRegimError();
	SetError();
	ControlRegimWork();


     _WDR();
	if(EndAd)
		{

	EndAd=0;
		}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{
    ReceiveTransmitSlave();

			}
	if(!CtErrorLink)//ErrorLink;
		{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;
   TWCR =(1<<TWEA)|(1<<TWEN);

	CtErrorLink=CtErrorLink0;

    CtStart=200;
	while(CtStart--)	_WDR();
		}



				

    }
  
}
Ejemplo n.º 4
0
    int main(void)
    {
	unsigned char Arg0;
 



//if DDRX,X=1 PORTX,X=OUT
    DDRA=0xbf;
	PORTA = 0xff;//0xc0 prov

    DDRB=1;
	PORTB = 0xff;

    DDRC=0xd4;
    PORTC =0xff;

    DDRD=0x12;
    PORTD=0xff;

//INIT TWI;
    TWBR=0x7f;//F TWI


    TCCR1B=0xc2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
	TWAR=4;
    TWCR =(1<<TWEA)|(1<<TWEN);
    ReadKn();
    CtStart=200;
	while(CtStart--)	_WDR();
    ReadKn();
   _SEI();
    RegimTime &=0xc0;

    CtUst=CtUst0;
		
	for(Arg0=1;Arg0<=10;++Arg0)
	RomReceive[Arg0]=0;


	CtEeprom=1;

	RegimWork=0;
	CtErrorLink=CtErrorLink0;

	InitUSART();
	Gashenie=0;//Gashenie=off;
	UNom=ReadEeprom(1);
	if(UNom>260)
	UNom=220;
	if(UNom<90)
	UNom=220;
	UMin=80;//95;//95B
	CtReceiveUsart=0;			
	Gashenie =4;//vozb=on	
//WORK	
	           
      while(1)
    {
	_WDR();
	if(!CtTransmitUsart)
		{
	if(NumberLinkUsart)
	--NumberLinkUsart;
	else
	NumberLinkUsart=2;



	CtReceiveUsart=0;
	LoadRegTransmitUsart(NumberLinkUsart);
	CtTransmitUsart=15;
	RCHReceive=0xff;
	RCLReceive=0xff;

		}


	if(RegS & 2)
	RegimWork &=0xfe;
	else if(RegSWork & 0x40)
		{
	if(RegimWork & 1)
	RegimWork &=0xfe;
	else
	RegimWork |=1;
	RegSWork &=0xbf;
		}


	if((RomReceive[1]& 0xe)&&(!(RomReceive[1]& 0x10)))
	PORTA &=0xdf;
	else
	PORTA |=0x20;
	if(RegS & 2)
	PORTA &=0x7f;
	else
	PORTA |=0x80;

	if(RegS & 4)
	PORTC &=0xef;
	else
	PORTC |=0x10;
	if(RegS & 8)
	PORTC &=0xfb;
	else
	PORTC |=0x4;

	ChangeUNom();







	IndicatorLed();
	++TestLink;
     _WDR();
	if(EndAd)
		{

	EndAd=0;
		}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{
    ReceiveTransmitSlave();
//	++TestTransmit;
			}
	if(!CtErrorLink)//ErrorLink;
		{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
   TWAR=4;
   TWCR =(1<<TWEA)|(1<<TWEN);
	CtErrorLink=CtErrorLink0;

    CtStart=200;
	while(CtStart--)	_WDR();
		}

    ReadKn();

				

    }
  
}
Ejemplo n.º 5
0
void ServiceRequests( void )
{
    BYTE num_return_bytes;          // Number of bytes to return in response to received command.
    BYTE cmd;                     // Store the command in the received packet.

    // Process packets received through the primary endpoint.
    if ( !USBHandleBusy( OutHandle[OutIndex] ) )
    {
        num_return_bytes = 0;   // Initially, assume nothing needs to be returned.

        // Got a packet, so start getting another packet while we process this one.
        OutPacket        = &OutBuffer[OutIndex]; // Store pointer to just-received packet.
        OutPacketLength  = USBHandleGetLength( OutHandle[OutIndex] );   // Store length of received packet.
        cmd              = OutPacket->cmd;

        blink_counter    = NUM_ACTIVITY_BLINKS; // Blink the LED whenever a USB transaction occurs.

        switch ( cmd )  // Process the contents of the packet based on the command byte.
        {
            case ID_BOARD_CMD:
                // Blink the LED in order to identify the board.
                blink_counter                  = 50;
                InPacket->cmd                  = cmd;
                num_return_bytes               = 1;
                break;

            case INFO_CMD:
//                memcpy( ( void * )( (BYTE *)InPacket ), (void *)&sdBuf, sizeof( sdBuf ) );
                InPacket->_dword[0] = numBlocks;
                InPacket->_word[2] = rdBlockSize;
                InPacket->_word[3] = wrBlockSize;
                InPacket->_word[4] = eraseSize;
                num_return_bytes = 16;
                break;
                // Return a packet with information about this USB interface device.
                InPacket->cmd                  = cmd;
                memcpypgm2ram( ( void * )( (BYTE *)InPacket + 1 ), (const rom void *)&device_info, sizeof( DEVICE_INFO ) );
//                InPacket->device_info.checksum = calc_checksum( (CHAR8 *)InPacket, sizeof( DEVICE_INFO ) );
                num_return_bytes               = sizeof( DEVICE_INFO ) + 1; // Return information stored in packet.
                break;

            case READ_EEDATA_CMD:
                InPacket->cmd = OutPacket->cmd;
                for(buffer_cntr=0; buffer_cntr < OutPacket->len; buffer_cntr++)
                {
                    InPacket->data[buffer_cntr] = ReadEeprom((BYTE)OutPacket->ADR.pAdr + buffer_cntr);
                }
                num_return_bytes = buffer_cntr + 5;
                break;

            case WRITE_EEDATA_CMD:
                InPacket->cmd = OutPacket->cmd;
                for(buffer_cntr=0; buffer_cntr < OutPacket->len; buffer_cntr++)
                {
                    WriteEeprom((BYTE)OutPacket->ADR.pAdr + buffer_cntr, OutPacket->data[buffer_cntr]);
                }
                num_return_bytes = 1;
                break;

            case RESET_CMD:
                // When resetting, make sure to drop the device off the bus
                // for a period of time. Helps when the device is suspended.
                UCONbits.USBEN = 0;
                lcntr = 0xFFFF;
                for(lcntr = 0xFFFF; lcntr; lcntr--)
                    ;
                Reset();
                break;

            default:
                num_return_bytes = 0;
                break;
        } /* switch */

        // This command packet has been handled, so get another.
        OutHandle[OutIndex] = USBGenRead( USBGEN_EP_NUM, (BYTE *)&OutBuffer[OutIndex], USBGEN_EP_SIZE );
        OutIndex ^= 1; // Point to next ping-pong buffer.

        // Packets of data are returned to the PC here.
        // The counter indicates the number of data bytes in the outgoing packet.
        if ( num_return_bytes != 0U )
        {
            InHandle[InIndex] = USBGenWrite( USBGEN_EP_NUM, (BYTE *)InPacket, num_return_bytes ); // Now send the packet.
            InIndex ^= 1;
            while ( USBHandleBusy( InHandle[InIndex] ) )
            {
                ;                           // Wait until transmitter is not busy.
            }
            InPacket = &InBuffer[InIndex];
        }
    }
} /* ServiceRequests */