|
|
View previous topic :: View next topic |
Author |
Message |
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Wed Feb 22, 2017 5:32 am |
|
|
PCM programmer wrote: | I looked at page 2 of this thread, at graphics.h, and it has function
prototypes that have the font array as a parameter. So yes, if the font
array is declared as 'rom', then you must edit all functions and function
prototypes to declare *font as 'rom'. |
I have tried by applying the changes in the <main.c> file, <graphics.h> file and in <graphics.c> file, but still, nothing appears where the letters should be. It is when I place the
Code: |
bounding_box_t draw_text(char *string, unsigned char x, unsigned char y, rom *font, unsigned char spacing);
bounding_box_t draw_char(unsigned char c, unsigned char x, unsigned char y, rom *font);
|
inside the void main() loop when it says not enough RAM. I have made the ROM[ change apparently everywhere where you said I should make the change. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9096 Location: Greensville,Ontario
|
|
Posted: Wed Feb 22, 2017 6:16 am |
|
|
re: not enough RAM
Since that PIC has over 3300 bytes of RAM the odds are the font arrays are still in RAM. That is a HUGE amount of RAM for a PIC.
A simple test is to cut/compile code without the font arrays and look at the size of RAM, ROM used then add the font array and see how much ROM,RAM is now used.
The other program to do is a very simple 'Hello World'. Get rid of everything NOT required to put 'Hello World' on the GLCD. So NO 'graphics' related drivers(boxes,circle,etc...),no ADC, no serial buffers,no timers,etc. This program should be very small,maybe 20-30 lines of code(plus TEXT driver) and font array in ROM. RAM usage might be 20-30 bytes(?), certainly less than 100.
I'm thinking you've got way too much 'cut and hacked' code snippets and it all 'looks OK' and you keep missing something that 'fresh eyes' would see.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19215
|
|
Posted: Wed Feb 22, 2017 6:41 am |
|
|
The other thing is that there is a graphics library supplied with the compiler. All this requires is a function to support setting a single pixel (glcd_pixel), and it then provides line, rectangle bar, circle and text functions. Written for the compiler. Honestly far easier than trying to port this library... |
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Wed Feb 22, 2017 6:45 am |
|
|
1) Hi, I am certain that the font is being stored in the ROM because it increases the total ROM value when used. I can see letters appearing in the display correctly when stored in the RAM, but nothing appears when storing them in the ROM. I believe that at some point i'm calling it wrongly calling the font. But I am not finding where.
2) Right now I am trying to display changing numbers in the display using the following simple code.
Code: |
for (i=1;i<1000;i++)
{
draw_text(i, 72, 30, Tahoma7, 1);
glcd_refresh();
delay_ms(200);
glcd_blank();
}
|
The problem I am encountering is that the value that should be changing from 1 to 1000 isn't displayed correctly. Where these numbers should be, changing letters, numbers and symbols appear. I believe that by not using the " ", I am somehow calling what is appearing in display from the library.
thanks
jaume |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9096 Location: Greensville,Ontario
|
|
Posted: Wed Feb 22, 2017 6:57 am |
|
|
Ok...
..... draw_text(i, 72, 30, Tahoma7, 1);
if this doesn't display a '1' when i=1, then look at the draw_text() function and decode what is happening.
what does get displayed ?
what does a '2' look like ? a '3', a '4' ??
...does draw_text(1, 72, 30, Tahoma7, 1);
properly display a '1' ?
If it does, try 2,3,4
if they display properly then the draw_text() function is OK, it's the variable 'i' that isn't correct for some reason.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19215
|
|
Posted: Wed Feb 22, 2017 8:06 am |
|
|
You do understand that _everything_ is stored in ROM at the start.
A font declared in RAM, uses it's full size in ROM, and then it's full size in RAM. It's copied from the ROM to RAM when the system boots. One declared in ROM only uses it's size in ROM, not the same again in the RAM.
So a font in RAM will still make the ROM size larger....
I'm with Temtronic in thinking you are actually using the font from RAM.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 22, 2017 9:16 am |
|
|
Quote: | for (i=1;i<1000;i++)
{
draw_text(i, 72, 30, Tahoma7, 1);
glcd_refresh();
delay_ms(200);
glcd_blank();
} |
Where's the declaration of 'i' ? is it int8 or int16 ?
Your function declaration below, doesn't want an integer as the first
parameter. It wants a string ! And then, you're giving it the same
starting coordinates each time, of 72, 30. All your characters, if you
even get any, will be piled on top of each other. Basically, you're not
even reading your own code. You're just throwing something together
without thinking.
Quote: | bounding_box_t draw_text(char *string, unsigned char x, unsigned char y, unsigned char *font, unsigned char spacing) { |
The code you posted on page 2 of this thread has an example of how
to call draw_text:
Code: | draw_text("Hello World", 10, 10, Tahoma10, 1); |
|
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Thu Feb 23, 2017 4:12 am |
|
|
PCM programmer wrote: | Quote: | for (i=1;i<1000;i++)
{
draw_text(i, 72, 30, Tahoma7, 1);
glcd_refresh();
delay_ms(200);
glcd_blank();
} |
Where's the declaration of 'i' ? is it int8 or int16 ?
Your function declaration below, doesn't want an integer as the first
parameter. It wants a string ! And then, you're giving it the same
starting coordinates each time, of 72, 30. All your characters, if you
even get any, will be piled on top of each other. Basically, you're not
even reading your own code. You're just throwing something together
without thinking.
Quote: | bounding_box_t draw_text(char *string, unsigned char x, unsigned char y, unsigned char *font, unsigned char spacing) { |
The code you posted on page 2 of this thread has an example of how
to call draw_text:
Code: | draw_text("Hello World", 10, 10, Tahoma10, 1); |
|
Hi, the characters do not pile on top of each other because as u can see in the code i clear the screen with "glcd_blank" every time the loops gets executed. The i variable is defined as int8 despite i know that it has to be a string, this is part of the question I was making though and that I don't know how to solve.
thanks
jaume |
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Thu Feb 23, 2017 4:14 am |
|
|
temtronic wrote: | Ok...
..... draw_text(i, 72, 30, Tahoma7, 1);
if this doesn't display a '1' when i=1, then look at the draw_text() function and decode what is happening.
what does get displayed ?
what does a '2' look like ? a '3', a '4' ??
...does draw_text(1, 72, 30, Tahoma7, 1);
properly display a '1' ?
If it does, try 2,3,4
if they display properly then the draw_text() function is OK, it's the variable 'i' that isn't correct for some reason.
Jay |
Hi, I have tried displaying various numbers and everything works fine. It has to be something to do with the variable "i".
thanks
jaume |
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Thu Feb 23, 2017 4:23 am |
|
|
Ttelmah wrote: | You do understand that _everything_ is stored in ROM at the start.
A font declared in RAM, uses it's full size in ROM, and then it's full size in RAM. It's copied from the ROM to RAM when the system boots. One declared in ROM only uses it's size in ROM, not the same again in the RAM.
So a font in RAM will still make the ROM size larger....
I'm with Temtronic in thinking you are actually using the font from RAM.... |
How is that even possible though? I am actually calling it with the ROM thing everywhere where the draw_text function appears. Furthermore, it behaves differently than when it doesn't have the font in the PIC. For example, when the font was like this <const unsigned char Tahoma10[] = >, random garbage was displayed. When < unsigned char Tahoma10[] = > works just fine but i can only store one font in the RAM. And when <cunsigned char rom Tahoma10[] = >, after making the pertinent changes in the functions in order to call the ROM information, no letters appear in the display.
thanks
jaume |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 23, 2017 4:43 am |
|
|
Quote: | The i variable is defined as int8 |
I think we have told you already that in CCS, an int8 can only go from
0 to 255. It can't go up to 1000. This is important to remember.
If you modify your loop as shown below in bold, it will convert 'i' to
a string and then you can call draw_text() with a string. Then it will
have a chance to work.
Quote: | int8 i;
int8 string[10];
for (i=1; i<255; i++)
{
sprintf(string, "%u", i); // Convert integer 'i' to an ASCII string
draw_text(string, 72, 30, Tahoma7, 1);
glcd_refresh();
delay_ms(200);
glcd_blank();
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19215
|
|
Posted: Thu Feb 23, 2017 4:50 am |
|
|
Understand. At boot, the only memory containing _anything_, is the ROM. The RAM is garbage.
Variables 'stored' in RAM, have an area of RAM declared for them, and as the system boots, the ROM version is copied to the RAM. Once in RAM it can be accessed using a pointer to the RAM address. However it uses space in both ROM and RAM.
A variable declared as 'const', is _only_ stored in ROM. A pointer cannot talk to it.
A variable declared as 'rom', is also only stored in ROM, but is stored with a little 'extra' data, to allow a _rom_ pointer to be constructed to it. Again a standard pointer to a RAM address cannot talk to it. |
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Thu Feb 23, 2017 7:44 am |
|
|
Ttelmah wrote: | Understand. At boot, the only memory containing _anything_, is the ROM. The RAM is garbage.
Variables 'stored' in RAM, have an area of RAM declared for them, and as the system boots, the ROM version is copied to the RAM. Once in RAM it can be accessed using a pointer to the RAM address. However it uses space in both ROM and RAM.
A variable declared as 'const', is _only_ stored in ROM. A pointer cannot talk to it.
A variable declared as 'rom', is also only stored in ROM, but is stored with a little 'extra' data, to allow a _rom_ pointer to be constructed to it. Again a standard pointer to a RAM address cannot talk to it. |
Do you know how to correclty declare a standard pointer for the ROM? I think then that here is where the problem might be
thanks
jaume |
|
|
jamalavedra
Joined: 25 Oct 2016 Posts: 62
|
|
Posted: Thu Feb 23, 2017 7:45 am |
|
|
PCM programmer wrote: | Quote: | The i variable is defined as int8 |
I think we have told you already that in CCS, an int8 can only go from
0 to 255. It can't go up to 1000. This is important to remember.
If you modify your loop as shown below in bold, it will convert 'i' to
a string and then you can call draw_text() with a string. Then it will
have a chance to work.
Quote: | int8 i;
int8 string[10];
for (i=1; i<255; i++)
{
sprintf(string, "%u", i); // Convert integer 'i' to an ASCII string
draw_text(string, 72, 30, Tahoma7, 1);
glcd_refresh();
delay_ms(200);
glcd_blank();
} |
|
thanks, with the sprintf the code did work correctly |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1315
|
|
Posted: Thu Feb 23, 2017 8:11 am |
|
|
jamalavedra wrote: |
How is that even possible though? I am actually calling it with the ROM thing everywhere where the draw_text function appears. Furthermore, it behaves differently than when it doesn't have the font in the PIC. For example, when the font was like this <const unsigned char Tahoma10[] = >, random garbage was displayed. When < unsigned char Tahoma10[] = > works just fine but i can only store one font in the RAM. And when <cunsigned char rom Tahoma10[] = >, after making the pertinent changes in the functions in order to call the ROM information, no letters appear in the display.
thanks
jaume |
Because when you use the "const" keyword in front of a variable, you cannot use pointers with it at all (which you were doing). A "const" variable can only be accessed by value, not by pointer (which includes bracketed array elements as ok).
In contrast, a variable marked as "rom" can be accessed by pointer provided the pointer is of "<whatever> rom *> type.
A possible alternative route is to create an enum with all your different FONTS and a function with a switch statement:
Code: |
//just pseudo code...you can also just include the font header files
const unsigned int8 tahoma10[][] = { /*stuff*/};
const unsigned int8 courier10[][] = {/*stuff*/};
typedef enum{
TAHOMA_10,
COURIER_10,
/*etc.*/
} font_t;
unsigned int8 font_value(font_t font, x, y){
switch(font){
case TAHOMA_10: return tahoma10[x][y];
case COURIER_10: return courier10[x][y];
/* etc. */
default: return 0; //or some visibly wrong character you identify
}
}
|
Then you change your table pointers to font_t enum values and call the font_value() method in your functions when you need a value.
If you still are having troubles with rom or const tables, then I highly suggest you take a step back and forget the GLCD for a bit. See if you can output data on a UART (or if you program with the ICD-U64 or higher, you can use it as a debug software UART). Write a small program that outputs all the values from a table declared as const. Get that working, then add a function that uses your table and then try to get that working. If you run into problems there, post it up in this thread so we have a smaller / easier example to debug and help with.
The main thing I am trying to promote is break the problem down and tackle it in small steps until you have it all down. const/rom tables do work (barring a particular compiler version bug) and have been used a lot, so it can be solved. You may just need to temporarily get back to basics and work back up. |
|
|
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|