无线温度采集器主控程序 能帮我解读一下吗 谢谢
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^6;
uchar count=0,second=0,minut=0,hour=12;
unsigned char count1,count_flag=0;
unsigned char key_mode;
bit key_bit=0,caiji=1;
int set_A_num_H=380,set_A_num_L=100,set_B_num_H=380, set_B_num_L=100;
int tempA=0,tempB=0,tempC=0,tempD=0;
uchar caidan_flag=0;
#include"1602.h"
#include"wuxian.h"
//按键扫面
void scant()
{
if(!key1){
while(!key1);
if(key_mode<2){ //key_mode 3
key_mode++;
}
else{
key_mode=0;
Lcd_ShowSring(2,0," ");
caiji=1;
// caidan_flag=0;
}
switch(key_mode){
case 0: Lcd_ShowSring(1,15,"0");TxBuf[0]=0;TxBuf[4]=0;tempA=0;tempB=0;break;
/////////////==========AB通道========////////////////////////////////
case 1: Lcd_ShowSring(1,15,"1"); caiji=0; TxBuf[0]=1;break;
case 2: Lcd_ShowSring(1,15,"2"); caiji=0; TxBuf[4]=2;break;
// case 3: Lcd_ShowSring(1,15,"3"); caiji=0; TxBuf[8]=3;caidan_flag=1;Lcd_ShowSring(2,0," ");break;
default :break;
}
}
}
void display()
{
if(key_mode==1){
if(caidan_flag==0){
write_com(0xc0);
write_date('A');
write_date(':');
Lcd_Display_Three_point_Date(2,2,tempA);
write_date('C');
}
}
else if(key_mode==2){
if(caidan_flag==0){
write_com(0xc0);
write_date('A');
write_date(':');
Lcd_Display_Three_point_Date(2,2,tempA);
write_date('C');
write_com(0xc8);
write_date('B');
write_date(':');
Lcd_Display_Three_point_Date(2,10,tempB);
write_date('C');
}
}
/* else if(key_mode==3){
if(caidan_flag==1){
write_com(0xc0);
write_date('C');
write_date(':');
Lcd_Display_Three_point_Date(2,2,tempC);
write_date('C');
}
} */
}
/******************主函数************************/
void main()
{
lcd1602_init(); //液晶初始化
init_NRF24L01();// 初始化24L01
Lcd_ShowSring(1,0,"R-temperature");
Lcd_ShowSring(1,15,"0");
TxBuf[0]=0;
TxBuf[4]=0;
while(1)
{
if(caiji==0){
nRF24L01_RxPacket(TxBuf); //使用这个语句之后 主函数扫面的进程慢到大概1s一轮
if(TxBuf[0]==1) { //接收到1说明是模块a发送回来的数据
tempA=TxBuf[1]*100+TxBuf[2]*10+TxBuf[3];
TxBuf[0]=0; //一次传送完毕之后清除等待下一次的数据
}
else if(TxBuf[4]==2){ //接收到2说明是模块b发送回来的数据
tempB=TxBuf[5]*100+TxBuf[6]*10+TxBuf[7];
TxBuf[4]=0; //一次传送完毕之后清除等待下一次的数据
}
else{
tempA=0;tempB=0;
TxBuf[0]=0;
TxBuf[4]=0;
}
}
scant(); //按键扫描
display(); //显示
}
}
|