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 CCS Technical Support

Expression must evaluate to a constant

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



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Expression must evaluate to a constant
PostPosted: Thu Jun 01, 2006 1:53 am     Reply with quote

Hello,

this is my keypad matrix scanning code :

in NS.h

Code:
// Defini�er keyboard matrix: 9R x 8K
//Rijen
#define R1 PIN_C0
#define R2 PIN_C1
#define R3 PIN_B1
#define R4 PIN_B2
#define R5 PIN_B3
#define R6 PIN_B4
#define R7 PIN_B5
#define R8 PIN_B6
#define R9 PIN_B7
//Kolommen
#define K1 PIN_D0
#define K2 PIN_D1
#define K3 PIN_D2
#define K4 PIN_D3
#define K5 PIN_D4
#define K6 PIN_D5
#define K7 PIN_D6
#define K8 PIN_D7


in main loop:

Code:
//******************************* READ MATRIX ********************************//
void Read_Matrix ()
{
   ALLES_LOS = TRUE;
   PRESSED = FALSE;
   
   Output_low (R1);
   delay_us (100);
   temp = input_d ();       // Lees de waarde van de poort
   Output_float (R1);
   if ( (buffer [0] & temp) != buffer [0] )   // er is gedrukt
      PRESSED = TRUE;
   buffer [0] = buffer [0] & temp;   // Onthoud dat er ingedrukt is
   if (temp != 255)
      Alles_los = FALSE;
   
// RIJ 2
   Output_low (R2);
   delay_us(100);
   temp = input_d();
   Output_float(R2);
   if ((buffer[1] & temp) != buffer[1])
      Pressed = TRUE;
   buffer[1] = buffer [1] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   
// RIJ 3
   Output_low(R3);
   delay_us(100);
   temp = input_d();
   Output_float(R3);
   if ((buffer[2] & temp) != buffer[2])
      Pressed = TRUE;
   buffer[2] = buffer [2] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 4
   Output_low(R4);
   delay_us(100);
   temp = input_d();
   Output_float(R4);
   if ((buffer[3] & temp) != buffer[3])
      Pressed = TRUE;
   buffer[3] = buffer [3] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 5
   Output_low(R5);
   delay_us(100);
   temp = input_d();
   Output_float(R5);
   if ((buffer[4] & temp) != buffer[4])
      Pressed = TRUE;
   buffer[4] = buffer [4] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 6
   Output_low(R6);
   delay_us(100);
   temp = input_d();
   Output_float(R6);
   if ((buffer[5] & temp) != buffer[5])
      Pressed = TRUE;
   buffer[5] = buffer [5] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 7
   Output_low(R7);
   delay_us(100);
   temp = input_d();
   Output_float(R7);
   if ((buffer[6] & temp) != buffer[6])
      Pressed = TRUE;
   buffer[6] = buffer [6] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 8
   Output_low(R8);
   delay_us(100);
   temp = input_d();
   Output_float(R8);
   if ((buffer[7] & temp) != buffer[7])
      Pressed = TRUE;
   buffer[7] = buffer [7] & temp;
   if (temp != 255)
      Alles_los = FALSE;
   // RIJ 9
   Output_low(R9);
   delay_us(100);
   temp = input_d();
   Output_float(R9);
   if ((buffer[8] & temp) != buffer[8])
      Pressed = TRUE;
   buffer[8] = buffer [8] & temp;
   if (temp != 255)
       Alles_los = FALSE;
}


Now this works fine, but you can see that there is many the same code used. So I want to that shorter. This is my idea:

Global const array:
Code:
const char Scan [9] = { PIN_C0, PIN_C1, PIN_B1, PIN_B2, PIN_B3, PIN_B4, PIN_B5,
PIN_B6, PIN_B7 };


scanning routine:
Code:
void Read_Matrix ()
{
   int8 j;
   ALLES_LOS = TRUE;
   PRESSED = FALSE;
   // RIJ per RIJ inscannen
   for ( j = 0 ; j < 9 ; j++ )
   {
      output_low (Scan [j]);
      delay_us (75);
      Temp = input_d ();
      output_float (Scan [j]);
      if ( ( Buffer [j] & Temp ) != Buffer [j] )   // er is gedrukt
         PRESSED = TRUE;
      Buffer [j] = Buffer [j] & Temp;
      if (temp != 255)
         ALLES_LOS = FALSE;
   }
}


Now my comp�ler gives error Expression must evaluate to a constant; I was hoping you guys could give hints on this?
ckielstra



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

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 3:53 am     Reply with quote

The output_low() function only accepts constants, not variables.

For a replacement function see:
PIC16: http://www.ccsinfo.com/forum/viewtopic.php?t=25280
PIC18: http://www.ccsinfo.com/forum/viewtopic.php?t=25591
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 5:33 am     Reply with quote

thanks,

that was exactly what I needed; thanks for sharing:

Code:
void Read_Matrix ()
{
   int8 j;
   ALLES_LOS = TRUE;
   PRESSED = FALSE;
   // RIJ per RIJ inscannen
   for ( j = 0 ; j < 9 ; j++ )
   {
      do_pin_io (Scan [j], 0);
      delay_us (75);
      Temp = input_d ();
      do_pin_io (Scan [j], 2);
      if ( ( Buffer [j] & Temp ) != Buffer [j] )   // er is gedrukt
         PRESSED = TRUE;
      Buffer [j] = Buffer [j] & Temp;
      if (temp != 255)
         ALLES_LOS = FALSE;
   }
}
// do_pin_io() --
// This function will perform an i/o action on a CCS pin.
// The ccs_pin parameter must be a value defined in the .H
// file for your PIC, such as PIN_B0, PIN_C5, etc.
// The CCS pin value and state can be passed in variables.
// The action must be as follows:
// Action = 0:  Set the specified pin = 0
// Action = 1:  Set the specified pin = 1
// Action = 2:  Read the specified pin and return
//                   its value (0 or 1).
// Any action value > 2 will be treated as 2.  For actions
// 0 and 1, the return value has no meaning (but 0 is
// returned).


int8 do_pin_io(int8 ccs_pin, int8 action)
{
int8 io_port;
int8 bitmask;
int8 retval;
int8 const bitmask_table[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

retval = 0;
io_port = ccs_pin >> 3;   // Get the i/o port address     
bitmask = bitmask_table[ccs_pin & 7];

if(action < 2)  // Is this an output action ?
  {
   *(io_port | 0x80) &= ~bitmask; // Set TRIS = output

   if(action)
     {
      *io_port |= bitmask;    // Set pin = 1
     }
   else
     {
      *io_port &= ~bitmask;   // Set pin = 0
     }
  }
else  // If not, we will read the pin  (action = 2)
  {
   *(io_port | 0x80) |= bitmask;     // Set TRIS = input

   retval = !!(*io_port & bitmask);  // Read pin (ret. 0 or 1)
  }

return(retval);   // This only has meaning if action = 2
}


However, when I want to say output_float (SOME_PIN), how can I state that?
Ttelmah
Guest







PostPosted: Thu Jun 01, 2006 5:52 am     Reply with quote

If you read a pin, it is 'floated'. Output_float, is really just a version of the input function, that doesn't actually return the value. So 'action=2', will do what you want.

Best Wishes
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