From Tim's website
Jump to: navigation, search

USB controlled Bike Light

This project is under development. Here are some things I have found useful:

PICkit2 and dev board

I am using a PIC18F14K50 processor and I bought the Low Pin Count USB Development Kit from Farnell, which includes the PICkit2 Programmer / debugger. The first thing I wanted to to was flash four the LEDs on port C, so I followed an online PIC tutorial using assembly. I then converted the project to a C program and recorded the steps taken here:

  • Install MPLAB IDE and the C18 compiler from the microchip website
  • Connect the PICkit2 to the development board as shown in the photo
  • Run MPLAB IDE and click on Project -> Project wizard...
  • Click Next and select PIC18F14K50
  • Click Next and select Microchip C18 Toolsuite
  • Click Next and enter a location and filename for the project
  • Click Next twice (without adding any files to the project) and click Finish
  • Click on File -> New and enter the following code in the new document
#include <p18f14k50.h>

#pragma config LVP  = OFF
#pragma config FOSC = XT

void main(void)
{
    int value = 0;

    TRISC = 0;
    PORTC = 0;

    while(1)
    {
        int delay = -1;

        PORTC = value++;

        while( delay-- );
    }
}
  • Click on File -> Save As... and enter a .c filename for the new file
  • Right click on the Source Files folder in the project window and select Add files...
  • Find the file we just saved and select it
  • Click on Project -> Build all
----------------------------------------------------------------------
Debug build of project `C:\Users\Styles\Desktop\test.mcp' started.
Language tool versions: mpasmwin.exe v5.37, mplink.exe v4.37, mcc18.exe v3.36, mplib.exe v4.37
Preprocessor symbol `__DEBUG' is defined.
Mon Nov 08 12:03:36 2010
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\Styles\Desktop\test.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MCC18\bin\mcc18.exe" -p=18F14K50 "test.c" -fo="test.o" -D__DEBUG -Ou- -Ot- - Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\Program Files\Microchip\MCC18\bin\mplink.exe" /p18F14K50 /l"C:\Program Files\Microchip\MCC18\lib"  "test.o" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test.cof" /M"test.map" /W
MPLINK 4.37, Linker
Copyright (c) 1998-2010 Microchip Technology Inc.
Errors    : 0

MP2HEX 4.37, COFF to HEX File Converter
Copyright (c) 1998-2010 Microchip Technology Inc.
Errors    : 0

Loaded C:\Users\Styles\Desktop\test.cof.
----------------------------------------------------------------------
Debug build of project `C:\Users\Styles\Desktop\test3.mcp' succeeded.
Language tool versions: mpasmwin.exe v5.37, mplink.exe v4.37, mcc18.exe v3.36, mplib.exe v4.37
Preprocessor symbol `__DEBUG' is defined.
Mon Nov 08 12:03:36 2010
----------------------------------------------------------------------
BUILD SUCCEEDED
  • Click on Programmer -> Select programmer -> PICKit 2
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 3.30V)
PIC18F14K50 found (Rev 0x6)
PICkit 2 Ready
  • Click on Programmer -> Program
Programming Target (08/11/2010  12:05:59)
PIC18F14K50 found (Rev 0x6)
Erasing Target
Programming Program Memory (0x0 - 0x13F)
Verifying Program Memory (0x0 - 0x13F)
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready
  • Click on Programmer -> Release from reset
  • Watch the LEDs count in binary!