User manual

384
mikoPascal PRO for dsPIC30/33 and PIC24
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
program Manchester_Receiver;
// LCD module connections
var LCD_RS : sbit at LATD0_bit;
LCD_EN : sbit at LATD1_bit;
LCD_D4 : sbit at LATB0_bit;
LCD_D5 : sbit at LATB1_bit;
LCD_D6 : sbit at LATB2_bit;
LCD_D7 : sbit at LATB3_bit;
var LCD_RS_Direction : sbit at TRISD0_bit;
LCD_EN_Direction : sbit at TRISD1_bit;
LCD_D4_Direction : sbit at TRISB0_bit;
LCD_D5_Direction : sbit at TRISB1_bit;
LCD_D6_Direction : sbit at TRISB2_bit;
LCD_D7_Direction : sbit at TRISB3_bit;
// End LCD module connections
// Manchester module connections
var MANRXPIN : sbit at RF0_bit;
MANRXPIN_Direction : sbit at TRISF0_bit;
MANTXPIN : sbit at LATF1_bit;
MANTXPIN_Direction : sbit at TRISF1_bit;
// End Manchester module connections
var error : word;
ErrorCount, chr_counter, byte_rcvd : byte;
begin
ErrorCount := 0;
chr_counter := 0;
ADPCFG := 0xFFFF; // Congure AN pins as digital I/O
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Man_Receive_Init(); // Initialize Receiver
while TRUE do // Endless loop
begin
Lcd_Cmd(_LCD_FIRST_ROW); // Move cursor to the 1st row
while TRUE do // Wait for the “start” byte
begin
byte_rcvd := Man_Receive(error); // Attempt byte receive
if (byte_rcvd = 0x0B) then // “Start” byte, see Transmitter example
break; // We got the starting sequence
if (error <> 0) then // Exit so we do not loop forever
break;