Constant array in PIC16 program memory

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
picchiedi
Professional User
Posts: 142
Joined: Thu 2014-12-25 9:32

Constant array in PIC16 program memory

Post by picchiedi »

Hello.
I'd like to put a constant array in program memory of PIC16F877, like below (see enclosure too):

Code: Select all

#include <htc.h>
#include <stdio.h>
#include <string.h>
void main(void)
{
  char a[5];
  const unsigned char buffer[]={'0','1','0','1','0'};
  const unsigned char* p ; 
  p=&buffer;
  for (char cur = 0; cur < 5; p+=1, cur++)
	{
     a[cur]=*p;
    }  
 while(1==1);
}
The code runs properly, but I wonder why when I debug step by step, the values in *main@p , that is the values pointed to the pointer, are not '0','1','0','1' but 'm',0xE2,0x18,'s'.
If I place instead the array in Data memory, that is I remove const in declaration, the values in *main@p during debug are as expected ('0','1','0','1').
Thank you in advance for a clarification, if any.
Regards
Attachments
debug.zip
(102.2 KiB) Downloaded 4 times
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Constant array in PIC16 program memory

Post by Ettore »

To me that const buffer data are stored into the program memory as the pic1.jpg shows (second line starting at 0x0010.
Those ascii data are then pasted into the a[] in the data memory, as pic2.jpg shows.
I suppose you are using a very old Proteus version, so that's explains the difference.
pic1.jpg
pic1.jpg (164.63 KiB) Viewed 54 times
pic2.jpg
pic2.jpg (357.54 KiB) Viewed 54 times
Kind regards,
Ettore Arena - Labcenter Electronics.
picchiedi
Professional User
Posts: 142
Joined: Thu 2014-12-25 9:32

Re: Constant array in PIC16 program memory

Post by picchiedi »

Thank you Ettore.
To me too they are stored in program memory.(in other locations).
What I found strange is that during debug, *main@p should show the values of the variable pointed by p (that are '0','1','0','1'), so the same values showed correctly by array a.
Instead, during debug, *main@p shows 'm' then 0xE2 then 0x18 then 's'.
In your print out *main@p has value Format (6), that is at the end when data are finished.
But what are (how they appear) its previous values during debug? In your simulation, are they successively '0','1','0','1','0' ?

Thank you very much for your attention.

Regards
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Constant array in PIC16 program memory

Post by Ettore »

No. Format (6) means not valid type, i.e. unsupported at the present .coff loader.
Immagine 2024-03-26 130212.jpg
Immagine 2024-03-26 130212.jpg (48.6 KiB) Viewed 31 times
Kind regards,
Ettore Arena - Labcenter Electronics.
Post Reply