本帖最后由 letao2013 于 2013-11-19 20:51 编辑
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
//
sbit KEY1=P2^1; //yi bu
sbit KEY2=P1^1; // tong bu ting zhi
sbit KEY3=P3^2; // tong bu fan zhuan int0
sbit KEY4=P3^3; // tong bu int1
//电机
sbit M1=P2^7;
sbit M2=P2^6;
sbit M3=P2^5;
//闪烁灯
sbit LED1=P2^4;
sbit LED2=P2^3;
sbit LED3=P2^2;
//void keyscan();
void delayms(uint x);
void delayms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
void main()
{
delayms(100);
P2=0xFF;
P1=0xFF;
IT0=1;
IT1=1;
EX0=1;
EX1=1;
EA=1;
while(1)
{
if(KEY1==0)
{
M1=0;
LED1=0;
}
else
{
M1=1;
LED1=1;
}
if(KEY2==0)
{
M2=1;
LED2=1;
M3=1;
LED3=1;
}
}
}
void exist1() interrupt 2
{
EX1=0;
M2=0;
LED2=0;
M3=1;
LED3=1;
EX1=1;
}
void exist0() interrupt 0
{
EX0=0;
LED2=1;
M2=1;
M3=0;
LED3=0;
EX0=1;
}
为啥按下KEY1键的时候,会进入中断0或者中断1?(KEY1,KEY2.KEY3,KEY4即图里S1,S2,S3,S4) |