User manual
390
mikoPascal PRO for PIC32
MikroElektronika
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 PIC32 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
CHECON := 0x32;
AD1PCFG := 0xFFFF; // Congure AN pins as digital I/O
TRISB := 0x00; // Set PORTB as output (error signalization)
PORTB := 0; // No error
error := Soft_UART_Init(PORTF, 2, 8, 56000, 0); // Initialize Soft UART at 56000 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.