Jump to content
Sign in to follow this  
c58_4311

Constant Rom Bytes

Recommended Posts

Dear Dave,

 

following are the point that I want to clear:

 

1) How we can store a constant value in the ROM area i.e. in the programing area of the pic.

 

2) How to write a DATA TABLE containing the constant values in the ROM and how to retrieve the stored values back.

 

hint: may be the #pragma DATA command will work? But how?

 

 

 

Recent edit:

 

I have seen that the following line of code compiles well in boostbasic:

 

dim A as rom byte //declare A as rom byte

dim B(12) as rom byte //declare B as an array stored in an array

 

The problem is that how to give values to the constant A and Array B?

 

 

Thanks

Edited by c58_4311

Share this post


Link to post
Share on other sites

Hello,

 

I have seen that the following line of code compiles well in boostbasic:

 

dim A as rom byte        //declare A as rom byte

dim B(12) as rom byte  //declare B as an array stored in an array

 

The problem is that how to give values to the constant A and Array B?

 

 

Thanks

 

this is the right way to do what you need, but i don't know how to code it in BoostBasic. You will have an answer from Dave or Pavel as soon as they will connect to the forum.

 

Regards,

 

Wally

Share this post


Link to post
Share on other sites

c58_4311,

 

I have seen that the following line of code compiles well in boostbasic:

 

dim A as rom byte        //declare A as rom byte

dim B(12) as rom byte  //declare B as an array stored in an array

 

The problem is that how to give values to the constant A and Array B?

Yes this part is missing. Arrays in RAM or ROM can't be initialised :lol:

 

So currently the only way to store data in ROM would be to use #pragma DATA and retrieve the data using table or memory reads.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Dear Wally

 

Thanks for your reply here and also for the reply you gave me to my personal message. I got an answer to my query from Dave.

 

 

Dear Dave,

 

I am thankfull to you also for your quick answer. But I want some other help from you:

 

1) I want the code lines in boostbasic/assambly (optemized for speed), that can be used to retrieve the data by using table or memory reads.

 

 

Thanks

Share this post


Link to post
Share on other sites

c58_4311,

 

I am thankfull to you also for your quick answer. But I want some other help from you:

 

1) I want the code lines in boostbasic/assambly (optemized for speed), that can be used to retrieve the data by using table or memory reads.

 

This will depend on which target device you are using, what are you using?

 

Regards

Dave

Share this post


Link to post
Share on other sites

Presently I am using the bit old pic 16F72.

 

 

I have aded the following line to my code:

 

#pragma DATA 0x00CB, 0x41, ox42, 0x43, 0x44

 

 

And at the end of the asm file after compilation I get the following:

 

 

ORG 0x000000C8

_startup

BCF PCLATH,3

BCF PCLATH,4

GOTO main

ORG 0x000000CB

DW 0x0041

DW 0x0042

DW 0x0043

DW 0x0044

END

 

 

I see that he data has been saved inside the Program Memory.

 

Now, how to call this data in my program? I dont think that some thing like calling the TABLE can be used here!

 

Please help.

 

 

Thanks.

Share this post


Link to post
Share on other sites

c58_4311

Presently I am using the bit old pic 16F72
I think there will be problems here. Table read is a function of PIC18. Some PIC16 devices allow there memory to be read and written using the EEPROM read and registers (if my memory serves me correctly).

 

I have the feeling that 16F72 wont do this. So the only option is a return table.

 

You can do this with #pragma DATA.

You will have to put some of the opcode values in manually, and call the code using some assembly.

 

You would need to work out the opcode for the following:

    addw pcl
   retlw 0x01
   retlw 0x02
   retlw 0x03
   retlw 0x04
   retlw 0x04

You must be careful that the table does not cross a 256 byte boundary.

 

You would need to call this code using a fixed address call, with W reg loaded with the table entry offset.

 

It seems just like the "good old days of assmebler".

 

Regards

Dave

Share this post


Link to post
Share on other sites

Dave,

 

I am really in a fix here. The need is urgent.

 

My code is here:

 

 

 

dim a as byte

'b here should be a table of any ten bytes.

 

Sub main()

 

 

for counter = 1 to 10

a = b(counter) * 2 // value of the 'b' should be taken from the table

next counter

 

Do while 1

Loop

 

End Sub

 

 

Please give me the assembler code to include in this programe such that the values of the 'b' are declared in the programe memory and read afterwards.

 

 

I tried to form the tables and reading them back using call statement. But all failed.

Edited by c58_4311

Share this post


Link to post
Share on other sites

c58_4311,

 

Here is a solution:

sub main()

    
    dim b as byte
    dim a as byte
    
    b = 1
    
    ' retrieve data
    
    asm
    {
        ' load up pclath ready
       movlw    0x02; high part of table address
        movwf    _pclath
    
        movf     _b,W
        call     0x200
        movwf    _a
    }
        
    do while( 1 )
    loop
    
    
    
end sub


' opcode for addwf _pcl,F
#pragma DATA 0x200, 0x0782
' table data, 0x34xx, xx is the data to store in the table
#pragma DATA 0x201, 0x3403, 0x3402, 0x3401, 0x3400

 

I hope that helps.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Dear Dave,

 

It helped me a lot, but there are certain queries of mine that need to be answered:

 

With reference to the above example:

 

1) Is it possible to change the address of the data? I have seen that when I change the address of the data and call statement from 0x200 to any other address, eg. 0x100, etc. The code fails to read the data. Please explain?

 

Actually I want to add the table at the end of the PIC's program memory. What I did is that, I subtracted 7 from the 0x7ff (the pics limit of program memory). But mere changing the addresses didnt helped!

 

 

2) Why we add 34 at high byte in 0x34xx?

 

The need is very much urgent.

 

Thanks.

Share this post


Link to post
Share on other sites
1) Is it possible to change the address of the data? I have seen that when I change the address of the data and call statement from 0x200 to any other address, eg. 0x100, etc. The code fails to read the data. Please explain?
Yes it can work at any address that start on a 256 byte boundary.

 

Actually I want to add the table at the end of the PIC's program memory. What I did is that, I subtracted 7 from the 0x7ff (the pics limit of program memory). But mere changing the addresses didnt helped!

Try this:

sub main()

   
   dim b as byte
   dim a as byte
   
   b = 1
   
   ' retrieve data
   
   asm
   {
       ' load up pclath ready
      movlw    0x7F; high part of table address
       movwf    _pclath
   
       movf     _b,W
       call     0x7F00
       movwf    _a
   }
       
   do while( 1 )
   loop
   
   
   
end sub


' opcode for addwf _pcl,F
#pragma DATA 0x7F00, 0x0782
' table data, 0x34xx, xx is the data to store in the table
#pragma DATA 0x7F01, 0x3403, 0x3402, 0x3401, 0x3400

 

2) Why we add 34 at high byte in 0x34xx?

0x34XX is the opcode for retlw.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×