[Linux项目实践] 物联网单板测试之任务五:ZigBee Module之ZigBee_Test

本文介绍了如何在Linux环境下进行ZigBee无线模块的测试,包括初始化设置、菜单交互、UART及ZigBee模块间的通信。通过SPI和UART接口,实现了对ZigBee的控制,例如发送特定指令开关风扇,并能够接收并显示来自其他ZigBee模块的数据。
摘要由CSDN通过智能技术生成

完成单板代码

/*任务5ZigBee无线模块应用*/

分析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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值