Wrong code or my mistake?

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
gozi
Posts: 29
Joined: 14 Aug 2006 12:04

Wrong code or my mistake?

#1 Post by gozi » 29 Oct 2007 22:08

Hi,

The following code not working. In the software simulator is ok, but in the PIC, don't work.
I use mP for dsPIC 6.0, dsPIC Pro2 board with 30F6014.

Code: Select all

program test_pr;
var i,j,data,data1:byte;
begin
uart1_init(9600);
trisb:=0;
i:=0;
j:=6;
data:=0;
data1:=172;
   for i := 7 downto 1 do
     begin
     data.i := data1.j;
     if j > 0 then j:=j-1 else break;
    end;
latb:=data;              // Software simulator value: 88, but the real: 0
uart1_write_char(data);
end.
Thanks for advance.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Wrong code or my mistake?

#2 Post by zristic » 30 Oct 2007 11:09

Look in the datasheet for 30F6014A how to set ADPCFG register in order to make PORTB to function as digital. It is analog by default.

gozi
Posts: 29
Joined: 14 Aug 2006 12:04

#3 Post by gozi » 30 Oct 2007 17:02

UUps. I forget set ADPCFG...
But why get zero from UART?

New test code, but this code have same problem.

Code: Select all

program test;
var i,j,data,data1:byte;
begin
adpcfg:=$FFFF;
trisb:=0;
i:=0;
j:=6;
data:=0;
data1:=172;
uart1_init(9600);
latb:=$AAAA;  // working!
delay_ms(1000);
latb:=$5555;   // working!
delay_ms(1000); 

   for i := 7 downto 1 do
     begin
     data.i := data1.j;
     if j > 0 then j:=j-1 else break;
    end;
latb:=data;              // Software simulator value: 88, but the real: 0
uart1_write_char(data);   // get 0 on PC
end.

User avatar
milan
mikroElektronika team
Posts: 1013
Joined: 04 May 2006 16:36
Contact:

#4 Post by milan » 31 Oct 2007 14:05

Hi,

we reproduced the problem, it is an error in the compiler.

Workaround: declare variables as word:

Code: Select all

var i,j,data,data1 : word;
Thank you for your report.

gozi
Posts: 29
Joined: 14 Aug 2006 12:04

#5 Post by gozi » 31 Oct 2007 14:14

Thank you for reply, Milan.

Post Reply

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