How to get Input from Button in PIC24 Code and Proteus Simulation
This post will help us to understand how to get input from external source. I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing code.
I supposed that you know following.
· How to blink an LED (if not then I suggest you to read this (link) first before continuing this post)
In this figure, a button is attached to PortA pin 7. Every time when button is pressed blue LED will glow and yellow LED will be off and vice versa.
In the following figure I made button pin as input and LEDs pins as output and as shown in circuit I am not using any pullup or pulldown resistor that’s why I enabled PIC internal Pullup resistor by writing 1 to “CNPU1bits.CN9PUE = 1”. Remember this is weak Pullup. By using this resistor I reduce one external component from hardware. You may use External resistor. If you want any help Please comment
|Code MPLAB X nd C30 Compiler.|
You can download Code and Proteus Simulation Click here