//动态显示数码管,第1个数码管从0开始显示,
//以后每次显示位数加1,且数加以,从0到f动态显示
//时间:*****
#include
#define uchar unsigned char
#define uint unsigned int
sbit duan="P2"^0;
sbit wei="P2"^1;
void delay(uint ms);
//位选从一位到两位到三位的编码
unsigned char code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//段选的编码
unsigned char code table2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void main()
{
uchar i;
wei=0;
duan=0;
while(1)
{
for(i=0;i<16;i++)
{
wei=1;
P1=table1[i%8]; //位选值到8个时,从新开始
wei=0;
duan=1;
P1=table2;
duan=0;
delay(500); //延时500ms
}
}
}
void delay(uint ms)
{
uint x,y;
for(x=ms;x>0;x--)
for(y=111;y>0;y--);
}
文章评论(0条评论)
登录后参与讨论