|
|
View previous topic :: View next topic |
Author |
Message |
Favre04 Guest
|
output pins |
Posted: Fri Dec 31, 2004 9:10 am |
|
|
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
|
|
Posted: Fri Dec 31, 2004 9:27 am |
|
|
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
|
|
Posted: Fri Dec 31, 2004 10:09 am |
|
|
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 |
Posted: Fri Dec 31, 2004 4:27 pm |
|
|
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. |
|
|
|
|
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
|