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

Extreme beginner question

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



Joined: 04 Nov 2004
Posts: 33

View user's profile Send private message Send e-mail

Extreme beginner question
PostPosted: Thu Nov 04, 2004 7:57 am     Reply with quote

I have a very basic question here regarding the INPUT function. I am playing with a PIC Microcontroler and trying to make it respond to buttons. In the process I learned that I need to have a debouncer for the buttons, since the pressing of a button is registered more than once on a single push.
Since I have multiple buttons, I would like to write a simple little function that will take as input the button pushed and debounce it.
Following is the code I am currently using:
void debounce(int bt)
{
delay_ms(250);
while(!input (bt))
delay_ms(20);
}
The message I get is:
Expression must evaluate to a constant.

Every example I saw sofar is not telling me how to pass a variable to a function like INPUT. They usually pass #DEFINEs i.e.
input (PIN_A1)

Is it possible to pass a variable to input?

thanx
Iggy
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 11:33 am     Reply with quote

The function input() needs something it can evaluate at compile time, not a variable. There are complex ways to get around this by reading the input as a memory location through a pointer. But I would first ask if all your buttons are on the same port? Then you can just read the port into a byte and address the individual buttons a bits within the byte. Bit_test() may have the same problem, I don't remember but you can find out quickly enough. If Bit_test() won't take a variable you can always shift the byte till you get the bit you want. More efficient would be a union of a byte for the port with a struct of boolians, but that might be confusing for a raw beginner. It is OK if there are other things on other pins of the port for you to ignore.

Happy exploring!
_________________
The search for better is endless. Instead simply find very good and get the job done.
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