This project implements a reusable, interrupt-safe GPIO Hardware Abstraction Layer (HAL) and a button driver using external using interrupts for the PIC18F4550 microcontroller.
The goal is demostrate clean embedded firmware architecture, whit a strictseparation between: -hardware access -driver logic -application logic
-GPIO abstraction using gpio.h / gpio.c
-Safe register access (avoids Read-Modify-Write issues)
-External interrupt handling (INT0)
-ISR-safe event signaling using software flags
-Minimal ISR design
-Application logic independent of hardware registers
-inc/
-gpio.h
-button.h
-config.h
-src/
-gpio.c
-button.c
-main.c
-Makefile
-build
-Output writes use LAT registers -Input reads use PORT registers -Shadow registers are used to prevent RMW hazards -No direct register access outside the HAL
-Button connected to RB0/INT0
-External interrupt triggers on falling edge
-ISR only sets a software event flag
-Debounce and state validation handled in main context
-Driver exposes a clean API:
-button_event_pending()
-button_process()
-button_get_state()
- System initializes GPIO HAL and button driver
- A button press triggers the external interrupt (INT0)
- The ISR executes and sets a software event flag
- The main loop detects the pending button event
- Button debounce and state validation are processed in main context
- Application logic reacts to the validated button state
make all
makle flash
-PIC18F4550 -Compiler: XC8 -Clock: 20 MHz