» Lab » Hello Palm using 'C'
|
| Project: | Hello Palm using 'C' |
| Source Code: | PIC 'C' (CCS PCM v2.2.1) |
| PIC: | 16F628 |
| Interface: | Cheap and Cheerful! |
| Author: | Source Code: Jacques, WriteUp: Ravi Deo |
| Last Updated: | 4th May 2005 |
|
Project Description
In this sample PIC project, Jacques demonstrates how a PIC 'C' compiler can be used to modulate an
output signal to drive a "cheap and cheerful" infra-red transmitter, with minimal external components.
The CCS PIC-C Compiler was used to generate a hex file from the 'C' source code.
Hello Palm using 'C'
: Zip file containing 'C' Source and Binary HEX files for the 16F628 (approx 2KB).

The above schematics show the minimalist component approach with the PIC16F628.
Jacques decided not to use the IrTx interface, and drive the infra-red LEDs directly.
Due to the excessive current drain for a single output pin, Jacques tied up four output pins
together to share the load of the IR-LED drain current. Also the driving signal has been inverted, active low
rather than active high (as used for IrTx).
Jacques also decided to use the internal 4 MHz clock (often anything but 4MHz!).
Luckily Jacques had an oscilloscope to check the output waveform, and compensated for the
innacurate clock by adding a suitable delay to the pulse widths (to pad the bit pulse durations to 104usec).
Unfortunately, others wishing to use this hex file (and not having the luxury of a 'C' compiler and scope)
may experience problems if their internal clock speed varies greatly from Jacques 16F628.
My PIC produced garbage, so good luck with your PIC. Those with a scope may be able to adjust the SirPic custom baud rate
to compensate for the differing internal clock frequency (ie derive new custom baud rate from actual bit period).
It is always better to use a reliable clock source for time critical code, or atleast calibrate the internal clock.
Unfortunately the 16F628 doesn't allow the internal clock to be calibrated via a register.
Never the less, keeping in mind Jacques minimalist design approach, it is a working solution for his requirements.
It is also interesting to see how its done in PIC 'C'.
The 'C' source code comprises of the following functions:
main(): Main forever-loop which calls the tx_palm() function for each
character in the printf() string.
pic_ini(): Initialises the PIC I/O pins, timers, comparators and vref.
tx_palm(): Passed in the char to transmit. Iterates through a bit at a time,
calling ir_pulse_1()or ir_pulse_0() correspondingly.
Followed by stop bit and small delay.
ir_Pulse_0(): transmits a 3/16th bit "active low" pulse (20us/84us=104us)
ir_Pulse_0(): transmits a full width "inactive high" bit (104us)
SirPic Communication and Options settings should be configured as shown below:

On starting the SirPic log session, you should see the string "Hello palm, from SIR PIC" repeated every 0.5sec.
|