stc51单片机仿真出来没问题 用开发板就显示乱码
时间:10-02
整理:3721RD
点击:
程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit cc=P3^2;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^0;
sbit key2=P3^1;
unsigned long int aa,num,i,j,a,kk;
unsigned long int c,d;
uchar wan,qian,bai,shi,ge;
uchar code tabel1[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tabel2[]=
{0xff,0xfe,0xfd,0xfb,
0xf7,0xef,0xdf};
void delayms(uint);
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{
TMOD=0x19;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TH0=0;
TL0=0;
EA=1;
ET1=1;
TR1=1;
ET0=1;
TR0=0;
IT0=1;
EX0=1;
while(cc==1);
TR0=1;
while(cc==0);
while(cc==1);
TR0=0;
while(1)
{
display(wan,qian,bai,shi,ge);
}
}
void int0()interrupt 0
{
num++;
}
void T0_time() interrupt 1
{
TH0=0;
TL0=0;
kk++;
}
void T1_time() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
j++;
if(j==20)
{
a=num;
num=0;
j=0;
}
}
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
aa=0;
c=a;
d=1.0*kk*65536+1.0*TH0*256+1.0*TL0;
if(key1==0)aa=c;
if(key2==0)aa=d*2;
wan=aa/10000;
qian=aa%10000/1000;
bai=aa%1000/100;
shi=aa%100/10;
ge=aa%100%10;
P0=tabel2[1];
wela=1;
wela=0;
P0=tabel1[wan];
dula=1;
dula=0;
delayms(1);
P0=tabel2[2];
wela=1;
wela=0;
P0=tabel1[qian];
dula=1;
dula=0;
delayms(1);
P0=tabel2[3];
wela=1;
wela=0;
P0=tabel1[bai];
dula=1;
dula=0;
delayms(1);
P0=tabel2[4];
wela=1;
wela=0;
P0=tabel1[shi];
dula=1;
dula=0;
delayms(1);
P0=tabel2[5];
wela=1;
wela=0;
P0=tabel1[ge];
dula=1;
dula=0;
delayms(1);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit cc=P3^2;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^0;
sbit key2=P3^1;
unsigned long int aa,num,i,j,a,kk;
unsigned long int c,d;
uchar wan,qian,bai,shi,ge;
uchar code tabel1[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tabel2[]=
{0xff,0xfe,0xfd,0xfb,
0xf7,0xef,0xdf};
void delayms(uint);
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{
TMOD=0x19;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TH0=0;
TL0=0;
EA=1;
ET1=1;
TR1=1;
ET0=1;
TR0=0;
IT0=1;
EX0=1;
while(cc==1);
TR0=1;
while(cc==0);
while(cc==1);
TR0=0;
while(1)
{
display(wan,qian,bai,shi,ge);
}
}
void int0()interrupt 0
{
num++;
}
void T0_time() interrupt 1
{
TH0=0;
TL0=0;
kk++;
}
void T1_time() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
j++;
if(j==20)
{
a=num;
num=0;
j=0;
}
}
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
aa=0;
c=a;
d=1.0*kk*65536+1.0*TH0*256+1.0*TL0;
if(key1==0)aa=c;
if(key2==0)aa=d*2;
wan=aa/10000;
qian=aa%10000/1000;
bai=aa%1000/100;
shi=aa%100/10;
ge=aa%100%10;
P0=tabel2[1];
wela=1;
wela=0;
P0=tabel1[wan];
dula=1;
dula=0;
delayms(1);
P0=tabel2[2];
wela=1;
wela=0;
P0=tabel1[qian];
dula=1;
dula=0;
delayms(1);
P0=tabel2[3];
wela=1;
wela=0;
P0=tabel1[bai];
dula=1;
dula=0;
delayms(1);
P0=tabel2[4];
wela=1;
wela=0;
P0=tabel1[shi];
dula=1;
dula=0;
delayms(1);
P0=tabel2[5];
wela=1;
wela=0;
P0=tabel1[ge];
dula=1;
dula=0;
delayms(1);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
测频率
不按键
测脉宽
仿真只是验证你的程序逻辑上通了,但是那元件都是理想化的,你以为实际和理想一致么?能不能用是要看硬件效果,不要以为靠仿真学习!
最有可能 是数码管共阳和共阴错了
仿真 不可全信 也不可不信,,因人而异吧 还有看下你电路连接是否有逻辑错误
首先,感谢各位的回答。
然后,数码管阴阳级没有问题,实际可以显示出频率,脉宽是乱码
这个既然单片本人感觉故障还应该在还是在译码器