Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/20/08 23:08
Modified:
  01/21/08 00:06

Read: times


 
#149788 - stopwatch
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, repeat6
djnz R5,    repeat5
djnz R4,    repeat4

            ret

;----------------------------------------------------------------------------------------------------------

            end


List of 4 messages in thread
TopicAuthorDate
stopwatch            01/01/70 00:00      
   Stopwatch == Learn to use timers            01/01/70 00:00      
      re Learn to use timers            01/01/70 00:00      
   delay routine            01/01/70 00:00      

Back to Subject List