/* 6位数码管演示程序: 显示数码从0---99循环,按 P3.2 按键,显示从"0" 开始*/
#include <reg52.h>
int count1s;
unsigned int count1m;
unsigned char dis_bitcount=0;
unsigned char display_o[6];
unsigned char display_q[6];
unsigned char code SEG[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
unsigned char dis_bitdriver=0;
void delay5ms()
{
register int i;
for (i=0;i<500;i++)
;
}
main()
{
unsigned char dcode;
unsigned char p2code,p3code;
count1m=0;
count1s=0;
while(1)
{
switch(dis_bitcount+1)
{
case 1:dis_bitdriver=0x01; break;/*display 1*/
case 2:dis_bitdriver=0x02; break;/*display 2*/
case 3:dis_bitdriver=0x04; break;/*display 3*/
case 4:dis_bitdriver=0x08; break;/*display 4*/
case 5:dis_bitdriver=0x10; break;/*display 5*/
default:dis_bitdriver=0x20; break;/*display 6 */
}
p2code=P2;
P2=p2code&0x40;
dcode=SEG[display_q[dis_bitcount]];
P0=SEG[display_q[dis_bitcount]];
P2=(p2code&0x40)|dis_bitdriver;
if(dis_bitcount>=5) dis_bitcount=0;
else dis_bitcount++;
count1s++;
if(count1s>=400)
{
count1m++;
count1s=0;
}
p3code=P3&0x04;
if(count1m>99) count1m=0;
if(p3code==0) count1m=0;
display_o[1]=count1m/10;
display_o[0]=count1m-display_o[1]*10;
display_q[1]=display_o[1];
display_q[0]=display_o[0];
delay5ms();
}
}
6位LED显示接口说明:
P0.0---P0.7 通过7406 驱动LED的8个段;
P2.0---P2.5 通过UN2003驱动6个LED 的公共端