老师叫我们调试,可是我们什么都不懂,只知道用AT89C51(protues那里只有这个cpu)来做(但是
开发板的是AT89S52的),现在想用protues
仿真,不知道那些零件怎么排,大家帮帮忙吧
#include <AT89X52.H>
#define uchar unsigned char
#define uint unsigned int
uchar num1,num2,num3,num4,s1=0x3f,s2=0x3f,m1=0xbf,m2=0x3f,h1=0,h2=0,a,b,tt;
uchar zt1=1,zt2=1,jia1,j1=0,j2=0,jian1,jia2,jian2,jia3,jian3,jia4,jian4,djian,djia,san=0,gesan=0,shisan=0;
uchar i,j;
sbit sjia=P3^4;
sbit zjian=P3^3;
sbit zt=P3^2;
uchar code table[]={ 0xbf , 0x06 , 0x5b , 0x4f , 0x66 , 0x6d ,
0x7d , 0x07 , 0x7f , 0x6f ,0x3f};
uchar code table2[]={ 0xbf , 0x86 , 0xdb , 0xcf , 0xe6 , 0xed ,
0xfd , 0x87 , 0xff , 0xef ,0xbf};
void delay(uchar z);
void main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
P3=0xfe;
while(1)
{
//选择功能
P2=0xf0;
if(P2==0xe0)
{
P2=0x0f;
if(P2==0x0e)
{
zt2=1;
djian=1;
san=0;
gesan=0;
shisan=0;
}
if(P2==0x0d)
{
gesan=1;
shisan=0;
}
if(P2==0x0b)
{
shisan=1;
gesan=0;
}
}
if(zjian==0)
{
zt2=0;
djian=0;
san=1;
}
if(sjia==0)
{
j1=1;
san=1;
}
//手动加
if(gesan==1)
{
if(j1==1&&sjia==0)
{
jia1=jia1+1;
if(jia1==10)
{
jia1=0;
jia2=jia2+1;
if(jia2==6)
{
jia2=0;
jia3=jia3+1;
if(jia3==10)
{
jia3=0;
jia4=jia4+1;
if(jia4==6)
{
jia4=0;
}
}
}
}
num1=jia1;
num2=jia2;
num3=jia3;
num4=jia4;
s1=table[num1];
s2=table[num2];
m1=table2[num3];
m2=table[num4];
j1=0;
}
}
if(shisan==1)
{
if(j1==1&&sjia==0)
{
jia3=jia3+1;
if(jia3==10)
{
jia3=0;
jia4=jia4+1;
if(jia4==6)
{
jia4=0;
}
}
num1=jia1;
num2=jia2;
num3=jia3;
num4=jia4;
s1=table[num1];
s2=table[num2];
m1=table2[num3];
m2=table[num4];
j1=0;
}
}
// 自动计数 减
if(zt2==0&&djian==0)
{
if(num1!=0||num2!=0||num3!=0||num4!=0)
{
if(num1==0)
{
if(num2==0)
{
if(num3==0)
{
num3=10;
m1=table2[num1];
num4--;
m2=table[num4];
}
num2=6;
s2=table[num1];
num3--;
m1=table2[num3];
}
num1=10;
s1=table[num1];
num2--;
s2=table[num2];
}
if(tt>=20)
{
tt=0;
num1--;
s1=table[num1];
}
}
}
// 开始位扫描
P2=0xfe;
P0=s1;
jia1=num1;
jian1=num1;
delay(10);
P2=0xfd;
P0=s2;
jia2=num2;
jian2=num2;
delay(10);
P2=0xfb;
P0=m1;
jia3=num3;
jian3=num3;
delay(10);
P2=0xf7;
P0=m2;
jia4=num4;
jian4=num4;
delay(10);
if(gesan==1)
{
for(i=0;i<=18;i++)
{
P2=0xfe;
P0=s1;
jia1=num1;
jian1=num1;
delay(10);
P2=0xfd;
P0=s2;
jia2=num2;
jian2=num2;
delay(10);
P2=0xfb;
P0=m1;
jia3=num3;
jian3=num3;
delay(10);
P2=0xf7;
P0=m2;
jia4=num4;
jian4=num4;
delay(10);
}
for(i=0;i<=18;i++)
{
P2=0xfe;
P0=0x00;
jia1=num1;
jian1=num1;
delay(10);
P2=0xfd;
P0=0x00;
jia2=num2;
jian2=num2;
delay(10);
P2=0xfb;
P0=m1;
jia3=num3;
jian3=num3;
delay(10);
P2=0xf7;
P0=m2;
jia4=num4;
jian4=num4;
delay(10);
}
}
if(shisan==1)
{
for(i=0;i<=18;i++)
{
P2=0xfe;
P0=s1;
jia1=num1;
jian1=num1;
delay(10);
P2=0xfd;
P0=s2;
jia2=num2;
jian2=num2;
delay(10);
P2=0xfb;
P0=m1;
jia3=num3;
jian3=num3;
delay(10);
P2=0xf7;
P0=m2;
jia4=num4;
jian4=num4;
delay(10);
}
for(i=0;i<=18;i++)
{
P2=0xfe;
P0=s1;
jia1=num1;
jian1=num1;
delay(10);
P2=0xfd;
P0=s2;
jia2=num2;
jian2=num2;
delay(10);
P2=0xfb;
P0=0x00;
jia3=num3;
jian3=num3;
delay(10);
P2=0xf7;
P0=0x00;
jia4=num4;
jian4=num4;
delay(10);
}
}
if(num1==0&&num2==0&&num3==0&&num4==0&&san==1)
{
P2=0x00;
P0=0xbf;
delay(200);
delay(200);
delay(200);
P2=0x00;
P0=0x80;
delay(200);
delay(200);
delay(200);
}
}
}
void zhongduan() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
tt++;
}
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
{
for(y=110;y>0;y--)
{}
}
}
要求倒计时功能的,因为已经焊好了电路板,AT89S52的芯片,但是下载程序那里一直不行,不知道为什么,连接电脑的时候装好驱动了,下载程序的软件也能读出芯片,但是就是写不进程序,我下星期就要交了,压力山大
这是老师给我们的程序,注释是有一点,我也看不懂
一周热门 更多>