32 lines
857 B
C
Executable File
32 lines
857 B
C
Executable File
#include <pic18f4550.h>
|
|
#include <stdint.h>
|
|
|
|
// Use this to define the interrupt vector for high-priority interrupts
|
|
void interrupt high_priority isr(void) {
|
|
// Check if it's a PORTB change interrupt
|
|
if (INTCON.RBIF) {
|
|
// Handle the change here
|
|
// Example: toggle a pin, read input, etc.
|
|
|
|
// Clear the interrupt flag
|
|
INTCON.RBIF = 0;
|
|
}
|
|
}
|
|
|
|
void main(void) {
|
|
// Set PORTB pins RB4-RB7 as input
|
|
TRISB |= 0xF0; // Set RB4-RB7 as input (1)
|
|
|
|
// Enable PORTB change interrupt
|
|
INTCON.RBIE = 1; // Enable PORTB change interrupt
|
|
INTCON.RBIF = 0; // Clear PORTB interrupt flag
|
|
INTCON.GIE = 1; // Enable global interrupts
|
|
INTCON.PEIE = 1; // Enable peripheral interrupts (recommended)
|
|
|
|
// Main loop
|
|
while (1) {
|
|
// Your main code here (e.g., sleep, check flags, etc.)
|
|
}
|
|
}
|
|
|