Datasheet
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 AVR
USART Terminal Tool.
// Soft UART connections
sbit Soft_UART_Rx_Pin at PIND.B0;
sbit Soft_UART_Tx_Pin at PORTD.B1;
sbit Soft_UART_Rx_Pin_Direction at DDRD.B0;
sbit Soft_UART_Tx_Pin_Direction at DDRD.B1;
// End Soft UART connections
char i, error, byte_read; // Auxiliary variables
void main(){
DDRB = 0xFF; // Set PORTB as output
(error signalization)
PORTB = 0; // No error
error = Soft_UART_Init(9600, 0); // Initialize Soft UART at
9600 bps
if (error > 0) {
PORTB = 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 flag
if (error) // If error was detected
PORTB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detect-
ed, return byte read
}
}
420
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6