proteus进行仿真为何LED不亮,且程序编译是正确的
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintsbitk=P3^4;sbitk1=P3^0...
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit k = P3^4;
sbit k1=P3^0;
sbit k2=P3^1;
uint a=0;
uint b=0;
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
uchar code Scan_BITs[]={0x20,0x10,0x08};
uchar data Buffer_Counts[]={0,0,0};
uint Count_A=0;
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void Show_Counts()
{
uint i;
Buffer_Counts[2] = Count_A / 100;
Buffer_Counts[1] = Count_A % 100 /10;
Buffer_Counts[0] = Count_A % 10;
if(Buffer_Counts[2]==0)
{
Buffer_Counts[2] = 0x0a;
if(Buffer_Counts[1]==0)
{
Buffer_Counts[1]=0x0a;
}
}
for(i=0;i<3;i++)
{
P2 = Scan_BITs[i];
P0 = DSY_CODE[Buffer_Counts[i]];
DelayMS(1);
}
}
void main()
{
IT0 = 1;
IT1 = 1;
PX0 = 1;
IE = 0x85;
while(1)
{
Show_Counts();
if(k == 0){ Count_A = 0; }
else if(k1==0)
{
DelayMS(5);
if(k1==0)
{
a++;
if(b!=0)
{
Count_A++;
a=0;
b=0;
}
while(!k1);
}
}
else if(k2==0)
{
DelayMS(5);
if(k2==0)
{
b++;
if(a!=0)
{
Count_A--;
a=0;
b=0;
}
while(!k2);
}
}
}
}
/*
void EX_INT0() interrupt 0
{
a++;
if(b!=0)
{
Count_A++;
a=0;
b=0;
}
while(k1!=0);
}
void EX_INT1() interrupt 2
{
b++;
if(a!=0)
{
Count_A--;
a=0;
b=0;
}
while(k2!=0);
} */
仿真时是这样的 展开
#define uchar unsigned char
#define uint unsigned int
sbit k = P3^4;
sbit k1=P3^0;
sbit k2=P3^1;
uint a=0;
uint b=0;
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
uchar code Scan_BITs[]={0x20,0x10,0x08};
uchar data Buffer_Counts[]={0,0,0};
uint Count_A=0;
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void Show_Counts()
{
uint i;
Buffer_Counts[2] = Count_A / 100;
Buffer_Counts[1] = Count_A % 100 /10;
Buffer_Counts[0] = Count_A % 10;
if(Buffer_Counts[2]==0)
{
Buffer_Counts[2] = 0x0a;
if(Buffer_Counts[1]==0)
{
Buffer_Counts[1]=0x0a;
}
}
for(i=0;i<3;i++)
{
P2 = Scan_BITs[i];
P0 = DSY_CODE[Buffer_Counts[i]];
DelayMS(1);
}
}
void main()
{
IT0 = 1;
IT1 = 1;
PX0 = 1;
IE = 0x85;
while(1)
{
Show_Counts();
if(k == 0){ Count_A = 0; }
else if(k1==0)
{
DelayMS(5);
if(k1==0)
{
a++;
if(b!=0)
{
Count_A++;
a=0;
b=0;
}
while(!k1);
}
}
else if(k2==0)
{
DelayMS(5);
if(k2==0)
{
b++;
if(a!=0)
{
Count_A--;
a=0;
b=0;
}
while(!k2);
}
}
}
}
/*
void EX_INT0() interrupt 0
{
a++;
if(b!=0)
{
Count_A++;
a=0;
b=0;
}
while(k1!=0);
}
void EX_INT1() interrupt 2
{
b++;
if(a!=0)
{
Count_A--;
a=0;
b=0;
}
while(k2!=0);
} */
仿真时是这样的 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询