It's a crazy story

General discussion on mikroPascal.
Post Reply
Author
Message
hamradio
Posts: 39
Joined: 01 Oct 2006 17:55
Contact:

It's a crazy story

#1 Post by hamradio » 14 Dec 2008 22:20

Try this code:

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

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#2 Post by yo2lio » 14 Dec 2008 23:30

String[1] ?????

replace this :

Code: Select all

ricevuto, x : string[1];
with this :

Code: Select all

ricevuto, x : string[2];
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

hamradio
Posts: 39
Joined: 01 Oct 2006 17:55
Contact:

#3 Post by hamradio » 15 Dec 2008 00:00

Ok, may be that [1] is wrong, but why this happen with X variable and not with "Ricevuto".


EDIT: I follow your suggestion and change declaration from [1] to [2] but nothing change . The X variable stop the echos back to terminal agn.

Tnx Carlo IW2FIV

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#4 Post by janni » 20 Dec 2008 14:31

I don't see you using the 'x' string anywhere, apart for the assignment, so the program behaviour is indeed strange.

I don' think you'll get any answer, though, as v 8.1 is obsolete (though official). There is v8.3 beta available with most quirks and bugs of v 8.1 fixed. You could try if the problem persists there.

BTW, there shouldn't be any reason prohibiting use of one character long strings (other than memory waste).

Post Reply

Return to “mikroPascal General”