想写一个DS18B20程序,用uart接收,然后用CC2420发送数据,写了个DS18B20驱动程序,但是不知道不知道采集的温度函数怎么给UART的接收寄存器,不知道这段函数该写到uart的中断函数中 还是写到main函数中 如下:
驱动程序:
/读取DS18B20的温度值
float ReadDSTemp()
{
//USIGN8 TH, TL;
USIGN16 result;
float t;
//启动温度转换
while(InitDS18B20() == 0);
//InitDS18B20();
WriteDS18B20(0xcc);//SKIP ROM
WriteDS18B20(0x44);//CONVERT T
_delay_us(8e5);
//读取温度值
while(InitDS18B20() == 0);
//InitDS18B20();
WriteDS18B20(0xcc);//SKIP ROM
WriteDS18B20(0xbe);//READ SCRATCHPAD
TL = ReadDS18B20();
TH = ReadDS18B20();
//TL = 0x90;
//TH = 0xFC;
if(TH & 0x80)
{
result = (TH << 8) | TL;
result = ~result + 1;
t = -((float)result * 0.0625);
}
else
{
result = (TH << 8) | TL;
t = result * 0.0625;
}
return t;
uart的中断函数:
#pragma vector = USART1RX_VECTOR
__interrupt void usart1_rx (void)
{
Usart0_RxBuffer[16]=ReadDSTemp();???????这么写?
Usart0_RxBuffer[ Usart_rxbuff_Count ] = U1RXBUF;
if(Usart_rxbuff_Count==0)
{
if( Usart0_RxBuffer[0] == 0x7E )
{
U1RCTL &= ~URXWIE;
Usart_rxbuff_Count=1;
}
else
{
U1RCTL|=URXWIE;
}
}
else
{
if(Usart0_RxBuffer[Usart_rxbuff_Count]==0x7E)
{
Len=pktDePack(Usart0_RxBuffer,Usart_rxbuff_Count);
CC2420_WriteTxFIFO(Len+2, &Usart0_RxBuffer[0]);
CC2420_Start_send();
Usart_rxbuff_Count = 0;
U1RCTL|=URXWIE;
}
else
{
Usart_rxbuff_Count++;
if(Usart_rxbuff_Count>120)
{
Usart_rxbuff_Count=0;
U1RCTL|=URXWIE;
}
}
}
}
哪位高手指点下,小弟初学者比较急 |