|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
1,上电lcd1602显示Qingqiushu:0) X* D8 G& Q( Y2 Q) p" w
2,1~8按键代表病人编号,9号按键代表应答(每次只能应答一个请求)
1 \: J) y+ w2 `" C0 \# w0 c0 |3,第二行显示当前请求病人编号,最先请求的编号在左中间空格,有按键按下后刷新显示,先按下的请求键优先级高优先被应答。
" Y g% B: D! J( o) C k$ M
0 H2 F, n! T5 _( e8 y7 y6 T仿真原理图如下(proteus仿真工程)/ K, X- o: `% j' V
9 B6 A* f5 n# ~3 G" x7 ^0 B2 p
" Q% q$ U/ O% [7 d' r7 |单片机源程序如下:
% Q2 m9 D7 `; S7 H- #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);
- ……………………
' F J V8 B. t' H4 m# w- B# F; Z % x% x3 N# z6 ?/ d* E* M) t
|
|