Mikroelektronika MIKROE-724 Scheda Tecnica
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
387
do
temp = Man_Receive(error_flag) ‘ Attempt byte receive
if (error_flag <> 0) then ‘ If error occured
Lcd_Chr_CP(“?”) ‘ Write question mark on LCD
Inc(ErrorCount) ‘ Update error counter
if (ErrorCount > 20) then ‘ In case of multiple errors
temp = Man_Synchro() ‘ Try to synchronize again
‘Man_Receive_Init() ‘ Alternative, try to Initialize Receiver again
ErrorCount = 0 ‘ Reset error counter
end if
else ‘ No error occured
if (temp <> 0x0E) then ‘ If “End” byte was received(see Transmitter example)
‘ do not write anymore received byte on Lcd
Lcd_Chr_CP(temp) ‘ else write character on Lcd
Inc(counter) ‘ Counts how many chars have been written on Lcd
if counter = 25 then ‘ If there were more then 25 characters
‘ synchronization is off
Lcd_Cmd(_LCD_CLEAR) ‘ Clear the Lcd of garbled communication
temp = Man_Synchro() ‘ Try to synchronize again
end if
else
counter = 0 ‘ reset counter
end if
Delay_ms(25)
end if
loop until ( temp = 0x0E )
wend ‘ If “End” byte was received exit do loop
end.
The following code is code for the Manchester transmitter, it shows how to use the Manchester Library for transmitting data:
Copy Code To Clipboard
program Manchester_Transmitter
‘ 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 index, character as byte
s1 as char[17]
main:
s1 = “mikroElektronika”
ADPCFG = 0xFFFF ‘ Configure AN pins as digital I/O
Man_Send_Init() ‘ Initialize transmitter
while TRUE ‘ Endless loop
Man_Send(0x0B) ‘ Send “start” byte
Delay_ms(100) ‘ Wait for a while