Need help on programming code count 00 to 99

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Need help on programming code count 00 to 99

Postby Fiz » Sun Mar 17, 2013 10:59 am

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);
        }
   }
}
Fiz
Novice
 
Posts: 31
Joined: Sat Jan 22, 2011 1:37 pm
Location: Melaka

Re: Need help on programming code count 00 to 99

Postby Fiz » Sun Mar 17, 2013 11:06 am

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);
        }
   }
}
Fiz
Novice
 
Posts: 31
Joined: Sat Jan 22, 2011 1:37 pm
Location: Melaka

Re: Need help on programming code count 00 to 99

Postby shahrul » Sun Mar 17, 2013 3:32 pm

How your schematic?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Need help on programming code count 00 to 99

Postby Fiz » Sun Mar 17, 2013 4:28 pm

Here my schematic,sorry for not include it earlier
Attachments
Schematic.png
Fiz
Novice
 
Posts: 31
Joined: Sat Jan 22, 2011 1:37 pm
Location: Melaka

Re: Need help on programming code count 00 to 99

Postby shahrul » Sun Mar 17, 2013 6:20 pm

I will use Timer Interrupt for the multiplexing and put transistor switching on common seven segment.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Need help on programming code count 00 to 99

Postby Fiz » Sun Mar 17, 2013 6:35 pm

Hello,

Thanks for your feedback,timer interrupt..something new,i'll try,thanks again
Fiz
Novice
 
Posts: 31
Joined: Sat Jan 22, 2011 1:37 pm
Location: Melaka

Re: Need help on programming code count 00 to 99

Postby Brian Griffin » Sun Mar 17, 2013 7:54 pm

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.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Need help on programming code count 00 to 99

Postby robosang » Tue Mar 19, 2013 10:14 am

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?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 24 guests