Thursday, January 19, 2006

8051: Example 8

Using LED display

The following examples describe the use of LED displays. Common chatode displays are used here, which means that all built-in LEDs are polarized in such a way that their anodes are connected to the microcontroller pins. Since the common way of thinking is that logic one (1) turns something on and logic zero (0) turns something of, Low Current displays (low power consumption) and their diodes (segments) are connected serially to resistors of relatively high resistance.
In order to save I/O pins, four LED displays are connected to operate in multiplex mode. It means that all segments having the same name are connected to one output port each and only one display is active at a time.
Tranzistors and segmenats on displays are quickly activated, thus making impression that all digits are active simultaneously.
Using LED display

Writing digits on LED display

This program is a kind of “warming up” exerciese before real work starts. The purpose of this example is to display something on any display. Multiplex mode is not used this time. Instead, digit 3 is displayed on only one of them (first one on the right).
Since the microcontroller “does not know” how we write number 3, a small subroutine called Disp is used (the microcontroller writes this number as 0000 0011). This subroutine enables all decimal digits (0-9) to be displayed (masked). The principle of operation is simple. A number to be displayed is added to the current address and program jump is executed. Different numbers require different jump length. Precisely determined combination of zeroes and ones appears on each of these new locations (digit 1 mask, digit 2 mask...digit 9 mask). When this combination is transferred to the port, the display shows desired digit.
;************************************************************************
;* PROGRAM NAME : 7Seg1.ASM
;* DESCRIPTION: Program displays number "3" on 7-segment LED display
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG1.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
          DSEG     AT     03FH
STACK_START:       DS     040H

;RESET VECTORS
          CSEG     AT     0
          JMP      XRESET               ; Reset vector

          ORG      100H

XRESET:   MOV      SP,#STACK_START      ; Define Stack pointer
          MOV      P1,#0                ; Turn off all segments on displays
          MOV      P3,#20h              ; Activate display D4

LOOP:
          MOV      A,#03                ; Send number “3” to display
          LCALL    Disp                 ; Perform appropriate masking for the number
          MOV      P1,A
          SJMP     LOOP

Disp:                                   ; Subroutine for displaying digits
          INC      A
          MOVC     A,@A+PC
          RET
          DB       3FH                  ; Digit 0 mask
          DB       06H                  ; Digit 1 mask
          DB       5BH                  ; Digit 2 mask
          DB       4FH                  ; Digit 3 mask
          DB       66H                  ; Digit 4 mask
          DB       6DH                  ; Digit 5 mask
          DB       7DH                  ; Digit 6 mask
          DB       07H                  ; Digit 7 mask
          DB       7FH                  ; Digit 8 mask
          DB       6FH                  ; Digit 9 mask
          END                           ; End of program