...0123456789ABCDEF,六个数码管是连续不同的六个数?
发布网友
发布时间:2024-10-03 08:18
我来回答
共2个回答
热心网友
时间:2024-10-06 08:57
# include<reg51.h>
# define uint unsigned int
# define uchar unsigned char
code uchar shu[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
/* 0 1 2 3 4 5 6 7 */
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //数码管段选
/* 8 9 a b c d e f */
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<x; 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;
}
}
}
照着你给你电路图写的,有问题请追问
热心网友
时间:2024-10-06 09:03
你把你的显示内容每次左移一位试试,看能不能行。