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:

  • RB6 and RB7 to control attached LED2, LED3,
  • RB2 and RB3 to read state of switches SW2, SW3.

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

  • already compiled windows executable including sources and
  • sources for PICx55x cooperating with windows application.

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:
    HardwareProfile.h
    #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:
    HardwareProfile - PICDEM FSUSB - PIC18F2550.h
    #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:

Archive PIC18F2550 Application template package.zip contains:

  • PIC18F2550 / PIC18F2455 USB LED switcher schematics compatible with USB programmer
  • windows USB application GenericHIDSimpleDemo.exe including sources by Microchip, part \microchip_solutions_v2013-06-15\USB\Device - HID - Custom Demos\HID DLL - PC Software\ of Microchip Libraries for Applications version 2013-06-15 Windows,
  • PIC FW Firmware.production.hex including sources \microchip_solutions_v2013-06-15\USB\Device - HID - Custom Demos\Firmware\ originally brought by Microchip in Microchip Libraries for Applications version 2013-06-15 Windows,
    modified by me, and working/compatible with Microchip's USB HID bootloader.
    Compiled by MPLAB C for PIC18 v3.46 in LITE mode.
    It can be uploaded into PIC using USB programmer.

If you found these information useful, please consider to:

in EUR
in USD

(Article created 12.1.2014)

  • hw_projects/pic_projects/pic18f2550/pic_test_programs/usb_pic_led_switch.txt
  • Last modified: 06.01.2024 21:39
  • by Radoslav Kastiel