基于stm89c52单片机矩阵按键数码管显示输出,内附Keil uVision4代码和proteus的仿真图
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- uchar S[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
- 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
- uchar keyscan()
- {
- uchar h,l;
- P1=0x0f;
- h=P1&0x0f;
- if(h!=0x0f)
- {
- if(h!=0x0f)
- {
- h=P1&0x0f;
- P1=0xf0;
- l=P1&0xf0;
- }
- }
- return(h+l);
- }
- void main()
- {
- uchar key;
- while(1)
- {
- key=keyscan();
- switch(key)
- {
- case 0xee:P0=S[0];break;
- case 0xde:P0=S[1];break;
- case 0xbe:P0=S[2];break;
- case 0x7e:P0=S[3];break;
- case 0xed:P0=S[4];break;
- case 0xdd:P0=S[5];break;
- case 0xbd:P0=S[6];break;
- case 0x7d:P0=S[7];break;
- case 0xeb:P0=S[8];break;
- case 0xdb:P0=S[9];break;
- case 0xbb:P0=S[10];break;
- case 0x7b:P0=S[11];break;
- case 0xe7:P0=S[12];break;
- case 0xd7:P0=S[13];break;
- case 0xb7:P0=S[14];break;
- case 0x77:P0=S[15];break;
- }
- }
- }
复制代码
所有资料51hei提供下载:
基于stm89c52矩阵数码管输出.zip
(55.07 KB, 下载次数: 38)
|