|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
1,上电lcd1602显示Qingqiushu:0
+ Y* `/ _1 o6 P6 P: y' |5 ?/ R6 P2,1~8按键代表病人编号,9号按键代表应答(每次只能应答一个请求)( k) d0 P4 V7 i# K& c
3,第二行显示当前请求病人编号,最先请求的编号在左中间空格,有按键按下后刷新显示,先按下的请求键优先级高优先被应答。- B+ A* q q% e' |/ `
7 `; w3 }% | ]3 j5 n7 C" T! t
仿真原理图如下(proteus仿真工程)
8 _ [% C7 V; a8 K/ G" r2 Y# @
& ?: O) {7 [/ f1 B7 r, P
/ a& f8 t1 f- J. w/ x9 y单片机源程序如下:
. K# |/ K* \( @2 b& t9 `1 b$ n- #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);
- ……………………
7 a( z6 U; ?# ^4 E : \; d2 o" Z9 Y. Q$ u+ G5 F
|
|