#include<ioCC2530.h>
#include<string.h>
#define LED1 P1_0
#define LED2 P1_1
#define uint unsigned int
#define uchar unsigned char
#define DATABUFF_SIZE 3
uchar buff_RxDat[DATABUFF_SIZE+1];
uchar uIndex=0;
void initUART0(void)
{
PERCFG=0x00;
P0SEL=0x3c;
U0BAUD=216;
U0GCR=10;
U0CSR|=0x80;
U0UCR|=0x80;
URX0IF=0;
U0CSR|=0x40;
EA=1;
}
void receive_handler(void)
{
uchar onoff=0;
uchar c;
c=U0DBUF;
if(c=='#')
{
buff_RxDat[0]=c;
uIndex=0;
}
else if(buff_RxDat[0]=='#')
{
uIndex++;
buff_RxDat[uIndex]=c;
}
if(uIndex>=2)
{
onoff=buff_RxDat[2]-0x30;
switch(buff_RxDat[1])
{
case'1':
LED1=onoff;
break;
case'2':
LED2=onoff;
break;
}
for(int i=0;i<DATABUFF_SIZE;i++)
{
buff_RxDat[i]=(uchar)NULL;
uIndex=0;
}
}
}
void main()
{
P1SEL&=~0x03;
P1DIR|=0x03;
LED1=0;
LED2=0;
CLKCONCMD&=0x80;
initUART0();
while(1)
if(URX0IF)
{
URX0IF=0;
receive_handler();
}
}这程序onoff=buff_RxDat[2]-0x30;这里是怎么赋值的,计算出来的值怎么对应下面程序啊,onoff值为多少。 当我发送#10 LED1关 #11 LED1开 #21 LED2 开 #22 LED2关 麻烦帮帮我, 拜托了
|