求一个单片机外部中断程序,要求用按键模拟单片机外部中断输入源,当按键按下时产生中断,进行中断处理
1个回答
展开全部
#include<reg51.h>
#define uchar unsigned char
sbit KEY=P3^2;
uchar LED=0xfe;
void delay(uchar a)
{
uchar i,j;
for(i=0;i<a;i++)
for(j=0;j<120;j++);
}
void ext0() interrupt 0
{
while(!KEY)
{
P0=led;
led=(led<<1)|0x01;
if(led==0xff)led=0xfe;
delay(50);
}
}
main()
{
EX0=1;
EA=1;
IT0=0;
while(1)
{
P0=0x00;
delay(100);
P0=0xff;
delay(100);
}
}
#define uchar unsigned char
sbit KEY=P3^2;
uchar LED=0xfe;
void delay(uchar a)
{
uchar i,j;
for(i=0;i<a;i++)
for(j=0;j<120;j++);
}
void ext0() interrupt 0
{
while(!KEY)
{
P0=led;
led=(led<<1)|0x01;
if(led==0xff)led=0xfe;
delay(50);
}
}
main()
{
EX0=1;
EA=1;
IT0=0;
while(1)
{
P0=0x00;
delay(100);
P0=0xff;
delay(100);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询