PIC: GPIO with MPLAB XC8
Configure PIC data-direction and output registers in embedded C.
◷ 45 minParts and tools
- PIC16F877A or trainer
- PICkit programmer
- LED and resistor
Lesson
Learning objective
Configure PIC data-direction and output registers in embedded C.
Procedure
- Review the circuit and confirm the board voltage.
- Build and inspect the wiring before applying power.
- Upload the example, observe the result and record your readings.
- Change one parameter, predict the result and test again.
Troubleshooting
Check power, ground, pin selection, polarity, compiler target and serial output. Use a multimeter or logic analyser where appropriate.
Example code
#include <xc.h>
void main(void){ TRISBbits.TRISB0=0; LATBbits.LATB0=1; while(1){} }Knowledge check
What does a TRIS register configure?
