procedures with strings in declaration

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

procedures with strings in declaration

#1 Post by Skydec » 06 Feb 2009 19:18

I have a very strange problem.

When I use strings in my declaration I get very strange results.

for example

Code: Select all


procedure Uart2_Writeln(var Sin : string[txbufsizeB]);
var cnt : byte;
begin
  for cnt:=0 to strlen(Sin) do
  begin
    Uart2_Write_Char_(Sin[cnt]);
  end;
end;
when I try to start the procedure with :

Code: Select all

procedure Uart2_Writeln(Sin : string[txbufsizeB]);
or

Code: Select all

procedure Uart2_Writeln(Sin : string);
I get an error.

The output from my controller on rs232 is alot of 0 en the text is somewhere within the zeros.

But when I run for example this:

Code: Select all

Uart2_Write_Char_('A');
Uart2_Write_Char_('A');
Uart2_Write_Char_('A');
etc.
it works just fine.

There is soemthing funny about strings.
What do I do wrong? is it a compiler setting?

p.s. txbufsizeB is a constant and does not have any effect on the result.

Thanks in advance

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

#2 Post by yo2lio » 06 Feb 2009 19:35

Everything it's ok ... but sin is a math function ... rename sin with sin_

Code: Select all

procedure Uart2_Writeln(var Sin_ : string[txbufsizeB]);
var cnt : byte;
begin
  for cnt:=0 to strlen(Sin_) do
  begin
    Uart2_Write_Char_(Sin_[cnt]);
  end;
end; 
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

Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

#3 Post by Skydec » 06 Feb 2009 23:02

I changed the code a bit for here in my original code sin is actually s.
But what causes the strange behavior?

Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

#4 Post by Skydec » 09 Feb 2009 14:35

Problem located.

It was not the string declaration, but Uart_Send_Char what caused the problem.

I think there is a bug in it, because when I replace this by U2TXREG:= or U1TXREG:= then it works fine.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”