How to use 44-pin demo-board of PICkit 2 set
with PIC16F887
as a brain of small home-made robot.
How to use in robotics light/image sensor of cheap
optical mouse as a local position finder.
How to use cheap optical mouse instead of gyroscope.
Source code in C for PIC16F887 for this.
PICkit 2 - Small size USB programmer from Microchip Technology Inc.
How to re-program it and use as a demo board.
Ricently we bought PICkit 2 Development Programmer/Debugger with
44-pin demo board with PIC16F887 midrange PIC microcontroller.
And we did some experiments with PICkit 2.
PICkit 2 is a small size programmer with USB interface.
It is interesting, that after re-programming it is possible to use PICkit 2 as a demo board.
You can use PICkit 2 as a testing board with USB interface.
PICkit 2 has PIC18F2550 on a board and there is a way to remove pre-installed software
(they call it 'OS', he-he-he),
put your own software to it and use it (the PICkit 2) as an USB-compliant demo device.
In this article we will describe all steps how to do this - with pictures, screens and code examples
in C language.
Step-by-step instructions:
) Download and install MPLAB v7.60 (this was the most fresh version, when we did our experiments)
Note: There is MPLAB 7.5 on the PICkit 2 CD, but we downloaded fresh version (7.60) right from the
www.microchip.com.
We do NOT use MPLAB 7.50 from this CD, we use v7.60.
) After the installation of downloaded MPLAB v7.60, normally you will see it's icon on your desktop.
It loks like:
MPLAB IDE 7.60 Icon.
) Download from www.microchip.com MPLAB C18 compiler ( file 'MPLAB-C18-StudentEdition-v3_12.exe'),
) Install it and tune it to work with MPLAB IDE.
Should be installed to C:\MCC18
Very useful file with installation and configuration instructions is 'MPLAB_C18_Getting_Started_51295f.pdf'.
Try to find if on www.microchip.com.
) Install PICkit 2 software on your PC. (You can find this soft on PICkit CD).
'Insert Firts CD'. Shipped with PICkit 2.
The directory and installation program: "CD:\Install\PICkit 2\setup.exe"
) After the installation the icon of PICkit software should appear on your desctop:
PICkit 2 v2.40 Icon.
) Download our code example (it is MPLAB project). www.RoboHobby.com_PICkit_2.zip
) Unzip the project to directory "c:\PICkit_2\www.RoboHobby.com_PICkit_2"
) Click on file 'c:\PICkit_2\www.RoboHobby.com_PICkit_2\PICkit_2.mcw'.
MPLAB will start to run with the project.
) Compile the project:
) Then you should export your HEX file to special format, which can be used with PICkit 2 programmer.
MPLAB IDE v7.60 Export HEX file for PICkit 2 - Settings for 'Memory Areas'.
MPLAB IDE v7.60 Export HEX file for PICkit 2 - Settings for 'File Format'.
You should put this hex file of new 'OS' for PICkit 2 to file:
) Turn Off you PICkit 2 device (disconnect it from PC).
) Hold power button (the red button on the device) and connect PICkit 2 device to the PC
) Red LED start to blink - means the device has no operation system, it is ready to load new OS.
) Run 'PICkit 2' program. (Click on it's icon):
PICkit 2 v2.40 Icon.
) You will see screen with yellow info window:
PICkit_2 Program: Device is ready to receive new 'OS'.
) Choose file "c:\Program Files\Microchip\PICkit 2 v2\PK2V022000.hex".
) PICkit 2 software will load new OS to the device and verify it. You will see two messages
on BLUE info screen:
a) 'Downloading New PICkit 2 Operation System.'
b) 'Verifing PICkit 2 Operation System.'
PICkit_2 Program:
Verification Successfull.
Waiting for PICkit 2 to reset...
PICkit_2 Program Message:
'PICkit 2 not found. Check USB connections and use Tools->Check Communication to retry.
NOTE (!): This is NORMAL situation. Please, don't panic. All is OK.
Don't worry about red color of the screen message and so strange text.
You can always return your previous OS (the original OS from Microchip),
just disconnect your PICkit 2 from the PC, press and hold power button,
connect it to PC, run PICkit 2 PC program, download original file - PK2V021000.hex and program it to device.
The device becomes programmer anew.
) Yellow LED of the PICkit 2 will start to blink. This means the device runs under new OS (my program).
) Your Windos should found new USB device.
) Now you should install Microchip's USB driver. Point driver installation wizard to:
"c:\PICkit_2\www.RoboHobby.com_PICkit_2\MCHPUSB Driver\Release\pickit2genisoc.inf"
Note: Normally Windows should ask about driver installation only one time - when you connected
new USB device to the computer.
) Run PC Client for communication between PC and PICkit 2.
c:\PICkit_2\www.RoboHobby.com_PICkit_2\ConsoleCPP\console.exe
You will see it's screen:
PC Client - command line program for PICkit 2 as a demo board.
The main idea of the client program is very simple -
you press key on PC keyboard and the robot goes to predefined direction.
In reality in our example we don't have any real robot in our hands,
we just show LEDs on the PICkit 2 device. (See pictures below on this page).
==============
Select an option
[1] Get PC Client Version
[3] Summarize Instances
-----
[2] Go Backward
[4] Go Left
[6] Go Right
[8] Go Forward
[0] Quit
>>
PC client part of PC-to-PIC USB connection.
How to compile it.
Originally this code example was created for Borland C++ Builder 6.
It is really good C/C++ compiler. But it is not free.
And I will describe the way to compile the code with free GCC/GCJ open source compiler.
) Download and install MSYS (~2.8Mb)
(!)It is supposed that it will be installed to 'c:\msys\1.0'
If you want to know more details about this open source project,
see: 'MinGW - Minimalist GNU for Windows'
After the installation the icon of MSYS software should appear on your desctop:
MSYS Icon.
) Download and install GCC/GCJ for Windows (~46Mb)
If you want to know more details about this open source project,
see: 'MingW build of GCC/GCJ for Windows'
) Copy file gcc34-20040607.tar.bz2 to c:\msys\1.0\home\user\
) Unzip it to c:\msys\1.0\home\user\thisiscool-gcc:
To do this - type in MSYS command line:
tar xvfj gcc34-20040607.tar.bz2
MSYS MINGW32 window.
) Rename file
c:\msys\1.0\home\user\thisiscool-gcc\examples\Makefile
to
c:\msys\1.0\home\user\thisiscool-gcc\examples\Makefile_old
) Copy file 'Makefile' from c:\PICkit_2\www.RoboHobby.com_PICkit_2\Makefile
to
c:\msys\1.0\home\user\thisiscool-gcc\examples\Makefile
) Copy directory 'c:\PICkit_2\www.RoboHobby.com_PICkit_2\ConsoleCPP'
to directory 'c:\msys\1.0\home\user\thisiscool-gcc34\examples\ConsoleCPP'.
) Delete file c:\msys\1.0\home\user\thisiscool-gcc\examples\ConsoleCPP\console.exe
(old version of our USB client program).
) In the MSYS environment go to directory 'thisiscool-gcc/examples/:
cd ./thisiscool-gcc/examples/
HINT(!): MSYS is Unix emulation, that means you can use Unix-like usefull things, for exampe,
you may type omly some first letters of the long file name, and then press 'Tab' key, in our case:
cd ./t <TAB>
and you will see all the name 'thisiscool-gcc'.
Then you can type 'e and you will see 'examples'.
One more hint: instead of DOS command 'dir, you can use 'ls' command (or ls with some options. I like to use 'ls -l')
) Run compilation - type word 'make' in the command line of MSYS program:
MSYS make console application.
) Normally you will see new EXE file 'console.exe' and you can run it.
c:\msys\1.0\home\user\thisiscool-gcc\examples\ConsoleCPP\console.exe
Note: Always delete old version of console.exe before re-compilation.
break;
case GO_BACKWARD:
PORTB = 0x32;
PORTC = 0;
dataPacket._byte[2] = dataPacket.CMD;
dataPacket._byte[3] = 1; //Just to say to PC 'Operation was OK'
counter= 0x04;
break;
case GO_LEFT:
PORTB = 0;
PORTC = 0;
dataPacket._byte[2] = dataPacket.CMD;
dataPacket._byte[3] = 1; //Just to say to PC 'Operation was OK'
counter= 0x04;
break;
case GO_RIGHT:
PORTB = 0x32;
PORTC = 1;
dataPacket._byte[2] = dataPacket.CMD;
dataPacket._byte[3] = 1; //Just to say to PC 'Operation was OK'
counter= 0x04;
break;
case GO_FORWARD:
PORTB = 0;
PORTC = 1;
dataPacket._byte[2] = dataPacket.CMD;
dataPacket._byte[3] = 1; //Just to say to PC 'Operation was OK'
counter= 0x04;
break;
case RESET:
Reset();
break;
default:
break;
}//end switch()
if(counter != 0)
{
if(!mUSBGenTxIsBusy())
USBGenWrite((byte*)&dataPacket,counter);
}//end if
}//end if
}//end ServiceRequests
PICkit_2 Debug Express - Both LEDs.
Means - Robot Command 'Go Forward'.
PICkit_2 Debug Express - Red LED.
Means - Robot Command 'Go Right'.
TO BE CONTINUED...
Next topics:
Comparison of several C compilers for PIC processors.
Is it possible to write C programs for PIC16F628, using soft from the box of PICkit 2?
Is it posible to use Java language for programming PIC microchips?
How to made your own USB device, based on PIC18F4550.
--------------------------------------------
List of devices, supported by PICkit 2:
* Indicates new parts supported with v1.40 of the device file.
+ Indicates parts that require 4.75V minimum VDD for programming.
PICkit 2 may not be able to generate sufficiently high VDD,
so an external 5.0v power supply may be required.
# indicates Midrange parts that support low Vdd programming
Serial EEPROM Devices
---------------------
NOTE: Other supported voltage grades are listed in paratheses
next to the device. Select the "LC" part number to program
these other voltage grades.