View Full Version : Getting started in PIC with a USB board

06-10-2010, 12:09 AM
Some of you may have seen my earlier post here asking about a dev board.Anyway, I have bought this board --> http://www.nex-robotics.com/products/microcontrollers-and-development-boards/pic-development-boards/picusb-rp-smart-board.html .

I got it today. Rigged it up. Got it detected on PC, drivers installed after some fooling around. Also installed MPLAB IDE etc. Now as I understand it, this chip has a firmware ( which I think is MCHPFSUSB Framework firmware from Microchip) on it to allow for programming without a programmer.

Now the issue.

I have found a couple of beginner tutorials for PIC but they are all for straight up "burning". I see there are some "configuration bits" which needs to be set and I am kind of afraid of setting the wrong ones and having to end up buying a programmer.

After a bit more digging I found that I may need to use a remapped linker script ( rm18f4550.lkr ), to avoid overwriting the bootloader. I do not have a problem with understanding C, but however I do not have any experience working with the PIC.

The problem is, all the demos that came with the board are about making USB devices ( which are a bit complex for me as of now ).
Nothing on starting from scratch, say, from an 'LED blinky'. I couldn't find anything on Google about this. Its either USB devices using USB firmware .. or from scratch without bootloader.

Is it just a matter of compiling the "normal" PIC C code with MPLAB C18 compiler and then writing the hex file using PDFSUSB.exe (PicDem FS USB Demo Tool). Is there any risk of me overwriting the bootloader? Or is are there anything specific I have to do while coding for a PIC USB Bootloader.

In retrospect .. Arduino was soo much easier .. as soon as I got my hands on some female header connectors, I was off blinking LEDs and making thermometer with LCD displays .. ;) . Oh well .. "With greater power comes greater responsibility/madness/pointless stuff"


06-10-2010, 12:55 AM
Look for PIC16F tutorials , only header file changes , most things remain same.

06-10-2010, 07:02 AM
ha ha ha !

What a beginner board !!!
Pic18 hAS VERY few tutorials

06-10-2010, 10:08 AM
There is nothing wrong with that beginner board. It is supposed to be a beginner board for USB, and not for understanding a PIC microcontroller. I understand from an other thread of yours,
that you wanted to do make something with HID..

You cannot jump directly into USB without understanding the basics. I understand you do not have a programmer. If you have, what you can do is to buy a 16F877A which is easily available, burn a few codes and get the LED blinking. You can youe the NEX board for that. Or you can request next some sample codes.

The fuse thing is a bit confusing. Normally they are set in code, you can look for that at the begining of the code. You will have to make a few changes in the PICC code to compile it in C18. I guess you must be using the students version.

Yes, you need a linker script, if you are using multiple c files.

Its a long story to tell, I suggest you go through microchip website,


then come back and ask for clarifications.

Please do not mock at other vendor products at every possible opportunity. That will not increase the traffic to your site. There was nothing wrong with that board, it is decently priced, and Microchip has more documentations and support than any other 8 bit vendor, if you know how to use their website. If you cannot help an OP question which was decenlty framed, just keep quiet.

06-10-2010, 03:49 PM
Thanks for the responses guys :)

@vikas - Roger that :)

@avinash .. well I am not beginner when it comes to programming. I think I can find my way around this new platform somehow.

I do not intend to jump instantly into USB HID. I bought this board as I figured I would be able to work on beginner stuff on this and then move on to USB once I figured out everything without having to buy another board/chip for that. I didn't want to shell out cash for a fancy "beginner board" and then have to spend more just to get out of its limitations.

As I said, I started off with Arduino, which seemed like the simplest way to apply my programming skill to real-world applications. I was also rather limited in budget then. Now I need to expand my horizons, which is why I decided to dip my toes into PIC.

Anyway, I was able to find some stuff after further Googling.

According to this:

I need not set any configuration bits when using the bootloader. I also need to use the modified linker script which I found in one of the example folders. I was able to compile a simple "Turn LED On" program and write it to the PIC without any problems or errors.

#include <p18cxxx.h>
void main(void)
/* Set PORT D as digital outputs */
LATD = 0x00;
TRISD = 0x00;
/* Turn on LED, D1 */

LATDbits.LATD0 = 1;
/* Do nothing until reset */

Wish someone made some 'digitalWrite' and 'pinMode' functions for the PIC. Things would be so much simpler ;).

Unfortunately the board doesn't come with the headers soldered on. And my soldering iron seems to be crapped out. So no way of testing it. Damn!

I will post back once I get it working.


06-10-2010, 06:38 PM
http://www.hackinglab.org/ Pinguino is what you need ..

Modify headers for 4550 :) ull do fine.

06-11-2010, 07:22 PM
Hey guys,
Just wanted to let you know that I finally got it working. After some shoddy soldering work ( I still suck at it :| ), and some rather frustrating attempts at making an LED blink properly, I decided to start with one of the demo programs and then modified it for LED blinking. But still it resulted with LED staying on. Then I came across this page:


Apparently the Delay10KTCYx thingy takes only 8-bit values and I was passing 1000 to it. Well anyway, after fixing that issue, I finally got it to work. For reference, I will attach the code that needs to go on top of the source for the code to work with bootloader. I got it from the example code. Turns out, it is there were guides specifically for this ( http://hades.mech.northwestern.edu/index.php/Compiling_for_a_bootloader_in_MPLAB ).

Here is my (rather long) LED blinker.

/** I N C L U D E S ************************************************** ********/
#include <p18cxxx.h>
#include <delays.h>
/** V A R I A B L E S ************************************************** ******/

#pragma udata

/** V E C T O R R E M A P P I N G *******************************************/
/* This part seems to be what was missing in my code */

extern void _startup (void); // See c018i.c in your C18 compiler dir

#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
_asm goto _startup _endasm
#pragma code

#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void _high_ISR (void)

#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
#pragma code

/** D E C L A R A T I O N S **************************************************/
#pragma code

/** L E D ************************************************** *********/
#define mInitAllLEDs() LATD &= 0xF0; TRISD &= 0xF0;

#define mLED_1 LATDbits.LATD0
#define mLED_2 LATDbits.LATD1
#define mLED_3 LATDbits.LATD2
#define mLED_4 LATDbits.LATD3

#define mLED_1_On() mLED_1 = 1;
#define mLED_2_On() mLED_2 = 1;
#define mLED_3_On() mLED_3 = 1;
#define mLED_4_On() mLED_4 = 1;

#define mLED_1_Off() mLED_1 = 0;
#define mLED_2_Off() mLED_2 = 0;
#define mLED_3_Off() mLED_3 = 0;
#define mLED_4_Off() mLED_4 = 0;

#define mLED_1_Toggle() mLED_1 = !mLED_1;
#define mLED_2_Toggle() mLED_2 = !mLED_2;
#define mLED_3_Toggle() mLED_3 = !mLED_3;
#define mLED_4_Toggle() mLED_4 = !mLED_4;

void main(void)
ADCON1 |= 0x0F; // Default all pins to digital --- Not really required in this case I think
mInitAllLEDs(); // Pull all those pins down by default
while(1) // Infinite loop
/* Turn on LED, D1 */

/* Delay for approx 1 second */
Delay10KTCYx(250); // This corresponds to around 200 ms .. for 20MHz PIC

/* Turn off LED, D1 */


After compiling in MPLAB C18, I loaded it up using the PICDEM FS USB Demo Tool ( rather fast ).
I put the LED with +ve on RD1 and -ve on RD0, and got it happily blinking away.

So thats it I guess :). After some more fundamental stuff, I should be able to dig into USB.

Yes I had heard of Pinguino sometime ago. I guess I will check it out. :)

Thanks for all the help.

06-11-2010, 09:34 PM
here is the link "http://www.elsevier.com/wps/find/bookdescription.authors/714114/description#description"

06-12-2010, 06:56 PM
@Ulhas Thanks :) I will check it out.

Working with registers directly has been fun. I was able to rig up this "running LED" thing with just a couple of bit shifting statements in a loop. Would have taken a lot more code using 'digitalWrite' or something similar.