Você está na página 1de 6

Embedded Systems IE403

Lab Work

Lab #9

Objective
To design a 4-digit decimal counter using multiplexed 7-segment displays.

Design Requirements BCD to 7-Segment encoder should be software implemented. Counter should reset automatically after the maximum count of 9999. MSDs (most significant digits) should be turned-off when the count has leading zeros (like 0036
should be displayed as 36).

Theory
Multiplexed Displays In some cases we need more than one 7 segment display, But we will be having limited pins to interface, so we cannot use for example 3x8 port pins for 3 seven segment displays. Therefore the effective approach is multiplexing the displays. This method takes advantage of POV i.e. Persistence Of Vision of a human eye, that means a human eye cannot observe changes that occur rapidly within milliseconds or microseconds. In this method we access 7-segment displays one by one so fast that a human eye cannot recognize and it appears like we are driving all the displays simultaneously. Figure 9.1 shows a general circuit configuration of 4-digit multiplexed 7-segments. Advantages Fewer wires are needed. Fewer controller pins are required. Simpler driving electronics can be used. If BCD encoder is hardware implemented then only one such IC is required. Leads to reduced cost. Reduced power consumption. Disadvantages Decrease in hardware complexity results in increase in software complexity. Software overhead is introduced due to delays in segments switching.

Figure 9.1: 4-digit multiplexed 7-segment display

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Embedded Systems IE403

Lab Work

Lab #9

Flow Chart

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Embedded Systems IE403

Lab Work

Lab #9

Source Code
LOC OBJ LINE 1 2 3 4 5 6 7 8 9 10 11 SOURCE ;0-9999 Counter ;Multiplexed 7-segments common-anode SEGDATA EQU P2 ;port for segment data SELSEG EQU P3 ;port for segment selection ORG 0000H LJMP MAIN

00A0 00B0 0000 0000 02001E

;bypass interrupt vector table

0150 ORG 0150H ;7-Seg. Common Cathode code for digits 0 to 9 0150 3F065B4F 12 CC: DB 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F 0154 666D7D07 0158 7F6F 13 0160 14 ORG 0160H ;7-Seg. Common Anode code for digits 0 to 9 0160 C0F9A4B0 15 CA: DB 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 0164 999282F8 0168 8090 16 17 18 000B 19 ORG 000BH 000B 02004E 20 LJMP ISR_T0 21 001B 22 ORG 001BH 001B 020082 23 LJMP ISR_T1 24 001E 25 MAIN: 001E 758911 26 MOV TMOD,#11H ;Timer-1 mode-1, Timer-0 mode-1 0021 758A00 27 MOV TL0,#00H ; 70ms timer 0024 758C00 28 MOV TH0,#00H ; to increment count at every 70ms 0027 758B1A 29 MOV TL1,#01AH ; 0.25ms timer 002A 758DFF 30 MOV TH1,#0FFH ; corresponding to 7-seg switch speed of 1/(0.25 x 4) = 1Khz 002D D2B9 31 SETB PT0 ; set timer 0 overflow to high priority interrupt 002F 75A88A 32 MOV IE,#8AH 33 34 ;Initialize registers 0032 7850 35 MOV R0,#0x50 ; Holds address of our count values 0034 7980 36 MOV R1,#0x80 ; Selects 7-segment 37 38 ;Ram locations 50h to 53h hold unit to 1000th digits

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Embedded Systems IE403


39 40 41 42 43 44 45 46 47 off (CC) 0048 D28C 004A D28E 004C interrupted 004C 80FE 004E unit place respective 004E C28C 0050 C0E0 0052 C000 0054 7850 0056 06 0057 E6 0058 B40A1A 005B 7600 005D 08 005E 06 place 005F E6 0060 B40A12 0063 7600 0065 08 0066 06 place 0067 E6 0068 B40A0A 006B 7600 006D 08 006E 06 place 006F E6 0070 B40A02 0073 7600 0075 0075 758A00 0078 758C00 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

Lab Work
;Count initialized to zero MOV 50H,#0x00 MOV 51H,#0x00 MOV 52H,#0x00 MOV 53H,#0x00

Lab #9

0036 0039 003C 003F

755000 755100 755200 755300

0042 900160 0045 75B000 (CA)

MOV DPTR,#CA ; Common-Anode/Cathode Choice MOV SELSEG,#0x00 ; Initially all segments are off ;MOV SELSEG,#0xFF SETB TR0 SETB TR1 IDLE: SJMP IDLE ISR_T0: ;53h,52h,51h,50h correspond to 1000th,100th,10th and CLR TR0 PUSH 0E0H ; push A PUSH 00H ; push R0 MOV R0,#50h ; point to unit INC @R0 ;increment unit MOV A,@R0 CJNE A,#10,RETURN ; if unit place exceeds MOV @R0,#0 ; reset it to 0 INC R0 ; point to 10th INC @R0 ; and increment ; Initially all segments are ; Start timer-0 ; Start timer-1 ; Remain here until

place place 9 place the 10th

MOV A,@R0 CJNE A,#10,RETURN ; if 10th place exceeds 9 MOV @R0,#0 ; reset it to 0 INC R0 ; point to 100th place INC @R0 ; and increment the 100th MOV A,@R0 CJNE A,#10,RETURN ; if 100th place exceeds 9 MOV @R0,#0 ; reset it to 0 INC R0 ; point to 1000th place INC @R0 ; and increment the 1000th MOV A,@R0 CJNE A,#10,RETURN ; if 1000th place exceeds 9 MOV @R0,#0 ; reset it to 0 RETURN: ;reload timer for next interrupt MOV TL0,#00H MOV TH0,#00H

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Embedded Systems IE403


007B 007D 007F 0081 D28C D000 D0E0 32 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

Lab Work
SETB TR0 POP 00H POP 0E0H RETI ISR_T1: CLR TR1 ;MOV SEGDATA,#0x00 MOV SEGDATA,#0xFF MOV A,@R0 MOVC A,@A+DPTR MOV SEGDATA,A INC R0 MOV A,R0 CJNE A,#0x54,NEXT1 MOV R0,#0x50 NEXT1: MOV A,R1 CJNE A,#0x08,NEXT2 MOV R1,#0x80 SJMP NEXT3 NEXT2: CJNE A,#0x10,CHK1 MOV A,0x53 CJNE A,#0x00,NEXT3 MOV SELSEG,#0x00 SJMP CONT CHK1: CJNE A,#0x20,CHK2 MOV A,0x52 CJNE A,#0x00,NEXT3 MOV A,0x53 CJNE A,#0x00,NEXT3 MOV SELSEG,#0x00 SJMP CONT CHK2: CJNE A,#0x40,NEXT3 MOV A,0x51 CJNE A,#0x00,NEXT3 MOV A,0x52 CJNE A,#0x00,NEXT3 MOV A,0x53

Lab #9
; start timer again ; pop R0 ; pop A

0082 0082 C28E cathode 0084 75A0FF anode 0087 E6 0088 93 0089 F5A0 008B 08 008C E8 008D B45402 0090 7850 0092 0092 E9 0093 B40804 0096 7980 segment 0098 8036 009A 009A B4100A 009D E553 place 009F B4002E 00A2 75B000 00A5 802B 00A7 00A7 B4200F 00AA E552 place 00AC B40021 00AF E553 place 00B1 B4001C 00B4 75B000 00B7 8019 00B9 00B9 B44014 00BC E551 place 00BE B4000F 00C1 E552 place 00C3 B4000A 00C6 E553 place

; uncomment this for common; uncomment this for common-

; Encode data to 7-segment ; Send data to port

; if all numbers are displayed ; then reset back to 1st number

; if all segments attended ; then reset back to 1st

; if it's 1000th place ; location of 1000th ; if the 1000th place has zero ; then turn-off 1000th place

; if it's 100th place ; location of 100th ; if the 100th place has zero ; location of 1000th ; if 1000th digit is also zero ; then turn-off 100th digit

; if it's 10th place ; location of the 10th ; if the 10th place has zero ; location of 100th ; if 100th digit is also zero ; location of 1000th

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Embedded Systems IE403


00C8 B40005 00CB 75B000 00CE 8002 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

Lab Work
CJNE A,#0x00,NEXT3 MOV SELSEG,#0x00 SJMP CONT

Lab #9
; if 1000th digit is also zero ; turn-off 10th digit

00D0 00D0 89B0 Digit 00D2 00D2 E9 00D3 03 00D4 F9

; if all above turn-off conditions are false then NEXT3: MOV SELSEG,R1 ; Select current 7-Segment

CONT: MOV A,R1 RR A MOV R1,A

; Switch to next segment

00D5 00D8 00DB 00DD

758B1A 758DFF D28E 32

;Reload timer for next interrupt MOV TL1,#01AH MOV TH1,#0FFH SETB TR1 ; start timer again RETI END

Code 9.1: ASM listing for 4-Digit Decimal Counter on MUX. 7-Segments

Group Members:

Ali Asad (1936)

Safdar Abbasi (1926)

Você também pode gostar