为什么在protues中仿真数码管显示的是乱码?而在学习板上又确实预期效果(正确的)。然而我用别的、用到数码管的程序去验证,只有部分程序能显示正确。希望各位高手能帮忙解答一下,在下感激不尽!
电路图是这样的
程序是
/*
电子钟P3.5调时间加按钮,p3.6调节调时间的位数码管,p3.7调时间加按钮*/
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
sbit jia=P3^7;
sbit jian=P3^5;
sbit move=P3^6;
uchar a,xg,xsh,fg,fsh,mg,msh;
uchar temp=0xfe;
int jiae;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
delay(uint count) //延时
{
uint r,c;
for(r=0;r<count;r++)
for(c=0;c<51;c++);
}
void check
time() //调节(校对)数码管显示的数字
{
if(move==0){delay(300);temp=_crol_(temp,1);if(temp==0xbf)temp=0xfe;}
switch(temp)
{
case 0xfe: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}xsh+=jiae;if(xsh>3)xsh=0;break;
case 0xfd: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}xg+=jiae;if(xg>9)xg=0;break;
case 0xfb: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}fsh+=jiae;if(fsh>6)fsh=0;break;
case 0xf7: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}fg+=jiae;if(fg>9)fg=0;break;
case 0xef: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}msh+=jiae;if(msh>6)msh=0;break;
case 0xdf: jiae=0;if(jia==0){delay(200);jiae++;}if(jian==0){delay(200);jiae--;}mg+=jiae;if(mg>9)mg=0;break;
}
}
void shijian(char xg1,char xsh1,char fg1,char fsh1,char mg1,char msh1) //显示数码管
{
dula=1;
if(temp==0xfe) P0=table[xsh1]|0x80;
else P0=table[xsh1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(2);
dula=1;
if(temp==0xfd)P0=table[xg1]|0x80;
else P0=table[xg1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(2);
dula=1;
if(temp==0xfb)P0=table[fsh1]|0x80;
else P0=table[fsh1];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(2);
dula=1;
if(temp==0xf7)P0=table[fg1]|0x80;
else P0=table[fg1];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(2);
dula=1;
if(temp==0xef)P0=table[msh1]|0x80;
else P0=table[msh1];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(2);
dula=1;
if(temp==0xdf) P0=table[mg1]|0x80;
else P0=table[mg1];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(2);
}
watchnumber() //电子表数值的控制,
{
if(a==100)
{a=0;
mg++;
if(mg>9)
{mg=0;
msh++;
if(mg==5&&msh==5)beep=0;
if(msh>5)
{beep=1;
msh=0;
fg++;
if(fg>9)
{fg=0;
fsh++;
if(fsh>5)
{fsh=0;
xg++;
if(xg>9)
{xg=0;
xsh++;
if(xsh==2&&xg==4)
{xg=0;xsh=0;fg=0;fsh=0;mg=0;msh=0;}
}
}
}
}
}
}
}
main() //主函数
{
TMOD=0x10;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
TR1=1;
ET1=1;
xg=0;xsh=0;fg=0;fsh=0;mg=0;msh=0;
while(1)
{ watchnumber();
checktime();
}
}
void timer0() interrupt 3 //定时器0的中断
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
a++;
shijian(xg,xsh,fg,fsh,mg,msh);
}
但是将上面的电路图里面的573改用为138并却程序做适当的修改(仅改动一下控制口)又能正常显示,
改动后的仿真图如下
针对用2个573,那么该怎么改动数码管才可以显示正确?
谢谢!
-
一周热门 更多>