Microchip PIC


  • 12-08-2022: Added 3D wireframe graphics via OpenGL and GLUT to display on OLED display. Also updated XCLib.

  • 11-25-2022: Updated Serial Boot Loader project to support 18F27Q10 (128K device) and ported the 18F assembler code to use pic-as instead of MPASM which was more difficult that it should have been.

  • 11-08-2022: Add Configurable Logic Cell (CLC) complier. With this tool it is now possible to configure the CLCs with a Verilog like hardware description language and integrate it into you PIC projects.

  • 3-24-2022: Added some projects:

    • A project to make a 1 hour timer using an 8 bit PIC and push button

    • A project to control our home furnace using wireless battery powered remote temperature sensors.

    • Updated all projects that use I2C to now use the bit bang functions in XCLib.


Send email to ted_rossin at yahoo

Note: When downloading files, click the circled icon at the top of the new page to retrieve the file.

Development Tools

  • Microchip website that has a nice (and free) development environment www.microchip.com (MPLAB X IDE)

  • SourceBoost Technologies www.sourceboost.com/home.html offers a free limited code size C compiler with a very low cost upgrade policy for a unlimited memory size which support the 16 and 18 series processors. They also offer a Basic and C++ compiler. The simulation/debug environment is very good. Code generation is much better than the free version from Microchip. SourceBoost now offers a new free version that is 95% compatable and has no code size limits but I have not tried it yet. It may work on some of the older projects which use SourceBoost for the compiler.



3D Wireframe graphics with OpenGL and GLUT

Projects: OLED3d.zip (V1.0 12-07-2022) also need XCLib

Devices: 18F26K40, 18F26Q10 and dsPIC33EP512MC202

Schematic: OLED 8 bit PIC.pdf OLED dsPIC.pdf (V1.0: 12-07-2022)

This project implements a 3D graphics pipeline with 3D clipping and perspective transforms for performing animations using the OpenGL API. Four projects are included which use GLUT to draw basic shapes and to control refreshing the display. The same exact source code runs on Windows so it is possible to develop on Windows and then copy to a PIC project and see the same result (although much slower).

The code was originally developed on the Raspberry Pi PICO ($4) and runs much faster but I thought I would give it a try on the 8 and 16 bit PIC devices. The dsPIC does pretty well but is a slow poke compared to the PICO. The code is adjusted for the speed of the device to try to get them to run a bit faster but not too fast as to make the animation jumpy.

Configurable Logic Cell (CLC) Compiler

Tool: ClcCompTool.zip (V1.0 11-08-2022)

Projects: ClcProjectExamples.zip (V1.0 11-08-2022) also need XCLib


16F15313, 16F15323, 16F15324, 16F15344

18F26Q10, 18F27Q10, 18F45Q10, 18F46Q10, 18F47Q10

Documentation: CompClc.pdf (V1.0: 11-07-2022)

The CLC compiler allows the CLCs in PIC devices to be set up using a hardware descriptive language which maps equations and simple functions into the available logic.

The ClcProjectExamples.zip file contains the following projects:


This project targets a 14 pin 16F15324 to combine 16 logic functions into a single project using 14 Clc source files. The main program reads a 4 bit bus at power up to select one of 16 functions (gates, counters, flip-flops ..) and configures the CLC resources then enters sleep. The chip will then continue to implement the desired function. This becomes a handy logic gate replacement chip.


This project targets a 28 pin 18F27Q10 to combine 16 logic functions into a single project using 14 Clc source files. The main program reads a 4 bit bus at power up to select one of 16 functions and configures the CLC resources then enters sleep. The chip will then continue to implement the desired function. This becomes a handy logic gate replacement chip.

ClcEnableFlop6: Using a 18F27Q10 to make a 6 bit D flip-flop with enable (implemented with JK flip-flops)

ClcShiftReg4: Using a 16F15313 to make a 4 bit shift register in an 8 pin package.

ClcSwFlag2: Using a 16F15324 to demonstrate PIC control of the CLCs using the CLC compilers software flags.

ClcToggleCounter6: Using a 18F27Q10 to make a 6 bit counter with enable and terminal count output so that it can be cascaded.

Below is example input to the CLC compiler which will create a counter that operates in 4 modes (0=reset, 1=count up, 2=count down and 3=hold count). The magic truth table values are explained in the CompClc.pdf document under the description of the logic module.

#include "clc16F15324.h"



#define Q1 CLC2

#define Q0 CLC1

module ClcCounter();

assign MODE1 = RA5;

assign MODE0 = RA4;

assign RC1 = Q1;

assign RC0 = Q0;

assign Q1 = logicflop(.d(MODE1),.c(MODE0),.b(Q1),.a(Q0)


,.truth_table(0xc960)); // D1

assign Q0 = logicflop(.d(MODE1),.c(MODE0),.b(Q1),.a(Q0)


,.truth_table(0xa550)); // D0


Remote Temperature/Humidity Sensor

Project: RemoteTempHum.X.zip (V1.0 3-10-2022) also need XCLib

Device: 18F26K40, Si7021, nRF24L01, 128x64 I2C OLED display

Schematic: RemoteTempHum.pdf (V1.0: 3-24-2022)

3D Printer Files: RemoteTemp3Dprint.zip (V1.0 3-24-2022) No supports are needed if printed on its face. 2mm screws are used to mount all the boards and modules.

Server Project: NodeMCU(ESP8266) page

This project uses an Si7210 temperature and humidity sensor along with an 128x64 I2C OLED display to transmit room information to a server via an nRF24L10 radio link running on two AA batteries. The nRF24L01 radios are amazing devices which allow up to 6 devices to transmit to a single device over virtual pipes and include automatic handshaking to make sure that transmissions are properly transmitted. The code in the PIC wakes the sensor and radio up every 30 seconds to transmit the temperature and humidity to the server. The display is powered up if a button is pushed and once awake allows the min and max temperature to be set as well as display the current readings.

The system acts as a room thermostat. The server side of this project is an ESP8266 which controls relays to turn on or force off a furnace as well as display a web page showing the temperature and humidity as well as the furnace power over the last 24 hours.

Power Control

Project: PowerControl.X.zip (V1.0 2-18-2022) also need XCLib

Device: 16LF15313

Schematic: PowerControl.pdf (V1.0: 2-19-2022)

This project is just is little one hour timer for some LED lights which run on two AA batteries. Construction is crude in that I just glued the PIC and a switch to the battery holder and soldered wires to the pins.

Rowing Machine Counter


Opto-interrupter holder

Project: RowingCounter.X.zip (V1.1 11-02-2021 to 2-15-2022) also need XCLib

Device: 16LF15313

Schematic: RowingCounter.pdf (V1.0: 11-11-2021)

3D printed parts: RowingCounter3Dparts.zip (V1.0 10-16-2021)

This project uses a 128x64 OLED display, a switch, a resistor an opto-interrupter and a little 8 pin PIC to create a counter/timer for an old rowing machine. The counter runs of two AA batteries and powers down after 5 minutes of non-use. The button is used to wake the PIC and also to clear the count and time. The timer starts when the first stroke is detected. The 3D printed parts were designed in Fusion 360 and printed on a Lulzbot Mini.

This little PIC only has 256 bytes of RAM and a small amount of flash memory so I hacked my OLED code in XCLib to just have large font digits and removed all the graphics code (Tiny version). Also, instead of using the frame buffer technique (which requires 1KB of RAM), it draw directly to the display.

I developed the code on a 2011 MacBook Air to see if I could use if for something useful since it can only run High Sierra. I found that I had to go back to MPLAB X v5.30 to get a stable development environment.

Digital Picture Frame in Retro TV Case

dsPIC33 and 18F26K40 PIC project: TftPicFrame.X.zip (V1.2 11-11-2021) also need XCLib

Device: dsPIC33EP512MC202 or 18F26K40

PC Code: CreateLcdGui for layout and code generation and ImgCrop for processing the images.

Schematic: TftSpiDsPICDisplay.pdf (SPI dsPIC V1.01: 10-08-2021)

TftDisplay.pdf (Parallel V1.00: 5-23-2021)

3D printed parts: DigiPicFrame3Dparts.zip (V1.0 10-16-2021)

This project uses an SPI 2.8 inch TFT display, a dsPIC, a 3.3V regulator and some resistors and caps to make a digital picture frame that reads images from an SD card. This final version uses a dsPIC and the SPI display while the project files and schematics also work for the 18F26K40 and parallel display (5V design).

The SD card is read and a list of directories is created that is displayed in a list box so that one or more directories can be displayed randomly. The code also allows the current time to be set as well as a wake up and sleep time to turn the display on and off. The user interface was created using CreateLcdGui. The layout file is included in the PIC project zip file.

No PC board was used. Instead, the PIC was glued to the back of the display and just wired to the pins of the display with wire wrap wire (28 gauge) using solder. The board is then screwed into the 3D printed case. The antenna was made with 70mm lengths of garden edging spikes. The antenna mount and legs for the TV case are just glued to the main case (the back is screwed on using M2.5 screws). The channel knobs are beads that are glued onto the face. The 3D printed parts were designed in Fusion 360.

dsPIC Virtual EEPROM

dsPIC33 PIC project: dsPICeeprom2.X.zip (V1.0 8-17-2021) also need XCLib

DsPIC Devices: dsPIC33EV256GM002, dsPIC33EP512MC202

This little project uses veeprom.c and veeprom.h (now included in XCLib) to implement a virtual EEPROM in flash memory with enhanced endurance compared to just using flash memory. The algorithm used is based on the one in AN1095 provided by Microchip. The code allows up to 256 32-bit words to be used. The less number of different address that are used, the greater the number of writes that can be performed before the flash memory fails.

I tried using the Microchip code but it did not work and after repairing it, I found that it required the large memory model to work so I wrote my own. The example project above allows EEPROM to be written, read and tested with a random test generator that includes a checker. I've tested it with a half million random writes (address and data) on both the EV and EP processors that I have with no problems found.

TFT Touchscreen Fun

Create LCD GUI editor

Running on TFT display

Click on pictures for larger views

PIC projects: TftFun.zip (Version 0.5: 11-11-2021) also need XCLib

Docs: LcdGui.pdf (8-27-2021 Describes usage and examples)

PC Code: CreateLcdGui for layout and code generation and ImgCrop for TftPicFrame.

Schematics: TftDisplay.pdf (Parallel Version 1.00: 5-23-2021)

TftSpiDisplay.pdf (SPI Version 1.00: 7-29-2021)

TftSpiDsPICDisplay.pdf (SPI dsPIC 1.01: 10-08-2021)

Devices: 18F26K40 or dsPIC33EP512MC202 and ELEGOO UNO R3 2.8 Inches TFT Touch display with ILI9341 controller chip (8 bit parallel or SPI interface). The SPI version has this name: WayinTop ILI9341 2.8" SPI TFT LCD Display Touch Panel 240X320 with SD Card Socket 5V/3.3V

This is a collection of example projects that use the TftGraphics library found in the Library of C Routines (XCLib) to run on a cheap display ($15 at Amazon [search for ELEGOO UNO R3 2.8 Inches TFT Touch] ). Also, a few examples are included that demonstrate the GUI creation tool named CreateLcdGui listed above next the the label PC Code.


Draws random 2D graphics on the screen as fast as possible with no GUI.


Simple example of a Graphical User Interface created with the tools and library.


More complicated example of the GUI with five screens, animation, a drawing example and list box. This project was used to develop the code.


Simple digital picture frame which reads images from an SD card (slot is included on the TFT display) and displays them. Picture period and times to turn on and off are controlled using GUI objects. The SD card code is included in XCLib.

Hanging Robot Machine (Motor Controller)

Quad Motor Controller

Worm Drive Motor

Animation Tool (ServoCnt)

The robots I use are RB v2.0 by Witchtail on Thingiverse

Click on pictures for larger views

PIC project: MotorControl.X.zip (Version 0.1: 7-12-2020) XCLib

PC side Code: ServoCnt.zip (Version 1.00: 7-12-2020)

Schematic: HangingRobotMach.pdf (Version 1.00: 5-05-2020)

3D Printed Parts: HangingRobot3DPrints.zip (Version 1.00 6-20-2020)

Device: 18F26K40

This project is made up of quad motor controllers that are chained together to form an eight channel system that is used to raise and lower little 3D printed robots to create motion. The PIC processor selected for this project has two UARTs so they are used to form a simple serially connected network where commands are preceded with a node ID or a global ID to send the same command to all devices in the chain. I have test the code with 4 devices and it seems to work well.

The motors are housed in 3D printed motor boxes with worm gear drive along with a quadrature encoder wheel with optical interrupters for relative position feedback. The PIC processor implements Bezier spline interpolation to create the set point for a PID control loop which takes the current position from the quadrature encoder and then outputs PWM control signals to the motors.

An editor is provided (ServoCnt) that can be used to create the position curves of each robot that is hanging from its corresponding motor drive. This editor is then used to communicate to the controller boards to play the animation. ServoCnt also works with the Robot Arm (Servo Controller) project.

16 bit dsPIC based Cheap Logic Analyzer

Host Code (click for larger image)

Breadboard and Final Versions

(click for larger version)

PIC project: CheapLA_DsPIC.X.zip (Version 17.07: 1-05-2022)

PC side Code: LogicAnalyzer16.zip (Version 1.09: 1-05-2022)

Schematic: DsPICCheapLogicA.pdf (Version 1.03: 3-12-2021)

3D Printed Case: dsPIC_LAcase.zip (STL and Fusion 360 source)

Device: 3.3V dsPIC33EP512MC202-I/SP (28 pin SDIP that can go into a solderless breadboard)

My other logic analyzers

Very Old: CDP1802CD CMOS processor built in 1985 using 1970's Technology

8-bit version: See this page

More features: CPLD based 32K sample, 24 channel with 30ns/sample sampling rate

This is a cheap logic analyzer that can be built for about $12 and works with 3.3 and 5V logic. The hardware is a dsPIC33EP512MC202 with 10 MHz crystal and a Silicon Labs USB to 3.3V TTL board (available at Amazon.com for about $5). A TTL OR gate (74AS32) is used to work around a UART pin configuration issue to get at all 16 bits.

There is 1 analog input that can be used as volt meter that can be displayed on the screen in real-time. Also, there is a clock generator that can make frequencies from 12KHz to 20.0MHz. The clock generator shares input bit 8 so a channel is lost in 16 channel mode when the clock generator is enabled.

The fastest sampling speed of 25ns is created by overclocking and changing the PLL divider to run the dsPIC at 80.0MHz. The next fastest speed of 30ns is implemented with the dsPIC running in spec at 66.667MHz. All other sampling rates are just multiples of 50ns using a 60.0MHz instruction rate. It takes two instruction cycles to sample PORTB and save to internal RAM because reading a port takes two cycles.

Since all silicon is not guaranteed to run above 70 MInst/sec, the host code warns about using 25ns and describes how to recover if things go bad. All the nagging can be disabled in the dialog boxes.


  • 16 channel 24,562 samples with 25ns/sample to 250us/sample
  • 8 channel 49,124 samples with 25ns/sample to 250us/sample
  • 4 channel 98,248 samples with 150ns/sample to 250us/sample
  • 2 channel 196,496 samples with 150ns/sample to 250us/sample
  • 1 channel 392,992 samples with 150ns/sample to 250us/sample

Serial Port PIC Boot Programmer

PC side Code: PicBootProg.zip [V 2.14 11-23-2022])

dsPIC33 PIC project: BootLoader_dsPIC.X.zip [V4.0 1-09-2021]

18F PIC project: BootLoader_18F.X.zip [11-23-2022]

16F PIC project: BootLoader.zip (just the source bootload.asm ) [9-22-2008]

16F Devices: 16F87x and 16F87xA and 16LF versions

18F Devices: 18F1230, 18F1330, 18F2620, 18F4620, 18F26K40 and 18F27Q10

DsPIC Devices: dsPIC33EV256GM002, dsPIC33EP512MC202

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 serial interface needs to be connected to the standard UART 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) or use the internal oscillator. Refer to the assembler code to figure out which pin is the boot pin. Also supports internal OSC with PLL enabled (32/64 MHz operation).

Note that the last 512 words or less of program memory are used by the boot loader depending on the device. The first 2 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 and XC8 for both the 16F and 18F devices. To use XC8, you have to prevent the linker from loading into the last few hundred locations (384 or 512):

      • Select Production, then Set Project Configuration then Customize ... Then, select XC8 Global Options, then XC8 Linker then change the Option Category to Memory Model. Click on the box next to ROM Ranges and enter -fe80-ffff

For dsPIC, there is no special settings required for XC16 as all the boot code sits at the end of memory and by default, memory is filled from low addresses to high addresses. RA[3] is the boot mode pin. If left floating or pulled low, the chip will run the loaded application. If RA[3] is pulled high (3.3V or 5V depending on device), it will enter the boot mode and allow memory to be downloaded or verified.

SD Cassette Interface

PIC project: SDCassetteInt.X.zip XCLib.zip is also needed (just the source SDCassetteInt.c) (Version 1.02: 7-17-2020 to 2-16-2022).

Schematic: SDCassetteInt.pdf (Version 1.01: 11-11-2020 to 12-17-2021)

3D Printed Case: CassetteIntCase.zip (Fusion 360 source and STL files)

Device: 18F26K40

Tools: WaveToHex.zip

This is a redesign of the Cassette Interface project so that it does not require being tied to a modern computer. Programs can be saved or loaded to the SD card via audio connectors from the target machines. The 1976 Popular Electronics COSMAC Elf, TRS80 Color Computer, Commodore 64 and Timex/Sinclair 1000 are supported. The WaveToHex tool can be used to translate cassette tape archives in Wav,TAP or P format. I found lots of TRS80 color computer games here (colorcomputerarchive.com) and lots of Commodore 64 games here (Ultimate Tape Archive).

Lots of real-time processing and FIFO management going on in the code. The PIC needs to deal with the random delays of the SD card (both read and write due to sector caching) but also needs to prevent gaps in sending out data and not losing receive data.

For the Commodore 64, I created a custom cable to remove the dataset cassette tape player. This required a 10 pin edge connector, some wire and a little circuit (transistor and a resistor) to deal with the 9V motor on signal. I placed the transistor and resistor inside the cable.

Commodore 64 Joystick/Paddle replacement

PIC project: JoyStick.X.zip (Version 1.00: 10-28-2020).

Schematic: Not yet. (The paddle is 470K. X is AN1 while Y is AN0)

3D Printed Case: JoyStick3DPrints.zip (Fusion 360 source and STL files)

Device: 16F628 (just glued on its back to case bottom)

This is a little hack to convert an analog joystick into a digital joystick for the C64. I also added a potentiometer for games that use the paddle. I used an old PIC processor I had laying around. The code is just using two analog channels into two comparators to drive 4 outputs faking open collector (open drain) signals to look like buttons are pressed if the voltage is above or below the midpoint voltage.

Here is the code minus the config bits:

#include <xc.h>
void main() { TRISA = 0x03; TRISB = 0x00; // Voltage reference takes 10us to settle when changing value VRCON = 0x81; // Enable voltage reference mode 0 Vref=(0.25+VRCON[3:0]/32)*VDD // 0x81 = (0.25+1/32)*5V=1.4V, 0x8f = (0.25+15/32)*5V = 3.6V // comparator takes 400ns to respond CMCON = 0x02; // Two comparators using RA[0] and RA[1] and voltage reference PORTB = 0; while(1){ VRCON = 0x81; // Check low voltage _delay(20); // Delay 20 instructions or 20us if(CMCONbits.C1OUT) TRISBbits.TRISB0=0; else TRISBbits.TRISB0=1; if(CMCONbits.C2OUT) TRISBbits.TRISB2=0; else TRISBbits.TRISB2=1; VRCON = 0x8f; // Check high voltage _delay(20); // Delay 20 instructions or 20us if(CMCONbits.C1OUT) TRISBbits.TRISB1=1; else TRISBbits.TRISB1=0; if(CMCONbits.C2OUT) TRISBbits.TRISB3=1; else TRISBbits.TRISB3=0; }}

8-bit Cheap Logic Analyzer

Old Version

New Version

Voltmeter mode

Click on images for larger views

PIC project: CheapLA_18F.X.zip (just the source CheapLA_18F.asm ) (Version 5.00: 11-01-2020)

PC side Code: LogicAnalyzer8.zip (Version 3.08: 12-15-2020)

Schematic: CheapLogicA.pdf (Version 2.04: 9-26-2020)

3D Printed Case: CheapLACase.zip

Device: 18F26K40 or 18F2620

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 30ns/sample sampling rate

This is a very cheap logic analyzer that can be built for about $10 and works with 3.3V to 5V logic. The hardware is simply an 18F26K40 with 16 MHz crystal or an 18F2620 with 10 MHz crystal and an FTDI USB to 5V TTL cable (available at Sparkfun.com for about $18) or Silicon Labs USB to 3.3V TTL board (available at Amazon.com for about $5). The specs are not great but it can be used to solve many problems. I found it very useful for debugging an antique computer as well as serial interfaces (I2C).

There are 5 analog inputs that can be used as volt meters that are displayed on the screen in real-time. With version 4.02 and above is the ability to run the serial port at 8x the normal 115K baud rate. To enable this feature, select the Configure menu then select "Enable Fast Serial". The setting will be remembered in the registry.

New to version 5.00, sample rates at 2us and longer can run in 4, 2 or 1 channel mode to get 2,4 or 8 times more samples. All 8 inputs can still be used as triggers when using the reduced channel widths. When using the 18F26K40, the fastest sampling rate is 125ns (8 Msamples/sec).

A square wave generator output allows selectable frequencies in the ranges described below. This output, if enabled, is driven on port C bit 1 (RC1).


  • 8 channel 3704 samples with 125ns/sample to 250us/sample
  • 4 channel 7408 samples with 2us/sample to 250us/sample
  • 2 channel 14,816 samples with 2us/sample to 250us/sample
  • 1 channel 29,632 samples with 2us/sample to 250us/sample
  • Clock generator range is 3.9 KHz to 5.33 MHz


  • 8 channel 3952 samples with 200ns/sample to 250us/sample
  • 4 channel 7904 samples with 2us/sample to 250us/sample
  • 2 channel 15808 samples with 2us/sample to 250us/sample
  • 1 channel 31616 samples with 2us/sample to 250us/sample
  • Clock generator range is 2.44 KHz to 2.5 MHz

The PC code has been updated to understand the two different devices and snap to edge has been added for marker movement to make time measurement a bit easier.

Old Version

PIC project: CheapLA.zip (just the source CheapLA.asm ) (Version 2.01: 12-21-2008)

PC side Code: LogicAnalyzer.zip (Version 3.05: 3-01-2014 Note that this is the same as the new version above)

Schematic: CheapLogicA.pdf

Device: 16F873, 16F873A or 16F876A

This is a very cheap logic analyzer that can be built for about $10. The hardware is simply a 16F873 with 20 MHz crystal and an RS-232 interface. The specs are not very good but it can be used to solve many problems. I found it very useful for debugging an interface to a serial EEPROM.

SD Card Interface

PIC project: SDFileSystem.X.zip XCLib.zip is also needed (V1.0 12-14-2021)

PIC project (Read only): SDFileSysReadOnly.X.zip XCLib.zip is also needed

PC side code for remote mode: SDFs.zip common.zip is also needed for serial port functions.

Schematic: SDInterface.pdf (V1.4 12-14-2021)

Device: 18F26K40, 18F2620 or dsPIC33EP512MC202

This project connects an 18F26K40, 18F2620 or dsPIC33EP512MC202 to a 3.3V SD card and is able to access FAT12, FAT16 and FAT32 file systems with long filename support. MMC, SD and SDHC cards are supported and cards from 16M bytes to 8G bytes have been tested. Both remote and local access is provided with examples of each such that the code can be used as a base layer for a project which needs the ablitiy to read and write SD cards or the code can be used as is with high level access via the serial port. The common C functions FsOpen, FsSeek, FsRead, FsWrite and FsClose are used to open a file to read or write. There are also functions to change and get the current directory name as well as to read the directory to see what files are on the card. Files and directories can be removed as well as created. The file SDFs.h has a variable defined named LOCAL_MODE. Comment this line out for remote access.

The default build is local mode which has a little application to simulate a unix command prompt via the USB to TTL port. Program up the PIC, build the circuit, insert the SD card and power up the PIC then open up a terminal to it (putty works well for this) and hit enter to get the PIC to mount the SD card. The PIC will mount the SD card and list the commands that you can enter.

      • ls will list the current directory (the attributes are listed as 3 letters drw. d is - for plain files and d for directories)

      • cd path will change the current directory to that given in path. For example: cd Zero 7/Simple Things

      • pwd will display the current directory path

      • cat filename will echo the file to the terminal window. Not a real good idea to do on binary files. For example: cat ../../TedDir/CBSDfileSystem.c

Some Info:

  • For remote mode, the Visual C++ project SDFs.zip has a file named SDLearn.cpp which implements a fake command line shell like local mode but interacts with the PIC using a serial interface.

  • Sector caching is implemented and the amount of memory allocated to it can be controlled as well as the number of open files allowed with the following defines that can be found in SDFs.c:

      • #define CACHE_SIZE 5

      • #define NUM_FD 4

  • If your application needs more RAM, reduce the CACHE_SIZE as each count uses 512 bytes of RAM. The sector cache helps out when there are multiple files open at once and also helps cache the File Allocation Table (FAT). It will also be used for a write buffer.

This has been a fun project in that I got to learn a lot about Microsoft's FAT file system and how they squeezed long filenames into a very old format.

Spooky Lights

click on pictures for larger view

PIC project (MPLAB X): HalloweenLamp.X.zip XCLib.zip is also needed (just the source HalloweenLamp.c) (V1 12-10-2019)

Schematics: SpookyLights.pdf

Device: 16LF873A

3D printed case: SpookyLightBox.zip

This is a new light controller for some blue LED ghost necklaces that I got on sale for 99 cents each at Pier One. The old controllers (little blobs with hearing aid batteries that were dead) were removed and the two stands were soldered together. The power now comes from AA rechargeable batteries and an old PIC is used to control the LEDS to make them pulse or just stay on based on the mode. A push button wakes the PIC from sleep. If just pushed once, the pulse mode will be actve. If pushed again, it will just leave the lights on. Push one more time and it will alternate every 10 seconds between the two modes. The lights go off and the PIC goes to sleep to prevent the batteries from draining after 3 hours. If you push the button after the lights have been on longer than 10 seconds, it will turn off the lights and put the PIC to sleep.

Hanging Pen Drawing Machine

PIC project (MPLAB X):

PC Side Code: DrawingMachine1.zip (V0.51 8-20-2019)

Schematics: Tethered to PC: DrawingMachineBasic.pdf or Standalone: DrawingMachine.pdf

Devices: 18F1330 and (18F26K40 or 18F2620)

3D printed parts: Drawing Machine 3D printed Files.zip

Other parts:

This project draws a picture using a pen suspended from two pull chains that are attached to two stepper motors. There are two versions of this project. One uses a single 18F1330 microcontroller and is controlled by a PC. The other replaces the PC with an 18F2620, an SD card, OLED display and rotary encoder to make a stand-alone system. The PC software can load SVG formatted files like those produced by Inkscape and either drive the drawing machine directly or create drawing files that can be stored on an SD card and drawn later without a PC.

OLED Display

PIC project (MPLAB X): OLEDdisplay.X.zip (12-10-2019 to 2-16-20220) XCLib.zip is also needed

Schematics: OLEDdisplay.pdf

Device: 18F26K40 or 18F2620

This example draws random graphics on a 128x64 pixel OLED display over an I2C interface. The custom library created uses the memory in the PIC to act as the framebuffer for clean double-buffered display updates. The performance is quite nice considering the serial interface to the display.

Servo Controller

PIC project: CBServo2.zip CBLib is also needed (just the source CBServo2.c) (V1.0 1-15-2015)

PC Side Code: ServoCnt.zip common.zip (V1.0 12-05-2015)

Schematic: ServoController.pdf (V1.0 12-08-2015)

Device: 18F1330

Another version based on the Raspberry Pi Pico can be found here.

This project is able to control 8 servos using a USB connection to a PC. The code in the PIC implements spline interpolation for smooth transitions between positions. The PC side code is a key frame animation system which allows manipulation of positions as well as the ability to tweak the spline bias controls.

This project was used with a Lynx Motion AL5D robot arm in order to control the motion of the arm.

Solar LED Light Controller


PIC project: CBBoostReg628.zip (just the source CBBoostReg628.c) (V1.0 7-01-2015)

Schematic: SolarLights.pdf (V1.0 7-07-2015)

Device: 16LF628

This project replaced the failed control circuit in a solar LED string of lights. The PIC runs down to 2.0V and makes a 4V power supply from two NiMH AA rechargeable batteries using a 100uH inductor and a bipolar transistor. The PIC also senses the solar cell voltage to turn the string on at night and off in the morning.

Power Switch

PIC project: PowerSwitch.zip (just the source PowerSwitch.asm) (V1.0 5-29-2015)

Schematic: PowerSwitch.pdf (V1.0 5-28-2015)

Device: 16LF628

This project is used to turn on and off a small load (<100 mA) attached to a battery with a momentary push button.

Wii Nunchuck Interface

PIC MPLabX project: WiiNunchuck.X.zip (XCLib.zip is also needed) (V1.02 12-17-2019 to 2-16-2022)

Device: 18F1330 or 18F26K40

PC side application plus source: WiiNunchuck.zip (V1.0 4-16-2015) Lib Code: common.zip librnf.zip

Schematic: WiiNunchuck.pdf WiiNunchuck2.pdf (18F26K40 version)

This project interfaces to a WiiNunchuck to get button and joystick position as well as orientation of the device. The PIC samples the X,Y and Z accelerometers and calculates the angle that the Nunchuck is pointing. No special hardware is used on the PIC except for two generic I/O pins (no hardware I2C peripherals are required). The PIC also performs some basic filtering to remove some jitter from the output. The USB interface is a Silicon Labs USB to 3.3V TTL board (available at Amazon.com for about $5). The interface board for the Wii Nunchuck is available from Sparkfun Electronics.

Auto Off

PIC project: CBAutoOff.zip CBLib is also needed (just the source CBAutoOff.c) (V1.0 4-23-2014)

Schematic: AutoOff.pdf (V1.0 4-05-2014)

Device: 18F1330

This project is used to turn on and off amplified speakers so that they are only on when the TV that they are hooked up to is on. The audio output from the TV is sampled to detect when the TV is on. The power is switched using a solid state relay. The project was placed in an old Radio Shack audio switch box to take advantage of the RCA jacks.

Stepper Motor Control

PIC SourceBoost project: CBStepper.zip CBLib is also needed (just the source CBStepper.c) (V1.0 7-27-2013)

PIC MPLABX project: Stepper.X.zip XCBLib is also needed (just the source Stepper.c) (V1.0 3-25-2014)

Schematic: NoneYet.pdf (V1.0 7-20-2013)

Device: 18F1330

This project independently controls three stepper motors using a cheap processor and some high voltage transistors

Logic Analyzer 2


Device: 18F2620 Xilinx XC9572XL CPLDs.

Details can be found on the Xilinx page Logic Analyzer 2 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.

Touch Screen Keypad


Click images for larger view

PIC project: CBTouchHex.zip (just the source CBTouchHex.c ) (V1.0 11-24-2011)

Schematic: TouchKeypad.pdf (V1.0 11-24-2011)

Device: 18F4620

This project implements a hex keypad using a Nintendo DS touch screen which I purchased from Sparkfun Electronics. I use this keypad to interface to a clone of my first computer which can be found here Elf Clone. The touch screen is clear so I printed out my desired virtual keypad onto a piece of paper (the Microsoft Word document is included in the zip file) and placed this under the touchscreen. To add some visual feedback, I placed an array of LEDs under this piece of paper. The LEDs are inserted into a thin piece of plywood which can be seen in the photo on the right (click it to see a larger view). I used Elmer's glue to hold the LEDs in place and hot glue to hold the PIC in place. I bent the pins out to solder it up. It is ugly but pretty stable. The case is just an old picture frame that I found which fit nearly perfectly. This could all be done on a double sided board using surface mount parts to make it very skinny. My keypad ended out being about one half inch thick.

The top four buttons as well as the DEBUG button are toggle buttons so the LED under them will toggle between on and off when the corresponding button is pressed. All the other buttons just flash the LED when they are pressed.

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

Click images for larger views

Note that the boys have moved and now have a new house and controller that can be found here: NodeMCU ESP8266

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.

Since making this project, the ducks have a new house and a new web controllable via WiFi controller. Found here: NodeMcu (ESP8266) WiFi

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 ElfCone.

Cassette Interface

Click image for larger view

PIC project: CBCassetteInt.zip (just the source CassetteInt.c ) (V1.0 1-31-2007)

PC Side Code: CassetteInt.zip common.zip

Schematic: CassetteInt.jpg (V1.0 7-16-2007)

Device: 16F876A

This project replaces a cassette recorder which was used for program and data storage for a vintage computer with a box and an RS-232 interface to a modern computer. This allows old programs and data to be saved as ASCII hex files and then later played back. The PIC processor A/D block is used to sample the REC input and convert the serial data to 8-bit binary numbers. These values are saved in RAM and then set to the modern computer via the RS-232 interface. The speaker out jack is driven out to the vintage computer in response to commands sent from the modern computer from the RS-232 interface. The timing and voltage settings have been hard wired for my first computer using constants but a slight change to the PIC code could be made to allow the values to be changed via host PC side software.

Here is a link to my first computer that uses this machine.

Camera Controller

Controller hanging below camera

Camera fitted with actuator


Inside the controller

Click on images for larger views

PIC project: CBTimelapse.zip (just the main source TimeLapse.c) (V1.0 10-25-2006)

Schematic: TimeLapse.jpg

Device: 16F876A

This project controls my old cannon S10 digital camera using a soleniod to take pictures during a specified time at a specified rate. The images are then processed to create a movie that can be played on a computer or authored onto a DVD. A serial port is included to allow the firmware to be upgraded or used for direct computer control or to allow custom time tables to be downloaded. My dream is to hook ups some stepper motors to be able to control the view as well one day.

Below are some videos I created with the camera. I used ImgConvert to convert the pictures into an MPEG (Motion Picture Experts Group) video before uploading to YouTube.

LCD Terminal

Click on images for larger views

PIC project: LcdTerminal.zip (just the source LcdTerminal.asm)

Schematic: LcdTerminal.jpg

Device: 16F628

This project controls a 20 character by 4 line LCD display so that a simple serial RS-232 or TTL interface can treat the display as an ASCII terminal. The source code explains all the control characters and escape sequences to control scrolling the display, clearing the display, downloading custom characters and other features. The interface runs at 115K baud by using a software FIFO to handle input characters during a vertical scroll. A select pin is provided that allows the interface to run at 9600 baud.


SourceBoost Project: CBMeter.zip (just the source CMeter.c )

Library of C routines: CBLib

This is a demo program that uses a 16F873 and the LCD Terminal to implement a volt meter. The CBLib.zip file is required as well as the SourceBoost C compiler. See the Lego Robot Controller below (or use the index at the top) for details.

Lego Robot Controller

Click on images for larger view

Library of C routines: Library of C can be found below (or use the index at the top of the page)

SourceBoost project 1: CBLegoBumper.zip (just the source Bumper.c)

SourceBoost project 2: CBLegoCrane.zip (just the source Crane.c)

Schematic: LegoController.jpg

Device: 16F877

This project controls Lego robots in a way similar to Lego Mindstorms. Two dual H-bridge chips(L283) are used with the PIC microcontroller to control 4 motors. Each motor has speed, direction, float and brake control. Eight A/D inputs are sampled sequentially and the motor PWM control is done in an interrupt routine so that user code can treat the inputs and outputs as continuous values.

User level control is done in C (compiled with the SourceBoost compiler). The controller is packaged with 8 Lithium-Ion AA batteries in a brick of legos using no glue or special parts. Programming is done through a RS-232 port using the Serial Port PIC Boot Programmer described below.

This is really cool stuff.

Funky Digital Clock

Click on picture for larger view

PIC project: FunkyClock.zip (just the source funkyclk.asm) (V1.0 3-28-2002)

Schematic: FunkyClock.jpg

Device: 16F84A

This project uses the same circuit as the Digital Clock below 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. The large 5V regulator below the display has been replaced with a smaller TO-92 case 78L05 regulator.

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.

Serial Port PIC Programmer

Click on picture for larger view

Just get a PICkit 2 or PICkit 3 to program devices.

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.

Library of C Routines

XC8 Library of C routines: XCLib.zip (3-11-2022)

SourceBoost Library of C routines: CBLib.zip

SourceBoost Plugins

The following plugins are for use with the SourceBoost IDE:


Opto-interrupter holder