我想一片8255做一个矩阵键盘,PA口八个口作列线,PC0到PC4作行线加上拉电阻接电源,下面程序,但编译不过去,希望高手们指点下: #include <REG51.H> #include<absacc.h> #define uchar unsigned char #define uint unsigned int void delay (uint); uchar scankey(void); uchar keyscan(void); void main(void) { uchar key; while (1) { key = keyscan(); delay (2000); } } // 延时// void delay(uint i) { uint j; for (j=0;j<i;j++) {} } //检测有无按键// uchar checkkey() //检测按键,有返回0XFF,无返回0// { uchar i; XBYTE[0x7f00]=0x00; i=XBYTE[0x7f02]; i=i&0x0f; if (i= = 0x0f) return (0); else return (0xff); } // 键盘扫描// uchar keyscan()//扫描键盘,有键按下返回键编码,无返回0XFF// { uchar scancode;//列扫描变量// uchar codevalue;//返回的编码变量// uchar m;//行首编码变量// uchar k;//行检测码// uchar i,j; if (checkkey()= =0) return (0xff);//检测按键,无返回0XFF// else { delay(200); if (checkkey()= =0) return (0xff); else { scancode=0xfe;m=0x00;//列扫描码,行首码赋初值 for(i=0;i<8;i++) { k=0x01; XBYTE[0x7f00]=scancode;//送列扫描码 for (j=0;j<4;j++) { if ((XBYTE[0x702]&k = = 0)//检测当前行是否有键按下 { codevalue=m+j;//有,求编码 while(checkkey()!=0);//等键释放 return (codevalue);//返回编码 } else k=k<<1;//检测下一行 } m=m+8;//计算下一行首编码 scancode=scancode<<1;//列扫描码左移一位,扫描下一列 } } }
|