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

output pins

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







output pins
PostPosted: Fri Dec 31, 2004 9:10 am     Reply with quote

I have been trying to write a keypad program that lights up an array of twelve led's. In order to save IO lines, I have decoded the locations. However, I would like to use only one write function. This would require being able to pass which pin to output to through a function. My decoding scheme decides which pin is applicable, then I output. When compiling I get this error. I know data_line should be a constant, but is there anyway to get around this.


Quote:
*** Error 27 "C:\Documents and Settings\sshill.PELHAM\Desktop\MY Code\Keys\keydriver.c" Line 235(54,55): Expression must evaluate to a constant


Code:
#define row1data   PIN_D1
#define row2data   PIN_D2


int data_line;
int button_id;


   if (button_id < 3)
   {   
      data_line = row1data;
      
   }
   if (button_id > 6)
   {   
      data_line = row2data;
      
   }

   output_bit(data_line, shift_left(&commandbyte[j],1,0));
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Dec 31, 2004 9:27 am     Reply with quote

The function output_bit() requires a constant, like the number 45 or PIN_D1(which has been previously defined in the devices file for the part). You are trying to use a variable, data_line, as part of the function. Read the help file on this function a bit more.

Ronald
Ttelmah
Guest







PostPosted: Fri Dec 31, 2004 10:09 am     Reply with quote

Why not just go one stage further in what you have already done?.

Code:

#define row1data   PIN_D1
#define row2data   PIN_D2


int bit_val;
int button_id;


   bit_val=shift_left(&commandbyte[j],1,0);
   if (button_id < 3)
   {   
      output_bit(row1data,bit_val);
       
   }
   if (button_id > 6)
   {   
      output_bit(row2data,bit_val);
       
   }


If you need to access multiple bits in a single byte, you can just use a bit mask, and the byte IO functions. The 'bit' IO functions, all require constant values, not variables.

Best Wishes
FAvre04
Guest







thanks
PostPosted: Fri Dec 31, 2004 4:27 pm     Reply with quote

Thanks for your suggestions. I was hoping there was a way to around the constant problem. But i can just code it out with switch statements.
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