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.
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.
2. SW
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):
- added
rm18f2550 - HID Bootload.lkrto project (based onrm18f4550 - HID Bootload.lkr) - to the
HardwareProfile.hwe 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"
- as next we need to add
HardwareProfile - PICDEM FSUSB - PIC18F2550.hfile to project (based onHardwareProfile - 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:
- MPLAB X IDE v1.95 for Windows released on 30.10.2013
- MPLAB C for PIC18 v3.46 in LITE mode released on 3.5.2013
3. Downloads
Archive PIC18F2550 Application template package.zip contains:
- PIC18F2550 / PIC18F2455 USB LED switcher schematics compatible with USB programmer
- windows USB application
GenericHIDSimpleDemo.exeincluding 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.hexincluding 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 USD
(Article created 12.1.2014)