|
使用的51单片机作为主控芯片,两个51单片机通过24L01通信,一个检测吊瓶滴液的速度,如果太快太慢或者不滴液都会报警,并发送到主机,输液者也可以主动通过按键呼叫主机,丛机用1602显示,主机用12864显示。
主机.7z
(63.93 KB, 下载次数: 75)
无线语音点滴系统 从机.7z
(76.39 KB, 下载次数: 66)
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #include "keys.h"
- #include "24L01.h"
- #include "LCD1602.h"
- #define uint unsigned int
- #define uchar unsigned char
- sbit YeDi=P2^0;//红外信号采集口
- sbit Speaker=P2^4;//蜂鸣器
- uchar TX_buf[32]=0;
- uchar View_Con=0;
- uchar View_Change=1;
- uchar View_Con_Change=1;
- uint Cap_Data=100;
- uint Cap_View=0;
- uchar View_Data[8];
- uint YeDi_Num=0;
- void InitTimer0(void)
- {
- TMOD |= 0x01;
- TH0 = 0x0D8; //10000us
- TL0 = 0x0F0;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- void InitTimer1(void)
- {
- TMOD |= 0x10;
- TH1 = 0x0FC; //1000us
- TL1 = 0x18;
- EA = 1;
- ET1 = 1;
-
- }
- void main()
- {
- TX_buf[1]=0;
- TX_buf[2]=2;
- TX_buf[3]=5;
- TX_buf[4]=4;
- InitLcd();
- Lcd_1602_word(0x80,16," NRF24L01 "); //1602第一行显示 NRF24L01
- //Lcd_1602_word(0xc0,16," Connecting "); //1602第二行显示 Connecting
- while(NRF24L01_Check()); //检查24L01是否存在
- NRF24L01_Init(); //开机的时候需要初始化24l01
- InitTimer0(); //定时计数器0初始化
- InitTimer1(); //定时计数器1初始化
- Lcd_1602_word(0xc0,16," Connecting ");
- while(1)
- {
- if(Key_Change) //如果Key_Change为真
- {
- Key_Change=0;
- View_Change=1;
- switch(Key_Value) //选择键值
- {
- case 1:
- {
- View_Con_Change=1;
- if(View_Con==0)
- {
- View_Con=1;
- TR1 = 1;
- Cap_View=Cap_Data*100;
- }
- if(View_Con==2)
- {
- View_Con=1;
- TR1 = 1;
- }
- break;
- }
- case 2:
- {
- if(View_Con==0) //液滴加
- {
- if(Cap_Data<=500)
- Cap_Data+=10;
- }
- break;
- }
- case 3:
- {
- if(View_Con==0)
- {
- if(Cap_Data>10) //液滴减
- Cap_Data-=10;
- }
- break;
- }
- case 4:
- {
- if(View_Con==1)
- {
- TR1 = 0;
- YeDi_Num=0;
- View_Con=2;
- View_Con_Change=1;
- TX_buf[0]=0xf5;//蜂鸣器响
- TX_buf[5]=4;//用户呼叫
- NRF24L01_TxPacket(TX_buf);
- NRF24L01_TxPacket(TX_buf);
-
- }
- break;
- }
- }
- }
- if(View_Change)
- {
- View_Change=0;
- if(View_Con_Change)
- {
- View_Con_Change=0;
- switch(View_Con)
- {
- case 0:Lcd_1602_word(0x80,16,"Infusion Set: ");Lcd_1602_word(0xc0,16," ");break;
- case 1:Lcd_1602_word(0x80,16,"In The Infusion ");Lcd_1602_word(0xc0,16," ");Speaker=1;break;
- case 2:
- {
- Lcd_1602_word(0x80,16,"****Warning*****");Lcd_1602_word(0xc0,16,"****Warning*****");Speaker=0;
- if(TX_buf[5]<4)
- while(1);
- break;
- }
- }
- }
- switch(View_Con)
- {
- case 0:
- {
- View_Data[0]=Cap_Data/100+0x30;
- View_Data[1]=Cap_Data%100/10+0x30;
- View_Data[2]=Cap_Data%10+0x30;
- View_Data[3]='m';
- View_Data[4]='l';
- if(View_Data[0]==0x30)
- View_Data[0]=' ';
- Lcd_1602_word(0xcb,5,View_Data);
- break;
- }
- case 1:
- {
- View_Data[0]=Cap_View/10000+0x30;
- View_Data[1]=Cap_View%10000/1000+0x30;
- View_Data[2]=Cap_View%1000/100+0x30;
- View_Data[3]='.';
- View_Data[4]=Cap_View%100/10+0x30;
- View_Data[5]=Cap_View%10+0x30;
- View_Data[6]='m';
- View_Data[7]='l';
- if(View_Data[0]==0x30)
- {
- View_Data[0]=' ';
- if(View_Data[1]==0x30)
- {
- View_Data[1]=' ';
- }
- }
- Lcd_1602_word(0xc8,8,View_Data);
- break;
- }
- }
- }
- }
- }
- void Timer0Interrupt(void) interrupt 1
- {
- static uchar YeDi_Con;
- static uchar Key_Time0_Con;
- TH0 = 0xfc;
- TL0 = 0x18;
- Key_Time0_Con++;
- switch(YeDi_Con)
- {
- case 0:
- {
- if(YeDi==1)
- YeDi_Con++;
- break;
- }
- case 1:
- {
- if(YeDi==0)
- {
- YeDi_Con=2;
- YeDi_Num=0;
- TR1 = 1;
- }
- break;
- }
- case 2:
- {
- if(YeDi==1)
- {
- TR1 = 0;
- YeDi_Con=0;
- if(View_Con==1)
- {
- View_Change=1;
- Cap_View=Cap_View-4;
- if(YeDi_Num<500) //小于0.5s则报警
- {
- View_Con=2;
- View_Con_Change=1;
- TX_buf[0]=0xf5;
- TX_buf[5]=1;
- NRF24L01_TxPacket(TX_buf);
- NRF24L01_TxPacket(TX_buf);
-
- }
- if(Cap_View<100) //小于1毫升,报警
- {
- View_Con=2;
- View_Con_Change=1;
- TX_buf[0]=0xf5;
- TX_buf[5]=3;
- NRF24L01_TxPacket(TX_buf);
- NRF24L01_TxPacket(TX_buf);
-
- }
- }
- TR1 = 1;
- YeDi_Num=0;
- }
- break;
- }
- }
- if(Key_Time0_Con==10)
- {
- Key_Time0_Con=0;
- Key_Acquisition();
- }
-
- }
- void Timer1Interrupt(void) interrupt 3
- {
- TH1 = 0x0FC;
- TL1 = 0x18;
- YeDi_Num++;
- if(YeDi_Num>5000&&View_Con==1) //大于5s则报警,
- {
- View_Con=2;
- View_Change=1;
- View_Con_Change=1;
- TX_buf[0]=0xf5;
- TX_buf[5]=2;
- NRF24L01_TxPacket(TX_buf);
- NRF24L01_TxPacket(TX_buf);
- Lcd_1602_word(0x80,16," ok ");
- }
- }
复制代码
|
|