病床呼叫系统设计仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint insigned int
- uchar code LED[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
- uchar Buffer[]={0x3F,0x3F};
- sbit CLAER=P3^1;
- sbit BUZZ=P3^0;
- uchar key_scan();
- void key_count(uchar num);
- void disp();
- void delay(uchar s);
- void buzz_on();
- void main()
- {
- uchar temp;
- while(1)
- {
- disp();
- temp=key_scan();
- if(temp!=0xFF)
- {
- key_count(temp+1);
- while(CLAER==1)
- {
- buzz_on();
- disp( );
- }
- Buffer[0]=0x3F;
- Buffer[1]=0x3F;
- BUZZ=1;
- }
- }
- }
- void disp()
- {
- uchar i,w;
- w=0x01;
- for(i=0;i<2;i++)
- {
- P2=~w;
- w<<=1;
- P0=Buffer[i];
- delay(10);
- P2=0xFF;
- }
- }
- uchar key_scan(void)
- {
- uchar key=0xFF,cord_h,cord_1;
- P1=0x0F;
- cord_h=P1&0x0F;
- if(cord_h!=0x0F)
- {
- delay(10);
- if(cord_h!=0x0F)
- {
- cord_h=P1&0x0F;
- P1=0xF0;
- cord_1=P1&0xF0;
- while((P1&0xF0)!=0xF0);
- switch(cord_h+cord_1)
- {
- case 0xEE:key=0;break;//S1
- case 0xED:key=1;break;//S2
- case 0xEB:key=2;break;//S3
- case 0xE7:key=3;break;//S4
- case 0xDE:key=4;break;//S5
- case 0xDD:key=5;break;//S6
- case 0xDB:key=6;break;//S7
- case 0xD7:key=7;break;//S8
- case 0xBE:key=8;break;//S9
- case 0xBD:key=9;break;//S10
- case 0xBB:key=10;break;//S11
- case 0xB7:key=11;break;//S12
- case 0x7E:key=12;break;//S13
- case 0x7D:key=13;break;//S14
- case 0x7B:key=14;break;//S15
- case 0x77:key=15;break;//S16
- default: key=0xFF;break;
- }
- }
- }
- return(key);
- }
- void key_count(uchar num)
- {
- Buffer[0]=LED[num/10];
- Buffer[1]=LED[num%10];
- }
- void buzz_on()
- {
- BUZZ=0;
- delay(1);
- BUZZ=1;
- delay(1);
- }
- void delay(uchar s)
- {
- int j;
- while(s--)
- for(j=0;j<20;j++);
- }
复制代码
所有资料51hei提供下载:
病床呼叫系统.zip
(18.59 KB, 下载次数: 123)
|