Difference between revisions of "IR communication between PICs"
(→Code) |
Victor Liu (talk | contribs) |
||
(81 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
== |
== Overview == |
||
Two PICs can easily communicate with one another using serial communication. IR communication is a basic extension of this method which can be easily implemented with a microcontroller (PIC) through an IR Encoder/Decoder (endec) and an IR Transceiver. The endec and transceiver used in this example support Serial IR (SIR) data rate, ranging from 9.6 kbps to 115.2 kbps. The typical range of the transceiver is nominally from 2 inches to 2 feet and extends upwards of 12 feet. The PIC, endec, and transceiver employed all support bidirectional use. However, when a transceiver is transmitting it essentially blinds its receiver and therefore cannot attain true full-duplex communication; only half-duplex was used with the transceiver taking turns transmitting and receiving. |
|||
Two PICs wired together can talk to each other using RS-232. Instead of wiring them together, we can use infrared transceivers so they communicate by IR. The goal of this project is to demonstrate bidirectional communication between two PICs using 38 kHz IR communication. Optional: show that these PICs can also receive data from a standard TV remote. |
|||
[[Image:ir_transceiver.jpg|thumb|right|300px|IR Transceiver]] |
|||
The Original Assignment indicates what you were assigned to do, and will eventually be erased from the final page. |
|||
When transmitting, the PIC sends the serial format data to the endec, which encodes (or modulates) it bit by bit. This encoded data is then outputted as electrical pulses to the transceiver. The transceiver converts these electrical pulses to IR light pulses. When receiving, the transceiver receives IR light pulses (data), which are outputted as electrical pulses. The endec decodes (or demodulates) these electrical pulses, with the data then being transmitted by the endec UART back to the receiving PIC. This modulation/demodulation method is performed in accordance with the IrDA standard. |
|||
== Overview == |
|||
The contents of this page explains how two PICs that are wired together can talk to each other using infrared transceivers, thus allowing them to communicate by IR. This projected demonstrates bidirectional communication between two PICs using 38 kHz IR communication. The UART within the PIC was used to send signals to the encoder/decoder, which communicated with the transceiver. This same technology can be used used to allow the PICs to receive data fro ma standard TV remote control. |
|||
Both the PIC and the endec used in this example were DIP packages, making them easy to prototype and inspect. The transceiver, however, was a surface mount chip with an uncommon pin configuration (0.95 mm pitch), requiring a different mounting approach. The simplest solution was to glue the transceiver onto one side of a 16 pin socket, and then soldering small wires from the 8 pins of the transceiver onto the pins of the socket (see image). In the previous years, other mounting methods were tried, including the use of a [http://www.radioshack.com/sm-2-sided-copper-clad-pc-board--pi-2102495.html copper-clad board] or a [http://www.schmartboard.com/index.asp?page=products_so&id=54 SchmartBoard]. However, these approaches saw limited success. |
|||
''IR Chip'' |
|||
The IR chip used for this project was a 0.95mm pitch surface mount chip, which was extremely difficult to work with. Both a copper-clad board an a SchmartBoard were used in attempts to mount this chip. A copper-clad board was etched by hand using an Exacto Knife as shown in the picture. This allowed for the IR chip to be soldered to the copper-clad board. There were leads coming from the IR chip to pins that were fanned out in such a way as to allow wires to easily be connected. |
|||
<!--We initially attempted to etch a [http://www.radioshack.com/sm-2-sided-copper-clad-pc-board--pi-2102495.html copper-clad board] for our circuit (see image). However, due to the way this board is set up, this attempt only works with exact precision. Unfortunately, due to the limited number of IR transceivers and copper-clad boards we had this approach led to a dead end. Another possible solution to mount the IR transceiver was to use a [http://www.schmartboard.com/index.asp?page=products_so&id=54 SchmartBoard]. These boards are more general and pre-fabricated for use with surface mount ICs (with a particular pitch or pin seperation). Theoretically, both solutions will allow for connections to a solderless breadboard. However, because none of the IR transceiver chips we could find came at the same pitch as the SchmartBoards, we could not use this approach. Overall, since the IR transceiver chips did not come at standard pitches, we were unable to find a way to mount the IR chip.--> |
|||
[[Image:copper_clad_board.jpg|thumb|400px|Copper-Clad Board]] |
|||
== Circuit == |
|||
A SchmartBoard with part number 202-0004-01 was also obtained as a way of mounting the chip. The link to the website for SchmartBoards is provided in the External Links section. |
|||
[[Image:IR_circuit.jpg|thumb|right|400px|Circuit Diagram]] |
|||
[[Image:ir_source.jpg|thumb|right|400px|Actual Circuit (Receiver)]] |
|||
The circuit diagram shows a complete half-duplex IR communication circuit. This circuit can either be used together with an identical circuit to communicate, with only one PIC transmitting at a time, or with a remote control. The software on the PIC can be configured to respond to a variety of commands sent by the remote. The electrical characteristics of the power supply and discrete components are given below. Some of the ranges for the IR circuitry are also given below in parentheses. In the circuit, there are two interfaces: the serial interface and the IR interface. |
|||
*IR employed for short-range communication |
|||
*Beam is modulated to encode data |
|||
*Supports IrDA(?) speeds up to 115.2 kbits/s (SIR) |
|||
*Transceiver module consists of: |
|||
**PIN photodiode |
|||
**Infrared emitter (IRED) |
|||
**Low-power control IC |
|||
*IR EnDec uses PDIP, SOIC pacakge |
|||
== |
===Serial Interface=== |
||
The serial interface is located between the PIC and the endec and sends data sequentially one bit at a time. The transmit (TX) and receive (RX) pins on the endec need to be connected between both ICs with a common ground. The data passing between the two components on these lines have the standard 8-N-1 serial data format. 8-N-1 is a serial configuration in which there are 8 data bits, no parity bits and 1 stop bit. Data bits contain the information to be transmitted. A parity bit is a binary digit used to ensure data accuracy, while a stop bit is used to indicate the end of a data string. |
|||
The Circuit Diagram shows the layout of the PIC, Encoder/Decoder, and IR Transceiver combination. Two of these set-ups are needed in order to have two independent circuits: one to transmit and one to receive data. The specifications of the circuit are as follows: |
|||
There is also a 16XCLK signal going to the endec from the PIC used to control the baud rate of the endec; that signal is a square wave pulse train at a frequency of 16*(the baud rate) and is generated in software. The <span style="text-decoration: overline">RESET</span> signal on the endec could be controlled with software but is simply held high since the endec need not be reset. |
|||
[[Image:IR_circuit.jpg|thumb|600px|Circuit Diagram]] |
|||
<!--[[Image:Serial_ir_data_format.jpg|right|thumb|400px|Serial & IR Data Format]]--> |
|||
''µController (PIC18F4520)'' |
|||
[[Image:ir_connect.jpg|right|thumb|400px|Source PIC Transmitting to the Receiver PIC]] |
|||
===IR Interface=== |
|||
The second interface — the IR interface — is located between the endec and the transceiver. This interface is straightforward with the TXIR and RXIR pins of the endec connecting to the TXD and RXD pins of the transceiver, respectively, and also has a common ground. The signals between these two components conform to the IrDA physical layer standard. When a logic high or '1' is to be transmitted, a logic low will be sent to the transceiver. When a logic low or '0' is to be transmitted, a logic high will be pulsed after 7-8 cycles of the 16XCLK signal for 3 cycles of the 16XCLK signal but no longer than 4 µs. |
|||
===Optical Interface=== |
|||
The optical interface refers to the actual IR energy being transmitted between two transceivers or a source and a receiver. The optical signal is a modulated form of the signal between the Endec and the Transceiver at the Transceiver's carrier frequency, 38 kHz. That means that when the Endec would transmit a pulse for 3 cycles at the 16XCLK frequency, the transceiver would start pulsing IR energy at 38 kHz until the pulse went low. When the transceiver receive IR pulsed at 38 kHz, the duration of the IR pulses is the duration of the pulse sent to the Endec. |
|||
===Electrical Characteristics=== |
|||
''Microcontroller ([http://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf Microchip PIC18F4520])'' |
|||
*V<sub>DD</sub> = 5.0V |
*V<sub>DD</sub> = 5.0V |
||
*C<sub>1</sub> = 1µF |
*C<sub>1</sub> = 1µF |
||
** |
**V<sub>DD</sub> - Pin 11 & 32 |
||
**Pin 12 |
**GND - Pin 12 & 31 |
||
**TX - Pin 25 (C6) |
|||
**RX - Pin 26 (C7) |
|||
**16XCLK - Pin 17 (C2/CCP1) |
|||
''IR Encoder/Decoder (MCP2122-E/P)'' |
''IR Encoder/Decoder ([http://ww1.microchip.com/downloads/en/DeviceDoc/21894c.pdf Microchip MCP2122-E/P])'' |
||
*V<sub>DD</sub> = 5.0V (1.8V-5.5V) |
*V<sub>DD</sub> = 5.0V (1.8V-5.5V) |
||
*C<sub>BYP</sub> = 0.01µF |
*C<sub>BYP</sub> = 0.01µF |
||
''IR Transceiver (TFDU4300 |
''IR Transceiver ([http://www.vishay.com/docs/82614/tfdu4300.pdf Vishay TFDU4300])'' |
||
*V<sub>cc1</sub> = 5.0V (2.4V-5.5V) |
*V<sub>cc1</sub> = 5.0V (2.4V-5.5V) |
||
*V<sub>cc2</sub> = 5.0V (-0.3V-6.0V) |
*V<sub>cc2</sub> = 5.0V (-0.3V-6.0V) |
||
*V<sub>logic</sub> = 5.0V ( |
*V<sub>logic</sub> = 5.0V (1.5V-5.5V) |
||
*R<sub>2</sub> = 47Ω |
*R<sub>2</sub> = 47Ω |
||
*C<sub>2</sub> = 0.1µF |
*C<sub>2</sub> = 0.1µF |
||
=== Limitations === |
|||
*IR Communication is only Half-Duplex (only one transceiver transmitting at a time) |
|||
The links to the data sheets for the Encoder/Decoder and the IR Transceiver can be found in the External Links sections. |
|||
*Transmission Distance maximum is about 12 feet (about 3ft in low power mode) |
|||
*Transmission is easily blocked or reflected by obstacles |
|||
*PIC interfaces serially with EnDec |
|||
*Communication Speed can only go up to 115.2 kpbs |
|||
*EnDec connected to transceiver through a transmit pin, a receive pin, and a V<sub>logic</sub> pin? |
|||
*Transceiver manufactured by Vishay Semiconductors |
|||
**Part # TFDU4300 |
|||
*EnDec manufactured by Microchip |
|||
**Part # MCP2122 |
|||
=== Surface Mount Prototyping === |
|||
*Transceiver lead pitch = 1.2mm/0.95mm/0.50mm/0.45mm? |
|||
*Multiple options for installation |
|||
**Schmart board |
|||
**Digikey board (need to find) |
|||
**Copper-clad board etching |
|||
**Funky pin adapter thing Prof. Peshkin gave us |
|||
**Funky adapter thing #2 Prof. Peshkin gave us |
|||
=== Limitations === |
|||
*Transceiver cannot simultaneously transmit and receive |
|||
== Code == |
== Code == |
||
Example code for a simple IR communication circuit |
Example code for a simple IR communication receiver circuit: |
||
/* |
/* |
||
Line 77: | Line 67: | ||
the first IR encoder/decoder feeds its TXIR to the RXIR of a second IR encoder/decoder. The |
the first IR encoder/decoder feeds its TXIR to the RXIR of a second IR encoder/decoder. The |
||
second IR encoder/decoder then transmits back to the PIC what it is receiving. When the |
second IR encoder/decoder then transmits back to the PIC what it is receiving. When the |
||
transceiver circuit is properly |
transceiver circuit is properly mounted and inserted into the circuit, this code can be adapted |
||
for half-duplex communication w/ another IR communications circuit. |
for half-duplex communication w/ another IR communications circuit. |
||
*/ |
|||
/* |
|||
Edits by Jad Carson, Victor Liu, Matt Watras 2009-02-04 |
|||
*/ |
*/ |
||
#include <18f4520.h> |
#include <18f4520.h> |
||
#fuses HS,NOLVP,NOWDT,NOPROTECT |
#fuses HS,NOLVP,NOWDT,NOPROTECT |
||
#use delay (clock= |
#use delay (clock=40000000) |
||
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps |
||
// (up to 115,200 bps) |
// (up to 115,200 bps) |
||
Line 90: | Line 83: | ||
// character. If you simply use getc(), the PIC might get slowed up if the data isn't ready right |
// character. If you simply use getc(), the PIC might get slowed up if the data isn't ready right |
||
// away. |
// away. |
||
int timed_getc(void){ |
|||
long timeout; |
long timeout; |
||
int timeout_error = FALSE; |
int timeout_error = FALSE; |
||
Line 104: | Line 97: | ||
} |
} |
||
// Main program |
// Main program, receiver end |
||
void main(void){ |
|||
int rx; |
|||
setup_timer_2(T2_DIV_BY_1, 64, 8); // Provides a 151.3 kHz clock for the Encoder/Decoder, in |
|||
setup_ccp1(CCP_PWM); // order for it to know the baud rate of the UART. Should be |
|||
set_pwm1_duty(32); // closer to 16 * 9600 = 153.6 kHz but the error is tolerable |
|||
while(TRUE){ |
|||
rx = timed_getc(); // message from the PIC, and displays the value on the LEDs/Port D. |
|||
output_d(rx); |
|||
} |
|||
} |
|||
Sample code for the transmitter sending a simple counting signal: |
|||
#include <18f4520.h> |
|||
#fuses HS,NOLVP,NOWDT,NOPROTECT |
|||
#use delay (clock=40000000) |
|||
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps |
|||
// (up to 115,200 bps) |
|||
// timed_getc() checks whether data is ready to be read. If it's not the function returns a null |
|||
// character. If you simply use getc(), the PIC might get slowed up if the data isn't ready right |
|||
// away. |
|||
int timed_getc(void){ |
|||
long timeout; |
|||
int timeout_error = FALSE; |
|||
timeout = 0; |
|||
while(!kbhit() && (++timeout<50000)) |
|||
delay_us(10); |
|||
if (kbhit()) |
|||
return(getc()); |
|||
else { |
|||
timeout_error = TRUE; |
|||
return(0); |
|||
} |
|||
} |
|||
// Main program, transmit end |
|||
void main(void){ |
void main(void){ |
||
int i; |
int i; |
||
char rx; |
|||
setup_timer_2(T2_DIV_BY_1, |
setup_timer_2(T2_DIV_BY_1, 64, 8); // Provides a 151.3 kHz clock for the Encoder/Decoder, in |
||
setup_ccp1(CCP_PWM); // order for it to know the baud rate of the UART. Should be |
setup_ccp1(CCP_PWM); // order for it to know the baud rate of the UART. Should be |
||
set_pwm1_duty( |
set_pwm1_duty(32); // closer to 16 * 9600 = 153.6 kHz but the error is tolerable |
||
while(TRUE){ |
while(TRUE){ |
||
for(i=0;i<16;i++){ |
for(i=0;i<16;i++) { |
||
putc(i); |
|||
putc(i); // Listens to the second Encoder/Decoder, which is simply the original |
|||
rx = timed_getc(); // message from the PIC, and displays the value on the LEDs/Port D. |
|||
output_d((int8) rx); |
|||
delay_ms(1000); |
|||
} |
} |
||
} |
} |
||
Line 124: | Line 152: | ||
= External Links and Further Reading = |
= External Links and Further Reading = |
||
*[http:// |
*[http://www.vishay.com/docs/82614/tfdu4300.pdf IR Transceiver (Vishay TFDU4300) Data Sheet] |
||
<!--*[http://ww1.microchip.com/downloads/en/DeviceDoc/21894c.pdf IR Transceiver Data Sheet]--> |
|||
*[http:// |
*[http://ww1.microchip.com/downloads/en/DeviceDoc/21894c.pdf IR Encoder/Decoder (Microchip MCP2122) Data Sheet] |
||
*[http://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf Microchip PIC18F4520 Data Sheet] |
|||
*[http://www.radioshack.com/sm-2-sided-copper-clad-pc-board--pi-2102495.html Copper-clad Board] |
|||
*[http://www.schmartboard.com/ Prototyping boards for SMT] |
|||
*[http://www.schmartboard.com/ Schmartboard (Prototyping boards for SMT)] |
|||
*[http://www.irda.org/ Infrared Data Association website] |
|||
== Relevant Wikipedia Articles == |
|||
*[http://en.wikipedia.org/wiki/Infrared_communication#Communications| Infrared communication] |
|||
*[http://en.wikipedia.org/wiki/Serial_communications| Serial communication] |
|||
== Relevant Technical Articles == |
|||
*[http://en.wikipedia.org/wiki/Surface_mount| Surface mount technology] |
|||
*[http://www.commsdesign.com/showArticle.jhtml?articleID=192200654 Infrared communication] |
|||
*[http://en.wikipedia.org/wiki/UART| UART] |
|||
*[http://en.wikipedia.org/wiki/Serial_communications Serial communication] |
|||
*[http://en.wikipedia.org/wiki/Surface_mount Surface mount technology] |
|||
*[http://en.wikipedia.org/wiki/UART UART] |
Latest revision as of 13:19, 12 February 2009
Overview
Two PICs can easily communicate with one another using serial communication. IR communication is a basic extension of this method which can be easily implemented with a microcontroller (PIC) through an IR Encoder/Decoder (endec) and an IR Transceiver. The endec and transceiver used in this example support Serial IR (SIR) data rate, ranging from 9.6 kbps to 115.2 kbps. The typical range of the transceiver is nominally from 2 inches to 2 feet and extends upwards of 12 feet. The PIC, endec, and transceiver employed all support bidirectional use. However, when a transceiver is transmitting it essentially blinds its receiver and therefore cannot attain true full-duplex communication; only half-duplex was used with the transceiver taking turns transmitting and receiving.
When transmitting, the PIC sends the serial format data to the endec, which encodes (or modulates) it bit by bit. This encoded data is then outputted as electrical pulses to the transceiver. The transceiver converts these electrical pulses to IR light pulses. When receiving, the transceiver receives IR light pulses (data), which are outputted as electrical pulses. The endec decodes (or demodulates) these electrical pulses, with the data then being transmitted by the endec UART back to the receiving PIC. This modulation/demodulation method is performed in accordance with the IrDA standard.
Both the PIC and the endec used in this example were DIP packages, making them easy to prototype and inspect. The transceiver, however, was a surface mount chip with an uncommon pin configuration (0.95 mm pitch), requiring a different mounting approach. The simplest solution was to glue the transceiver onto one side of a 16 pin socket, and then soldering small wires from the 8 pins of the transceiver onto the pins of the socket (see image). In the previous years, other mounting methods were tried, including the use of a copper-clad board or a SchmartBoard. However, these approaches saw limited success.
Circuit
The circuit diagram shows a complete half-duplex IR communication circuit. This circuit can either be used together with an identical circuit to communicate, with only one PIC transmitting at a time, or with a remote control. The software on the PIC can be configured to respond to a variety of commands sent by the remote. The electrical characteristics of the power supply and discrete components are given below. Some of the ranges for the IR circuitry are also given below in parentheses. In the circuit, there are two interfaces: the serial interface and the IR interface.
Serial Interface
The serial interface is located between the PIC and the endec and sends data sequentially one bit at a time. The transmit (TX) and receive (RX) pins on the endec need to be connected between both ICs with a common ground. The data passing between the two components on these lines have the standard 8-N-1 serial data format. 8-N-1 is a serial configuration in which there are 8 data bits, no parity bits and 1 stop bit. Data bits contain the information to be transmitted. A parity bit is a binary digit used to ensure data accuracy, while a stop bit is used to indicate the end of a data string.
There is also a 16XCLK signal going to the endec from the PIC used to control the baud rate of the endec; that signal is a square wave pulse train at a frequency of 16*(the baud rate) and is generated in software. The RESET signal on the endec could be controlled with software but is simply held high since the endec need not be reset.
IR Interface
The second interface — the IR interface — is located between the endec and the transceiver. This interface is straightforward with the TXIR and RXIR pins of the endec connecting to the TXD and RXD pins of the transceiver, respectively, and also has a common ground. The signals between these two components conform to the IrDA physical layer standard. When a logic high or '1' is to be transmitted, a logic low will be sent to the transceiver. When a logic low or '0' is to be transmitted, a logic high will be pulsed after 7-8 cycles of the 16XCLK signal for 3 cycles of the 16XCLK signal but no longer than 4 µs.
Optical Interface
The optical interface refers to the actual IR energy being transmitted between two transceivers or a source and a receiver. The optical signal is a modulated form of the signal between the Endec and the Transceiver at the Transceiver's carrier frequency, 38 kHz. That means that when the Endec would transmit a pulse for 3 cycles at the 16XCLK frequency, the transceiver would start pulsing IR energy at 38 kHz until the pulse went low. When the transceiver receive IR pulsed at 38 kHz, the duration of the IR pulses is the duration of the pulse sent to the Endec.
Electrical Characteristics
Microcontroller (Microchip PIC18F4520)
- VDD = 5.0V
- C1 = 1µF
- VDD - Pin 11 & 32
- GND - Pin 12 & 31
- TX - Pin 25 (C6)
- RX - Pin 26 (C7)
- 16XCLK - Pin 17 (C2/CCP1)
IR Encoder/Decoder (Microchip MCP2122-E/P)
- VDD = 5.0V (1.8V-5.5V)
- CBYP = 0.01µF
IR Transceiver (Vishay TFDU4300)
- Vcc1 = 5.0V (2.4V-5.5V)
- Vcc2 = 5.0V (-0.3V-6.0V)
- Vlogic = 5.0V (1.5V-5.5V)
- R2 = 47Ω
- C2 = 0.1µF
Limitations
- IR Communication is only Half-Duplex (only one transceiver transmitting at a time)
- Transmission Distance maximum is about 12 feet (about 3ft in low power mode)
- Transmission is easily blocked or reflected by obstacles
- Communication Speed can only go up to 115.2 kpbs
Code
Example code for a simple IR communication receiver circuit:
/* ircomm.c Jennifer Breger, Brian Lesperance, Dan Pinkawa 2008-02-05 Using the PIC's built-in UART, a counter continually is sent to one IR encoder/decoder. Then the first IR encoder/decoder feeds its TXIR to the RXIR of a second IR encoder/decoder. The second IR encoder/decoder then transmits back to the PIC what it is receiving. When the transceiver circuit is properly mounted and inserted into the circuit, this code can be adapted for half-duplex communication w/ another IR communications circuit. */ /* Edits by Jad Carson, Victor Liu, Matt Watras 2009-02-04 */ #include <18f4520.h> #fuses HS,NOLVP,NOWDT,NOPROTECT #use delay (clock=40000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps // (up to 115,200 bps) // timed_getc() checks whether data is ready to be read. If it's not the function returns a null // character. If you simply use getc(), the PIC might get slowed up if the data isn't ready right // away. int timed_getc(void){ long timeout; int timeout_error = FALSE; timeout = 0; while(!kbhit() && (++timeout<50000)) delay_us(10); if (kbhit()) return(getc()); else { timeout_error = TRUE; return(0); } } // Main program, receiver end void main(void){ int rx; setup_timer_2(T2_DIV_BY_1, 64, 8); // Provides a 151.3 kHz clock for the Encoder/Decoder, in setup_ccp1(CCP_PWM); // order for it to know the baud rate of the UART. Should be set_pwm1_duty(32); // closer to 16 * 9600 = 153.6 kHz but the error is tolerable while(TRUE){ rx = timed_getc(); // message from the PIC, and displays the value on the LEDs/Port D. output_d(rx); } }
Sample code for the transmitter sending a simple counting signal:
#include <18f4520.h> #fuses HS,NOLVP,NOWDT,NOPROTECT #use delay (clock=40000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps // (up to 115,200 bps) // timed_getc() checks whether data is ready to be read. If it's not the function returns a null // character. If you simply use getc(), the PIC might get slowed up if the data isn't ready right // away. int timed_getc(void){ long timeout; int timeout_error = FALSE; timeout = 0; while(!kbhit() && (++timeout<50000)) delay_us(10); if (kbhit()) return(getc()); else { timeout_error = TRUE; return(0); } } // Main program, transmit end void main(void){ int i; setup_timer_2(T2_DIV_BY_1, 64, 8); // Provides a 151.3 kHz clock for the Encoder/Decoder, in setup_ccp1(CCP_PWM); // order for it to know the baud rate of the UART. Should be set_pwm1_duty(32); // closer to 16 * 9600 = 153.6 kHz but the error is tolerable while(TRUE){ for(i=0;i<16;i++) { putc(i); } } }
External Links and Further Reading
- IR Transceiver (Vishay TFDU4300) Data Sheet
- IR Encoder/Decoder (Microchip MCP2122) Data Sheet
- Microchip PIC18F4520 Data Sheet
- Copper-clad Board
- Schmartboard (Prototyping boards for SMT)