EDF - OnePIC MCU
v1.1.0
|
00001 00018 #include <htc.h> //PIC specific hardware 00019 #include <stdio.h> //Used for printf and sprintf 00020 00021 #include "bsp.h" //XTAL Frequ 00022 #include "OnePIC_8bit_demo_irda.h" //prototypes 00023 00033 void irda_putch(char c) { 00034 unsigned char i; 00035 00036 IRDA_TX = 0; 00037 for (i = NUM_DATA_BITS + 1; i != 0; i--) { 00038 __delay_us(BIT_UDLY); 00039 if (c & 1) 00040 IRDA_TX = 1; 00041 if (!(c & 1)) 00042 IRDA_TX = 0; 00043 c = (c >> 1) | 0x80; 00044 } 00045 IRDA_TX = 1; 00046 00047 } 00048 00059 char irda_getch(void) { 00060 char c = 0; //returned character received 00061 uint8_t i; 00062 00063 //Worst case is that start bit is caught 20us from inital start, depending on rate of sampling start bit 00064 //Want to sample in the middle( 104us/2) 00065 00066 __delay_us(5); 00067 if (IRDA_RX) 00068 return 0; // twas just noise 00069 for(i=NUM_DATA_BITS+1;i!=0;i--){ 00070 c = (c >> 1) | (IRDA_RX << 7); //LSB is transmitted first 00071 __delay_us(BIT_UDLY); 00072 } 00073 return c; //return the char 00074 } 00075 00080 char irda_getche(void) { 00081 char c; 00082 00083 c = irda_getch(); 00084 irda_putch(c); 00085 return c; 00086 }