用8255A来实现一个小键盘的输入识别(用扫描法)的程序

2020-05-10 社会 77阅读
#include
#include
#define COM8255 XBYTE[0X0300]
#define PA8255 XBYTE[0X0000]
#define PB8255 XBYTE[0X0100]
#define PC8255 XBYTE[0X0200]
typedef unsigned char BYTE;
typedef unsigned int WORD;
void delay(WORD num)
{
WORD k;
for(k=0;k}
BYTE a[10]={0x0b,0x08,0x05,0xff,0x02,0x0c,0x09,0x06,0xff,0x03};
main()
{
BYTE linecode,rowcode;
BYTE t1=0;
BYTE t2=0;
BYTE out=0;
BYTE i;
delay(1000);
COM8255=0X88;
PA8255=0XF0;
while(1){
rowcode=0xfe;
for(i=0;i<4;i++){
PC8255=rowcode;
linecode=PC8255;
linecode=linecode&0x60;
if(linecode!=0x60)
{
t1=linecode>>5;//result is line 2 1;line 3 2;
t2=(~rowcode)>>1;
out=(t1-1)*5+t2;
out=a[out];
PA8255=~out;
delay(200000);
}
rowcode=~(~rowcode<<1);
PA8255=0XFF;
}
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com