求助各位大大们
时间:10-02
整理:3721RD
点击:
我在书上找的程序,代码如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit M1=P1^0;
sbit dula=P2^6;
sbit wela=P2^7;
uchar i,num,num1,num2;
uchar shi,ge;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay();
void display(uchar,uchar);
void main()
{
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;
while(1)
{
display(shi,ge) ;
}
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=tab[shi];
dula=0;
P0=0xff;
delay();
wela=1;
P0=0xfe;
wela=0;
delay();
dula=1;
P0=tab[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay();
}
void delay()
{
uint p,q;
for(p=5;i>0;i--)
for(q=110;i>0;i--);
}
void delayT0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==4)
{
num1=0;
M1=~M1;
}
}
void delayT1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;
}
}
但是我用protues仿真时,数码管一直是处于八段全亮的状态,求教各位大大,是怎么回事呢?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit M1=P1^0;
sbit dula=P2^6;
sbit wela=P2^7;
uchar i,num,num1,num2;
uchar shi,ge;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay();
void display(uchar,uchar);
void main()
{
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;
while(1)
{
display(shi,ge) ;
}
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=tab[shi];
dula=0;
P0=0xff;
delay();
wela=1;
P0=0xfe;
wela=0;
delay();
dula=1;
P0=tab[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay();
}
void delay()
{
uint p,q;
for(p=5;i>0;i--)
for(q=110;i>0;i--);
}
void delayT0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==4)
{
num1=0;
M1=~M1;
}
}
void delayT1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;
}
}
但是我用protues仿真时,数码管一直是处于八段全亮的状态,求教各位大大,是怎么回事呢?
先确定电路图是不是正确,完了在确定数码管共阳或者共阴,是否和你代码匹配
完全是按照书上的一步一步来的,就是不行啊!是不是数码管扫描的时间有问题?
你的数码管很可能是搞错了,把共阳的搞成共阴的了。
先自己简单的写代码测试一下数码管是共阳的还是共阴的
嗯 好的 谢谢了