[8051] Edsim51 7 Segment Display Issue

Status
Not open for further replies.

Thread Starter

Kloakk

Joined Mar 9, 2024
2
Hi all - I'm making a 2 minute countdown timer, for an assignment. I currently have a register holding the minutes, and the seconds. For some reason though, sometimes a single (but different each time) segment of my 7 segment display will momentarily turn off and back on, it's quite a minor thing, but it's bugging me. I don't know if this is an error I've written in the code, or just a "feature" of the emulator? Heres the code :

ORG 00h
MOV R4, #2 ; Initialize minutes to 2
MOV R5, #30 ; Initialize seconds to 30
ACALL DisplayR4 ; Initial display update
Back: ACALL Delay
DEC R5
CJNE R5, #0FFh, NotUnderflow ; Check if R5 has underflowed
MOV R5, #59
ACALL DisplayR4 ; Reset seconds to 59
DEC R4 ; Decrement minutes
; Update display since R4 changed

NotUnderflow:
CJNE R4, #0, Back ; Check if R4 is zero, if not, continue the loop
CJNE R5, #0, Back ; Check if R5 is zero, if not, continue the loop
SJMP $ ; If both R4 and R5 are zero, stop the program
; Delay subroutine that creates an approximate one-second delay
Delay: MOV R2, #8
OuterLoop: MOV R0, #0FFh
Again: MOV R1, #0FFh
Here: DJNZ R1, Here
DJNZ R0, Again
DJNZ R2, OuterLoop
RET
; Subroutine to display the value of R4 on the 7-segment display
DisplayR4:
MOV A, R4 ; Move the value in R4 to the accumulator
ADD A, #0 ; OFFSET is zero because DisplayTable starts at 30h (no need for an offset)
MOV DPTR, #DisplayTable
MOVC A, u/A+DPTR ; Move the pattern for the digit in R4 into A
MOV P1, A ; Move the pattern to port P1 to display it
RET
; DisplayTable that contains the 7-segment patterns for the numbers 0-2
; The table is located starting at 30h in the code memory
DisplayTable:
DB 11000000B ; Pattern for '0'
DB 11111001B ; Pattern for '1'
DB 10100100B ; Pattern for '2'
; Make sure this table is at address 30h in your code memory
END

Find a video here :
 
Status
Not open for further replies.
Top