时隔许久
遇到两个bug
- 这个两位七段数码管好像是 共阳极的 内部含有电源估计
- 在进行高低位显示的时候 不能直接转化 必须暂缓到00状态 否则会有一位不能显示
code
某大佬的计时器实现倒计时
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar segcode[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint t=0;
uint count=0;
sbit select0=P2^0;
sbit select1=P2^1;
void delay(uint aim)
{
uint j=0;
for(;aim>0;aim--)
for(j=0;j<125;j++);
}
void timer0_isr() interrupt 1
{
TH0 = (65536 - 1000) / 256;
TL0 = (65536 - 1000) % 256;
count++;
if(count>=1000)
{
t++;
if(t==100)
{
t=0;
}
count=0;
}
}
void main()
{
EX0=1;
EA = 1;
TMOD=0x01;
TH0 = (65536 - 1000) / 256;
TL0 = (65536 - 1000) % 256;
ET0 = 1;
TR0 = 1;
while(1)
{
P1=~segcode[t/10];
select0=0;
select1=1;
delay(5);
select0=0;
select1=0;
delay(2);
P1=~segcode[t%10];
select0=1;
select1=0;
delay(5);
select0=0;
select1=0;
delay(2);
}
}