Code: Select all
// *
// * Project name:
// Soft_Uart_Test
// * Copyright:
// (c) mikroElektronika, 2006
// * Revision History:
// 20060922:
// - initial release.
// * Description:
// This code demonstrates how to use usart library routines. Upon receiving
// data via RS232, PIC MCU immediately sends it back to the sender.
// * Test configuration:
// MCU: PIC18F4520
// Dev.Board: EasyPIC4
// Oscillator: HS, 20.000 MHz
// Ext. Modules: none.
// SW: mikroPascal v8.1
// * NOTES:
// - make sure you switch ON RC7 and RC6 (board specific)
// *
program Soft_Uart_Test;
var i, pos, read_error : byte;
L0, L1, L2, L3, L4, L5, L6, L7, txt : string[20];
ricevuto, x : string[1];
procedure print_display;
begin
Glcd_fill(0);
glcd_Write_Text(L0, 0, 0, 1);
glcd_Write_Text(L1, 0, 1, 1);
glcd_Write_Text(L2, 0, 2, 1);
glcd_Write_Text(L3, 0, 3, 1);
glcd_Write_Text(L4, 0, 4, 1);
glcd_Write_Text(L5, 0, 5, 1);
glcd_Write_Text(L6, 0, 6, 1);
glcd_Write_Text(L7, 0, 7, 1);
end;
procedure nuova_freq;
begin
L7 := 'input start';
txt:= '';
pos := 0;
ricevuto := '';
x := '';
L0:= '';
L1:= '';
print_display;
end;
procedure end_input;
begin
L7 := 'input end';
print_display;
end;
Procedure byte2ascii;
begin
case i of
48 : begin
ricevuto := '0';
inc(pos);
end;
49 : begin
ricevuto := '1';
inc(pos);
end;
50 : begin
ricevuto := '2';
inc(pos);
end;
51 :begin
ricevuto := '3';
inc(pos);
end;
52 : begin
ricevuto := '4';
inc(pos);
end;
53 : begin
ricevuto := '5';
inc(pos);
end;
54 : begin
ricevuto := '6';
inc(pos);
end;
55 : begin
ricevuto := '7';
inc(pos);
end;
56 : begin
ricevuto := '8';
inc(pos);
end;
57 : begin
ricevuto := '9';
inc(pos);
end;
63 : nuova_freq;
42 : end_input;
end;
end;
Procedure elabora_input;
begin
L0 := 'elab_input';
byte2ascii;
strncat2(L1, ricevuto);
print_display;
//if pos >7 then end_input;
end;
begin
ADCON1 := 15;
Soft_Uart_Init(PORTC, 7, 6, 19200, 0); // Initialize Soft_UART module
trisa := 0;
trisb := 0;
trise := 0;
Glcd_Init(portb, 0, 1, 2, 3, 5, 4, PORTd);
Glcd_fill(0);
//Glcd_set_font(@fontsystem5x8, 5, 8, 32);
pos := 0;
txt :='';
L0 := '';
L1 := '';
L2 := '';
L3 := '';
L4 := '';
L5 := '';
L6 := '';
L7 := 'elefante';
ricevuto :='';
while true do
begin
i := Soft_Uart_Read(read_error); // Read the received data, blocking call.
Soft_Uart_Write(i); // Send data back via UART.
elabora_input;
end;
end.
Input by terminal only number 0 to 9 or * or ?
Nothing happen on the display the sent caaracters isn't shows on display and aren't echoed to terminal.
Now go to procedure "nuova_freq" and commented the line "x := '';"
Now all work fine.
I have changed the x's variable name in many manner but the code don't operate until I comment the line.
No error is show by compiler.
Have anyone a expalin why this happen ?
Thanks Carlo