hello guys
so i made this counter, when i press ra3 the counter adds by one, from 0 to 99, the problem is that when i press the button, the counter doesnt increase, it does nothing, i putted the button part on other code and it does recognize it, it adds and increases, but in this code, no matter how many times i try it does nothing, i cant see the mistake i could possibly made since the button part works in other simpler codes. ive tried a timer counter adding 1 each 300 mili seconds and it works, so the multiplexing part is working fine
here is the code
int i;
int j;
int var;
int conmutador;
int oldstate;
void main() {
TRISB = 0;
TRISA = 1;
TRISA1_bit = 0;
TRISA2_bit = 0;
PORTA = 0;
PORTB = 0;
var = 0;
i = 0;
j = 0;
CMCON = 0x07;
conmutador = 0;
oldstate = 0;
while(1){
if (Button(&PORTA, 3, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&PORTA, 3, 1, 0)) { // Detect one-to-zero transition
i ++; // Invert PORTC
oldstate = 0; // Update flag
}
if(i==10){
i = 0;
j++;
}
if(j==10){
j = 0;
}
if(conmutador == 0){
RA2_bit = 1;
RA1_bit = 0;
var = i;
Delay_ms(10);
conmutador = 1;
}
else{
RA2_bit = 0;
RA1_bit = 1;
var = j;
conmutador = 0;
}
Delay_ms(5);
switch(var){
case 0 : PORTB = 0x3F;break;
case 1 : PORTB = 0x06;break;
case 2 : PORTB = 0x5B;break;
case 3 : PORTB = 0x4F;break;
case 4 : PORTB = 0x66;break;
case 5 : PORTB = 0x6D;break;
case 6 : PORTB = 0x7D;break;
case 7 : PORTB = 0x07;break;
case 8 : PORTB = 0x7F;break;
case 9 : PORTB = 0x6F;break;
}
}
}
if any one of you could help me with this, i really would apreciate it