Program Download:
Main C File
wireless_serial_tx.c
wireless_serial_rx.c
wireless_serial_tx.hex
wireless_serial_rx.hex
Main C File
wireless_serial_tx.c
wireless_serial_rx.c
wireless_serial_tx.hex
wireless_serial_rx.hex
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.