这是共阳极数码管的电路图,其间JP3接到P0口,JP3的8-1对应数码管的a-dp引脚。
共阳极数码管的编码表如下,留意a—最低位,dp—最高位:
【0—3】0xco,0xf9,0xa4,0xb0,
【4—7】0x99,0x92,0x82,0xf8,
【8—B】0x80,0x90,0x88,0x83,
【C—F】0xc6,0xa1,0x86,0x8e。
C51程序显现数字0-9:
#include
#define uchar unsigned char
void delay();
uchar smg[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int k;
void main()
{
//不显现
P0 = 0xff;
while(1)
{
for(k = 0; k 《 10; k++)
{
P0 = smg[k];
delay();
}
}
}
void delay()
{
int i,j;
for(i = 10000; i 》 0; i–)
for(j = 10; j 》 0; j–);
}