仿真电路
代码
#include<reg51.h>
#include<display.c>
unsigned char bit_scan[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned int cp1,cp;//cp1 500次计数, cp 依次8位电子表
sbit LE = P1^0;
void timer0_ser(void) interrupt 1
{
TL0 = (65536 - 2000)%256;
TH0 = (65536 - 2000)/256; //2ms
cp1++; //cp 计数500次后归0
if(cp1 >= 500) //经过一秒
{
flash = ~flash; //中间杠
sec = (sec + 1) % 60; //sec,min,hour 得到当前时分秒数值
min = (min + !sec) % 60;
hour =(hour + !(min + sec)) % 24;
cp1 = 0; //归0,重新开始
}
P0 = 0xff;
P0 = bit_scan[cp]; //左
LE = 1;
LE = 0;
P0 = display_num[cp]; //右
cp++; //依次显示8位
if(cp >= 8){cp = 0;}
}
void timer0_init()
{
TMOD = 0x01;
TL0=(65536 - 2000) % 256;
TH0=(65536 - 2000) / 256;
EA = 1;
ET0 = 1;
TR0 = 1; 6
}
void main(void)
{
timer0_init();
while(1)
{
display_dat();
}
}
/*
code unsigned char seg[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,};
unsigned int cp;
unsigned char hour=12,min=34,sec=56,cycle,flash;
sbit LE = P1^0;
void timer0_ser(void) interrupt 1
{
TL0 = (65536 - 2000)%256;
TH0 = (65536 - 2000)/256; //2ms
cp++; //cp 计数500次后归0
if(cp >= 500) //经过一秒
{
flash = ~flash; //中间杠
sec = (sec + 1) % 60; //sec,min,hour 得到当前时分秒数值
min = (min + !sec) % 60;
hour=(hour + !(min + sec)) % 24;
cp = 0;
}
P0 = 0xff;
switch(cycle % 8)
{
case 0:P0=0x01;LE = 1;LE = 0;P0=seg[hour / 10];break;
case 1:P0=0x02;LE = 1;LE = 0;P0=seg[hour % 10];break;
case 2:P0=0x04;LE = 1;LE = 0;P0=0xbf | flash;break;
case 3:P0=0x08;LE = 1;LE = 0;P0=seg[min / 10];break;
case 4:P0=0x10;LE = 1;LE = 0;P0=seg[min % 10];break;
case 5:P0=0x20;LE = 1;LE = 0;P0=0xbf | flash;break;
case 6:P0=0x40;LE = 1;LE = 0;P0=seg[sec / 10];break;
case 7:P0=0x80;LE = 1;LE = 0;P0=seg[sec % 10];break;
}
cycle++;
if(cycle >= 8)cycle = 0;
}
void timer0_init()
{
TMOD = 0x01;
TL0=(65536 - 2000) % 256;
TH0=(65536 - 2000) / 256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
timer0_init();
while(1);
}
*/
资源链接
有6位和8位的
链接:https://pan.baidu.com/s/1BZpx45Ilud-0GDAGGNpspQ?pwd=9999
提取码:9999