User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
462
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 mikroPascal 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;
var error : byte;
counter, byte_read : byte; // Auxiliary variables
begin
ADPCFG := 0xFFFF; // Congure 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
begin
PORTB := error; // Signalize Init error
while (TRUE) do nop; // Stop program
end;
Delay_ms(100);
for counter := ‘z’ downto ‘A’ do // Send bytes from ‘z’ downto ‘A’
begin
Soft_UART_Write(counter);
Delay_ms(100);
end;
while TRUE do // Endless loop
begin
byte_read := Soft_UART_Read(error); // Read byte, then test error ag
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;
end.