请各位大侠们有空的话帮我看看这个数码管的显示程序应该怎么写,程序里面哪里还有问题的也请帮忙指出~~~小弟初学单片机,先谢过了
P3.0-P3.1是COM口,共阴数码管
---------------------------------------------------------------- #include <reg52.h>
#define uchar unsigned char #define uint unsigned int #define data P2
uchar getkey(void) //键扫描函数 { uchar a,b; if((P1&0xf0)==0xf0) //无键按下返归0值 return(0); a=0xfe; while((a&0x10)!=0) { P1=a; if((P1&0xf0)!=0xf0) { b=(a&0xf0)|0x0f; return((~a)+(~b)); } else a=a<<1|0x01; } }
void delay(void) //键消抖函数 { uchar i; for(i=300;i>0;i++); }
void display(void) // 数码管显示函数 { }
void main() { uchar code led[]={0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x7b,0x71,0x00,0x40}; uchar code led1[]={0x0f,0x0e,0x0d,0x0b,0x07}; uint k,key,dig;
P1=0xf0; while(1) { P3=led1[0];
if((P1&0xf0)!=0xf0) // 是否有按键按下 { delay(); //消抖动 if((P1&0xf0)!=0xf0) //再判断是否有按键按下 { key=getkey(); //获取键值 switch(key) { case 0x11: // 1行1列 k = 0; break; case 0x21: // 1行2列 k = 1; break; case 0x41: // 1行3列 k = 2; break; case 0x81: // 1行4列 k = 3; break; case 0x12: // 2行1列 k = 4; break; case 0x22: // 2行2列 k = 5; break; case 0x42: // 2行3列 k = 6; break; case 0x82: // 2行4列 k = 7; break; case 0x14: // 3行1列 k = 8; break; case 0x24: // 3行2列 k = 9; break; case 0x44: // 3行3列 k = 10; break; case 0x84: // 3行4列 k = 11; break; case 0x18: // 3行4列 k = 12; break; case 0x28: // 3行4列 k = 13; break; case 0x48: // 3行4列 k = 14; break; case 0x88: // 3行4列 k = 15; break; default: break; } data=led[k]; //数码管赋值 display(); } } } } |