|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
1,上电lcd1602显示Qingqiushu:0
- N- Z, P6 s# ~7 q, E5 q- N2 J2,1~8按键代表病人编号,9号按键代表应答(每次只能应答一个请求)
6 x, t8 Z$ a3 c: z- t3,第二行显示当前请求病人编号,最先请求的编号在左中间空格,有按键按下后刷新显示,先按下的请求键优先级高优先被应答。
; {+ k! Z# _% B9 r6 Q/ k* A; f- Z( E
仿真原理图如下(proteus仿真工程)) s' T2 p- [% K" v: B
1 c' B) R* I0 Y6 z3 m O9 E% a+ V
* O/ |' Y3 }: Z* v" `1 T单片机源程序如下:1 p# B$ n9 |9 [0 L& e; ]
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code table[]="Qing qiu shu:";
- uchar code table1[]="012345678";//键盘
- uchar table2[8];
- uint code table3[]={0,1,2,3,4,5,6,7,8};//键盘
- uint table4[]={0,0,0,0,0,0,0,0};
- uint table5[8];
- sbit lcden=P3^4;
- sbit lcdrs=P3^5;
- sbit dula=P2^6;
- sbit wela=P2^7;
- uchar num,key,N,s;
- uint i,w;
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_com(uchar com)
- {
- lcdrs=0;
- P0=com;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_data(uchar date)
- {
- lcdrs=1;
- P0=date;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void init()
- {
- dula=0;
- wela=0;
- lcden=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void matrixkeyscan()
- {
- uchar temp,key;
- if(N>=0||N<=8)
- {
- P1=0xfe;
- temp=P1;
- temp=temp&0xf0;
- if(temp != 0xf0)
- {
- delay(10);
- temp=P1;
- temp=temp & 0xf0;
- if(temp != 0xf0)
- {
- temp=P1;
- switch(temp)
- {
- case 0xee:key=1;table4[0]+=1;break;
- case 0xde:key=2;table4[1]+=1;break;
- case 0xbe:key=3;table4[2]+=1;break;
- case 0x7e:key=4;table4[3]+=1;break;
- }
- while(temp != 0xf0)
- {
- temp=P1;
- temp=temp & 0xf0;
- }
- if(table4[key-1]==1)
- {table5[N]=table3[key];
- table2[N]=table1[key];N++;
- }
- }
- }
- P1=0xfd;
- temp=P1;
- temp=temp&0xf0;
- if(temp != 0xf0)
- {
- delay(10);
- temp=P1;
- temp=temp & 0xf0;
- if(temp != 0xf0)
- {
- temp=P1;
- switch(temp)
- {
- case 0xed:key=5;table4[4]+=1;break;
- case 0xdd:key=6;table4[5]+=1;break;
- case 0xbd:key=7;table4[6]+=1;break;
- case 0x7d:key=8;table4[7]+=1;break;
- }
- while(temp != 0xf0)
- {
- temp=P1;
- temp=temp & 0xf0;
- }
- if(table4[key-1]==1)
- { table5[N]=table3[key];
- table2[N]=table1[key];N++;
- }
- }
- }
- P1=0xfb;
- temp=P1;
- temp=temp&0xf0;
- if(temp != 0xf0)
- {
- delay(10);
- temp=P1;
- temp=temp & 0xf0;
- if(temp != 0xf0)
- {
- temp=P1;
- switch(temp)
- {
- case 0xeb:key=9;break;
- }
- while(temp != 0xf0)
- {
- temp=P1;
- temp=temp & 0xf0;
- }
- if(N>0)
- {
- if(key=9)
- {
- w=table5[0];
- table4[w-1]=table3[0];
- delay(10);
- for(i=0;i<N;i++)
- { table5[ i]=table5[i+1];[ i]
- table2[ i]=table2[i+1];[ i]
- }table2[N]='\0';table5[N]='\0';
- N--;
- }
- }
- }
- }
- }
- }
- void main()
- {
- init();
- write_com(0x80);
- ……………………
4 ?) c5 s. R3 V " r6 {. E- S! J* @+ Y& r9 r
|
|