中文字幕无码不卡一区二区三区_少妇被又大又粗又爽毛片久久黑人_91精品国产在热久久无毒不卡_久久久久久亚洲综合网站

技術(shù)熱線: 4007-888-234
設(shè)計開發(fā)

專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命

開發(fā)工具

提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享

技術(shù)支持

從全面的產(chǎn)品導(dǎo)入到強大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產(chǎn)品競爭力

新聞中心

提供最新的單片機資訊,行業(yè)消息以及公司新聞動態(tài)

PIC單片機數(shù)字鐘程序

更新時間: 2019-03-22
閱讀量:2089

十年單片機開發(fā)方案公司深圳英銳恩分享PIC單片機數(shù)字鐘程序,希望對大家有所幫助?。?!
;*******************************************
;數(shù)字鐘程序
;*******************************************
        LIST        P=16F877
        INCLUDE         BCDMIAO        EQU        70H;存放秒的二進制轉(zhuǎn)化為BCD后的BCD嗎
BCDFEN        EQU        71H;存分的
BCDSHI        EQU        72H;存十的
GMIAO        EQU        73H;秒個位寄存器
SMIAO        EQU        74H;十位
GFEN        EQU 75H;分個位寄存器
SFEN        EQU 76H;十位
GSHI        EQU 77H;時個位寄存器
SSHI        EQU 78H;十位
COUNT        EQU        79H;計數(shù)器
DY1                EQU 7AH;延時計數(shù)器1
DY2                EQU 7BH;延時計數(shù)器2
WTEMP        EQU        7CH;W備份寄存器
STEMP        EQU 7DH;STATUS備份寄存器
TEMP        EQU        7EH;定時器0初值寄存器
RBTEMP        EQU        7FH;RB口寄存器
DY5                EQU 20H;延時計數(shù)器5
DY6                EQU        21H;6
PCLATH_TEMP        EQU        22H;PCLATH備份寄存器
DISPBUF EQU 24H          ;顯示值暫存

DISPBUF_H EQU 25H         ;顯示器高位
DISPBUF_L EQU 26H         ;顯示器低位
BUFFER    EQU 27H;移位寄存器(之所以這樣稱呼它,是應(yīng)為BUFFER1中得數(shù)左移到它中)
BUFFER1   EQU 28H;存放個/分/時的數(shù)據(jù)(可對它進行移位)
SUM       EQU 29H;判斷寄存器(判斷高低四位加三后是否大于7)
DIGHT    EQU 2AH ;存放個/分/時的數(shù)據(jù)(中轉(zhuǎn)寄存器)
CMIAO        EQU        30H;存秒的數(shù)(二進制)
CFEN        EQU 31H;分的
CSHI        EQU 32H;時的
COUNTER        EQU 33H 
;主程序
                ORG        0000H
                GOTO MAIN
                ORG        0004H
                GOTO SERVE
                ORG        0005H
MAIN        NOP;
                BCF        STATUS,RP0;
                MOVLW        00H;P口清0
                MOVWF        PORTC;
                BSF        STATUS,RP0;
                MOVLW        00H        ;P口輸出
                MOVWF        TRISC;
                MOVLW        0FFH;
                MOVWF        TRISB;
                MOVLW        47H;INT上升沿觸發(fā),分頻器為TMR0,1:256
                MOVWF        OPTION_REG;
                BCF                STATUS,RP0;

     MOVLW        0F8H;開中斷
                MOVWF        INTCON;
                BCF                INTCON,T0IF;清標志位
                BCF                INTCON,INTF;
                BCF                INTCON,RBIF;
                CLRF        CMIAO;清存寄存器
                CLRF        CFEN;
                CLRF        CSHI;
                MOVLW        D'20';設(shè)置定時期的中斷次數(shù)
                MOVWF        COUNT;
                MOVLW        D'60';定時期初值
                MOVWF        TEMP;
                MOVWF        TMR0;開定時期
;循環(huán)掃描程序
SHAOMIAO

BCF                STATUS,RP0;
                MOVF        CMIAO,0;
                MOVWF        DIGHT;秒位數(shù)據(jù)送出轉(zhuǎn)換為BCD碼
                CALL        BCD2;
                MOVWF        BCDMIAO;帶會BCD碼                           
                MOVWF        GMIAO;給秒的個位積存器
                MOVLW        0FH;屏蔽高四位
                ANDWF        GMIAO;
                MOVLW        50H;位選碼
                IORWF        GMIAO;BCD碼+位選
                MOVF        GMIAO,0;
                MOVWF        PORTC;送顯
                CALL        YANSHI;
               
                MOVF        BCDMIAO,0;同上
                MOVWF        SMIAO;
                MOVLW        0F0H;
                ANDWF        SMIAO,1;
                SWAPF        SMIAO,1;注意此處要反轉(zhuǎn)
                MOVLW        40H;
                IORWF        SMIAO;

MOVF        SMIAO,0;
                MOVWF        PORTC;
                CALL        YANSHI;
               
                MOVF        CFEN,0;同上
                MOVWF        DIGHT;
                CALL        BCD2;
                MOVWF        BCDFEN;
                MOVWF        GFEN;
                MOVLW        0FH;
                ANDWF        GFEN;
                MOVLW        30H;
                IORWF        GFEN;
                MOVF        GFEN,0;
                MOVWF        PORTC;
                CALL        YANSHI;
               
                MOVF        BCDFEN,0;
                MOVWF        SFEN;
                MOVLW        0F0H;
                ANDWF        SFEN;
                SWAPF        SFEN;
                MOVLW        20H;

IORWF        SFEN;
                MOVF        SFEN,0;
                MOVWF        PORTC;
                CALL        YANSHI;
               
                MOVF        CSHI,0;
                MOVWF        DIGHT;
                CALL        BCD2;
                MOVWF        BCDSHI;
                MOVWF        GSHI;
                MOVLW        0FH;
                ANDWF        GSHI;
                MOVLW        10H;
                IORWF        GSHI;
                MOVF        GSHI,0;
                MOVWF        PORTC;
                CALL        YANSHI;
               
                MOVF        BCDSHI,0;
                MOVWF        SSHI;
                MOVLW        0F0H;
                ANDWF        SSHI;
                SWAPF        SSHI;
                MOVLW        00H;

IORWF        SSHI;
                MOVF        SSHI,0;
                MOVWF        PORTC;
                CALL        YANSHI;
                GOTO        SHAOMIAO;循環(huán)掃描
;查中斷源
SERVE   MOVWF        WTEMP;
                SWAPF        STATUS,W;
                CLRF        STATUS;
                MOVWF        STEMP;保護現(xiàn)場 
                MOVF        PCLATH,W;
                MOVWF        PCLATH_TEMP;
                CLRF        PCLATH
            BTFSS        INTCON,INTF;是INT中斷嗎?
                GOTO        SERVE1;不是,轉(zhuǎn)SERVE1
                GOTO        INTT;是,轉(zhuǎn)INT中斷處理
SERVE1        BTFSS        INTCON,T0IF;是定時期中斷嗎?
                GOTO        SERVE2;不是,轉(zhuǎn)SERVE2
                GOTO        T0II;是,轉(zhuǎn)定時期中斷處理
SERVE2        BTFSS        INTCON,RBIF;是RB中斷嗎?

  GOTO        SERVE3;不是,返回
                GOTO        PDRB;是,轉(zhuǎn)RB中斷處理
SERVE3        RETFIE
               
               
               
;定時器中斷處理               
T0II  
               
        BCF                INTCON,T0IF;清中斷標志位
        BCF                INTCON,T0IE;關(guān)定時期中斷
                MOVF        TEMP,0;重新值數(shù)
                MOVWF        TMR0;
                BCF                INTCON,GIE;防止/原因是:產(chǎn)生中斷時,GIE位清0,并轉(zhuǎn)入中斷入口,當GIE清0后,如果這時正好CPU在執(zhí)行
                BSF                INTCON,T0IE;產(chǎn)生/一條對INTCON“讀,修改,寫”的指令,則GIE位還會被寫會操作重新值1,這樣會使CPU
                BSF                INTCON,GIE;兩次中斷/產(chǎn)生兩次中斷,解決的辦法就是,在對INTCON進行修改之前,事先值GIE=0,修改完后
                DECFSZ        COUNT,1;/再恢復(fù)GIE=1。
                GOTO        LOOP;返回

 MOVLW        D'20';
                MOVWF        COUNT;賦記數(shù)次數(shù)
                INCF        CMIAO,1;
                MOVLW        D'60';
                XORWF        CMIAO,W;
                BTFSS        STATUS,Z;
                GOTO        LOOP;
                CLRF        CMIAO;60秒到清0
                INCF        CFEN;
                MOVLW        D'60';
                XORWF        CFEN,W;
                BTFSS        STATUS,Z;
                GOTO        LOOP;
                CLRF        CFEN;60分到清0
                INCF        CSHI;
                MOVLW        D'24';
                XORWF        CSHI,W;
                BTFSS        STATUS,Z;
                GOTO        LOOP;
                CLRF        CSHI;24時到清0
                RETFIE;
               
;判斷是那一個產(chǎn)生的中斷

PDRB        MOVF        PORTB,0;
                MOVWF        RBTEMP        ;
                BTFSC        RBTEMP,5;是0嗎?是轉(zhuǎn)向RBII
                GOTO        RBIII;不是,轉(zhuǎn)向RBIII
;RB5口中斷處理   調(diào)秒               
               
RBII 
                CALL        DELAY;去抖
                BTFSC        PORTB,5;是下降沿嗎?
                GOTO        LOOP8;不是,轉(zhuǎn)(清除上升沿產(chǎn)生的虛假中斷)
                MOVF        PORTB,1;讀PORTB,終結(jié)失陪條件
                BCF                INTCON,RBIF;清標志位
;                BCF                INTCON,T0IF
                BCF                INTCON,T0IE;關(guān)定時期中斷
                MOVF        TEMP,0;
                MOVWF        TMR0;重新賦值
                BSF                INTCON,T0IE;開定時期中斷
                INCF        CMIAO,1;
                MOVLW        D'60';
                XORWF        CMIAO,W;判斷到60秒了嗎?

  BTFSS        STATUS,Z;
                GOTO        LOOP;返回
                CLRF        CMIAO;
                INCF        CFEN,1;
                RETFIE
LOOP8               
         MOVF        PORTB,1;清除RBIF前要讀口
             BCF        INTCON,RBIF;               
                RETFIE
;RB4口中斷處理 調(diào)分
RBIII       
                CALL        DELAY;去抖
                BTFSC        PORTB,4;
                GOTO        LOOP8;
                MOVF        PORTB,1;
                BCF                INTCON,RBIF;
                BCF                INTCON,T0IE;
;                BCF                INTCON,T0IF
                MOVF        TEMP,W;
                MOVWF        TMR0;
                BSF                INTCON,T0IE;
                INCF        CFEN,1;
                MOVLW        D'60';
                XORWF        CFEN,W;

  BTFSS        STATUS,Z;
                GOTO        LOOP;
                CLRF        CFEN;
                INCF        CSHI;
                RETFIE               
               
;外部中斷處理 調(diào)時
INTT               
                BCF                INTCON,INTF;
                CALL        DELAY;
                INCF        CSHI,1;
                MOVLW        D'24';
                XORWF        CSHI,W;
                BTFSS        STATUS,Z;
                GOTO        LOOP;
                CLRF        CSHI;
                RETFIE
;恢復(fù)現(xiàn)場               
LOOP        MOVF        PCLATH_TEMP,W;
                MOVWF        PCLATH;
                SWAPF        STEMP,0;
                MOVWF        STATUS;
                SWAPF        WTEMP;
                SWAPF        WTEMP,0;
                RETFIE               
;去抖程序,延時8MS(5-10MS)             

DELAY        MOVLW        D'51';
                MOVWF        DY1;
LOOP4        MOVLW        D'51';
                MOVWF        DY2;
LOOP5        DECFSZ        DY2,1;
                GOTO        LOOP5;
                DECFSZ        DY1,1;
                GOTO        LOOP4;
                RETURN
                               
;延時程序,延時約3MS,(10-20MS循環(huán)一次,六個數(shù)碼官需要18MS,在次范圍內(nèi))
YANSHI        MOVLW        D'21';
                MOVWF        DY5;
LOOP7        MOVLW        D'51';
                MOVWF        DY6;
LOOP6        DECFSZ        DY6,1;
                GOTO        LOOP6;

DECFSZ        DY5,1;
                GOTO        LOOP7;
                RETURN
BCD2        MOVLW            8;
                  MOVWF            COUNTER;              ;循環(huán)左移計數(shù)器置8
                  CLRF                   BUFFER  ;        ;清除緩沖器
                  MOVF                   DIGHT,W  ;
                  MOVWF            BUFFER1   ;     
LOOP2                 
        RLF                BUFFER1,1    ;     ;二進制數(shù)轉(zhuǎn)換成BCD碼(以便顯示)
                  RLF                      BUFFER,1;
                  DECFSZ           COUNTER,1;          ;左移8次
                  GOTO                   ADJUST    ;         ;
                  MOVF                   BUFFER,W;
                  MOVWF            DISPBUF ;
                  MOVF                DISPBUF,W;
                  RETURN        ;是否有進位(即已達100),如已計數(shù)到100則
;                  SKPC                            ;從0開始再計數(shù)顯示(顯示00~99)
ADJUST                 

 MOVLW            3    ;           ;二進制轉(zhuǎn)BCD的調(diào)整
                  ADDWF            BUFFER,W;            ;每次移位后都檢查低四位LSD+3是否大于7
                  MOVWF            SUM      ;      
                  BTFSC            SUM,3;
                  MOVWF            BUFFER;
                  MOVLW            30H;
                  ADDWF            BUFFER,W ;       ;如果是則再加3,否則不加。
                  MOVWF            SUM;
                  BTFSC            SUM,7;
                  MOVWF            BUFFER;          ;接著再將高四位MSD作相同處理
                  GOTO                   LOOP2;
                  END 

(文源網(wǎng)絡(luò),侵刪)

凤阳县| 仙游县| 九江县| 霍邱县| 尼木县| 南郑县| 东丰县| 商洛市| 鱼台县| 琼海市| 五大连池市| 嘉定区| 应用必备| 咸宁市| 通州市| 咸阳市| 紫云| 西丰县| 蕲春县| 城口县| 大竹县| 白沙| 齐齐哈尔市| 绥江县| 光泽县| 年辖:市辖区| 陆丰市| 东兴市| 青龙| 吴忠市| 邹平县| 弥勒县| 叙永县| 河东区| 东乡族自治县| 巴彦县| 唐山市| 保德县| 江山市| 泉州市| 黄大仙区|