PIC18F14K50 USB HID Bootloader compatible sample – “LEDFlash”
I’ve received a few requests for a simple ‘flashing led’ example for my PIC18F14K50 USB Breakout Board, specifically one compatible with the bootloader. This code here aims to meet that request. Additionally, it serves as a template of sorts for the beginnings of your own HID USB bootloader compatible code.
To keep things simple, all we’re doing here is alternately flashing the two user LEDs on one of my PIC18F14K50 v3 USB Breakout Boards. Aside from this code, you will also need to add a linker script (.lkr file, available in the project download at the end of this article) to your project in order to get it to run on the bootloader. That file is available as part of the project download towards the bottom of this post.
The code requirements to make this compatible with the USB HID Bootloader is actually pretty simple. All that is necessary for this basic example is the code between the “bootloader support code” comments, and the linker file attached to the project as mentioned above. If we were using interrupts, the code would require us to remap those as well, but that’s just a few more lines of code. We’ll save that for a future example. you can also check out Microchip’s USB HID – Mouse demo code for an example which uses interrupts (Available in the Microchip Application Libraries download, http://www.microchip.com/mal)
And now, to the code!:
#include <p18f14k50.h>
//Bootloader support code start
extern void _startup (void); // See c018i.c in your C18 compiler dir
#pragma code REMAPPED_RESET_VECTOR = 0×1000
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
//Bootloader support code end
void main (void)
{
TRISC = 0;
LATC = 0;
LATCbits.LATC4 = 1;
LATCbits.LATC5 = 0;
while (1) {
Delay10KTCYx(125); // Delay 1,250,000 cycles
LATCbits.LATC4 = !LATCbits.LATC4;
LATCbits.LATC5 = !LATCbits.LATC5;
}
}
The code for this example is available via git here: LEDFlash
- Posted by
Jayson - Posted in Electronics
Apr, 26, 2011
9 Comments.
-
Nax
-
Jayson
-
-
AL
-
http://www.tautic.com Jayson
-
AL
-
http://www.tautic.com Jayson
-
AL
-
-
-
-
-
Richard
-
Ali
Categories
- DipTrace (1)
- Electronics (29)
- Reviews (3)
- Tindie (1)
- Uncategorized (8)

860.255.8324