User manual
mikroBasic PRO for PIC32
MikroElektronika
331
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
dim LCD_RS as sbit at LATB2_bit
LCD_EN as sbit at LATB3_bit
LCD_D4 as sbit at LATB4_bit
LCD_D5 as sbit at LATB5_bit
LCD_D6 as sbit at LATB6_bit
LCD_D7 as sbit at LATB7_bit
dim LCD_RS_Direction as sbit at TRISB2_bit
LCD_EN_Direction as sbit at TRISB3_bit
LCD_D4_Direction as sbit at TRISB4_bit
LCD_D5_Direction as sbit at TRISB5_bit
LCD_D6_Direction as sbit at TRISB6_bit
LCD_D7_Direction as sbit at TRISB7_bit
// End LCD module connections
// Manchester module connections
dim MANRXPIN as sbit at RF0_bit
MANRXPIN_Direction as sbit at TRISF0_bit
MANTXPIN as sbit at LATF1_bit
MANTXPIN_Direction as sbit at TRISF1_bit
// End Manchester module connections
dim error_ag, ErrorCount, counter, temp as byte
main:
ErrorCount = 0
counter = 0
CHECON = 0x32
AD1PCFG = 0xFFFF ‘ Congure AN pins as digital I/O
Lcd_Init() ‘ Initialize LCD
Lcd_Cmd(_LCD_CLEAR) ‘ Clear LCD display
Man_Receive_Init() ‘ Initialize Receiver
while TRUE ‘ Endless loop
Lcd_Cmd(_LCD_FIRST_ROW) ‘ Move cursor to the 1st row
while TRUE ‘ Wait for the “start” byte
temp = Man_Receive(error_ag) ‘ Attempt byte receive
if (temp = 0x0B) then ‘ “Start” byte, see Transmitter example
break ‘ We got the starting sequence
end if
if (error_ag <> 0) then ‘ Exit so we do not loop forever
break
end if
wend