bit oldstate; // Old state flag
void main() {
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Disable comparators
TRISB0_bit = 1; // Set pin as input
TRISC = 0x00; // Configure PORTC as output
PORTC = 0xAA; // Initial PORTC value
oldstate = 0;
do {
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC
oldstate = 0; // Update flag
}
} while(1); // Endless loop
}
you can copy the same code and past it in the same program under the first one
make sure to change the port pin and the name of the temp variable (i.e. flag2 etc...)
oldstate = 0;
oldstate1 = 0;
oldstate2 = 0;
do {
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC
oldstate = 0; // Update flag
}
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate1 = 1; // Update flag
}
if (oldstate1 && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC
oldstate1 = 0; // Update flag
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate2 = 1; // Update flag
}
if (oldstate2 && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC
oldstate2 = 0; // Update flag
} while(1);
oldstate = 0;
oldstate1 = 0;
oldstate2 = 0;
do {
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC or Action 1
oldstate = 0; // Update flag
}
if (Button(&PORTB, 1, 1, 1)) { // Detect logical one
oldstate1 = 1; // Update flag
}
if (oldstate1 && Button(&PORTB, 1, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC or Action 2
oldstate1 = 0; // Update flag
if (Button(&PORTB, 2, 1, 1)) { // Detect logical one
oldstate2 = 1; // Update flag
}
if (oldstate2 && Button(&PORTB, 2, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC or Action3
oldstate2 = 0; // Update flag
} while(1);
bit oldstate; // Old state flag
void main() {
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0; // configure pins of GPIO as output
TRISIO3_bit = 1;
GPIO = 0xFF;
while(1){
if(Button(&GPIO,3,1,1)){
oldstate=1;
}
if(oldstate && Button(&GPIO,3,1,0)){
GPIO = ~ GPIO;
oldstate = 0;
}
}
}
I tried the pull down but it doesn't workZip and post your project files and proteus file. I think if you connect a 10 K pull down resistor from pin GP3 to GND it will work.
Code C - [expand] 1GPIO = ~GPIO
Code C - [expand] 1GPIO = ~GPIO
Code C - [expand] 1 GPIO.F1 = ~GPIO.F1
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?