Stopwatch project (almost finished)
Discussion in "Project Help" started by alepitbull Jan 21, 2008.
Mon Jan 21 2008, 04:27 am
Hello everyone, I'm doing a stopwatch using a 4-digits LCD display,
in a 8051 with a P89c668 chip and the crystal frequency is 11.0592.
I'm having trouble with the delays. They seem to be interfering each other.
If I set a shorter display delay (so I can't see the numbers flipping),
the counter/time delay goes faster and doesn't count properly.
And the only way I can get the numbers counting on the
proper time is with a longer display delay, but with this way,
I can see the number blinking and it doesn't look very nice.
So, I don't know what to do anymore.
Could you guys have a look on my code below and see what's wrong, please?
Any help would be appreciatted.
thanks.
$include (reg66x.inc)
digitOne equ P3.5
digitTwo equ P3.4
digitThree equ P3.3
digitFour equ P3.2
displayEn equ P2.0
Sec_10th equ R0
Secs1 equ R1
Secs2 equ R2
Mins equ R3
;
org 0
sjmp START
;
org 40H
START: acall init
again: acall upDate
acall Display
;acall readSW ;I'm not using it at the moment.
sjmp again
; ------------------------------------------------------------------------------------------------------------
init: setb displayEn
clr digitOne
clr digitTwo
clr digitThree
clr digitFour
mov A,#0
mov Sec_10th, A
mov Secs1, A
mov Secs2, A
mov Mins, A
ret
;-------------------------------------------------------------------------------------------------------------
Display: clr displayEn
mov P1, Sec_10th
setb digitOne
acall disp_Delay
clr digitOne
mov P1, Secs1
setb digitTwo
acall disp_delay
clr digitTwo
mov P1, Secs2
setb digitThree
acall disp_Delay
clr digitThree
mov P1, Mins
setb digitFour
acall disp_Delay
clr digitFour
setb displayEn
ret
;-------------------------------------------------------------------------------------------------------------
;readSW: nop ; I'm not using it at the moment
;ret
;-------------------------------------------------------------------------------------------------------------
upDate: mov Sec_10th, #0
next: acall time_Delay
acall Display
inc Sec_10th
cjne Sec_10th, #10, next
mov Sec_10th, #0
inc Secs1
cjne Secs1, #10, next
mov Secs1, #0
inc Secs2
cjne Secs2, #6, next
mov Secs2, #0
inc Mins
cjne Mins, #10, next
mov Mins, #0
ret
;-------------------------------------------------------------------------------------------------------------
disp_Delay: mov R4, #218
repeat3: mov R5, #3
repeat2: mov R6, #2
repeat1: djnz R6, repeat1
djnz R5, repeat2
djnz R4, repeat3
ret
;-------------------------------------------------------------------------------------------------------------
time_Delay: mov R4, #218
repeat6: mov R5, #120
repeat5: mov R6, #2
repeat4: djnz R6, repeat4
djnz R5, repeat5
djnz R4, repeat6
ret
;-------------------------------------------------------------------------------------------------------------
end
in a 8051 with a P89c668 chip and the crystal frequency is 11.0592.
I'm having trouble with the delays. They seem to be interfering each other.
If I set a shorter display delay (so I can't see the numbers flipping),
the counter/time delay goes faster and doesn't count properly.
And the only way I can get the numbers counting on the
proper time is with a longer display delay, but with this way,
I can see the number blinking and it doesn't look very nice.
So, I don't know what to do anymore.
Could you guys have a look on my code below and see what's wrong, please?
Any help would be appreciatted.
thanks.
$include (reg66x.inc)
digitOne equ P3.5
digitTwo equ P3.4
digitThree equ P3.3
digitFour equ P3.2
displayEn equ P2.0
Sec_10th equ R0
Secs1 equ R1
Secs2 equ R2
Mins equ R3
;
org 0
sjmp START
;
org 40H
START: acall init
again: acall upDate
acall Display
;acall readSW ;I'm not using it at the moment.
sjmp again
; ------------------------------------------------------------------------------------------------------------
init: setb displayEn
clr digitOne
clr digitTwo
clr digitThree
clr digitFour
mov A,#0
mov Sec_10th, A
mov Secs1, A
mov Secs2, A
mov Mins, A
ret
;-------------------------------------------------------------------------------------------------------------
Display: clr displayEn
mov P1, Sec_10th
setb digitOne
acall disp_Delay
clr digitOne
mov P1, Secs1
setb digitTwo
acall disp_delay
clr digitTwo
mov P1, Secs2
setb digitThree
acall disp_Delay
clr digitThree
mov P1, Mins
setb digitFour
acall disp_Delay
clr digitFour
setb displayEn
ret
;-------------------------------------------------------------------------------------------------------------
;readSW: nop ; I'm not using it at the moment
;ret
;-------------------------------------------------------------------------------------------------------------
upDate: mov Sec_10th, #0
next: acall time_Delay
acall Display
inc Sec_10th
cjne Sec_10th, #10, next
mov Sec_10th, #0
inc Secs1
cjne Secs1, #10, next
mov Secs1, #0
inc Secs2
cjne Secs2, #6, next
mov Secs2, #0
inc Mins
cjne Mins, #10, next
mov Mins, #0
ret
;-------------------------------------------------------------------------------------------------------------
disp_Delay: mov R4, #218
repeat3: mov R5, #3
repeat2: mov R6, #2
repeat1: djnz R6, repeat1
djnz R5, repeat2
djnz R4, repeat3
ret
;-------------------------------------------------------------------------------------------------------------
time_Delay: mov R4, #218
repeat6: mov R5, #120
repeat5: mov R6, #2
repeat4: djnz R6, repeat4
djnz R5, repeat5
djnz R4, repeat6
ret
;-------------------------------------------------------------------------------------------------------------
end
[ Edited Mon Jan 21 2008, 11:13 am ]
Mon Jan 21 2008, 05:30 am
this is the problem please correct it first
disp_Delay: mov R4, #218 repeat3: mov R5, #3 repeat2: mov R6, #2 repeat1: djnz R6, repeat1 djnz R5, repeat2 djnz R4, repeat3 ret ;------------------------------------------------------------------------------- time_Delay: mov R4, #218 repeat3: mov R5, #120 ; repeats (1,2,3) are the problem they ; already defined repeat2: mov R6, #2 ; so please change repeats (4,5,6) i hope ; it will work repeat1: djnz R6, repeat1 djnz R5, repeat2 djnz R4, repeat3 ret
[ Edited Mon Jan 21 2008, 11:20 am ]
Mon Jan 21 2008, 05:33 am
Oh yeh, sorry, I wrote it wrong in there.
On my actual code is already definied repeat 4, 5 and 6.
sorry it's my mistake... I've just changed it now.
On my actual code is already definied repeat 4, 5 and 6.
sorry it's my mistake... I've just changed it now.
[ Edited Mon Jan 21 2008, 05:35 am ]
Mon Jan 21 2008, 11:49 pm
i feel the 10th of sec is obviously very fast.. and it changes very very fast..
so if you want my suggestion then i will suggest you to use 8-bit latch shift register (CD4094).. will be good in your case.. tell me what you think
so if you want my suggestion then i will suggest you to use 8-bit latch shift register (CD4094).. will be good in your case.. tell me what you think
Powered by e107 Forum System