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

problem with comparing arrays

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

problem with comparing arrays
PostPosted: Tue May 08, 2007 12:24 am     Reply with quote

Dear sir,
here i am using 16f913, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.

here i am comparing the pointer 'ptr' with array value.
but while debugging on ICD2 i saw the ptr value changing after 2 increments.
and pointing to random locations.
Plz tell me the proper way of comparing.
here is my sample code
Code:

#include<16F913.h>
#fuses INTRC_IO,NOWDT,PUT,MCLR,PROTECT,NOCPD,NOBROWNOUT,NOPROTECT,NOIESO,NOFCMEN
#use delay(clock=8000000)

#define DIGIT1  COM3+6,   COM2+6,   COM0+6,   COM1+6,   COM0+5,   COM3+5,   COM2+5,   COM1+5   // DISPALYS FROM RIGHT SIDE
#define DIGIT2  COM3+7,   COM2+7,   COM0+7,   COM1+7,   COM0+4,   COM3+4,   COM2+4               

#define VLCD_ENABLE 0x10

#define BLANK 0

byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
byte  *ptr;

void init_CPU();
void lcd_putc(int);
byte lcd_pos = 1;


void main()
{
int number = 0 ;
ptr = Digit_Map[0];
init_CPU();
while(TRUE)
   {   
      lcd_putc(number);
      if(number++ == 9)
              {
                 number = 0;
              }
               
   //      delay_ms(1000);
   }

}


void lcd_putc(int c)
{
byte segments;

if((c>=0)&&(c <=9))
   {
      segments=Digit_Map[c];

   }
             
else
   {
      segments = BLANK;
      lcd_symbol(segments,DIGIT6);
            lcd_symbol(segments,DIGIT5);
            lcd_symbol(segments,DIGIT4);
            lcd_symbol(segments,DIGIT3);
            lcd_symbol(segments,DIGIT2);
            lcd_symbol(segments,DIGIT1);
         }   
switch(lcd_pos)
   {
      case 1:
              LCD_SYMBOL(segments,DIGIT1);   
              LCD_SYMBOL(ptr,DIGIT2);
              if(segments == Digit_Map[9])
                 {
                    ptr++;      // Ater 2 increment it shows garbage value
                     segments = Digit_Map[0];
                     if(ptr == Digit_Map[9])   
                        {
                          lcd_pos++;
                           ptr = Digit_Map[0];   
                        }
                                                         
                  }
             break;
           case 2:
              break;
                                       
               }
       
}   

void init_CPU()
{
/**************  PORT SETTINGS ****************/
   PORT_B_PULLUPS(0XC0);
   SET_TRIS_A(0X80);
   SET_TRIS_B(0XC0);
   SET_TRIS_C(0X27);   
   SET_TRIS_E(0X08);
   OUTPUT_A(0X00);
   OUTPUT_B(0X00);
   OUTPUT_C(0X00);
   OUTPUT_E(0X00);

/****************  COMPARATOR SETTINGS  ***************/
   SETUP_COMPARATOR(NC_NC_NC_NC);

/****************  INTERRUPT SETTINGS  *****************/
   ENABLE_INTERRUPTS(GLOBAL);
   ENABLE_INTERRUPTS(INT_TIMER1);      //enable timer1 interrupt
/*************** LCD SETTINGS ********************/
SETUP_LCD( LCD_MUX14 | LCD_INTRC |VLCD_ENABLE , 2);

}


_________________
Thank You,
With Best Regards,
Deepak.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 08, 2007 2:46 am     Reply with quote

You enable the timer1 interrupt but you don't have an interrupt handler present. Either disable the interrupt or add an interrupt handler for timer1.

Code:
ptr = Digit_Map[0];
To get the address of an array you have to use
Code:
  ptr = &Digit_Map[0];

or equivalent

  ptr = Digit_Map;


The same error is in
Code:
if(ptr == Digit_Map[9])    // add an '&'

and
Code:
ptr = Digit_Map[0];    // add an '&'
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

problem with assigning arrays....
PostPosted: Wed May 09, 2007 12:19 am     Reply with quote

Dear Support,
thanks for replying,
but, at first i was did the same what u suggest i.e.
Code:

ptr = &Digit_Map[0];

or equivalent

  ptr = Digit_Map;

and
if(ptr == &Digit_Map[9])   
and
ptr = &Digit_Map[0];   


but while compling it gives three error,
Line 32(19,20): Expecting an identifier
Line 82(34,35): Expecting an identifier
Line 85(28,29): Expecting an identifier

thats why i changed format of assigning arrays.
plz tell the modifications.
_________________
Thank You,
With Best Regards,
Deepak.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: problem with assigning arrays....
PostPosted: Wed May 09, 2007 1:37 am     Reply with quote

Code:
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
Remove the 'const' keyword and your code will compile.

Explanation:
The PIC processor has two different memories: program memory and data memory (this is called a Harvard architecture while your normal PC has only a single memory space, called a _von Neumann architecture). The v3.xxx compiler is limited and only supports pointers to data memory, not to program memory.
When you define the array as 'const' the data will be placed in program memory. Remove 'const' and the array will be located in data memory.
Yes, the error message you got is not very helpfull.
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