PIC18, MPLAB X IDE, XC8, GPIO, Interrupt
0. 참고 사항
1. HW 연결
RB0, PB1이 인터럽트를 설정할 수 있는 Pin이므로
Key Jupmper와 LED Jumper를 연결하였습니다.
2. 소스 설명
full 소스는 아래 github를 통해 확인하세요.
LED : RB7 ~ RB2
Interrupt : RB1 ~ RB0
//void __interrupt(high_priority) isr_low (void) void __interrupt(low_priority) isr_low (void) { if(INT0IE && INT0IF) { if ((PORTB & 0x80)) PORTB &= ~(0x80); else PORTB |= 0x80;
__delay_ms(300); INT0IF = 0; } else if(INT1IE && INT1IF) { if ((PORTB & 0x40)) PORTB &= ~(0x40); else PORTB |= 0x40; __delay_ms(300); INT1IF = 0; } }
void INT_01(void) { GIE = 1; // Global Interrupt Enable bit PEIE= 1; // Peripheral Interrupt Enable bit INT0IE = 1; // INT0 External Interrupt Enable bit INTEDG0 = 0; // External Interrupt 0 Edge Select bit // 1 rigisng, 0 falling INT0IF = 0; // INT0 External Interrupt Flag bit INT1IE = 1; INTEDG1 = 0; INT1IF = 0; }
void main(void) { TRISB = 0x03; // bit7~bit2 output / bit1~bit0 input PORTB = 0xFF; // led on INT_01(); while(1) { __delay_ms(100); } return; }
|
3. 소스
4. 결과
'PIC18' 카테고리의 다른 글
PIC18, MPLAB X IDE, XC8, UART, printf (2) |
2018.09.12 |
PIC18, MPLAB X IDE, XC8, TIMER, Interrupt (0) |
2018.09.12 |
PIC18, MPLAB X IDE, XC8, GPIO, BlinkLED (0) |
2018.09.11 |
PIC18, MPLAB X IPE PICkit3 오류 발생 시 대응방법 (0) |
2018.07.31 |
PIC18, MPLAB X IPE 펌웨어 다운로드 (1) |
2018.07.31 |