|
|
1,上電lcd1602顯示Qingqiushu:0
2,1~8按鍵代表病人編號(hào),9號(hào)按鍵代表應(yīng)答(每次只能應(yīng)答一個(gè)請(qǐng)求)
3,第二行顯示當(dāng)前請(qǐng)求病人編號(hào),最先請(qǐng)求的編號(hào)在左中間空格,有按鍵按下后刷新顯示,先按下的請(qǐng)求鍵優(yōu)先級(jí)高優(yōu)先被應(yīng)答。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
(FM17J{K$O52HA$HD5GHLW2.png (6.73 KB, 下載次數(shù): 34)
下載附件
2022-6-26 20:19 上傳
51hei.png (28.78 KB, 下載次數(shù): 30)
下載附件
2022-6-26 22:19 上傳
單片機(jī)源程序如下:
- #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);
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
Keil代碼與Proteus8.8仿真下載:
仿真程序.7z
(56.44 KB, 下載次數(shù): 53)
2022-6-26 22:20 上傳
點(diǎn)擊文件名下載附件
仿真圖和代碼 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|