User manual

488
mikoC PRO for dsPIC
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 mikroC 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
char i, error, byte_read; // Auxiliary variables
void main(){
ADPCFG = 0xFFFF;
TRISB = 0; // Set PORTB as output (error signalization)
LATB = 0;
error = Soft_UART_Init(&PORTF, 4, 5, 14400, 0); // Initialize Soft UART at 14400 bps
if (error > 0) {
LATB = error; // Signalize Init error
while(1); // Stop program
}
Delay_ms(100);
for (i = 'z'; i >= 'A'; i--) { // Send bytes from 'z' downto 'A'
Soft_UART_Write(i);
Delay_ms(100);
}
while(1) { // Endless loop
byte_read = Soft_UART_Read(&error); // Read byte, then test error ag
if (error) // If error was detected
LATB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detected, return
byte read
}
}