Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
Group Members:
Lab Work
Lab #9
Flow Chart
Group Members:
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
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:
Lab Work
;Count initialized to zero MOV 50H,#0x00 MOV 51H,#0x00 MOV 52H,#0x00 MOV 53H,#0x00
Lab #9
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
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:
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
; 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:
Lab Work
CJNE A,#0x00,NEXT3 MOV SELSEG,#0x00 SJMP CONT
Lab #9
; if 1000th digit is also zero ; turn-off 10th digit
; if all above turn-off conditions are false then NEXT3: MOV SELSEG,R1 ; Select current 7-Segment
;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: