|
|
View previous topic :: View next topic |
Author |
Message |
wynnet
Joined: 02 Dec 2003 Posts: 15
|
portB and momentary pushbutton? |
Posted: Wed Feb 04, 2004 12:03 pm |
|
|
Hi,
Assuming I have 3 momentary pushbutton on port B:7,6, and 5, but only focus on portB:7 here.
With the interrupt-on-change, for port B pin 7, on PIC18F452,
Assuming the pin is normally pull high.
When I press a button (HiToLow), this should give me one interrupt-on-change,
I suppose I need to do value=input_B() to clear the interrupt and see what pin goes to GND. I expect a LOW on pin 7 here.
So When I release the momentary pushbutton, do I get a second interrupt-on-change?
Please clarify this.
Also on the example EX_PBUTT.C, I don't understand:
when will the section after HIGHTOLOW execute?
#define LOWTOHIGH =TRUE
#define HIGHTOLOW = FALSE
#int_rb
void detect_rb_change() {
int current;
static int last=0;
set_tris_b(0xF0);
current=input_b();
#if LOWTOHIGH
if ((!bit_test(last,4))&&(bit_test(current,4))) {dbutton4=1;}
if ((!bit_test(last,5))&&(bit_test(current,5))) {dbutton5=1;}
if ((!bit_test(last,6))&&(bit_test(current,6))) {dbutton6=1;}
if ((!bit_test(last,7))&&(bit_test(current,7))) {dbutton7=1;}
#elif HIGHTOLOW
if ((!bit_test(current,4))&&(bit_test(last,4))) {dbutton4=1;}
if ((!bit_test(current,5))&&(bit_test(last,5))) {dbutton5=1;}
if ((!bit_test(current,6))&&(bit_test(last,6))) {dbutton6=1;}
if ((!bit_test(current,7))&&(bit_test(last,7))) {dbutton7=1;}
#endif
last=current;
} |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
|
Posted: Wed Feb 04, 2004 1:07 pm |
|
|
Yes, it will interrupt at each change to any of the interupt-on-change inputs, so high-low and low-high each generate an interrupt.
I haven't used the ex_pbutt, but I think I see what you are asking. The section is a conditional compile. If the define is true, the section following it is compiled in. So in the example, since LOWTOHIGH is TRUE the 4 lines following #if LOWTOHIGH are compiled and the #elif (else if) section is skipped. To get the second section to compile LOWTOHIGH must be FALSE and HIGHTOLOW must be TRUE. If both are FALSE neither section is compiled in. Note these are at compile time not run time! Is that what you were asking about?
- SteveS |
|
|
wynnet
Joined: 02 Dec 2003 Posts: 15
|
portB and Momentary pushbutton |
Posted: Thu Feb 05, 2004 5:24 am |
|
|
Thank you Steve,
I appreciate your clarification especially the example, #if,
I need to do some more thinking to reduce one interrupt out of two interrupt-on-change. |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
|
Posted: Thu Feb 05, 2004 12:51 pm |
|
|
The #if structure is a standard c preprocessor directive - there are many sources that will help you there. Start with a Google search on condition inclusion in C.
I use the interrupt-on-change and just ignore the edge I don't need ( ie - enter the interrupt, check the edge, then process or return). Yes, you get extra interrupts, but generally it's no big deal - especially a pushbutton which doesn't occur often, unless it's not debounced; but that's another story. |
|
|
|
|
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
|