Exemplo n.º 1
0
/*****************************************************************************
 * Function: ADCLoadTemperature()
 *
 * Preconditions:  SPIMPolInit and EEPROMInit must be called before.
 *
 * Overview: The function returns temperature stored by ADCStoreTemperature
 * into EEPROM.
 *
 * Input: None.
 *
 * Output: Temperature value read from EEPROM.
 *
 *****************************************************************************/
unsigned ADCLoadTemperature(){
unsigned Temp;
    // Read MS byte from EEPROM address = 0
    Temp =  EEPROMReadByte(0);
    Temp = (Temp<<8)&0xff00;
    // Read LS byte from EEPROM address = 1
    Temp |= (EEPROMReadByte(1)&0x00ff);
    // If there's not valid value replace it with 25.0 C
    if(Temp > 990)
        Temp = 250;
    return Temp;
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------------------------------------------
// Public functions
//---------------------------------------------------------------------------------------------------------------
unsigned short EEPROMReadWord(unsigned char Address)
{
	unsigned short Return_Value = 0;
	unsigned char High_Byte, Low_Byte;
	
	if (Address < EEPROM_SIZE_BYTES - 1)
	{
		// Retrieve little-endian data
		Low_Byte = EEPROMReadByte(Address); // Low order byte
		High_Byte = EEPROMReadByte(Address + 1); // High order byte
		Return_Value = (High_Byte << 8) | Low_Byte;
	}
		
	return Return_Value;
}
/*******延时函数*************/
void delay(unsigned int i)
{
    unsigned char j;
    for(i; i > 0; i--)    //循环600*255次 机器在这里执行需要一段时间 也就达到了延时效果
        for(j = 255; j > 0; j--);
}

 /*******中继函数*************/

void ser() interrupt 4
{
   
	static unsigned char count=0;	//串口接收计数的变量
	RI=0;			//先把接收标志位清零
	 b=EEPROMReadByte(0);
	receive[count]=SBUF;

   	if(receive[count]==0xaa) 					    	//控制位	当输入首位为0xaa
	{
			count=1;
	}
    else if(receive[count]==0xbb)						 //写地址位	  当输入首位为0xbb
	{
		    count=1;									
	}
	else if(receive[count]==0xdd)						 //写地址位	  当输入首位为0xbb
	{
		    count=1;									
	}
	else if(receive[0]==0xaa&&receive[count]==b)		//标识位两个字节