USB PIC LED switcher (for PIC18F2550, PIC18F2455)

1 HW

There will be used same scheme like in previous project LED blinker. To the USB programmer scheme there were added 2x LEDs and 2x resistors. LEDs are not connected same way - see LED blinker for details. To the scheme LED blinker there were added 2 switches, their state we will read through USB.

PIC18F2550 USB LED controller scheme
Figure 1: PIC18F2550 USB LED controller scheme

There are used PIC's pins:

2 SW

For testing I have used already existing Microchip's code from Microchip Libraries for Applications where is complete solution available:

There is nothing to be changed in windows application source code, aplication may be used compiled as is.
Source code of PIC firmware has to be changed in several places to work properly with PIC18F2550 (or PIC18Fx55x):

  1. added rm18f2550 - HID Bootload.lkr to project (based on rm18f4550 - HID Bootload.lkr)
  2. to the HardwareProfile.h we need to add definition for PIC18F2550:

    #if defined(__18CXX)
         #if defined(__18F2550)
         #include "HardwareProfile - PICDEM FSUSB - PIC18F2550.h"
    #elif defined(__18F4550)
    #include "HardwareProfile - PICDEM FSUSB.h"


  3. as next we need to add HardwareProfile - PICDEM FSUSB - PIC18F2550.h file to project (based on HardwareProfile - PICDEM FSUSB.h). Here are relevant code changes

    #ifndef HARDWARE_PROFILE_PICDEM_FSUSB_PIC18F2550_H
    #define HARDWARE_PROFILE_PICDEM_FSUSB_PIC18F2550_H

    ...

    /** LED ************************************************************/
    #define mInitAllLEDs()     LATB &= 0x3F; TRISB &= 0x3F;

    #define mLED_1               LATBbits.LATB7
    #define mLED_2               LATBbits.LATB6
    #define mLED_3
    #define mLED_4

    ...

    /** SWITCH *********************************************************/
    #define mInitAllSwitches()      TRISBbits.TRISB2=1;TRISBbits.TRISB3=1;
    #define mInitSwitch2()           TRISBbits.TRISB2=1;
    #define mInitSwitch3()           TRISBbits.TRISB3=1;
    #define sw2                           PORTBbits.RB2
    #define sw3                           PORTBbits.RB3

To compile code I have used:


3 Downloads

Archive PIC18F2550 Application template package.zip contains:



If you found these information useful, please consider to:

This will allow me to bring more interesting projects for you.