Hi There,
I Tried to impliment digital timer using 8051, user pushed button to enter desired amount of delay and then presses start button, when user pushes start button the value in timer0 (which i configured as counter), is displayed decreasing and when the value becomes 0 the relay is switched off,
the problem which i cannot sort out is that controller is counting values and displays them perfect but when it comes to display value in decreasing i dunno what happens and output becomes ambiguous.
Please help, because my hommies don't consider me an engineer without repairing home appliances
Code that i wrote for it
I Tried to impliment digital timer using 8051, user pushed button to enter desired amount of delay and then presses start button, when user pushes start button the value in timer0 (which i configured as counter), is displayed decreasing and when the value becomes 0 the relay is switched off,
the problem which i cannot sort out is that controller is counting values and displays them perfect but when it comes to display value in decreasing i dunno what happens and output becomes ambiguous.
Please help, because my hommies don't consider me an engineer without repairing home appliances
Code that i wrote for it
Rich (BB code):
SEG0 EQU 30H
SEG1 EQU 31H
SEG2 EQU 32H
SEG3 EQU 33H
BUTTON EQU P3.4
SEGMENT7 EQU P2
STOP EQU P1.0
START EQU P1.1
ORG 00H
TIMER_SETUP:
MOV TMOD, #00010110B ;; 8 BIT AUTO RELOAD TIMER 0 AS COUNTER TIMER 1 AS 16 BIT TIMER
MOV TH0, #0D
MAIN:
SETB TR0
SETB BUTTON
SETB STOP
SETB START
MOV SEG0, #00H
MOV SEG1, #00H
MOV SEG2, #00H
MOV SEG3, #00H
CALL DISPLAY
GET:
MOV A, TL0
CALL CONV
CALL DISPLAY
JNB START, GO
JNB TF0, GET
JMP MAIN
GO:
CLR TR0
MOV A, TL0
GOT:
DEC A
CALL CONV
CALL DISPLAY
CALL DELAY_1S
MOV B, A
DJNZ B, GOT
CONV:
MOV B, #10D
DIV AB
MOV SEG0, B
MOV B, #10D
DIV AB
MOV SEG1, B
MOV SEG2, A
RET
DISPLAY:
MOV A, SEG0
ANL A, #0FH
ORL A, #80H
MOV SEG0, A
MOV SEGMENT7,SEG0
CALL DELAY
MOV A, SEG1
ANL A, #0FH
ORL A, #40H
MOV SEGMENT7,A
CALL DELAY
MOV A, SEG2
ANL A, #0FH
ORL A, #20H
MOV SEGMENT7,A
CALL DELAY
MOV A, SEG3
ANL A, #0FH
ORL A, #10H
MOV SEGMENT7,A
CALL DELAY
RET
DELAY_TIME:
MOV R2, TH0
AGAIN_TIME:
CALL DELAY_1MIN
DJNZ R2, AGAIN_TIME
DELAY_1MIN:
MOV R1, #60D
AGAIN_1MIN:
CALL DELAY_1S
DJNZ R1, AGAIN_1MIN
DELAY_1S:
MOV R0, #20D
AGAIN_1S:
CALL DELAY_50MS
DJNZ R0, AGAIN_1S
DELAY_50MS:
MOV TL1, #0B0H
MOV TH1, #3CH
SETB TR1
CHECK:
JNB TF1, CHECK
CLR TR1
CLR TF1
RET
DELAY:
MOV R4, 255
DJNZ R4, $
RET
END
Attachments
-
126.1 KB Views: 26
Last edited by a moderator: