Programming a clock that counts down

Discussion in 'Programmer's Corner' started by SofiaEdqvist, May 9, 2012.

  1. SofiaEdqvist

    Thread Starter New Member

    May 9, 2012
    1
    0
    Hello! I need help to program a clock that counts down from two minutes to zero. I've done a code in Keil, it should be so here 2:00 with three 7-segment displays. Here is the code that I have done:
    START EQU P3.1
    RESET EQU P3.0

    DISA EQU P3.3
    DISB EQU P3.2
    DISC EQU P3.6
    ORG 0000H
    LJMP MAIN
    ORG 0060H
    MAIN:
    JB START,$ ;WAIT FOR START BUTTON TO BE PRESSED
    SETB DISA
    SETB DISB
    SETB DISC
    DD1:SETB DISA
    MOV A,#02H ;SETTING FOR MINUTE
    MOV R1,A
    DS1:MOV P0,R1
    DD2:MOV A,#00H
    MOV A,#05H
    DS2:MOV P2,A
    DD3:MOV A,#00H
    MOV P0,R1
    MOV A,#09H
    DS3:MOV P1,A
    LCALL DELAY
    DEC A
    CJNE A,#00H,DS3
    MOV A,P2
    MOV P1,#00H
    ACALL DELAY
    DEC A
    CJNE A,#00H,DS2
    TEN:MOV P2,#00H
    MOV R6,#09H
    TE:MOV P1,R6
    DEC R6
    ACALL DELAY
    CJNE R6,#00H,TE
    MOV P1,#00H
    DEC R1
    ACALL DELAY
    MOV P0,R1
    CJNE R1,#00H,DS1
    MOV P0,#00H
    LASTMIN:
    DE2:MOV A,#05H
    DF2:MOV P2,A
    DE3:MOV A,#09H
    DF3:MOV P1,A
    LCALL DELAY
    DEC A
    CJNE A,#00H,DF3
    MOV A,P2
    MOV P1,#00H
    ACALL DELAY
    DEC A
    CJNE A,#00H,DF2
    LASTEN:
    MOV P0,#00H
    MOV P2,#00H
    MOV R6,#09H
    TE1:MOV P1,R6
    DEC R6
    ACALL DELAY
    CJNE R6,#00H,TE1
    MOV P1,#00H

    RST: ;CLEARS ALL DISPLAYS AND RETURNS TO START
    JB RESET,$
    CLR DISA
    CLR DISB
    CLR DISC
    JMP MAIN
    DELAY: ;DELAY OF ONE SECOND
    MOV TMOD,#01H
    MOV TH0,#3CH
    MOV TL0,#0B0H
    MOV R7,#00H
    SETB TR0
    DEL:JNB TF0,DEL
    MOV TH0,#3CH
    MOV TL0,#0B0H
    CLR TF0
    INC R7
    CJNE R7,#14H,DEL
    RET
    END

    I'm really grateful if anyone can help me, I've been doing this for several hours, days and nothing works.
     
  2. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    You might want to post this in "Programmers Corner" on this site.
    I'll tell the boss and see if he wants to move this.
     
    Last edited: May 9, 2012
Loading...