程序如下:
GP4作为输入无法触发电平变化中断,点亮GP0上的LED,哪位指导下
#pragma config FOSC = INTOSCIO // 4M Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
void main(void) {
// OSCCON = 0x78;
//OPTION_REG=0b00000000; //全局使能上拉
CMCON0 = 0x07; //关比较器,并设GP0-GP5为数字IO口
//CMCON1 = 0x07; //关闭比较器
ANSEL = 0x00; //设GP0-GP5为数字IO口
OPTION_REG = 0b00000000; //GPIO pull-ups are enabled by individual PORT latch values in WPU register Tck=FOSC/4
TRISIO4 = 1; // 0001 0000 GP4 IN, Other Outputs; Rest are O/Ps
WPU4 = 0;
WPU0 = 1;
IOC4 = 1; //GP4 as INT if IO change
//ADON = 0;
GIE = 1;
PEIE = 1; //开外部中断
GPIE = 1; //GPIO Change Interrupt Enable bit 开电平变化中断
//INTE = 1;
GPtemp = GP4;
GPIF = 0; //GPIO Change Interrupt Flag bit
GP0=0;
for(;;) // ?????
{