Page 1 of 1

Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 10:59 am
by Fiz
Hello,

i have problem to write programming code in MikroC Pro for PIC,since i'm quite new in micro c and programming,i do not know what my programming code mistake,btw i'm using PIC16F877A. Here i attach my code,hope someone can guide me,really appreciate it.
CODE: SELECT_ALL_CODE
int i,j,k;

void display_s1(int j,int i){
PORTB = 0b00100000 + j;
PORTB = 0b00010000 + i;

delay_ms(2);
}

void main() {
   TRISB = 0;
   PORTB = 0;

   while(1){
        for(k=0;k<100;k++){
        j = k%10;
        i = k/10;
        display_s1(j,i);
        delay_ms(200);
        }
   }
}

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 11:06 am
by Fiz
This is my another coding,also cant get nice count 00 to 99 because the 7-segments are alternating count.
CODE: SELECT_ALL_CODE
int i,j,k;

void display_s1(int j){
PORTB = 0b00100000 + j;
delay_ms(2);
}
void display_s2(int i){
PORTB = 0b00010000 + i;
delay_ms(2);
}

void main() {
   TRISB = 0;
   PORTB = 0;

   while(1){
        for(k=0;k<100;k++){
        j = k%10;
        i = k/10;
        display_s1(j);
        delay_ms(200);
        display_s2(i);
        delay_ms(200);
        }
   }
}

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 3:32 pm
by shahrul
How your schematic?

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 4:28 pm
by Fiz
Here my schematic,sorry for not include it earlier

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 6:20 pm
by shahrul
I will use Timer Interrupt for the multiplexing and put transistor switching on common seven segment.

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 6:35 pm
by Fiz
Hello,

Thanks for your feedback,timer interrupt..something new,i'll try,thanks again

Re: Need help on programming code count 00 to 99

PostPosted: Sun Mar 17, 2013 7:54 pm
by Brian Griffin
I do not see a lookup table there. Depending on the connection of the 7-segment, your lookup table will be different. Therefore,

CODE: SELECT_ALL_CODE
const unsigned char sevenSegment[10] = { ... }


keeps all your patterns for each number per digit.

Then, to multiplex it, you

CODE: SELECT_ALL_CODE

while(1) {

1.) turn digit 1 on, and turn digit 2 off
2.) put digit (10s) into PORTB, like sevenSegment[x] where x is the number. If it's 1, then it'll show up one.
3.) delay for 1-5ms
4.) turn digit 1 off, and turn digit 2 on
5.) put digit (1s) into PORTB, like sevenSegment[x] where x is the number. If it's 1, then it'll show up one.
6.) delay for 1-5ms

}



There's also the timer and interrupt trick as Shahrul said. You can use that as well. This sample pseudocode is just for understanding only.

Re: Need help on programming code count 00 to 99

PostPosted: Tue Mar 19, 2013 10:14 am
by robosang
Yup, agreed with Shahrul where transistor is needed because the current required to be absorb is more than what single PIC pin can take.

what is the common polarity of the 7segment? Common anode or cathode? Is the 74 chip decoder?