7-Segment Display Interfacing and Programming


5.1    Introduction

                    Till now you have learn what is an embedded system, basic memory architecture of a microcontroller, how to implement assembly language and use of some softwares like pinnacle 52, keil-C and flash magic; we also have come across how to interface LEDs from a microcontroller and how to generate different pattern through it. now its time to move forward and learn one more step ahead towards the completion of our 6-weak training. so here today we will learn about 7-Segment display; How to interface and program it; and some of the applications of it.

5.2    7-Segment Display


                    A 7-Segment display is a useful electronic component use to produce numeric, alphabetic and some non-alphabetic symbols using a specific arrangement of LEDs as shown in figure here.

                    A 7-Segment display has 10-Pins representing each a, b, c, b, e, f, g and h LEDs respectively along with two extra pins for GND and VSS. following shown an original 7-Segment display device along with its pin diagram. LED h is also denoted by symbol dp.




















                    As we have studied in LED interfacing a 7-segment display is also interfaced in same way as it is also made of LEDs. So we can interface LEDs in three ways bu here difference is that 7-Segment displays comes in two types by manufacturers i.e. "Common Anode" and "Common Cathode"; the logics are shown in figure below.


and


and thus which logic is o implement is on the bases of these specifications provided by 
manufacturer. interfacing in our case has been shown below.

5.3    7-Segment Display Interfacing

                    We interface 7-Segment display with port zero of microcontroller; and to do so we connect P0.0 to P0.7 to Pin a to dp (h) of 7-Segment display respectively; and connect Vss terminal of display to 5V Power supply and GND pin to ground. the configuration is shown in figure below.



5.4    Cascading seven segment display

                    Here we have a question in mind that if we want to interface more then one 7-Segment display with microcontroller what we will do??? as we are using one port for one 7-segment display if we use all the four ports for four 7-Segment display??? isn't it less efficient???

                    The answer of all these questions are hidden under this topic "CASCADING" cascading refers to connecting similar or non-similar component from the same connections with a reference of enabling and disabling each components according to specification.

                    For cascading four 7-Segment display we use the following schem where all the a to f (dp) pins of 7-segment display are connected paralleled to the port zero of microcontroller along with common ground and Vss pin of all the four 7-segments are use for enabling and disabling them so are connected to port two of microcontroller along with NOT Gate in order to " " and thus clearing or sending "0" on pins of port two cause enabling the display and signal "1" cause disabling it.




5.5    7-Segment Display Programming

                    Programming a 7-Segment display is so easy as to program a LED array but here pattern should be generate in a manner so as it appears as a meaningful character and with cascaded mode we also need to send "clear" (0) or "set bit" (1) signal on respected pins of port two in order to enable or disable respected 7-Segment display. The signals on Port zero which can generate meaningful characters on 7-Segment display are listed in table below.



Example

  •   Lets write a program to show character "3" on 7-Segment display.

Showing character "3" on 7-Segment display

;****************************************
;** Showing character "3" on 7-Segment display **
;****************************************

    org 0000h                ;Origin

    main:                        ;Main subroutine

        clr   P2.0                ;Enabling Display-1
        sbit P2.1                ;Disabling Display-2
        sbit P2.2                ;Disabling Display-3
        sbit P2.3                ;Disabling Display-4

        mov P0,11110010b    ;Sending LED pattern of character "3" at port zero

    jmp $

    end                            ;End

OUTPUT







5.6    Generating counting from 0 to 9

0 to 9 Counter

;*************************************
;************ 0 to 9 Counter *************
;*************************************

    org 0000h                    ;Start

    main:                            ;Main Subroutine

        clr   P2.0                ;Enabling Display-1
        sbit P2.1                ;Disabling Display-2
        sbit P2.2                ;Disabling Display-3
        sbit P2.3                ;Disabling Display-4

        mov P0,#0FCh            ;Sending character "0" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#60h               ;Sending pattern of character "1" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0DAh               ;Sending pattern of
 character "2" to Port zero
        call delay                      ;Calling Delay Function

        mov P0,#0F2h           ;Sending pattern of
 character "3" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#66h           ;Sending pattern of
 character "4" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0B6h           ;Sending pattern of
 character "5" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0BEh           ;Sending pattern of
 character "6" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0E0h           ;Sending pattern of
 character "7" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0FEh           ;Sending pattern of
 character "8" to Port zero
        call delay                    ;Calling Delay Function

        mov P0,#0F6h           ;Sending pattern of
 character "9" to Port zero
        call delay                    ;Calling Delay Function

    jmp main                    ;Infinite Loop

    delay:                        ;Delay Function

        mov 40h,#0FFh        ;Move FFh to memory location with address 40h
        L1:                        ;Label "L1"
            mov 41h,#99h        ;Move 99h to memory 41h
            djnz 41h,$            ;Jump here till 41h becomes zero
        djnz 40h,L1            ;Jump to "L1" till 40h becomes zero
    ret                            ;return

    end                                ;End


OUTPUT



5.7    Generating counting from 0 to 9 [using array]

0 to 9 Counter using Array

;*************************************
;******** 0 to 9 Counter using Array*********
;*************************************

    org 0000h

    main:

        clr   P2.0                ;Enabling Display-1
        sbit P2.1                ;Disabling Display-2
        sbit P2.2                ;Disabling Display-3
        sbit P2.3                ;Disabling Display-4

        mov a,#00h

    Up:
        mov 30h,a
        mov dptr,#arr
        movc a,@a+dptr
        mov P0,a
        call delay
        mov a, 30h
        inc a
    jmp Up

    jmp main

    arr:
        db 11111100b
        db 01100000b
        db 11011010b
        db 11110010b
        db 01100110b
        db 10110110b
        db 10111110b
        db 11100000b
        db 11111110b
        db 11110110b

    delay:
        mov 40h,#0FFh
        L1:
            mov 41h,#99h
            djnz 41h,$
        djnz 40h,L1
    ret

    end


OUTPUT





5.8    Generating two digit numbers

Two digit number

;*************************************
;*********** Two digit number ************
;*************************************

    org 0000h

    main:
            clr   P2.0
            sbit P2.1
            sbit P2.2
            sbit P2.3

            mov P0,#01100000b
            call delay

            clr   P2.1
            sbit P2.0
            sbit P2.2
            sbit P2.3

            mov P0,#11011010b
            call delay

    jmp main

    delay:
        mov 40h,#50h
        L1:
            mov 41h,#99h
            djnz 41h,$
        djnz 40h,L1
    ret

    end


OUTPUT




5.9    Generating two four bit numbers alternatively

Alternating two four digit numbers

;************************************
;***** Alternating two four digit numbers *****
;************************************

    org 0000h

    main:
            mov 30h,#0FFh

            UP1:
                clr   P2.0
                sbit P2.1
                sbit P2.2
                sbit P2.3

                mov P0,#01100000b
                call delay

                clr   P2.1
                sbit P2.0
                sbit P2.2
                sbit P2.3

                mov P0,#11011010b
                call delay

                clr   P2.2
                sbit P2.1
                sbit P2.0
                sbit P2.3

                mov P0,#11110010b
                call delay

                clr   P2.3
                sbit P2.1
                sbit P2.2
                sbit P2.0

                mov P0,#01100110b
                call delay

                djnz 30h,UP1
            jmp $

            mov 30h,#0FFh

            UP2:
                clr   P2.0
                sbit P2.1
                sbit P2.2
                sbit P2.3

                mov P0,#10110110b
                call delay

                clr   P2.1
                sbit P2.0
                sbit P2.2
                sbit P2.3

                mov P0,#10111110b
                call delay

                clr   P2.2
                sbit P2.1
                sbit P2.0
                sbit P2.3

                mov P0,#11100000b
                call delay

                clr   P2.3
                sbit P2.1
                sbit P2.2
                sbit P2.0

                mov P0,#11111110b
                call delay

                djnz 30h,UP2
            jmp $
    jmp main

    delay:
            mov 40h,#30h
            L1:
                mov 41h,#99h
                djnz 41h,$
            djnz 40h,L1
    ret

    end



OUTPUT




CLICK TO DOWNLOAD SOURCE CODES



Comments