6位8段數(shù)碼管動態(tài)驅(qū)動電路原理圖及Keil C51驅(qū)動程序
/* 6位數(shù)碼管演示程序: 顯示數(shù)碼從0---99循環(huán),按 P3.2 按鍵,顯示從"0" 開始*/
#i nclude
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 驅(qū)動LED的8個段;
P2.0---P2.5 通過UN2003驅(qū)動6個LED 的公共端