怎么让六位数码管数字循环例如 1234567循环显示
答案:1 悬赏:30 手机版
解决时间 2021-03-07 11:31
- 提问者网友:饥饿走向夜
- 2021-03-07 06:24
怎么让六位数码管数字循环例如 1234567循环显示
最佳答案
- 五星知识达人网友:街头电车
- 2021-03-07 07:19
# include
# define uint unsigned int
# define uchar unsigned char
code uchar shu[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //数码管段选
code uchar wen[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //数码管位选
uchar huancun[] = {0x00,0x00,0x00,0x00,0x00,0x00}; //数码管段选缓存
sbit duan = P2^6; //段选
sbit wei = P2^7; //位选
void delay(uchar x) //延时函数
{
uchar i,j;
for(i = 0; i for(j = 0; j<255; j--)
;
}
void xianshi() //显示函数
{
uchar i;
for(i = 0; i<6; i++)
{
P0=wen[i]; //位选
wei=1; //开锁存
wei=0; //关锁存
P0=huancun[i]; //段选
duan=1;
duan=0;
P0=0xff; //消影
delay(5);
}
}
void init()
{
uchar i;
TMOD=0x01;
TH0=(65536-50000)/256; //10ms定时初值(T0计时用)
TL0=(65536-50000)%256;
TR0=1; //T0计时关断
ET0=1; //T0中断允许位关断
EA=1; //开总中断
for(i = 0; i<6; i++)
{
huancun[i] = shu[i]; //段选送缓存
}
}
void main()
{
init();
while(1)
{
xianshi();
}
}
void time_intt0 (void) interrupt 1 //50ms中断
{
uchar t,i,j;
TH0=(65536-50000)/256; //重置初值
TL0=(65536-50000)%256;
t++;
if(t == 20) //1秒到 50ms*20 = 1s
{
t=0;
j++; //j+1
for(i = 0; i<6; i++) //使段选数据移位输入缓存
{
huancun[i] = shu[i+j];
}
if(j>9) //移到最后面 回到初始状态
{
j = 0;
}
}
}
# define uint unsigned int
# define uchar unsigned char
code uchar shu[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //数码管段选
code uchar wen[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //数码管位选
uchar huancun[] = {0x00,0x00,0x00,0x00,0x00,0x00}; //数码管段选缓存
sbit duan = P2^6; //段选
sbit wei = P2^7; //位选
void delay(uchar x) //延时函数
{
uchar i,j;
for(i = 0; i
;
}
void xianshi() //显示函数
{
uchar i;
for(i = 0; i<6; i++)
{
P0=wen[i]; //位选
wei=1; //开锁存
wei=0; //关锁存
P0=huancun[i]; //段选
duan=1;
duan=0;
P0=0xff; //消影
delay(5);
}
}
void init()
{
uchar i;
TMOD=0x01;
TH0=(65536-50000)/256; //10ms定时初值(T0计时用)
TL0=(65536-50000)%256;
TR0=1; //T0计时关断
ET0=1; //T0中断允许位关断
EA=1; //开总中断
for(i = 0; i<6; i++)
{
huancun[i] = shu[i]; //段选送缓存
}
}
void main()
{
init();
while(1)
{
xianshi();
}
}
void time_intt0 (void) interrupt 1 //50ms中断
{
uchar t,i,j;
TH0=(65536-50000)/256; //重置初值
TL0=(65536-50000)%256;
t++;
if(t == 20) //1秒到 50ms*20 = 1s
{
t=0;
j++; //j+1
for(i = 0; i<6; i++) //使段选数据移位输入缓存
{
huancun[i] = shu[i+j];
}
if(j>9) //移到最后面 回到初始状态
{
j = 0;
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯