
The example shows the initialization, writing, and reading data from the transmitter and receiver of an UART module, respectively. The realization is carried out by using the mikroPascal compiler for dsPIC30F microcontrollers. Fig. 13-8 shows the electrical connection of an UART module to an RS-232 transiever and further connection to the serial port of a PC.
Fig. 13-8 Electrical connection of an UART module to an RS-232 transiever and further connection to the serial port of a PC.
program Uart_Test;
var rx1 : word;
begin
Uart1_Init(9600);
while TRUE do
begin
if Uart1_Data_Ready = 1 then
begin
rx1 := Uart1_Read_Char();
Uart1_Write_Char(rx1);
end;
end;
end.