#include <iocc2430.h>
void init_led() //初始化三个LED,开始时熄灭
{
//P1_0 接RLED P1_1 接GLED P1_2接YLED
P1SEL &= 0x07; //P1_0,P1_1,P1_2通用IO
P1DIR |= 0x07; //作输出,1--输出,0--输入
P1_0 = 1;
P1_1 = 1;
P1_2 = 1; //全熄灭
}
//P0_6按下为低电平
void init_key_interrupt() //出事话P0_6按键中断,下降沿中断
{
P0SEL &= 0x40; //通用IO
P0DIR &= 0x40; //作输入
P0INP &= ~0x40; //上拉 1--下拉,0--上拉
P0IFG = 0; //清中断标志
PICTL |= 0x11; //上升沿触发,开P0_4,--P0_7中断
P0IE = 1; //开P0中断
EA = 1; //开总中断
}
#pragma vector = P0INT_VECTOR
__interrupt void P0_ISR()
{
if(P0IFG & 0x40)
P1_0 = !P1_0;
P0IFG = 0;
P0IF = 0;
}
void main()
{
init_led();
init_key_interrupt();
while(1);
}
来源:https://www.cnblogs.com/LakeFollow/archive/2012/07/31/2616577.html