Author Topic: Problems with c code for pic16f628a(0-99 counter 7 segment display)  (Read 1780 times)

0 Members and 1 Guest are viewing this topic.

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 133
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
Code: [Select]
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
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
what is "Button(&PORTA, 3, 1, 1)" ?
what compiler are you using?
 

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 133
what is "Button(&PORTA, 3, 1, 1)" ?
what compiler are you using?
is an anti bouncing library, im using mikroc
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Code: [Select]
TRISA = 1;
TRISA1_bit = 0;
TRISA2_bit = 0;
I could be wrong, but I think you have defined portA,3 to be an output. The first statement will set TRISA to 0000 0001.
 

Offline EPTech

  • Regular Contributor
  • *
  • Posts: 168
  • Country: be
    • EP Technical Services
Hi there,

Try getting rid of the space between the i and the ++. I have had a similar problem with another compiler compiling the code but not linking it.

happy hunting.
Kind greetings,

Pascal.
 

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 133
Code: [Select]
TRISA = 1;
TRISA1_bit = 0;
TRISA2_bit = 0;
I could be wrong, but I think you have defined portA,3 to be an output. The first statement will set TRISA to 0000 0001.
thanks! that was the mistake
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf