PIC Microcontrollers

Latest News:
Added new Logic Analyzer 2 project which uses CPLDs plus a PIC to sample 24 channels at up to 30ns/sample.
Updated Cheap Logic Analyzer to use10K pull-down resistors instead of PIC's 4.5V internal weak pull-ups so that it can be safely used with 3.3V logic.
Fixed bug with SD Card Interface so that FsSeek works correctly with writes so that cache line is marked dirty.
Added another cheaper USB to TTL interface to Cheap Logic Analyzer schematic.

Development Tools:


All Projects:
SourceBoost Plugins
Library of C Routines
Serial Port PIC Programmer
Serial Port PIC Boot Programmer
Digital Clock
Funky Digital Clock
Lego Robot Controller
LCD Terminal
Cheap Logic Analyzer
Temperature Logger
Camera Controller
Cassette Interface
1976 Popular Electronics COSMAC Elf Clone
Duck House Controller
Touch Screen Keypad
SD Card Interface
Logic Analyzer 2

SourceBoost Plugins:
Description Plugin V6 Example V6 Plugin V7 Example V7
Active Low push buttons BoostDigIO.zip CButtonTest.zip

4 Channel Pulse Width Modulation monitor BoostPWM.zip CPWMTest.zip BoostPWM7.zip CPWMTest7.zip
Value Change Dump (VCD) sampler.  This plug in allows all the ports (A through E)  of a PIC to be sampled into a file during simulation.  This file is formated to allow it to be read by ECAD tools in order to display a graphical representation of the signals over the length of the simulation.  For a VCD viewer, click this link to get one I wrote a few years back:  VcdView




Library of C Routines:
Library of C routines: CBLib.zip
This zip file contains the following files:
clock.c clock.h
clock18F.c clock18F.h
Code to implement a real-time clock plus functions to perform math on time in day, hour, minute, second format.  This code also includes the ability to trim the clock to make up for crystal errors.  I've tuned to a 1 second error ever 3 or 4 days.  Without triming, the error can be as high as 10 to 20 seconds per day.  Most crystals are accurate but have a fixed error from their stamped frequency of 20 parts per million.  Do the math.  It is a big error when being used as a clock.
ExtEeprom.c ExtEeprom.h  Code to interface to an external serial EEPROM.  Just change the defines at the top of ExtEeprom.c to use any two pins for the interface.
Lcd2Line.c Lcd2Line.h Code to interface to a 2 line by 16 character LCD module using 6 pins.
Lcd.h Header file for interfacing to a the serial 4 line by 20 character LCD terminal.
legocore.c legocore.h Code to implement PWM conrtrol and direction of 4 motors as well as sampling 8 analog channels.  This code is used for the Lego Robot Controller project.
Serial.c Serial.h
Serial18F.c Serial18F.h
Code to implement RS-232 interface using PIC hardware.
String.c String.h Code to implement a limited version of sprintf (sprintf1, sprintf2 .. sprintfx)
Timer.c Timer.h
Timer18F.c Timer18F.h
Code to implement delays using hardware timers and interrupts
Serial Port PIC Programmer:
Just get a PICkit 2 or PICkit 3 to program devices.

Click on picture for larger view
PC side Code: picprog.zip (Source code:  HostPicProg.zip   Lib Code:  common.zip)
PIC project: SerialProg.zip (just the source serprog.asm )
Schematic: PicProgrammer.jpg
Device: 16F84A or 16F628
This project allows flash based PIC microcontrollers to be programmed using the serial port on a PC.  The serial interface runs at 115K baud.  I found parallel port connection solutions to be flaky and dependent on which PC/OS was used so I made my own.  The only bummer is that you need to program a 16F84A to build this programmer.  Only locations that need to be modified are programmed to limit the erase/program cycles and speed up programming.

This updated version now supports 16F87xA as well as the non A versions.

Serial Port PIC Boot Programmer:
PC side Code: PicBootProg.zip (Source code:  PicBootProgSource.zip  [V 2.0 11-22-2010])
Lib Code: common.zip
18F PIC project: BootLoader_18F.zip (just the source Bootload_18F.asm )  [11-18-2013]
16F PIC project: BootLoader.zip (just the source bootload.asm )  [9-22-2008]
Schematic: None.  Just software
16F Devices:  16F87x and 16F87xA and 16LF versions
18F Devices:  18F1230, 18F1330, 18F2620 and 18F4620
This project allows flash based PIC microcontrollers to be programmed using a simple in circuit serial interface once the device has been programmed with the code supplied.  The RS-232 interface needs to be connected to the standard RS-232 pins of the device PORTC[TX] and PORTC[RX].  In addition to this connection, PORTC[2] is used to select, at power up, whether to run the user program (low) or to run the boot loader code (high).  The 16F device must be running with a 20MHz crystal but other frequencies could be used with a slight modification to the baud rate value in the boot loader.  The serial transfer rate is 115K baud.  Slower frequencies may require the baud rate to be reduced which would require the PC code to change as well.  The 18F devices require a 10 MHz crystal with the PLL enabled (40 MHz operation).  Refer to the assembler code to figure out which pin is the boot pin.  Also supports internal OSC with PLL enabled (32 MHz operation).

Note that the last 256 words or less of program memory are used by the boot loader depending on the device.  The first 4 word locations of the user program can be used as they are copied into the bootloader space by the loader while it then puts a jump into the first few locations.

This bootloader works with code produced from BoostC for both the 16F and 18F devices.

Digital Clock:

Click on picture for larger view
PIC project: Clock.zip (just the source clock.asm )
Schematic: Clock.jpg
Device: 16F84A
This project uses a 3 and a half digit 7-segment LED display from a broken bread machine to show the time of day.  The non-resetable TRM0 timer (if it is reset time drifts)  is used to generate interrupts at a rate of 610 and 45/128 Hz using a 20 MHz crystal (488 and 9/32 Hz using a 4 MHz crystal).  This is the display refresh rate.  The interrupts are counted to get seconds, minutes and hours using some games to implement the fractions.  The time is set using two push button switches that are scanned using the digit drive enables and sampled using a free input pin.  This circuit consumes less than 20mA at 5V using a 20 MHz crystal.
Funky Digital Clock:

Click on picture for larger view
PIC project: FunkyClock.zip (just the source funkyclk.asm )
Schematic: FunkyClock.jpg
Device: 16F84A
This project uses the same circuit as the Digital Clock but  runs at 4 MHz and uses different software to add some visual effects.  The time is displayed for a random amount of time followed by one of several effects for a random amount of time.  This loop is repeated.

The stand is made from the metal brackets of a file folder.

Lego Robot Controller:

Click on pictures for larger view
LCD Terminal:

Click on pictures for larger view
Cheap Logic Analyzer:

Old Version
New Version
New Voltmeter mode
Click on images for larger versions

My other logic analyzers

Very Old:  CDP1802CD CMOS processor built in 1985 using 1970's Technology
More features: CPLD based 32K sample, 24 channel with 33.33 MHz sampling rate

Latest Version

Old Version
Camera Controller:

Click on pictures for larger view
Cassette Interface:

Clone of 1976 Popular Electronics COSMAC Elf using two PICs:
Device: 18F4620 to emulate CDP1802 processor and 18F2620 to emulate CDP1861 video chip.
This is a bus accurate full speed Elf created without an 1802 or 1861.  This project is able to load a programs via dip switches (and now a hex keypad) and execute it.  More details can be found here ElfClone.
Duck House Controller:
Display on outside of the duck house
Controller inside the duck house
The boys outside their house in their run. That is not the house they sleep in at night.  Their house is 8x10 feet.
 Temperature log display after samples have been collected
PIC project for Controller: CBDuckHouse.zip (just the source CBDuckHouse.c ) (V1.0 3-10-2011)
PIC project for Display: CBDuckDisp.zip (just the source CBDuckDisp.c ) (V1.0 12-21-2010)
Schematic:  DuckHouse.pdf
Device: 18F4620 for controller and 16F628 for display (source compiled with SourceBoost C compiler).  Also uses two TC77 serial temperature sensors.
Host Code to download and display temperature data: TempLog.zip
This project is used to log temperature inside and outside our duck house.  The project also includes a numeric 2 digit LED display which is controlled by a synchronous serial interface to display the inside temperature so that it can be seen from the house using a spotting scope.  The samples and time are saved into the flash memory of the 18F4620.  The Host code connects to the controller via RS-232 and is able to set the current time and sampling rate.  The host code is able to download samples and clear memory after the sample have been recorded.  In the display above, the purple wave shows the outside temperatures and the white wave shows the inside temperatures.
Touch Screen Keypad:

SD Card Interface:
Logic Analyzer 2:

Device: 18F2620 Xilinx XC9572XL CPLDs.
Details can be found on the Xilinx page here or click the picture above.
Other Logic Analyzers: Very old   Very simple and cheap

This project uses a couple XC9572XL 5V tolerant CPLDs, some static RAM, a PIC microcontroller and some glue logic to form a 24 channel 32K deep 30ns per sample logic analyzer.  The sampling rate can be varied from 30ns to 250us and can also be controlled by an external clock with selectable delays and dividers.  The machine also has 3 primitive 0 to 5 volt meters and has a 5V TTL compatible programmable clock generator which can go from 100 Hz to 2.5 MHz.

More details can be found on the Xilinx page here.

Last Updated April 4th, 2014
Send Comments