1,上電lcd1602顯示Qingqiushu:0
2,1~8按鍵代表病人編號,9號按鍵代表應答(每次只能應答一個請求)
3,第二行顯示當前請求病人編號,最先請求的編號在左中間空格,有按鍵按下后刷新顯示,先按下的請求鍵優先級高優先被應答。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #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);
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
Keil代碼與Proteus8.8仿真下載:
仿真程序.7z
(56.44 KB, 下載次數: 53)
2022-6-26 22:20 上傳
點擊文件名下載附件
仿真圖和代碼
|