FOR and WHILE

Beta Testing discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
Ryazanec
Posts: 3
Joined: 03 May 2014 21:59

FOR and WHILE

#1 Post by Ryazanec » 03 May 2014 22:18

Hello!
There is a problem.
This function does not work.

Code: Select all

Procedure put_str(x, y : byte; var str : string);
var i :  byte;
Begin
     gotoxy(x,y);
     for  i := 0 to length(str)-1 do
     Begin
          put_char(str[i]);
     End;
End;
This works

Code: Select all

Procedure put_str1(x, y : byte; var str : string);
var i: byte;
Begin
     gotoxy(x,y);
     i := 0;
     while i < length(str) do
     Begin
          put_char(str[i]);
          inc(i);
     End;
End;
When the first function freezes.

Code: Select all

//######################
_sclk : byte =5; //#####
_sda  : byte =4; //#####
_cs   : byte =3; //#####
_rst  : byte =2; //#####
//######################
_data : byte =1; //#####
_cmd  : byte =0; //#####
//######################


Procedure LCD_WRITE (cd,simvol : byte);     
Var i : integer;                           
Begin
CLEARBIT ( PORTC , _sclk );                
CLEARBIT ( PORTC , _cs );                 
if  cd then  SETBIT ( PORTC , _sda )   else CLEARBIT ( PORTC , _sda );   // 
SETBIT ( PORTC , _sclk );                                            
for  i := 7  downto 0 do          
  begin
  CLEARBIT ( PORTC , _sclk );                                                        
  if  TestBit(simvol,i) then SETBIT ( PORTC , _sda ) else CLEARBIT ( PORTC , _sda );     
  SETBIT ( PORTC , _sclk );
  end;
    SETBIT ( PORTC , _cs );
End;



Procedure put_char(c : char);
  var
  i : Byte;
  begin
  i := 0;
    for  i := 0 to 4 do
    begin
       if((32<=c)and(c<=64)) then LCD_WRITE(_data,nlcd_Font[c-32][i]) else  LCD_WRITE(_data,nlcd_Font[c-159][i]); //nlcd_Font -> array[] of array[5] of byte  
    end;
  LCD_WRITE(_data,0x00); 
  end;



Procedure gotoxy(x,y : byte);  // LCD NOKIA 1100
begin
 LCD_WRITE(_cmd,(0xB0 or (y and 0x0F)));// Y axis initialisation: 1011 yyyy
 LCD_WRITE(_cmd,(0x00 or (x and 0x0F))); // X axis initialisation: 0000 xxxx ( x3 x2 x1 x0)
 LCD_WRITE(_cmd,(0x10 or ((x shr 4) and 0x07) ) ); // X axis initialisation: 0001 0xxx  ( x6 x5 x4)
end;


Procedure put_str(x, y : byte; var str : string);
var i :  byte;
Begin
     gotoxy(x,y);
     for  i := 0 to length(str)-1 do
     Begin
          put_char(str[i]);
     End;
End;


Procedure put_str1(x, y : byte; var str : string);
var i: byte;
Begin
     gotoxy(x,y);
     i := 0;
     while i < length(str) do
     Begin
          put_char(str[i]);
          inc(i);
     End;
End;


//**************************************
put_str1(3,3,'0000');  <- OK!!!!
put_str(3,3,'0000'); <- FREEZE!!!!!!!!!!!!!!!!!!!!!


jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: FOR and WHILE

#2 Post by jpc » 05 May 2014 11:09

maybe you try

Code: Select all

for  i := 0 to (length(str)-1) do
, it may be that i evaluates to -1 in your code
Au royaume des aveugles, les borgnes sont rois.

Ryazanec
Posts: 3
Joined: 03 May 2014 21:59

Re: FOR and WHILE

#3 Post by Ryazanec » 05 May 2014 13:01

length(str) not work
(length (str) -1) does not work




does not work !!!!!! (what O_o ????????????) !!!!!!

Code: Select all

Procedure put_str(x, y : byte; var str : string);
var i :  byte;
Begin
     gotoxy(x,y);
     for  i := 0 to 5 do
     Begin
          put_char(str[i]);
     End;
End;
Does not work in this function.

In another function FOR loop works. It is no longer true, I just do not use the FOR

Ryazanec
Posts: 3
Joined: 03 May 2014 21:59

Re: FOR and WHILE

#4 Post by Ryazanec » 05 May 2014 13:03

jpc wrote:maybe you try

Code: Select all

for  i := 0 to (length(str)-1) do
, it may be that i evaluates to -1 in your code

Code: Select all

a:word;

a:=length(str)-1;


for  i := 0 to a do
     Begin
          put_char(str[i]);
     End;
not work.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: FOR and WHILE

#5 Post by filip » 06 May 2014 12:38

Hi,

Please, your code needs some modifications in order to be able to compile.
Could you attach here the minimal project that demonstrates this issue that doesn't need to be modified ?

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for AVR Beta Testing”