辜渝傧

13037102709

027-87870986

教学实训

您当前的位置:首页 > 教学资源 > 实训方案 >

RFID实训|环境检测系统程序源码

发布者:唯众    布时间:2020-12-03 14:34:02    点击量:

项目实现

#include "wirelessplay.h"
#include "24l01.h"     
#include "spi.h"           
#include "paint.h"                   
//重画按钮的名字
u8*const wireless_cbtn_caption_tbl[GUI_LANGUAGE_NUM]=
{
"返回","重畫","CLEAR",
};
//提醒内容
u8*const wireless_remind_msg_tbl[GUI_LANGUAGE_NUM]=
{
"未检测到NRF24L01,请检查!","未檢測到NRF24L01,請檢查!","No NRF24L01,Please Check...",     
};
//模式选择
u8*const wireless_mode_tbl[GUI_LANGUAGE_NUM][2]=
{
{"发送模式","接收模式",},
{"發送模式","接收模式",},             
{"TX Mode","RX Mode",},
};         
/////////////////////////////////////////////////////////////////////////////////
 
u8 wireless_play(void)
{
     _btn_obj* cbtn=0;            //清除按钮控件
       u8 res;
         u8 *caption;                       //标题
         u8 mode=0;                                 //0,发送模式;1,接收模式
         u8 tmp_buf[27];                         //buf[0~3]:坐标值;buf[4]:0,正常画图;1,清屏;2,退出.
         u16 x=0,y=0;
         u16 lastx=0XFFFF,lasty=0XFFFF;
        u8 rval=0;
         u8 key;
         u8 Str[20];
br=0;
    caption=(u8*)APP_MFUNS_CAPTION_TBL[14][gui_phy.language];//无线传输    
         gui_fill_rectangle(0,gui_phy.tbheight,lcddev.width,lcddev.height-gui_phy.tbheight,LGRAY);         //填充背景色
        app_filebrower(caption,0X07);                                                              //显示标题
         gui_draw_line(30,42,225,42,BLUE);
         gui_show_string("继电器",35,52,107,84,24,BLACK);
         gui_draw_line(30,87,225,87,BLUE);
         gui_show_string("In:",35,97,107,129,24,BLACK);
         gui_draw_line(30,132,225,132,BLUE);
         gui_show_string("Out:",35,142,107,174,24,BLACK);
         gui_draw_line(30,177,225,177,BLUE);
         gui_draw_line(30,257-22,225,257-22,BLUE);
         gui_show_string("噪声检测",35,245,131,277,24,BLACK);
         gui_draw_line(30,302-22,225,302-22,BLUE);
         gui_show_string("Val:",35,290,107,322,24,BLACK);
         gui_draw_line(30,347-22,225,347-22,BLUE);
         gui_draw_line(30,392-22,225,392-22,BLUE); 
         gui_draw_line(30,472-44,225,472-44,BLUE);
         gui_show_string("温湿度",35,438,107,470,24,BLACK);
         gui_draw_line(30,517-44,225,517-44,BLUE);
         gui_show_string("Tem:",35,483,107,515,24,BLACK);
         gui_draw_line(30,562-44,225,562-44,BLUE);
         gui_show_string("Hum:",35,528,107,560,24,BLACK);
         gui_draw_line(30,607-44,225,607-44,BLUE);
         gui_draw_line(30,687-66,225,687-66,BLUE);
         gui_show_string("空气质量",35,631,131,663,24,BLACK);
         gui_draw_line(30,666,225,666,BLUE);
         gui_show_string("Sig:",35,676,107,708,24,BLACK);
         gui_draw_line(30,711,225,711,BLUE);
         gui_show_string("Val:",35,721,107,753,24,BLACK);
         gui_draw_line(30,756,225,756,BLUE);
        
         gui_draw_line(255,42,450,42,BLUE);
         gui_show_string("人体红外",260,52,356,84,24,BLACK);
         gui_draw_line(255,87,450,87,BLUE);
         gui_show_string("Sig:",260,97,356,129,24,BLACK);
         gui_draw_line(255,132,450,132,BLUE);
         gui_show_string("Val:",260,142,356,174,24,BLACK);
         gui_draw_line(255,177,450,177,BLUE);
        
         gui_draw_line(255,257-22,450,257-22,BLUE);
         gui_show_string("光敏",260,245,356,287,24,BLACK);
         gui_draw_line(255,302-22,450,302-22,BLUE);
         gui_show_string("Sig:",260,290,356,322,24,BLACK);
         gui_draw_line(255,347-22,450,347-22,BLUE);
         gui_show_string("Val:",260,335,356,367,24,BLACK);
         gui_draw_line(255,392-22,450,392-22,BLUE);
                  
         gui_draw_line(255,472-44,450,472-44,BLUE);
         gui_show_string("雨滴",260,438,356,470,24,BLACK);
         gui_draw_line(255,517-44,450,517-44,BLUE);
         gui_show_string("Sig:",260,483,356,515,24,BLACK);
         gui_draw_line(255,562-44,450,562-44,BLUE);
         gui_show_string("Val:",260,528,356,560,24,BLACK);
         gui_draw_line(255,607-44,450,607-44,BLUE);
                  
         gui_draw_line(255,687-66,450,687-66,BLUE);
         gui_show_string("烟雾",260,631,356,663,24,BLACK);
         gui_draw_line(255,666,450,666,BLUE);
         gui_show_string("Sig:",260,676,356,708,24,BLACK);
         gui_draw_line(255,711,450,711,BLUE);
         gui_show_string("Val:",260,721,356,753,24,BLACK);
         gui_draw_line(255,756,450,756,BLUE);
         cbtn=btn_creat(400,lcddev.height-gui_phy.tbheight,2*gui_phy.tbheight+8,gui_phy.tbheight-1,0,0x03);//创建文字按钮
         if(cbtn==NULL)rval=1;      //没有足够内存够分配
         else
         {                                                                                                                                                                      
                           cbtn->caption=(u8*)wireless_cbtn_caption_tbl[gui_phy.language];//重画
                            cbtn->font=gui_phy.tbfsize;//设置新的字体大小          
                            cbtn->bcfdcolor=WHITE; //按下时的颜色
                            cbtn->bcfucolor=WHITE; //松开时的颜色
                            btn_draw(cbtn);//画按钮
        }
         NRF24L01_Init();                   //初始化NRF24L01
                   res=0;
                   while(NRF24L01_Check())                  //检测不到24L01,连续检查5秒
                   {
                            if(res==0)window_msg_box((lcddev.width-200)/2,(lcddev.height-70)/2-15,200,70,(u8*)wireless_remind_msg_tbl[gui_phy.language],(u8*)APP_REMIND_CAPTION_TBL[gui_phy.language],12,0,0,0);
                            delay_ms(500);
                            res++;
                            if(res>5)return 0;//超时未检测到,退出
                   }                                     
                   NRF24L01_RX_Mode();
                  
                   while(rval==0)
                   {       
                            tp_dev.scan(0);                 
                            in_obj.get_key(&tp_dev,IN_TYPE_TOUCH);    //得到按键键值
                            key=btn_check(cbtn,&in_obj);                   //扫描返回按键
                           if(system_task_return)    //TPAD返回
                            {    
                                     break;//接收模式,直接退出                             
                           }           
                            if(key)
                            {
                                     if(((cbtn->sta&0X80)==0))//按钮状态改变了
                                     {
                                               break;
                                     }
                            }
                            NRF24L01_RX_Mode(); 
                            delay_ms(30);
                            if(NRF24L01_RxPacket(tmp_buf)==0)//一旦接收到信息,则显示出来.
                            {
                                     if(tmp_buf[0]=='#'&&tmp_buf[26]=='$')
                                     {
                                               switch(tmp_buf[3])
                                               {
                                                        case 1://继电器
                                                                 gui_fill_circle(209,62,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(161,97,225,129,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[9]);
                                                                 gui_show_ptstr(161,142,225,174,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(209,62,16,LGRAY);
                                                                 break;
                                                        case 20://噪声
                                                                 gui_fill_circle(209,255,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(161,290,225,322,0,RED,24,Str,0);
                                                                
                                                                 sprintf((char*)Str," %d ",tmp_buf[9]);
                                                                 gui_show_ptstr(161,335,225,367,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(209,255,16,LGRAY);
                                                                 break;
 
                                                        case 18://温湿度
                                                                 gui_fill_circle(209,448,8,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(161,483,225,515,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[9]);
                                                                 gui_show_ptstr(161,528,225,560,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(209,448,16,LGRAY);
                                                                 break;
                                                       
                                                        case 8://空气质量
                                                                 gui_fill_circle(209,641,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(161,676,225,708,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[10]);
                                                                 gui_show_ptstr(161,721,225,753,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(209,641,16,LGRAY);
                                                                 break;
                                                                          
                                                        case 17://人体红外
                                                                 gui_fill_circle(418,62,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(356,97,420,129,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[10]);
                                                                 gui_show_ptstr(356,142,420,174,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(418,62,16,LGRAY);
                                                                 break;
                                                       
                                                        case 26://光敏
                                                                 gui_fill_circle(418,255,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(356,290,420,322,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[10]);
                                                                 gui_show_ptstr(356,335,420,367,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(418,255,16,LGRAY);
                                                                 break;
                                                       
                                                        case 4://雨滴
                                                                 gui_fill_circle(418,448,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(356,483,420,515,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[10]);
                                                                 gui_show_ptstr(356,528,420,560,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(418,448,16,LGRAY);
                                                                 break;
                                                       
                                                        case 25://烟雾
                                                                 gui_fill_circle(418,641,16,RED);
                                                                 sprintf((char*)Str," %d ",tmp_buf[8]);
                                                                 gui_show_ptstr(356,676,420,708,0,RED,24,Str,0);
                                                                 sprintf((char*)Str," %d ",tmp_buf[10]);
                                                                 gui_show_ptstr(356,721,420,753,0,RED,24,Str,0);
                                                                 delay_ms(300);
                                                                 gui_fill_circle(418,641,16,LGRAY);
                                                                 break;
                                              
                                               }
                                              
                                     }
                                    
                           }         
                          
                   }
                             
 
         SPI1_Init();           //初始化SPI   
         SPI1_SetSpeed(SPI_BaudRatePrescaler_4);//设置到高速模式    
        btn_delete(cbtn);    //删除按钮
         return 0;
}


上一篇:RFID实训|环境检测系统

下一篇:C#应用实训|《C#编程技术》项目设计