User manual

410
mikoC PRO for dsPIC
MikroElektronika
Library Example
The following code is code for the Manchester receiver, it shows how to use the Manchester Library for receiving data:
Copy Code To Clipboard
// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
// Manchester module connections
sbit MANRXPIN at RF0_bit;
sbit MANRXPIN_Direction at TRISF0_bit;
sbit MANTXPIN at LATF1_bit;
sbit MANTXPIN_Direction at TRISF1_bit;
// End Manchester module connections
char error, ErrorCount, temp;
void main() {
ErrorCount = 0;
ADPCFG = 0xFFFF; // Congure AN pins as digital I/O
TRISB = 0;
LATB = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Man_Receive_Init(); // Initialize Receiver
while (1) { // Endless loop
Lcd_Cmd(_LCD_FIRST_ROW); // Move cursor to the 1st row
while (1) { // Wait for the “start” byte
temp = Man_Receive(&error); // Attempt byte receive
if (temp == 0x0B) // “Start” byte, see Transmitter example
break; // We got the starting sequence
if (error) // Exit so we do not loop forever
break;
}