Example #1
0
void WriteEepromWord( int WordAddress, unsigned long data )
{
	int i;
	
	for( i=0 ; i < 2 ; i++, data >>= 8 )
		WriteEeprom( WordAddress++, data & 0xff ); 
}
Example #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;		
	}																		        
Example #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();
		}



				

    }
  
}
Example #4
0
main()
{
	int i=0, j;


	SetupVICVACDefault();

	WriteEeprom( i++, 0x01 ); 	/* Address 0x27 */	
	WriteEeprom( i++, 0xEA ); 	/* Address 0x47 */	
	WriteEeprom( i++, 0x0F );	/* Address 0x57 */
	WriteEeprom( i++, 0x56 );	/* Address 0xA7 */	
	WriteEeprom( i++, 0x70 );	/* Address 0xB3 */	
	WriteEeprom( i++, 0x0D );	/* Address 0xB7 */
	WriteEeprom( i++, 0x10 );	/* Address 0xC3 */
	WriteEeprom( i++, 0xFF );	/* Address 0xC7 */
	WriteEeprom( i++, 0x14 );	/* Address 0xCB */
	WriteEeprom( i++, 0xFF );	/* Address 0xCF */
	i++;

	WriteEepromWord( i, 0xFFFF );	/* Address 0x00 */
	i += 2;
	WriteEepromWord( i, 0xFFFE );	/* Address 0x01 */
	i += 2;
	WriteEepromWord( i, 0xFF00 );	/* Address 0x02 */
	i += 2;
	WriteEepromWord( i, 0x3400 );	/* Address 0x03 */
	i += 2;
	WriteEepromWord( i, 0xF0F1 );	/* Address 0x04 */
	i += 2;
	WriteEepromWord( i, 0x0001 );	/* Address 0x05 */
	i += 2;
	WriteEepromWord( i, 0x0002 );	/* Address 0x06 */
	i += 2;
	WriteEepromWord( i, 0xFDFF );	/* Address 0x07 */
	i += 2;
	WriteEepromWord( i, 0x7F00 );	/* Address 0x08 */
	i += 2;
	WriteEepromWord( i, 0x2C00 );	/* Address 0x09 */
	i += 2;
	WriteEepromWord( i, 0x4C00 );	/* Address 0x0A */
	i += 2;
	WriteEepromWord( i, 0x0400 );	/* Address 0x0B */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x0C */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x0D */
	i += 2;
	WriteEepromWord( i, 0xF110 );	/* Address 0x0E */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x0F */
	i += 2;
	WriteEepromWord( i, 0xE014 );	/* Address 0x10 */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x11 */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x12 */
	i += 2;
	WriteEepromWord( i, 0xF810 );	/* Address 0x13 */
	i += 2;
	WriteEepromWord( i, 0xEBFE );	/* Address 0x14 */
	i += 2;
	WriteEepromWord( i, 0x0010 );	/* Address 0x16 */
	i += 2;
	WriteEepromWord( i, 0x4000 );	/* Address 0x1A */
	i += 2;
	WriteEepromWord( i, 0x1FFF );	/* Address 0x1B */
	i += 2;
	WriteEepromWord( i, 0x4200 );	/* Address 0x1C */
	i += 2;
	WriteEepromWord( i, 0x77C0 );	/* Address 0x1D */
	i += 2;
	WriteEepromWord( i, 0x77C0 );	/* Address 0x1F */
	i += 2;
	WriteEepromWord( i, 0x8000 );	/* Address 0x23 */
	i += 2;
	WriteEepromWord( i, 0x1 );	/* DRAM size */
	i += 2;
	WriteEepromWord( i, 0 );	/* Daughter present */
	i += 2;
	WriteEepromWord( i, 64 );	/* SRAM1 size */
	i += 2;
	WriteEepromWord( i, 64 );	/* SRAM2 size */
	i += 2;
	WriteEepromWord( i, 64 );	/* SRAM3 size */
	i += 2;
	WriteEepromWord( i, 64 );	/* SRAM4 size */
	i+=2;
	WriteEeprom( i, 'B' );	/* Board revision */
}
Example #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 */