CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer constants

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Diego López



Joined: 25 May 2012
Posts: 11
Location: Colombia

View user's profile Send private message

Pointer constants
PostPosted: Wed Dec 05, 2012 11:43 am     Reply with quote

Hi, sorry I do not speak English, I speak Spanish.

I call collaboration.

I work pointers to constants in this program, can you help?

Thank you very much.
Code:

#include <16f876A.h>

#use delay(clock=4mhz)
#fuses xt,put,brownout,nowdt

#byte   porta=5      //Definicion de variables del pic
#byte   portb=6
#byte   portc=7

#define   port_lcd portb

int status;

char rom *dir_tabla_g;
char rom tab_grafico1[] = {   0xff,0xff,
                     0xff,0xff,
                     0xc0,0x0f,
                     0xc0,0x0f,
                     0xc0,0x0f,
                     0xcf,0xcf,
                     0xcc,0xcf,
                     0xfc,0xff,
                     0xfc,0xff,
                     0xfc,0xc3,
                     0xfc,0xc3,
                     0x84,0xdb,
                     0x84,0xdb,
                     0xfc,0xc3,
                     0xfc,0xc3,
                     0xfc,0xff};

void grafico(int y, x, filas, columnas);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#zero_ram   //Borrado de la memoria ram

void main()      //Rutina principal
{
set_tris_a(0b000000);      //Configuracion de entradas y salidas del puerto A
set_tris_b(0b00000000);      //Configuracion de entradas y salidas del puerto B
//port_b_pullups(true);      //Habilitación de las resistencias pull-ups
porta = 0xff;
portb = 0;
///////////////////////////////////////////////////////////////////////////////
//se carga el puntero de la tabla a presentar
dir_tabla_g = &tab_grafico1[0];

//y,x,filas,columnas
grafico(1,1,16,2);
///////////////////////////////////////////////////////////////////////////////
while(true)      //Rutina general
   {
   
   }
}
///////////////////////////////////////////////////////////////////////////////
//realiza un barrido de filas y columnas copiando la tabla de constantes
void grafico(int y, x, filas, columnas)
{
   int i1, i2;
   int registro = 0;
   
   for(i1=0;i1<filas;i1++)
   {
      
      for(i2=0;i2<columnas;i2++)
      {
         status = *dir_tabla_g + registro;
         registro++;
      }
   }
}   
///////////////////////////////////////////////////////////////////////////////
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 06, 2012 1:01 am     Reply with quote

I made the changes shown in the grafico() function shown below.
Then it worked. With those changes, I ran your program in MPLAB
simulator and I got the following output. It matches your tab_grafico1[]
table. I tested the program with CCS version 4.140:
Code:

ff ff
ff ff
c0 0f
c0 0f
c0 0f
cf cf
cc cf
fc ff
fc ff
fc c3
fc c3
84 db
84 db
fc c3
fc c3
fc ff


This is the grafico() function with changes noted in comments:
Code:

void grafico(int y, x, filas, columnas)
{
   int i1, i2;
   int registro = 0;
   
   for(i1=0;i1<filas;i1++)
   {
      for(i2=0;i2<columnas;i2++)
      {
       dir_tabla_g = tab_grafico1;  // *** Added this line
       dir_tabla_g += registro;     // *** Added this line

       status = *dir_tabla_g;       // *** Modified this line
         
       printf("%x ", status);       // *** Added for debug output
       registro++;
      }
    printf("\r");                   // *** Added for debug output
   }
 printf("\r");                      // *** Added for debug output
}   



Note that this line in your original program is wrong:
Quote:
status = *dir_tabla_g + registro;

You are doing pointer arithmetic incorrectly. But even if you do it
write the line correctly as shown below, the program still doesn't work:
Code:
 status = *(dir_tabla_g + registro);

To make the program work correctly, you have to do it the way
that I show in the modified grafico() function given above.

The problem occurs because if you try to do pointer arithmetic (even as
shown above), the compiler does not call the @READ_PROGRAM_MEMORY
library routine. But if you use the modified grafico() function, then it
does call the library code. Then it works.
Diego López



Joined: 25 May 2012
Posts: 11
Location: Colombia

View user's profile Send private message

PostPosted: Thu Dec 06, 2012 8:09 am     Reply with quote

Hello friend, thank you very much for answering.

This works perfect

Code:
for(i2=0;i2<columnas;i2++)
      {
         status = *(dir_tabla_g + registro);
         registro++;
      }


thank you
Diego López



Joined: 25 May 2012
Posts: 11
Location: Colombia

View user's profile Send private message

PostPosted: Tue Dec 11, 2012 9:50 am     Reply with quote

Hello friends,

The constant pointer i work well in this way,

Code:
int variable;

char rom *dir_tabla;

char rom c_30[] = {0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3c,0x00,0x00,0x00,};
char rom c_31[] = {0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x7f,0x00,0x00,0x00,};
char rom c_32[] = {0x3c,0x42,0x42,0x04,0x08,0x10,0x20,0x42,0x7e,0x00,0x00,0x00,};
char rom c_33[] = {0x3c,0x42,0x02,0x02,0x0c,0x02,0x02,0x42,0x3c,0x00,0x00,0x00,};
char rom c_34[] = {0x0c,0x14,0x14,0x24,0x24,0x7e,0x04,0x04,0x1e,0x00,0x00,0x00,};
char rom c_35[] = {0x3e,0x20,0x20,0x3c,0x02,0x02,0x02,0x42,0x3c,0x00,0x00,0x00,};


dir_tabla = c_30;
grafico1();

void grafico1()
{
   int registro;
   
   for(registro = 0; registro<12;registro++)
   {
      variable = *(dir_tabla + registro);
   }
}



can teach me how to make a tables pointer?

thank you very much

! I speak Spanish!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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