外部中断

mac2024-10-28  12

#include <reg51.h>

typedef unsigned int u16; typedef unsigned char u8;

sbit k3 = P3^2; sbit k4 = P3^3; sbit led1 = P2^1; sbit led0 = P2^0;

void delay(u16 i) { while(i–); }

void interrupt_init() { EA = 1; //打开总中断 EX0 = 1; //打开INT0的中断允许 IT0 = 1; //设置下降沿触发,如果等于0则为低电平触发

EX1 = 1; //打开INT1的中断允许 IT1 = 1; //设置下降沿触发,如果等于0则为低电平触发

}

void interrupt0_fun() interrupt 0 { delay(1000); if(k3 == 0) { led0 = ~led0; } } void interrupt1_fun() interrupt 1 { delay(1000); if(k4 == 0) { led1 = ~led1; } }

void main() { interrupt_init(); while(1); }

最新回复(0)