Home > Engineering Projects > Chris Projects > Wireless Infrared Link - Software

Wireless Infrared Communication Link System
Software

The Software

There are two main portions of code that we are concerned with:

Transmitter Code
     Transmits USART Serial Data
Receiver Code
      Receives and Translates USART Data

Since this circuit operates as if the transmitter and receiver were connected directly with a wire, the software has nothing out of the ordinary. The transmitter is constantly counting 0 to 8 over and over, and the receiver is parsing this input and lighting up the corresponding LEDs, over and over.

Infrared Link Transmitter Code

------------« Begin Code »------------
void main(void){
unsigned char rs232_s = '1';
OpenUSART( USART_TX_INT_OFF &
       USART_RX_INT_OFF &
       USART_ASYNCH_MODE &
       USART_EIGHT_BIT &
       USART_CONT_RX &
       USART_BRGH_HIGH,
       25 );
  while(1){
  putcUSART(rs232_s);
  Delay10KTCYx(10);
  rs232_s += 1;
  if(rs232_s == '8')
    rs232_s='0';
  }
}
 
------------« End Code »------------

There really are no surprises here. The transmitter is setup with a routine and simple while loop that counts then transmits, then counts and then transmits over and over until infinity.

Infrared Link Receiver Code

------------« Begin Code »------------
void main(void)
{
unsigned char input;

TRISC = 0xFF;
TRISD = 0x00;

PORTD = 0x00;
OpenUSART( USART_TX_INT_OFF &
       USART_RX_INT_OFF &
       USART_ASYNCH_MODE &
       USART_EIGHT_BIT &
       USART_CONT_RX &
       USART_BRGH_HIGH,
       25 );

  while(1){
  Delay1KTCYx(1);
  input = getcUSART();
    switch(input){
      case '1' : PORTD = 0x01;
      break;
      case '2' : PORTD = 0x03;
      break;
      case '3' : PORTD = 0x07;
      break;
      case '4' : PORTD = 0x0F;
      break;
      case '5' : PORTD = 0x1F;
      break;
      case '6' : PORTD = 0x3F;
      break;
      case '7' : PORTD = 0x7F;
      break;
      case '8' : PORTD = 0xFF;
      break;
      case '0' : PORTD = 0x00;
      break;
}
  }
CloseUSART();
}
 
------------« End Code »------------

The receiver does the same thing as the transmitter just with the opposite function: receiving. It continually checks to see if data is ready in the USART receiver buffer. When data is accepted, it is then evaluated and the LEDs updated to output the change.

Program Download:

Main C File

wireless_serial_tx.c
wireless_serial_rx.c

wireless_serial_tx.hex
wireless_serial_rx.hex

(Infrared Receiver) << Previous

6 of 8

Next >> (Data & Observations)

Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Wireless IR Link
Part 1: Introduction

Part 2: Parts List

Part 3: Schematic

Part 4: Theory of Operation

Part 5: Hardware
      (i)  Infrared Transmitter
      (ii) Infrared Receiver

Part 6: Software

Part 7: Data & Observations

Part 8: Conclusion

Discover

     more......