Pointer problem ... need help asap please

General discussion on mikroC.
Post Reply
Author
Message
OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Pointer problem ... need help asap please

#1 Post by OTCHU » 29 Jul 2010 16:27

Hello, I am not an expert on C and I am pretty sure my problem will be easy to fix for some people. I will appreciate a lot some help.

Here is my problem: I want to show on my GLCD the tab_fan. Everything is working good when I do put the tab on RAM memory.
But when I want to put it in the ROM, I have a pointer mistake ........



const unsigned char Tab_fan[234] ={ 0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,
0,0,0,1,1,0,1,0,1,0,1,0,1,1,0,0,0,0,
0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,0,
0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,
0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,
0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,0,
1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,
0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,0,
0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,
0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,
0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,0,
0,0,0,1,1,0,1,0,1,0,1,0,1,1,0,0,0,0,
0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0};

void Affiche_Tab(unsigned char *tab[],unsigned int X, unsigned int Y)
{
int i,j,k;
k=0;
for (i = 0; i < 13; i++ ) {
for (j=0; j < 18; j++) {
Glcd_Dot(X+j, Y+i, tab[k]);
k++;
}
}
}




void main() {
TMR0L = 96;
INTCON = 0xA0;
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0


ADCON1 = 0x07;
Glcd_Init(&PORTB, 0,1,2,3,5,4, &PORTD); // Init for EasyPIC4board
Glcd_Set_Font(font5x7, 5, 7, 32);

Affiche_Tab(*Tab_fan,100,20);


while(1) {}
}


When I do build my project I do have: pointer conversion to int type and implicit cast of integral value to pointer warning. To be honest, I do not understand a lot about the pointer so if somebody can help me to resolve that, THANK YOU

Vincent

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: Pointer problem ... need help asap please

#2 Post by braus » 29 Jul 2010 19:23

Vincent.
When you are going to work with pointers you should remember that pointers hold down another variable´s address location and that in order a particular pointer will be able to point a variable both of them should be declared the same type.
Arrays and pointers are intimately linked because the array's name is a pointer that points the first element in that array.
When you are going to pass an array to a function it is not neccesary to use pointer notation, prior comment, only thing you have to do is to declare the actual parameter the same type the array is. I mean

Code: Select all

void Affiche_Tab(unsigned char tab[],unsigned int X, unsigned int Y)
{
int i,j,k;
k=0;
for (i = 0; i < 13; i++ ) {
for (j=0; j < 18; j++) {
Glcd_Dot(X+j, Y+i, tab[k]);
k++;
}
}
}
void main() {
TMR0L = 96;
INTCON = 0xA0;
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0


ADCON1 = 0x07;
Glcd_Init(&PORTB, 0,1,2,3,5,4, &PORTD); // Init for EasyPIC4board
Glcd_Set_Font(font5x7, 5, 7, 32);

Affiche_Tab(Tab_fan,100,20);


while(1) {}
}
}
Best Regards
Omar Galicia
Mexico City

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: Pointer problem ... need help asap please

#3 Post by braus » 29 Jul 2010 19:29

Besides prior, you have to take care about the way the GLCD is going to display the data you are feeding it, I mean, you have to tell the GLCD the row, column and chip where it must show the corresponding byte.
Best Regards
Omar Galicia
Mexico City

OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Re: Pointer problem ... need help asap please

#4 Post by OTCHU » 29 Jul 2010 19:46

everythings is fine for the GLCD because when I put my tab in RAM ... that's working perfectly. Just have this problem when I do put this tab in Rom (Const)

So I still have the problem ... :(

Braus, I can not declare the same way my tab because one is in ROM (initialisation of my tab):
const unsigned char Tab_fan[234] ={ 0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,
0,0,0,1,1,0,1,0,1,0,1,0,1,1,0,0,0,0,
0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,0,
0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,
0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,
0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,0,
1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,
0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,0,
0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,
0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,
0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,0,
0,0,0,1,1,0,1,0,1,0,1,0,1,1,0,0,0,0,
0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0};

and after have to be in RAM for the procedure, right ?
void Affiche_Tab(unsigned char tab[],unsigned int X, unsigned int Y)
{
int i,j,k;
k=0;
for (i = 0; i < 13; i++ ) {
for (j=0; j < 18; j++) {
Glcd_Dot(X+j, Y+i, tab[k]);
k++;
}
}
}

AM I STUPID or I do miss something ???? HELPPPPPP :)

kada200
Posts: 56
Joined: 10 Jul 2010 08:04
Location: Phoenix, AZ

Re: Pointer problem ... need help asap please

#5 Post by kada200 » 29 Jul 2010 22:41

Hang in there vincent, i'm watching this post cuz i want to learn more about pointers like you.
Did you say in the MikroC Pro forum (which you posted by accident) that MikroC(not Pro) doesn't support the 'const' declaration? Just curious.
I found a good article on pointers at:
http://en.wikipedia.org/wiki/Pointer_%28computing%29
I plan to read and re-read it till it soaks into my brain-pan until it makes sense.

Pointers are used alot and I know its a concept I must master. If i cant, then I must consider myself too stupid to own my EasyPic5, and will just have to relinquish it to you :wink:

I know braus is watching this post(as am i) and maybe he can shed more light on what needs to be done.
#DEFINE ENDEAVOR_TO_PERSERVERE 1
While (ENDEAVOR_TO_PERSERVERE != 1) {
ENDEAVOR_TO_PERSERVERE = 1;
}

Phoenix, AZ (USA)

OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Re: Pointer problem ... need help asap please

#6 Post by OTCHU » 29 Jul 2010 23:02

again I don't understand a lot but it looks like you can't store somethings in ROM and print that on your LCD immediately .... you have to do a copy in Ram first ...... I don't like that. Hope somebody will found my problem

kada200
Posts: 56
Joined: 10 Jul 2010 08:04
Location: Phoenix, AZ

Re: Pointer problem ... need help asap please

#7 Post by kada200 » 29 Jul 2010 23:11

Tell me why you want to store something in ROM and what is its advantage?
Maybe this will help if your wanting to store to a particular place in ROM. It's from my MikroC Pro help file.
Directive org
Directive org specifies a starting address of a routine in ROM.

Directive org is appended to the function definition. Directives applied to non-defining declarations will be ignored, with an appropriate warning issued by the linker.

Here is a simple example:

void func(int par) org 0x200 {
// Function will start at address 0x200
asm nop;
}
It is possible to use org directive with functions that are defined externally (such as library functions). Simply add org directive to function declaration:

void UART1_Write(char data) org 0x200;

Directive orgall
If the user wants to place his routines, constants, etc, above a specified address in ROM, #pragma orgall directive should be used:

#pragma orgall 0x200
Directive funcorg
You can use the #pragma funcorg directive to specify the starting address of a routine in ROM using routine name only:

#pragma funcorg <func_name> <starting_address>
#DEFINE ENDEAVOR_TO_PERSERVERE 1
While (ENDEAVOR_TO_PERSERVERE != 1) {
ENDEAVOR_TO_PERSERVERE = 1;
}

Phoenix, AZ (USA)

OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Re: Pointer problem ... need help asap please

#8 Post by OTCHU » 29 Jul 2010 23:23

I just need to store a lot of tab ... n I don't have enough space in the RAM so I want to put that in ROM

kada200
Posts: 56
Joined: 10 Jul 2010 08:04
Location: Phoenix, AZ

Re: Pointer problem ... need help asap please

#9 Post by kada200 » 30 Jul 2010 00:09

so...what is this project your doing? what is the tab...n all about?
#DEFINE ENDEAVOR_TO_PERSERVERE 1
While (ENDEAVOR_TO_PERSERVERE != 1) {
ENDEAVOR_TO_PERSERVERE = 1;
}

Phoenix, AZ (USA)

OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Re: Pointer problem ... need help asap please

#10 Post by OTCHU » 30 Jul 2010 00:10

my project is a controller for reef tank. The tab are just icons for the GLCD with touch screen

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: Pointer problem ... need help asap please

#11 Post by braus » 30 Jul 2010 18:52

program ROM Memory in PIC's (despite of which flavour they are, FLASH, EE, OTP, etc.) is used to store instructions as well as data tables, just as you want Vincent, this is this way because as all of us know amount of RAM memory PIC's have is not enough in the major cases, so, key to store a data table (array) in ROM memory is to precede its name with const keyword. The way the programmer is going to proccess that information is then transparent for MCU, all he/she has to do is call array by it's name and that's all.
Best Regards
Omar Galicia
Mexico City

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: Pointer problem ... need help asap please

#12 Post by braus » 30 Jul 2010 18:55

Again, I remind you that GLCD must be instructed about where it should display the data it receives from MCU, I think a big part of your problem is there.
Best Regards
Omar Galicia
Mexico City

OTCHU
Posts: 29
Joined: 20 Jun 2009 15:35

Re: Pointer problem ... need help asap please

#13 Post by OTCHU » 30 Jul 2010 19:18

Got the solution:

const unsigned char Tab_fan[234] = { 0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,
0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,0,
0,1,0,0,1,1,1,0,0,0,0,1,1,1,0,0,1,0,
0,1,0,1,1,1,1,1,0,0,1,1,1,1,1,0,1,0,
1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,
1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,
0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,0,
0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,
0,0,1,0,0,1,1,1,1,1,1,1,1,0,0,1,0,0,
0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

void Affiche_Tab(const unsigned char tab[], unsigned int X, unsigned int Y)
{
int i,j,k;
k=0;
for (i = 0; i < 13; i++ ) {
for (j=0; j < 18; j++) {
Glcd_Dot(X+j, Y+i, tab[k]);
k++;
}
}
}

void main() {

TMR0L = 96;
INTCON = 0xA0;
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0


ADCON1 = 0x07;
Glcd_Init(&PORTB, 0,1,2,3,5,4, &PORTD); // Init for EasyPIC4board
Glcd_Set_Font(font5x7, 5, 7, 32);

Affiche_Tab(Tab_fan,80,20);
while(1) {}
}

Thank you Braus !

Post Reply

Return to “mikroC General”