#include<reg52.h>
unsigned char code duanma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};//共阳极数码管的段码表
unsigned char code weima[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char tempdata[8]; //用于存放4位数码管显示数字的段码
void delay(int ms)
{
unsigned char j;
for(;ms>0;ms--)
for(j=125;j>0;j++);
}
void main()
{
int i;
P1=0x00; //P1是位码显示端口,共阳极数码管位选要给低电平,另外,只有位码打开一格口子,断码才能显示
while(1)
{
for(i=0;i<10;i++)
{
P0=duanma[i]; //P0是段码显示端口
delay(1000);
}
}
}
另外,此处附上共阴极数码管的段码表和对应位码表
unsigned char code duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};