Thursday, 12 February 2015

Multiple 7 Segment Multiplexing using PIC16F877A for Beginners

I decided to write an article on simple 7 segment multiplexing for beginners during  my leisure time. my goal is to help create basic and easy understanding of using Pic microcontroller. The Applications of 7 segment multiplexing includes Digital Multimeter, Inverters, power electronics,speedometers,digital clock display, heart beat rate measurement and many others. in this tutorial i assumed that you understands PIC16F877A and 7-Segment Display. Multiplexing in 7 segment display is a ways of  reducing pins needed for each segments to display e.g if i want to display three 7-segment display normally then you needed about 27 pins but using multiplexing mode then it produces only 10 pins to display all the segments.

The techniques used in displaying all segment with desires data on each is called scanning which occurs at a very high speed (less than 20ms ) then it seems to be all turned on at the same time due to persistence of vision.

if you wish to know more about Microcontroller and it Programming(C, Basic and Assembly language) then visit our Embedded system Class or call +2348188515146

the code is written with MikroC compiler and can easily be port in any other Compiler(Hitech C, xc8 compiler, CCS compiler and many others)

#define col1 PORTD.F0
#define col2 PORTD.F1
#define col3 PORTD.F2
#define col4 PORTD.F3
#define col5 PORTD.F4
#define col6 PORTD.F5
#define col7 PORTD.F6
#define col8 PORTD.F7
#define col9 PORTC.F0
       unsigned char pnt=0;
       unsigned char SEG1[]="123"; // numbers to display
       unsigned char SEG2[]="456";
       unsigned char SEG3[]="789";
table(unsigned char sch){
               switch(sch){
             case 0:  return 0b00111111 ;
             case 1:  return 0b00000110;
             case 2:  return 0b01011011;
             case 3:  return 0b01001111;
             case 4:  return 0b01100110;
             case 5:  return 0b01101101;
             case 6:  return 0b01111101;
             case 7:  return 0b00000111;
             case 8:  return 0b01111111;
             case 9:  return 0b01101111;
             }
}
Segment3_Display(unsigned char *val,unsigned char *val1, unsigned char *val2){
                        int str=0;
                        col1 =1; col2=0; col3=0;
                        PORTB = table(val[str++]-48);
                        delay_ms(1);
                        col1 =0; col2=1; col3=0;
                        PORTB = table(val[str++]-48);
                        delay_ms(1);
                        col1 =0; col2=0; col3=1;
                        PORTB = table(val[str]-48);
                        delay_ms(1);
                        col1=0; col2=0; col3=0;
                        col4 =1; col5=0; col6=0;
                        str=0;
                        PORTB = table(val1[str++]-48);
                        delay_ms(1);
                        col4 =0; col5=1; col6=0;
                        PORTB = table(val1[str++]-48);
                        delay_ms(1);
                        col4 =0; col5=0; col6=1;
                        PORTB = table(val1[str]-48);
                        delay_ms(1);
                        col1=4; col5=6; col6=0;
                        col7 =1; col8=0; col9=0;
                        str=0;
                        PORTB = table(val2[str++]-48);
                        delay_ms(1);
                        col7 =0; col8=1; col9=0;
                        PORTB = table(val2[str++]-48);
                        delay_ms(1);
                        col7 =0; col8=0; col9=1;
                        PORTB = table(val2[str]-48);
                        delay_ms(1);
                        col7=0; col8=0; col9=0;
                       
                        }

void main() {
              TRISB=0; PORTB=0; // makes PORTB outputs
              TRISC=0; PORTC=0;
              TRISD=0; PORTD=0;
             while(1)Segment3_Display(SEG1,SEG2,SEG3); //function to display all segments

                 
}


Image result for 7 segment display








Image result for 7 segment display

No comments:

Post a Comment