完成单板代码
/*任务5:ZigBee无线模块应用*/
分析ZigBee_Test:
/*******************************************************************************
* Function Name : ZigBee_Test
* Description : ZigBee test.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ZigBee_Test(void)
{
Menu_TypeDef menu; //set a ZigBee_Test menu
uint8_t buf[16]; //give a buffer
uint8_t rd; //the information
uint16_t key, x;
uint32_t i;
/*完成一些初始化工作*/
SPI_IOConfig(1); /*set the SPI I/O config*/
SPI_Init(1, 8, 2); /*init spi*/
SPI752_Init(1, 115200); /*set the SPI*/
menu.max_numb = 3; //set some menu information
menu.numb = 1;
menu.title = "ZigBee";
menu.item[0] = "1.Send Hello ZigBee!";
menu.item[1] = "2.Turn on other FAN";
menu.item[2] = "3.Turn off other FAN";
Dis_Menu(menu);
x = 0;
delay_ms(250);
while(menu.numb)
{
if(UART0_GetChar(&rd)) //if the ZigBee board uart get some information, then use the ZigBee send it out
{
ZigBee_PutChar(rd); //send out by ZigBee
}
if(ZigBee_GetChar(&rd)) //if ZigBee module get some information from another zigbee
{
printf("rd =%d\n",rd);
OLED_DisChar(2-1 + 6, x, 0, rd);
x += 6;
if(x > 120)
{
x = 0;
}
UART0_PutChar(rd); //and send the information out by UART
for(i=0; i<8; i++)
{
buf[i] = buf[i+1];
}
buf[i] = rd;
if((buf[0]=='F') && (buf[1]=='A') //judge the buffer received, this is "FAN On "
&& (buf[2]=='N') && (buf[3]==' ')
&& (buf[4]=='O') && (buf[5]=='n')
&& (buf[6]==' ') && (buf[7]==' '))
{
GPIOSetValue(PORT0, 2, 1); // Turn on Fan
}
else if((buf[0]=='F') && (buf[1]=='A') //judge the buffer received, this is "FAN Off "
&& (buf[2]=='N') && (buf[3]==' ')
&& (buf[4]=='O') && (buf[5]=='f')
&& (buf[6]=='f') && (buf[7]==' '))
{
GPIOSetValue(PORT0, 2, 0); // Turn off Fan
}
}
key = KEY_Read();
switch(key) //key setting
{
case KEY_UP:
if(menu.numb > 1)
menu.numb --;
else
menu.numb = menu.max_numb;
Dis_Menu(menu);
x = 0;
break;
case KEY_DOWN:
if(menu.numb < menu.max_numb)
menu.numb ++;
else
menu.numb = 1;
Dis_Menu(menu);
x = 0;
break;
case KEY_SEL:
switch(menu.numb)
{
case 1:
ZigBee_PutString("Hello ZigBee! ");
printf("Send: Hello ZigBee! \n");
break;
case 2:
ZigBee_PutString("FAN On ");
printf("Send: FAN On \n");
break;
case 3:
ZigBee_PutString("FAN Off ");
printf("Send: FAN Off \n");
break;
default:
break;
}
break;
case KEY_ESC:
menu.numb = 0;
break;
default:
break;
}
if((key!=KEY_NONE) && (menu.numb!=0))
{
delay_ms(250);
}
}
}
void ZigBee_Test(void)
1