PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 07, 2010 6:12 pm |
|
|
Here is a test program which shows what the input_change_x() function
does. It's not a finished, useful program. It just displays the "delta"
variable whenever button4 or button5 is pressed or released. Button4
is a pushbutton connected to pin RB4. Button5 is connected to pin RB5.
When a button is pushed, it connects the pin to ground. When it's not
pushed, a pull-up holds the pin at a logic high level.
As a test, I pressed and released button4 four times. Then I pressed
and released button5 three times. It displayed the following output
on the serial terminal. Each pair ("10 10") represents a press and a
release of the button. "10" is the Hex bitmask for pin RB4. "20" is the
hex bitmask for pin RB5.
Quote: |
10 10 10 10 10 10 10 10 20 20 20 20 20 20 20 20
|
I don't want to write a complete "button state detection" program.
I only wanted to make this simple test program:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
int8 delta = 0;
#define BUTTON4_MASK 0x10 // Button on pin B4
#define BUTTON5_MASK 0x20 // Button on pin B5
#define ALL_BUTTONS_MASK (BUTTON4_MASK | BUTTON5_MASK)
#int_rb
void rb_isr(void)
{
delta = input_change_b() & ALL_BUTTONS_MASK;
}
//======================================
void main()
{
port_b_pullups(TRUE);
delay_us(10);
input_change_b(); // Init Change_B state
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
while(1)
{
if(delta)
{
printf("%X ", delta);
delta = 0;
}
}
} |
|
|