PIC18F26K22 Switch and LED Control

Home Forums Microcontrollers PIC Microcontroller PIC18F26K22 Switch and LED Control

Tagged: , , , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13490
    Afi Gee
    Participant

    Hi,

    I am new to XC8 compiler and I need help. I want to compile a program to switch on 4 LED’s with different switches. I want to use PORTB for the switches and PORTC for the LED’s.

    #13580
    Ligo George
    Keymaster

    It is very easy to do. Simply follow our first two MPLAB XC8 Tutorials, if you want to do it without using any interrupts. The only thing that you need to take care is the LAT register. PIC 18F microcontrollers have LAT register to solve Read Modify Write problems. So for writing data (controlling LED) you need to use LAT register instead of PORT. But for reading data you can use PORT as before.

    Here is the logic.

    1. If switch 1 is pressed toggle the LED 1
    2. If switch 2 is pressed toggle the LED2
    3. If switch 3 is pressed toggle the LED3
    4. If switch 4 is pressed toggle the LED4

     

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
>