» Home

  » Products

  » Interfaces

  » Lab

  » Downloads

  » Buy It

  » Contact

  » Links

» Lab » PIC Serial to Infra-red Converter using 'C'

top
Project:PIC Serial to Infra-red Converter
Source Code:PIC 'C' (CCS PCM v2.2.1)
PIC:16F628
Interface:Cheap and Cheerful!
Author:Source Code: Jacques, WriteUp: Ravi Deo
Last Updated:25th May 2005

Project Description

In this sample PIC project, Jacques demonstrates how a PIC 'C' compiler can be used to convert an input serial TTL bitstream, to an infra-red output signal. Again the infra-red output signal drive the "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.

Project Download

PIC Serial to Infra-red Converter using 'C' : Zip file containing 'C' Source and Binary HEX files for the 16F628 (approx 2KB).

Hardware Schematic

16f628

In this design, Jacques uses the PIC's onboard USART to receive the serial bitstream. This allows the PIC to receive data concurrently in th background, whilst transmitting infra-red data at the same time. 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 inaccurate internal 4 MHz clock. Jacques 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. Again, 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).

Source Code

The 'C' source code comprises of the following functions:
main():        Main forever-loop which calls getc() to receive data, which is then
               the transmitted via the tx_palm() function for each received character.
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 Settings

SirPic Communication and Options settings should be configured as shown below:

16f628   16f628

SirPic Output

On starting the SirPic log session, you should see the Hello Palm string (in french) "Allo Palm de VE2EEM". It will then wait for a serial input character before transmitting it as infra-red. You will require another PIC project to feed the Serial TTL bitstream.