代码:
#include
#define uint unsigned int
#define uchar unsigned char
//sbit A=P2^0;
//sbit B=P2^1;
//sbit C=P2^2;
void delay(uchar);
uchar code table[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
//共阴级数码管字形代码表
void main()
{
//uchar i;
while(1)
{
P2=(0X00)&(0X07); //位选
P0=table[2]; //段选
delay(1);
P2=(0X01)&(0X07);
P0=table[0];
delay(1);
P2=(0X02)&(0X07);
P0=table[0];
delay(1);
P2=(0X03)&(0X07);
P0=table[8];
delay(1);
P2=(0X04)&(0X07);
P0=table[0];
delay(1);
P2=(0X05)&(0X07);
P0=table[8];
delay(1);
P2=(0X06)&(0X07);
P0=table[0];
delay(1);
P2=(0X07)&(0X07);
P0=table[8];
delay(1);
}
}
void delay(uchar y) //延时程序
{
uchar i;
uint j;
for(i=0;i
for(j=0;j<100;j++);
}
}
本例显现成果为20080808,详细段位能够依据字码表挑选。