Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
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 AVR
USART Terminal Tool.
program Soft_UART;
// Soft UART connections
var Soft_UART_Rx_Pin : sbit at PIND.B0;
Soft_UART_Tx_Pin : 
sbit at PORTD.B1;
Soft_UART_Rx_Pin_Direction : 
sbit at DDRD.B0;
Soft_UART_Tx_Pin_Direction : 
sbit at DDRD.B1;
// End Soft UART connections
var error : byte;
counter, byte_read : byte;             // Auxiliary variables
begin
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) 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 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 detect-
ed, return byte read
end;
end.
369
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6