Download Data Sheet - MikroElektronika

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