This is a collection of sample C routines to illustrate applications of
low end Microchip PICs including the 12C508/509, 12CE518/519, 16C505,
16HV540, 12C671/672 and 12CE673/674. Routines for the 12-bit and 14-bit core
devices are written using CCS PCB and PCM, respectively.
This consists of 130 pages of discussion in .pdf format and about 70
sample routines which are distributed via e-mail.
Payment may be made via PayPal. My
info is pha@phanderson.com, Last name is Anderson.
Each processor is discussed in the context of a simple design problem, a frost alarm. This is a simple device that gardeners or farmers might use to warn of a potential frost. The device continually monitors and displays the temperature and if this is less than an alarm temperature setting, a sonalert is pulsed to warn the user of a potential frost condition.
The user may set the alarm threshold using a potentiometer and while setting the threshold, its value is displayed.
Note that this design involves a 1-wire interface with a Dallas DS18S20, some means of measuring the value of a potentiometer and some means of displaying either the alarm threshold and the current temperature. I found that in developing each of the modules and then combining all of the pieces to realize the final design I was able to cover most of the features of each the processors. Thus, for each processor, there are routines to measure temperature using a DS18S20, measuring the value of a potentiometer using an RC network and displaying quantities using 9600 baud serial, flashing an LED or outputting a series of tones. For some processors having adequate IO pins, programs include directly driving a Hitachi type text LCD, sequentially outputting digits to single 7-segment LED
Additional routines were also written to illustrate various other features of each processor that did not fit into the frost alarm design.
Listing of Routines
PIC12C508/509
defs_509.h - Definitions of all SFR bytes and bits.
delay.c - Delay Routines.
flash_1.c - Simple LED flash
ser_509.c - "Bit bang", Serial output routines.
tst_ser.c - Illustrates the use of the functions in ser_509.c
flsh_q.c - "Displaying" a quantity using a flashing LED.
tone_q.c - Sounding out a quantity to a speaker - Uses TMR0.
rctime.c - Measures time in us for decay of charged C - Uses TMR0
1820.c - Measures temperature using a Dallas DS18S20
frst_alm.c - Implements the frost alarm using the above modules.
inteeprm.c - Random write to and read from the internal EEPROM (12CE518/CE519)
PIC16C505
defs_505.h
delay.c
ser_505.c
tst_ser.c
flsh_q.c
tone_q.c
rctime.c
1820.c
frst_alm.c
lcd_out.c - Direct interface with Hitachi HD44870 text style LCD
tst_lcd.c - Illustrates the use of the functions in lcd_out.c.
_7_seg.c - Display of a quantity using a common anode 7-segment LED
PIC16HV540
defs_540.h
delay.c
ser_540.c
tst_ser.c
flsh_q.c
tone_q
rctime.c
1820.c
_7_seg.c
frst_alm.c
sl_wake.c - Illustrates wakeup on slow pin change on RB7 and use of the status bits to determine the cause of a boot.
clk_out.c - Use of OCS2/CLKOUT to generate a tone when clocked by an external RC.
event.c - Uses T0CKI to determine if an event occurred.
flsh_alm.c - Uses T0CKI to determine if a directional signal has been on for an extended period and provides alarm.
PIC12C672
defs_672.h
delay.c
ser_672.c
tst_ser.c
flsh_q.c
tone_q
rctime.c - Uses TMR0 and external interrupt.
_1_wire.c - Low level Dallas 1-W routines.
ad.c - Illustrates use of the A/D converters.
1820.c
frst_alm.c
pwm_1.c - Illustrates PWM output. Duty varies with a potentiometer setting.
32khz.C - Illustrates the use of a 32.768 kHz watch crystal.
int_ee_1.c - Use of the internal EEPROM (12CE673/CE674)
first_tm.c - Use of EEPROM to determine if first boot (12CE673/CE674)
nv_total.c - Use of EEPROM as a non-volatile totalizer (12CE673/CE674)