Author Topic: problem with c code for pic (0-99 counter, multiplexing 7 segment)  (Read 2287 times)

0 Members and 1 Guest are viewing this topic.

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 133
hello, i made a code for a pic 16f628a to count from 0 to 99, the thing is that the left digit turns on, and counts as it should be(every time i == 10 j increases), its displays that, but the units doesnt display on the 7 segment.
ive measured with the multimeter and a scope to see if ra2 turns on, but it doesnt, ive tried with other ports as well but it doesnt go high, so i suppose is a code problem.
here is the code:

Code: [Select]
int i;
int j;
int var;
int conmutador;

void main() {
TRISB = 0;
TRISA = 0;
PORTA = 0;
PORTB = 0;
var = 0;
i = 0;
j = 0;
conmutador = 0;
while(1){
Delay_ms(300);
i++;
Delay_ms(300);

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;

}
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;
}

}
}

i stands for units
j stands for dozens

im doing the multiplexing by using 2 bc547's
the transistors are working fine, as well as the resistors, the problem is on the pic not activating the pin for units

thanks for your time
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: problem with c code for pic (0-99 counter, multiplexing 7 segment)
« Reply #1 on: May 27, 2016, 12:31:39 am »
Have you disabled the analogue inputs? I believe the default state is analogue, which takes precedence over logic in/out.
 

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 133
Re: problem with c code for pic (0-99 counter, multiplexing 7 segment)
« Reply #2 on: May 27, 2016, 12:47:27 am »
Have you disabled the analogue inputs? I believe the default state is analogue, which takes precedence over logic in/out.
how do i do that in code?
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: problem with c code for pic (0-99 counter, multiplexing 7 segment)
« Reply #3 on: May 27, 2016, 12:53:49 am »
This chip does not appear to have the usual ADC, but it does have analogue comparator inputs. I am looking at Microchip's datasheet DS40044F (probably out of date now), example 5.1, "Initializing PortA". It is suggesting that the comparators need to be disabled by writing 0x07 to a register called CMCON.
 
The following users thanked this post: little_carlos

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: problem with c code for pic (0-99 counter, multiplexing 7 segment)
« Reply #4 on: May 27, 2016, 01:17:49 am »
Have you disabled the analogue inputs? I believe the default state is analogue, which takes precedence over logic in/out.
how do i do that in code?
Same way you do everything else in code, or a PIC, or electronics, or a car, or a baby crib, or breakfast...RTFM.
If you have a problem with an I/O pin, you look at the section in the datasheet about...you may have guessed already...I/O pins.
If you have a problem with Port A, maybe you want to read the section that talks all about Port A.
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf