It is currently 22 Apr 2018 13:43

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 23 May 2017 09:22 
Offline

Joined: 12 Apr 2005 13:33
Posts: 36
Location: Germany
Hello,

I have written a program for PIC16F688.
In this program I want to read in 152 Bytes via UART.

As it was not possible to define return_data: array[0..151] of Byte, i have splitted up the array into two:

return_data :array[0..79] of Byte;
return_data2 :array[0..71] of Byte;

I read in the data via UART and store 0 to 79 into return_data and 80 to 151 into return_data2

But the result is not correct. I guess this is because one variable is in a different bank.

During compilation I get the message: IRP must be set manually for indirect access to return_data2 variable
I have used in the code: setbit(status,IRP) in the main program without success.

What can I do to make it running?

many thanks
peter

_________________
Regards Peter N.


Top
 Profile  
 
PostPosted: 23 May 2017 13:10 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4892
Hi Peter,

To effectively control the IRP bit you have to know where your data arrays are in RAM. It's best to place them by yourself than to leave it to compiler, and to this purpose one may use the directive absolute. For example
var return_data :array[0..79] of Byte; absolute 0x120;
    return_data2 :array[0..71] of Byte; absolute 0xA8;
This will place return_data in Bank2 (requires IRP=1) and return_data2 in Bank1 (requires IRP=0 for indirect access). Thus Bank2 will be used up while there'll be some space left in Bank1 for the compiler to use.

Note that indirect access (requiring control of IRP) is used in statements like
return_data[idx]:=0;
where compiler has to calculate RAM address depending on a variable, but not when the address may be estimated during compilation, like in
return_data[40]:=0;


Here's an example how to clear your arrays
 STATUS.IRP:=1;
 for i:=0 to 79 do return_data[i]:=0;
 STATUS.IRP:=0;
 for i:=0 to 71 do return_data2[i]:=0;

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
PostPosted: 23 May 2017 14:23 
Offline

Joined: 12 Apr 2005 13:33
Posts: 36
Location: Germany
Hello,

thank you for your help.
With the absolute Statement and STATUS.IRP:=1; or :=0; it seems to work.

But I have two additional questions:


1) if you have a Statement like this:

if (return_value = $0A) AND (return_value2 = $23) then do something

how to handle this? (bringing the two array var first to some temp var?)



2) can you explain the statement return_data[idx]:=0; in more detail

if we assume the begining of the var array is stored in 0x120, what do I have to use for [idx] to access the 5th byte of the array?
Is it [id5]?

best regards
Peter

_________________
Regards Peter N.


Top
 Profile  
 
PostPosted: 23 May 2017 15:11 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4892
ad 1) If array indexes are constant, like in
if (return_value[7] = $0A) and (return_value2[30] = $23) then
then IRP bit is not involved. On the other hand, if the indexes are unknown at compile time then such conditional cannot work properly and has to be modified, for example
 STATUS.IRP:=1;
 if return_value[i] = $0A then
  begin
   STATUS.IRP:=0;
   if return_value2[j] = $23 then
     begin

     end;
  end;
 STATUS.IRP:=0;

ad 2) idx is just a name of a variable (short for index) :) . To access the 5th byte of the array the variable has to have value of 4 (indexes start from 0).

Note that for the compiler
 idx:=4;
 return_data[idx]:=0;
is equivalent to
return_data[4]:=0;
due to simple code optimization and thus the relevant memory byte will be accessed directly, regardless of IRP bit.

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: