个位大侠 我是菜鸟 帮忙看看我写的pic单片机的外部中断为什么进入不了呢
#include <p18f4520.h>
void init(); void delay(); void inter(); void main() { init(); while(1) { //delay(); PORTAbits.RA1 = 1; PORTD = 0x7f; } } void init() { INTCON = 0x00;//清中断; INTCONbits.INT0IE = 1;//INT0外部中断使能 INTCONbits.GIE = 1;//开全局中断; TRISD = 0x00;//PORTD端口设为输出; INTCON2bits.INTEDG0 = 0;//INT0下降沿触发; PORTD = 0;//PORTD口清零; DDRAbits.RA1 = 0;//RA1口设为输出; DDRAbits.RA2 = 0; DDRBbits.RB0 = 1;//RB0口设为输入; INTCONbits.INT0IF = 0; //INTCONbits.RBIE = 0; } void delay() { int m,n; for(m = 0;m < 100;m++) for(n = 0;n <100;n++) ; } #pragma code high_vector = 0x08 void high_vector(void) { _asm GOTO inter _endasm } #pragma code #pragma interrupt inter void inter(void) { INTCONbits.GIE = 0; if(INTCONbits.INT0IF = 1) { delay(); PORTD = 0x3f; PORTAbits.RA2 = 1; PORTAbits.RA1 = 0; delay(); } INTCONbits.INT0IF = 0; INTCONbits.GIE = 1; }
顺便说一下 我用的是c18编译器 |