• Latest Posts

    Subscribe my Youtube channel for mere videos

    Wednesday, 15 March 2017

    7 segment display interface with PIC microcontroller

    7 segment Display Interfacing








    7 segment display is commonly uses where we want to display any data like temperature display, stop watch, industrial meters etc. We can found different colors & different sizes 7seg displays. Inside the 7seg display seven lightemitting diodes are arranged so that all ten digits (0 - 9) can roughly be displayed.  Seven-segment displays are used for decimal numeric displays.

    Now we will discuss about 0.5”, 5vdc, common anode (all of the led digits anode pins connect together and share a common pin) 7seg display and will use PIC18f2520 microcontroller to display data on 7seg. We will use BC547 (NPN Epitaxial Silicon Transistor) for digit driving.


    7seg display pinout and digit numbers.





    We can display any of the number and character that can be possible to combination of segments. But in this example we will display 0-900 decimal value in a sequence. See the given blow char, how to 7-seg display appears decimal value with pin combination.



    Circuit Diagam

    In the circuit diagram three 7seg display ABCDEFG pins connected to same pins each other and connect to microcontroller port. Common anode pins connected to BC547 transistors. With this circuit, every beginner confused that how to display on indusial 7-segment a specific decimal value. Now i clear this, for example we want to display 123, fist we will turn on first digit’s transistor (Q3) and turn on specific pins of controller port. Turn off Q3 and clear port pins, next turn on Q2 and turn on specific pins of controller port that will display 2. Now turn off Q2 and clear the controller port pins. Next turn on Q1 and turn on specific pins. It will done very fast and human eyes can not see turn off digits. Timer-0 used to adjustment digits on/off interval. So all decimal value can be display crisply.







    Codes

    // 3 transistor for switching 7_seg digits.
    // 20Mhz Oscillator.
    // All configuration bits set in IDE.

    #include <p18f2520.h>

    //-------------------------------------------------------------------------

    void Digit_Show(void);
    #pragma interrupt chk_isr        // Timer-0 interrupt vector
    void chk_isr(void)
    {
                if(INTCONbits.TMR0IF==1) Digit_Show();
    }

    #pragma code isr = 0x08        // store the below code at address 0x08
    void isr(void)
    {
                _asm
                            GOTO chk_isr
                _endasm
    }
    #pragma code


    void Break_val( int val);
    char dig_val[3];
    char dig_no;
    unsigned int a, counter = 0;

    void main()
    {
              dig_no = 0;
              TRISC = 0x00;
              TRISB = 0x00;
              PORTB = 0x00;
              PORTC = 0x00;
               
    T0CON = 0x06;         // Set timer-0 for display digits switching time arrangement.
              TMR0H = 0xF0;      // Using timer-0 interrupt.
              TMR0L = 0xC0;       
              INTCONbits.TMR0IF = 0;
              INTCONbits.TMR0IE = 1;
              INTCONbits.GIE = 1;
              INTCONbits.PEIE = 1;
              T0CONbits.TMR0ON = 1;
              while(1)
                {
                            Break_val(counter);
                            counter++;
                            for(a=0;a<0xFFFF;a++);
                            for(a=0;a<0xFFFF;a++);
                            if(counter>900) counter = 0;
                }

    }

    void Break_val( int val)    // Display 0 to 999 decimal value.
    {
                INTCONbits.TMR0IF = 0;
                dig_val[0] = val % 10;
                dig_val[1] = (val % 100) / 10;
                dig_val[2] = val / 100;
    }

    void Digit_Show()
    {
                INTCONbits.TMR0IF = 0;
                TMR0H = 0xFF;
                TMR0L = 0xC0;
                switch (dig_no){
                            case 0 :  PORTBbits.RB1 = 0;                   // Switch on right digit.
                                            PORTBbits.RB2 = 0;
                                            PORTBbits.RB0 = 1;
                                            break;       
                            case 1 :  PORTBbits.RB0 = 0;                   // Switch on middle digit.
                                            PORTBbits.RB2 = 0;
                                            PORTBbits.RB1 = 1;
                                            break;
                            case 2 :  PORTBbits.RB0 = 0;                   // Switch on left digit.
                                            PORTBbits.RB1 = 0;
                                            PORTBbits.RB2 = 1;
                                            break;
                            default : ;
                }

                            switch (dig_val[dig_no]){
                                        case 0 :  PORTC = 0x3F;                // Print 0 on 7_seg.
                                                        break;
                                        case 1 :  PORTC = 0x06;                // Print 1 on 7_seg.
                                                        break;
                                        case 2 :  PORTC = 0x5B;                // Print 2 on 7_seg.
                                                        break;
                                        case 3 :  PORTC = 0x4F;                // Print 3 on 7_seg.
                                                        break;
                                        case 4 :  PORTC = 0x66;                // Print 4 on 7_seg.
                                                        break;                   
                                        case 5 :  PORTC = 0x6D;               // Print 5 on 7_seg.
                                                        break;
                                        case 6 :  PORTC = 0x7D;               // Print 6 on 7_seg.
                                                        break;
                                        case 7 :  PORTC = 0x07;                // Print 7 on 7_seg.
                                                        break;
                                        case 8 :  PORTC = 0x7F;                // Print 8 on 7_seg.
                                                        break;
                                        case 9 :  PORTC = 0x6F;                // Print 9 on 7_seg.
                                                        break;
                                        default : ;
                            }
                dig_no++;
                if(dig_no>2) dig_no = 0;
    }









    If you have any question, ask feel free. I  will totally devoted for your help.

    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel