程序循环问题,按键不起作用,各位大侠指导下谢谢!
时间:10-02
整理:3721RD
点击:
#include<reg51.h>
#include<intrins.h>
#define GPIO_LED P2
sbit k3=P3^3;
sbit k4=P3^4;
void IntConfiguoration();
void delay(unsigned int n);
unsigned char keyvalus;
void main()
{
GPIO_LED=0x01;
IntConfiguoration();
while(1)
{
if(keyvalus)
GPIO_LED=_crol_(GPIO_LED,1);
else
GPIO_LED=_cror_(GPIO_LED,1);
delay(2000);
}
}
void IntConfiguoration()
{
IT0=1;
EX0=1;
IT1=1;
EX1=1;
EA=1;
}
void delay(unsigned int n)
{unsigned char a,b;
for(;n>0;n--)
{for(b=1;b>0;b--)
for(a=22;a>0;a--);
}
}
void Int0() interrupt 0
{
delay(1);
if(k3==0)
keyvalus=1;
}
void Int1() interrupt 1
{
delay(1);
if(k4==0)
keyvalus=0;
}
#include<intrins.h>
#define GPIO_LED P2
sbit k3=P3^3;
sbit k4=P3^4;
void IntConfiguoration();
void delay(unsigned int n);
unsigned char keyvalus;
void main()
{
GPIO_LED=0x01;
IntConfiguoration();
while(1)
{
if(keyvalus)
GPIO_LED=_crol_(GPIO_LED,1);
else
GPIO_LED=_cror_(GPIO_LED,1);
delay(2000);
}
}
void IntConfiguoration()
{
IT0=1;
EX0=1;
IT1=1;
EX1=1;
EA=1;
}
void delay(unsigned int n)
{unsigned char a,b;
for(;n>0;n--)
{for(b=1;b>0;b--)
for(a=22;a>0;a--);
}
}
void Int0() interrupt 0
{
delay(1);
if(k3==0)
keyvalus=1;
}
void Int1() interrupt 1
{
delay(1);
if(k4==0)
keyvalus=0;
}
实验效果是要K3按下LED左循环,K4按下LED变右循环.
但是一直右循环,K3,K4中断不起作用?
外部中断0和1对应的中断入口号为0和2。1和3对应的是定时器0和1。
哦谢谢大侠帮忙,学到了!