硬件设计
方案框图
原理图:
仿真图:
程序设计
流程图
/*基于单片机的无线病床呼叫系统*/#include <reg52.h>//头文件#define uc unsigned char#define ui unsigned int //宏定义sbit RS=P1^4;sbit RW=P1^5;sbit E=P1^6;//这3个是1602引脚定义sbit D0=P1^3;//上升按键sbit D1=P1^2;//下降按键sbit D2=P1^1;//模式切换sbit D3=P1^0;//光敏识别引脚sbit bg_1602=P2^6;//1602背光sbit key=P3^3;//应答按键sbit Beep=P3^4;//蜂鸣器uc code tab0[]=" 123456789#"; //显示几号的码表uc code tab1[]="Calling!!!"; //显示呼叫的码表uc code tab2[]="I Know!"; //显示相应的码表uc code tab3[]="Happy Every Day!"; //显示开心快乐每一天的码表ucnum_D0=0,num_D1=0,num_D2=0,num_D3=0;//床号bit bdatafu_D0=0, fu_D1=0, fu_D2=0, fu_D3=0,flag;//初始床号void delay(ui x)//延时函数{ui i,j;for(i=0;i<x;i++)for(j=0;j<121;j++); //为1ms的延时函数}void init()//初始化函数{bg_1602=0;//开启背光TMOD=0x01;//定时器0工作方式1TH0=0x4b;TL0=0xff; //赋初值EA=1; //开总中断ET0=1; //定时器中断开TR0=1; //定时器0中断开D0=0;D1=0;D2=0;D3=0;//清零床号引脚}/******LCD1602******/void com_1602(uc com)//写命令{RS=0;P0=com;delay(1);E=1;delay(1);E=0;RS=1;}void data_1602(uc date)//写数据{RS=1;P0=date;delay(1);E=1;delay(1);E=0;RS=0;}void dis_1602(uc word_num,uc hang,uc lie,uc tab_num,uc num)/**word_num:显示字符个数,hang,lie:显示坐标,*******tab_num:显示数组号,num:从第几字符开始显示****/{uc n;for(n=0;n<word_num;n++){com_1602(0x80+hang*0x40+lie);if(tab_num==0)data_1602(tab0[num+n]);else if(tab_num==1)data_1602(tab1[num+n]);else if(tab_num==2)data_1602(tab2[num+n]);else if(tab_num==3)data_1602(tab3[num+n]);delay(5);lie++;}}void init_1602()//初始化1602{RW=0;//写命令com_1602(0x38);//设置1602com_1602(0x0c);//设置显示,光标不闪烁com_1602(0x06);//不移动,指针加1com_1602(0x01);//清屏}void know()//应答函数{if(D0!=fu_D0)num_D0=1;if(D1!=fu_D1)num_D1=2;if(D2!=fu_D2)num_D2=3;if(D3!=fu_D3)num_D3=4; //数据脚状态改变,将床号赋给变量if(key==0)//检测按键{delay(5);if(key==0){if((num_D0!=0)||(num_D1!=0)||(num_D2!=0)||(num_D3!=0))//如果有呼叫时{bg_1602=0;//打开背光Beep=1;//关闭蜂鸣器flag=0;//标志位清零num_D0=0;num_D1=0;num_D2=0;num_D3=0;fu_D0=D0;fu_D1=D1;fu_D2=D2;fu_D3=D3;//将床位清零,并记录当前引脚状态com_1602(0x01);//清屏dis_1602(7,1,4,2,0);//显示I Know }else//如果没有呼叫时bg_1602=0;//只点亮背光}while(!key);//按键释放delay(2000);com_1602(0x01);//清屏}}void display()//显示函数{if((num_D0==0)&&(num_D1==0)&&(num_D2==0)&&(num_D3==0))//当没有床位呼叫时dis_1602(16,0,0,3,0);//显示Happy else//有床位呼叫时{if(flag==0){flag=1;com_1602(0x01);//清屏}if(num_D0==1){dis_1602(1,0,2,0,num_D0);dis_1602(1,0,3,0,10);}if(num_D1==2){dis_1602(1,0,5,0,num_D1);dis_1602(1,0,6,0,10);}if(num_D2==3){dis_1602(1,0,8,0,num_D2);dis_1602(1,0,9,0,10);}if(num_D3==4){dis_1602(1,0,11,0,num_D3);dis_1602(1,0,12,0,10);}dis_1602(10,1,3,1,0);//在对应床位显示床位号}}void LED()//背光函数{if((D0!=fu_D0)||(D1!=fu_D1)||(D2!=fu_D2)||(D3!=fu_D3))//如果有呼叫bg_1602=0;//打开背光}
附:http://www.jh-/archives/7547