我按照郭天祥十天学会
单片机里的
电路图写的数码管但是
仿真的数字乱 亮,。,。也不晓得哪个问题帮我瞅瞅
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar a,b,temp,bai,shi,ge;
uint shu;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tablewe[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delay(uchar x);
void display(uchar q,uchar w,uchar e,uchar r,uchar t,uchar y);
void init();
void main()
{
init();
while(1)
{ bai=shu/100;
shi=shu%100/10;
ge=shu%10;
display(7,6,5,bai,shi,ge);
}
}
void
timer0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
if(a==2)
{
a=0;
shu--;
if(shu==398)
{
TR0=0;
TR1=0;
}
}
}
void timer1()interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
b++;
if(b==10)
{
b=0;
temp=_crol_(temp,1);
P1=temp;
}
}
void init()
{
shu=432;
wela=0;
dula=0;
temp=0xfe;
P1=temp;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void delay(uchar x)
{
uchar y,z;
for(z=x;z>0;z--)
for(y=110;y>0;y--);
}
void display(uchar q,uchar w,uchar e,uchar r,uchar t,uchar y)
{
dula=1;
P0=table[q];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[w];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[e];
dula=0;
wela=1;
P0=0xff;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[r];
dula=0;
wela=1;
P0=0xff;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[t];
dula=0;
wela=1;
P0=0xff;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[y];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
额。。。。。。。。加了注释就知道了么。。。
一周热门 更多>