Sample PIC Code in
Hitech C and Assembler
|
Use this sample code any way you want to. If you make major changes it's yours. If you make minor changes or none at all or just change the comments, then do the decent thing and include the appropriate credits. |
| switch.c switch.h |
6K 5K |
Keyboard management. Scan and process 6 key keyboard. The code is designed for a directly connected keypad. Key debouncing, auto-repeat after delay and LCD backlight management are included. |
| spi.c spi.h |
5K 4K |
SPI utility control methods. Makes use of the SPI hardware built into the mid-range and high-end PIC's. Revised 2mar99 due error in setup_spi() |
| serial.c serial.h |
10K 5K |
Serial communications methods. Makes use of the PIC's USART to implement interrupt driven serial communications with hardware handshaking. A simple response protocol is implemented to enable data transfer with 16 bit CRC as well as external control of the embedded system. |
| opticsw.c opticsw.h |
6K 5K |
Methods to manage two Optek Photologic switches (or equivalent). The switches are integrated into the interrupt logic to enable interval timing to a resolution of 250ns (with 16MHz clock). |
| motor.c motor.h |
5K 4K |
Methods to manage a Siemens ProFet Smart Switch. This code is tested on the BTS410E2, the application driving an electric motor. ProFets are intelligent, fully protected switching devices designed for the automotive environment and are a very suitable device for control by a PIC. |
| lcd44780.c lcd44780.h |
10K 8K |
Manage a character based LCD which uses a HD44780 or equivalent controller in 4 bit data bus mode. The header has macros allowing selection of display type (lines and characters per line) as well as backlight type. The methods implement the verbose initialisation as specified by Hitachi, which ensures that the display always starts. Cursor management is also implemented. |
| int.c | 7K | Interrupt service routines required to support the sample code on this page. |
| delays.c delays.h |
5K 4K |
General purpose delays and macros for PIC's running with 8 and 16MHz clocks. Why? 16MHz divides nicely for timing duties. 8MHz is for development because the ME02 chips used in the emulators could only run to about 10MHz. |
| commdefs.h | 9K | Common PIC macros not defined in supplied header files. |
| buzzer.c buzzer.h |
1K 5K |
Buzzer control. Interrupt driven control methods for a self oscillating buzzer, allowing the buzzer to be started and control returned to the program. The interrupt service routines will manage the buzzer thereafter. |
| 25cxxspi.c 25cxxspi.h |
6K 5K |
Manage an SPI serial EEPROM. Methods are included to read, write, and initialise the eeprom as well as some utility methods to read and write strings and double precision floating point numbers. |
| 1306spi.c 1306spi.h |
8K 5K |
Manage the Dallas DS1306 SPI RTC. Read and write the date/time registers with legal date/time validation. Read and write the NVRAM user area with double precision floating point numbers. |
| main.c main.h |
13K 8K |
A stripped down main application module for use with the support modules presented on this page. Useful to demonstrate how the support modules are used and how their methods are called. |
| boom.c boom.h |
7K 5K |
Professional display boomerang lighting controller. This application demonstrates the technique of driving a lighting sequence from a lookup table. The hardware is the PIC 12C508/9 and the method of wake-up on key press is also demonstrated. In fact, the controller has no power switch and is woken from sleep mode whenever a sequence is to be displayed. Written in C, the compiled code is just 214 bytes of executable and 205 bytes for the table. |
| rcswitch.c rcswitch.h |
5K 3K |
Power switch for radio control systems. The hardware consists of a PIC 12C508 and a Siemens ProFet smart power switch. This application demonstrates real time pulse width measurement using embedded assembler while the C code takes care of the program logic and other basic hack jobs. |
| pwmeter.asm e16f84.inc e16c84.inc |
45K 6K 6K |
Servo pulse width meter for radio control systems. Everyone has to start somewhere.
This was my first PIC program, developed in order to learn how to program PIC's. The hardware consists of a PIC16C84,
a crystal, two capacitors, a resistor and three switches. The meter will measure the pulse width and frame width
of servo control pulses to an accuracy of 1µs. If no pulses exist, then the meter automatically becomes a
servo pulse generator. The user interface is just three switches and a 2 line x 16 character liquid crystal display.
The application demonstrates numerous techniques including fast, high resolution pulse width measurement using
interrupts. Pulse width meter specifications and description Sample membrane front panel design 19K |
| mixer.asm e16f84.inc mixer.pdf |
17K 6K 147K |
Servo mixer for radio control systems. Microprocessor based mixer for older
style ppm receivers. Uses only three components and resolves to 1µs (better than 10 bits or one part in 1024).
Designed for home construction, the mixer is supplied with complete engineering drawings and program source code. Schematic in Protel format 5K PCB in Protel format 44K Details and pricing Note: Do not confuse this design with the multitude of other PIC based mixers available. If you cannot resolve and generate pulse widths to better than 2µs then it is not worth the trouble of designing. This is the resolution of all of the medium to high quality radio systems. |
| expdiff.asm e16f84.inc |
19K 6K |
Servo exponential/differential rate generator for radio control systems. Microprocessor based servo rate generator for older style ppm receivers. This is the same circuit as the mixer and only the software is different. |
| crc16.c | Implementation of CCITT CRC16 algorithm in HiTech C. Optimised PIC HiTech C code for computing the 16 bit CRC (X16+X12+X5+1) of a serial data stream. Can handle data rates of 115KBaud on a 16MHz PIC with interrupt driven serial I/O. |
|
Copyright © 1995-1999. Eagle Air Australia Pty.Ltd. All Rights Reserved.