<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        基于AT89S52和HD7279A的多功能電子鐘

        作者:浪子   來源:浪子   點擊數:  更新時間:2014年06月10日   【字體:

        功能:整點報時,時分秒調整,鬧鐘的設置,鬧鐘開關,萬年歷及其調整,閏年

         

        判斷,秒表,芯片:AT89S52,HD7279A

        切換到年月日顯示當前日期

        將日期調整到2008年驗證閏年

         

        PCB圖

         

         系統原理圖

         

        計時開始,黃燈為鬧鐘就緒燈

         

         

         

        萬年歷從0000年可到9999年

         

        59分59秒了,整點報時燈紅燈準備亮起

        紅燈亮了,整點到了,30S后整點報時燈(紅)自動熄滅

        下一步驗證鬧鐘,鬧鐘就緒燈(黃)為開,當前鬧鐘時間為01時01分

        鬧鐘燈(綠)亮了,其實還有一個蜂鳴器在響,關掉鬧鐘,黃燈和綠燈都被關掉,若不關閉則一分鐘后自動關閉,但是鬧鐘就緒燈不會自動關閉,下圖為手動關閉

        秒表準備

        秒表

        秒表停止,計時1S90MS

         

        ORG  0000H
             LJMP   MAIN
        ORG  000BH
             LJMP     CLOCK
        ORG  001BH
             LJMP     BRT
        ORG  0030H
        KEY BIT  P1.4
        CLK BIT  P1.5
        DAT BIT  P1.6
        CS  BIT  P1.7
                           ;說明:P1.0為正點報時標志,在正點時亮器,半分鐘后自動關閉,
                           ;P1.1為鬧鐘開關標志,可由鍵盤設置 ,初始狀態為開,亮30秒
                           ;P1.3,P1.2為鬧鐘,一分鐘后自動關閉,亮的前提是鬧鐘開關打開
                           ;P1.4為KEY,P1.7CS
                           ;可通過在正常顯示狀態下按3鍵隨時關閉鬧鈴
                           ;在走時狀態下按1鍵進入時間調整,按3小時加1,按4時加1,再按1切換到分,按3加1,按4減1,按F返回
                           ;在時鐘狀態下,按2進入鬧鐘設置,其它同時間調整
                           ;在時鐘狀態下,按3進入鬧鐘開關,可隨時開關鬧鈴?若不關則1分鐘后  自動關閉
                           ;在時鐘狀態下按C進入秒表,按D開始,按E停止,按c清零,再按D可重新開始,按f退出秒表
                           ;在時鐘狀態下按0顯示年月日,按D進入日期調整,可自動識別閏年。
        MAIN: MOV     SP,#60H
              MOV     TMOD,#11H           ;定時器0,1工作在方式1
              MOV     IE,#8AH               ;開定時器中斷
              MOV     TH1,#0D8H
              MOV     TL1,#0F0H
              MOV     TL0,#0B0H             ;定時器地低位初始化
              MOV     TH0,#3CH              ;定時器高位初始化
              MOV     2AH,#14H              ;年高位
              MOV     2BH,#09H              ;年低位
              MOV     2CH,#05H              ;月
              MOV     2DH,#19H              ;日
              MOV     20H,#17H              ;時單位
              MOV     21H,#3BH              ;分單元
              MOV     22H,#30H              ;秒單元
              MOV     23H,#00H              ;定時器計數單元
              MOV     50H,#00H              ;鬧鐘時位
              MOV     51H,#00H              ;鬧鐘分位
              MOV     52H,#00H              ;鬧鐘秒位
              SETB    TR0                   ;開始定時
              CLR     P1.1                  ;鬧鈴狀態開關
              SETB    P1.0                 ;關整點報時燈
              SETB    P1.3                  ;鬧鈴關
              SETB    P1.2
               ;*******************初始化完畢********************************
        SS:LCALL CUTIN0
           LCALL DISP
           JB KEY,LK
           LCALL READ
           LCALL  LDELAY
           MOV A,28H
        LP1:JNB  KEY,LP1
           CJNE A,#01H,NAO           ;按1鍵進入時間設置
           LCALL KEY0
           SJMP  LK
        NAO:CJNE A,#02H,SWITCH             ;按2鍵鍵入鬧鐘設置
            LCALL  LDELAY
            LCALL  KEY1
            SJMP  LK
        SWITCH:CJNE A,#03H,MB               ;按3鍵進入鬧鐘開關
               MOV C,P1.1
               CPL C
               LCALL  LONG
               MOV P1.1,C
               SJMP LK
        MB:  CJNE A,#0CH,DATE               ;按C鍵進入秒表
             LCALL MBWAIT                   ;按0鍵進入年月日顯示
               SJMP  LK
        DATE: CJNE  A,#00H,SETD
         D1:  LCALL CUTIN2
              LCALL DISPD
              LCALL SHORT
              JB KEY,D1
              LCALL  READ
              MOV A,28H
              CJNE  A,#0FH,D1
              MOV 29H,#98H
              LCALL SEND
              MOV 29H,#03FH
              CALL SEND
              SJMP  SS
        SETD:CJNE    A,#0DH,LK           ;按D鍵進入年月日調整
             LCALL     KEY2
           LK:SJMP  SS
        CUTIN0: MOV     25H,R0
                MOV     R0,#78H
                MOV     A,22H
                ACALL   BCD
                MOV     A,21H
                ACALL   BCD
                MOV     A,20H
                ACALL   BCD
                MOV     R0,25H
                RET
        CUTIN1: MOV     25H,R0
                MOV     R0,#78H
                MOV     A,42H
                ACALL   BCD
                MOV     A,41H
                ACALL   BCD
                MOV     A,40H
                ACALL   BCD
                MOV     R0,25H
                RET
        CUTIN2:MOV 25H,R0
               MOV R0,#78H;78H中為日個位
               MOV A , 2DH
               ACALL BCD
               MOV A ,2CH
               ACALL BCD
               MOV A,2BH
               ACALL BCD
               MOV A,2AH
               ACALL BCD
               MOV  R0,25H;7FH中為年千?
               RET
        BCD:    MOV     B,#0AH        ;把數據調整為兩位BCD碼
                DIV     AB
                MOV     @R0,B
                INC     R0
                MOV     @R0,A
                INC     R0
                RET
        CLOCK:  MOV     TL0,#0B0H     ;分秒單元進位
                MOV     TH0,#3CH
                PUSH    PSW
                PUSH    ACC
                INC     23H
                MOV     A,23H
                CJNE    A,#14H,RET0
                MOV     23H,#00H
                INC     22H
                JNB     P1.1,NZD
                SETB    P1.2
                SETB    P1.3
        NZD:    MOV     A,21H
                CJNE    A,#00H,CLO
        OPEN:   MOV     A,22H
                CJNE    A,#1EH,ZD        ;正點報時半分鐘后關閉
                SETB    P1.0
        ZD:     CJNE    A,#3CH,RET0
                MOV     22H,#00H
                INC     21H
                SETB     P1.2             ;鬧1分鐘后鐘關
                SETB     P1.3
                MOV     A,21H
                CJNE    A,#3CH,RET0
                MOV     21H,#00H
                CLR     P1.0
                INC     20H
                MOV     A,20H
                CJNE    A,#18H,RET0
                MOV     20H,#00H
                MOV     A,2CH
                CJNE    A,#02H,OTHERMON
                LCALL YEAR
                CJNE    A,#00H,NEXT7
        OTHERMON:LCALL DAYS
                 CJNE  A,2DH,NEXT6
                 MOV   2DH,#01H
                 SJMP  ADM
          CLO:   SETB   P1.0
                 SJMP  OPEN
        NEXT6:   INC   2DH
                 SJMP  B0
        NEXT7:   MOV   A,2DH
                 CJNE  A,#1DH,NEXT6
                 MOV   2DH,#01H
        ADM:     INC   2CH
                 MOV   A,2CH
                 CJNE  A,#0DH,B0
                 MOV   2CH,#01H
                 INC   2BH
                 MOV   A,2BH
                 CJNE  A,#64H,B0
                 MOV   2BH,#00H
                 INC   2AH
                 MOV   A,2AH
                 CJNE  A,#64H,B0
                 MOV   2AH,#00H
        RET0:   JB      P1.1, B0
                MOV     A,20H           ;開關為開時判斷時間,為關則直接退出中斷
                CJNE    A,50H,B0
                MOV     A,21H
                CJNE    A,51H,B0
                CLR    P1.3         ;開鬧鐘
                CLR    P1.2
        B0:     POP     ACC
                POP     PSW
        FH:     RETI
        YEAR:   MOV     A,2BH
                MOV     B,#04H
                DIV     AB
                MOV     A,B
                CJNE    A,#00H,NL
                MOV     A,2BH
                MOV     B,#64H
                DIV     AB
                MOV     A,B
                CJNE    A,#00H,LEAP
                MOV     A,2AH
                MOV     B,#04H
                DIV     AB
                MOV     A,B
                CJNE    A,#00H,NL
        LEAP:   MOV     A,#01H
                SJMP    BACKY
        NL:     MOV     A,#00H
        BACKY:  RET
                      ;****************************每月天數(按平年計)***************************
        DAYS:   DEC     2CH
                MOV     A,2CH
                MOV     DPTR,#TAB
                MOVC    A,@A+DPTR
                INC     2CH
                RET
         TAB:DB 1FH,1CH,1FH,1EH,1FH,1EH
             DB 1FH,1FH,1EH,1FH,1EH,1FH
              ;*********年月日調整************1鍵切換,3鍵+1,4鍵-1,F鍵返回****************
        KEY2:  LCALL CUTIN2
               LCALL DISPD
                MOV   29H,#88H
                LCALL SEND
                MOV   29H,#3FH
                LCALL SEND
                JB    KEY,KEY2
                LCALL READ
        LP2:    JNB   KEY,LP2
                LCALL  LDELAY
                MOV   A,28H
        SYH2:   CJNE  A,#02H,SYH3
                INC   2AH
                MOV   A,2AH
                CJNE  A,#64H,KEY2
                MOV   2AH,#00H
                SJMP  KEY2
        SYH3:   CJNE  A,#03H,YLK1
                DEC   2AH
                MOV   A,2AH
                CJNE  A,#0FFH,KEY2
                MOV   2AH,#63H
                SJMP  KEY2
        YLK1:   CJNE  A,#01H,KEY2
        YLK:    LCALL   CUTIN2
                LCALL    DISPD
                MOV   29H,#88H
                LCALL SEND
                MOV    29H,#0CFH
                LCALL SEND
                LCALL  SHORT
                LCALL  LDELAY
                JB    KEY,YLK
                LCALL  READ
        LP3:    JNB   KEY,LP3
                LCALL  LDELAY
                MOV    A,28H
        SYL2:   CJNE   A,#02H,SYL3
                INC    2BH
                MOV    A,2BH
                CJNE   A,#64H,YLK
                MOV    2BH,#00H
                SJMP   YLK
        SYL3:   CJNE   A,#03H,MK1
                DEC    2BH
                MOV    A,2BH
                CJNE   A,#0FFH,YLK
                MOV    2BH,#63H
                LCALL  SHORT
                SJMP   YLK
        MK1 :   CJNE   A,#01H,YLK
        SM:     LCALL DISPD
                MOV   29H,#88H
                LCALL SEND
                MOV   29H,#0F3H
                LCALL SEND
                LCALL   CUTIN2
                LCALL DISPD
                JB     KEY,SM
                LCALL  READ
        LP4:    JNB    KEY,LP4
                LCALL  LDELAY
                MOV    A,28H
        SETM2:  CJNE   A,#02H,SETM3
                INC    2CH
                MOV    A,2CH
                CJNE   A,#0DH,SM
                MOV    2CH,#01H
                SJMP   SM
        SETM3:  CJNE   A,#03H,DK1
                DEC    2CH
                MOV    A,2CH
                CJNE   A,#00H,SM
                MOV    2CH,#0CH
                SJMP   SM
        DK1:    CJNE   A,#01H,SM
        DK:     LCALL  CUTIN2
                LCALL DISPD
                MOV   29H,#88H
                LCALL   SEND
                MOV     29H,#0FCH
                LCALL   SEND
                JB      KEY,DK
                LCALL   READ
                LCALL   LDELAY
        LP5:    JNB     KEY,LP5
                MOV     A,28H
        SD2:    CJNE    A,#02H,SD3
                MOV     A,2CH
                CJNE    A,#02H,OTHER1
                LCALL   YEAR
                CJNE    A,#01H,OTHER1
                INC     2DH
                MOV     A,2DH
                CJNE    A,#1EH,DK
                MOV     2DH,#01H
                SJMP    DK
        OTHER1: LCALL   DAYS
                CJNE    A,2DH,AD
                MOV     2DH,#01H
                SJMP    DK
        AD:     INC     2DH
                SJMP    DK
        SD3:    CJNE    A,#03H,FK0
                DEC     2DH
                LCALL   SHORT
                MOV     A,2DH
                CJNE    A,#00H,DK
                MOV     A,2CH
                CJNE    A,#02H,OTHER2
                LCALL   YEAR
                CJNE    A,#01H,NEXT4
                MOV     2DH,#1DH
                LCALL  SHORT
                SJMP    DK
        NEXT4:  MOV     2DH,#1CH
        DBK:    LJMP  DK
        OTHER2: LCALL   DAYS
                MOV     2DH,A
                LJMP    DK
        FK0:    CJNE    A,#01H,FK
                LJMP    KEY2
        FK:     CJNE    A,#0FH,DBK
                MOV     29H,#88H
                LCALL   SEND
                MOV     29H,#0FFH
                LCALL   SEND
                MOV     29H,#98H
                LCALL  SEND
                MOV   29H,#03FH
                LCALL  SEND
                RET
               ;************秒表*********
        
        MBWAIT:     MOV 78H,#00H             ;D鍵開始
                    MOV 79H,#00H             ; E鍵停止
                    MOV 7AH,#00H              ; 按C鍵清零
                    MOV 7BH,#00H              ; 再按D鍵重新開始
                    MOV 7CH,#00H               ;F鍵退出
                    MOV 7DH,#00H
                    MOV 7EH,#00H
                    MOV 7FH,#00H
                    LCALL  DISPD
                    JB   KEY,MBWAIT
                    LCALL  READ
                    MOV  A,28H
                    CJNE  A,#0DH,MBWAIT
        KAISHI:     SETB TR1  ;開啟定時器T1
        WAIT0:    LCALL DISPD
                  JB  KEY,WAIT0  ; 等按鍵,按E停止
                  LCALL  READ
                  MOV A,28H
                  CJNE A,#0EH,WAIT0
                  CLR  TR1
        WAIT1:    LCALL  DISPD
                  JB   KEY,WAIT1          ;按F鍵清零
                  LCALL  READ
                  MOV  A,28H
                  CJNE A,#0CH,WAIT1
                  MOV  78H,#00H
                  MOV  79H,#00H
                  MOV  7AH,#00H
                  MOV  7BH,#00H
                  MOV  7CH,#00H
                  MOV  7DH,#00H
                  MOV  7EH,#00H
                  MOV  7FH,#00H
        WAIT2:    LCALL  DISPD
                  JB  KEY,WAIT2
                  LCALL  READ
                  MOV  A,28H
                  CJNE A,#0DH,WAIT3         ; 按D鍵重新開始,其他鍵退出秒表
                  SJMP  KAISHI
        WAIT3:    CJNE A,#0FH,WAIT2           ;按E鍵退出秒表
        EXIT:     MOV  29H,#98H
                  LCALL  SEND
                  MOV   29H,#3FH
                  LCALL   SEND
                      RET
        DISPM:CALL DISP
              MOV   29H,#88H
              LCALL  SEND
              MOV   29H,#0F3H
              LCALL  SEND
              RET
        DISPH:CALL  DISP
              MOV    29H,#88H
              LCALL   SEND
              MOV    29H,#0CFH
              LCALL   SEND
              RET
        DISPD:MOV   29H,#98H
              LCALL   SEND
              MOV    29H,#0FFH
              LCALL    SEND
              LCALL DISP
              MOV 29H,#0CEH
              CALL SEND
              MOV  29H,7EH
              ACALL SEND
              MOV 29H,#0CFH
              LCALL SEND
              MOV  29H,7FH
              LCALL SEND
              RET
        DISP:MOV R1,#78H
             MOV R4,#0C8H
             MOV R2,#06
        DISP_LOOP:MOV 29H,R4
                  LCALL SEND
                  MOV 29H,@R1
                  LCALL SEND
                  INC R4
                  INC R1
                  DJNZ R2,DISP_LOOP
                  RET
        SEND:     MOV R3,#08H
                  CLR CS
                  LCALL LONG
        SEND_LOOP:MOV C,29H.7
                  MOV DAT,C
                  SETB CLK
                  LCALL SHORT
                  CLR CLK
                  LCALL SHORT
                  MOV A,29H
                  RL A
                  MOV 29H,A
                  DJNZ R3,SEND_LOOP
                  CLR DAT
                  RET
        BRT:      MOV     TL1,#0F0H
                  MOV     TH1,#0D8H     ;初值,10ms中斷一次
                  PUSH    PSW
                  PUSH    ACC
                  INC 78H
                  MOV A,78H
                  CJNE A,#0AH,FH1
                  MOV  78H,#00H
                  INC  79H
                  MOV A,79H
                  CJNE A,#0AH,FH1
                  MOV  79H,#00H
                  INC  7AH
                  MOV A,7AH
                  CJNE A,#0AH,FH1
                  MOV  7AH,#00H
                  INC  7BH
                  MOV A,7BH
                  CJNE A,#06H,FH1
                  MOV  7BH,#00H
                  INC  7CH
                  MOV A,7CH
                  CJNE A,#0AH,FH1
                  MOV  7CH,#00H
                  INC  7DH
                  MOV A,7DH
                  CJNE A,#06H,FH1
                  MOV  7DH,#00H
                  INC  7EH
                  MOV  A,7EH
                  CJNE  A,#0AH,FH1
                  INC   7FH
                  MOV   A,7FH
                  CJNE   A,#0AH,FH1
                  MOV    7FH,#00H
        FH1:            POP  ACC
                        POP PSW
                        RETI
        LONG:           MOV  70H,#25    ; 50uS
        DELAY_LOOP:     DJNZ  70H,DELAY_LOOP
                        RET
        SHORT:          MOV  70H,#4    ; 8uS
        SHORT_LP:       DJNZ 70H,SHORT_LP
                        RET
        READ:           MOV 29H,#15H                      ;發送讀鍵盤指令
          ACALL SEND
                        LCALL LONG
                        LCALL RESE
                        LCALL LONG
                        RET
        RESE:           MOV 71H,#8   ; =8
                        SETB DAT   ; P1.2(DATA)
                        CALL LONG  ;
        RECEIVE_LOOP:   SETB CLK ; CLK
                        CALL SHORT  ;
                        MOV A,28H  ;
                        RL A
                        MOV 28H,A
                        MOV C,DAT   ;
                        MOV 28H.0,C
                        CLR CLK   ; CLK
                        CALL SHORT
                        DJNZ 71H,RECEIVE_LOOP; 8
                        CLR DAT ; DAT
                        RET
        SKEY:MOV  42H,#00H
            LCALL  CUTIN1
            LCALL  DISPH
            JB  KEY,SKEY
            LCALL READ
            LCALL  LDELAY
        LP6:JNB  KEY,LP6
            MOV A,28H
        HK2:CJNE A,#02H,HK3
            INC  40H
            MOV  A,40H
            CJNE A,#18H,NEXT0
            MOV  40H,#00H
        NEXT0:AJMP SKEY
        HK3: CJNE A,#03H,K1
             DEC 40H
             MOV A,40H
             CJNE A,#0FFH,NEXT1
             MOV  40H,#17H
        NEXT1:AJMP SKEY
        K1:CJNE A,#01H,NEXT1
        TURNTO:LCALL CUTIN1
               LCALL DISPM
               JB KEY,TURNTO
               LCALL READ
               LCALL  LDELAY
        LP7:   JNB  KEY,LP7
               MOV A,28H
        MK2:   CJNE A,#02H,MK3
               INC 41H
               MOV A,41H
               CJNE A,#3CH,TURNTO
               MOV 41H,#00H
        NEXT2: LCALL SHORT
               AJMP TURNTO
        MK3:   CJNE A,#03H,F4
               DEC 41H
               LCALL SHORT
               MOV A,41H
               CJNE A,#0FFH,TURNTO
               MOV 41H,#3BH
               AJMP  TURNTO
        F4:    CJNE   A,#01H,BACK
               AJMP  SKEY
        BACK:  CJNE A,#0FH,TURNTO
               MOV 29H,#88H
               LCALL SEND
               MOV 29H,#0FFH
               LCALL SEND
               RET
               ;************校時子程序**********
        KEY0:  MOV 41H,21H
               MOV 40H,20H
               CLR TR0
               MOV  23H,#00H
               ACALL SKEY
               MOV 22H,42H
               MOV 21H,41H
               MOV 20H,40H
               MOV TH0,#3CH
               MOV TL0,#0B0H
               SETB TR0
               RET
        KEY1:  MOV 41H,51H     ;************鬧鐘設置子程序************
               MOV 40H,50H
               ACALL SKEY
               MOV 51H,41H
               MOV 50H,40H
               SETB  P1.2
               SETB  P1.3
               RET
               ;**********延時子程序******
        LDELAY: MOV     53H,#0AFH
        LDLY1:  MOV     54H,#0AFH
        LDLY:   DJNZ    54H,LDLY
                DJNZ    53H,LDLY1
                RET
        END
        
        終于做完了,硬件:
        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮