Mikroelektronika MIKROE-724 データシート
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
463
Library Example
This example demonstrates simple data exchange via software UART. If MCU is connected to the PC, you can test
the example from the mikroBasic PRO for dsPIC30/33 and PIC24 USART communication terminal, launch it from the
drop-down menu
Tools › USART Terminal or simply click the USART Terminal Icon .
Copy Code To Clipboard
program Soft_UART
dim error_ as byte
counter, byte_read as byte ‘ Auxiliary variables
main:
ADPCFG = 0xFFFF ‘ Configure AN pins as digital I/O
TRISB = 0x00 ‘ Set PORTB as output (error signalization)
PORTB = 0 ‘ No error
error_ = Soft_UART_Init(PORTF, 2, 3, 14400, 0) ‘ Initialize Soft UART at 14400 bps
if (error_ > 0) then
PORTB = error_ ‘ Signalize Init error
while TRUE
nop ‘ Stop program
wend
end if
Delay_ms(100)
for counter = “z” to “A” step-1 ‘ Send bytes from “z” downto “A”
Soft_UART_Write(counter)
Delay_ms(100)
next counter
while TRUE ‘ Endless loop
byte_read = Soft_UART_Read(error_) ‘ Read byte, then test error flag
if (error_ <> 0) then ‘ If error was detected
PORTB = error_ ‘ signal it on PORTB
else
Soft_UART_Write(byte_read) ‘ If error was not detected, return byte read
end if
wend
end.