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

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

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

開發(fā)工具

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

技術(shù)支持

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

新品推廣

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

新聞中心

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

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

更新時(shí)間: 2019-03-22
閱讀量:2092

十年單片機(jī)開發(fā)方案公司深圳英銳恩分享PIC單片機(jī)數(shù)字鐘程序,希望對(duì)大家有所幫助!?。?br/>;*******************************************
;數(shù)字鐘程序
;*******************************************
        LIST        P=16F877
        INCLUDE         BCDMIAO        EQU        70H;存放秒的二進(jìn)制轉(zhuǎn)化為BCD后的BCD嗎
BCDFEN        EQU        71H;存分的
BCDSHI        EQU        72H;存十的
GMIAO        EQU        73H;秒個(gè)位寄存器
SMIAO        EQU        74H;十位
GFEN        EQU 75H;分個(gè)位寄存器
SFEN        EQU 76H;十位
GSHI        EQU 77H;時(shí)個(gè)位寄存器
SSHI        EQU 78H;十位
COUNT        EQU        79H;計(jì)數(shù)器
DY1                EQU 7AH;延時(shí)計(jì)數(shù)器1
DY2                EQU 7BH;延時(shí)計(jì)數(shù)器2
WTEMP        EQU        7CH;W備份寄存器
STEMP        EQU 7DH;STATUS備份寄存器
TEMP        EQU        7EH;定時(shí)器0初值寄存器
RBTEMP        EQU        7FH;RB口寄存器
DY5                EQU 20H;延時(shí)計(jì)數(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;存放個(gè)/分/時(shí)的數(shù)據(jù)(可對(duì)它進(jìn)行移位)
SUM       EQU 29H;判斷寄存器(判斷高低四位加三后是否大于7)
DIGHT    EQU 2AH ;存放個(gè)/分/時(shí)的數(shù)據(jù)(中轉(zhuǎn)寄存器)
CMIAO        EQU        30H;存秒的數(shù)(二進(jìn)制)
CFEN        EQU 31H;分的
CSHI        EQU 32H;時(shí)的
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;清標(biāo)志位
                BCF                INTCON,INTF;
                BCF                INTCON,RBIF;
                CLRF        CMIAO;清存寄存器
                CLRF        CFEN;
                CLRF        CSHI;
                MOVLW        D'20';設(shè)置定時(shí)期的中斷次數(shù)
                MOVWF        COUNT;
                MOVLW        D'60';定時(shí)期初值
                MOVWF        TEMP;
                MOVWF        TMR0;開定時(shí)期
;循環(huán)掃描程序
SHAOMIAO

BCF                STATUS,RP0;
                MOVF        CMIAO,0;
                MOVWF        DIGHT;秒位數(shù)據(jù)送出轉(zhuǎn)換為BCD碼
                CALL        BCD2;
                MOVWF        BCDMIAO;帶會(huì)BCD碼                           
                MOVWF        GMIAO;給秒的個(gè)位積存器
                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;保護(hù)現(xiàn)場(chǎng) 
                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;是定時(shí)期中斷嗎?
                GOTO        SERVE2;不是,轉(zhuǎn)SERVE2
                GOTO        T0II;是,轉(zhuǎn)定時(shí)期中斷處理
SERVE2        BTFSS        INTCON,RBIF;是RB中斷嗎?

  GOTO        SERVE3;不是,返回
                GOTO        PDRB;是,轉(zhuǎn)RB中斷處理
SERVE3        RETFIE
               
               
               
;定時(shí)器中斷處理               
T0II  
               
        BCF                INTCON,T0IF;清中斷標(biāo)志位
        BCF                INTCON,T0IE;關(guān)定時(shí)期中斷
                MOVF        TEMP,0;重新值數(shù)
                MOVWF        TMR0;
                BCF                INTCON,GIE;防止/原因是:產(chǎn)生中斷時(shí),GIE位清0,并轉(zhuǎn)入中斷入口,當(dāng)GIE清0后,如果這時(shí)正好CPU在執(zhí)行
                BSF                INTCON,T0IE;產(chǎn)生/一條對(duì)INTCON“讀,修改,寫”的指令,則GIE位還會(huì)被寫會(huì)操作重新值1,這樣會(huì)使CPU
                BSF                INTCON,GIE;兩次中斷/產(chǎn)生兩次中斷,解決的辦法就是,在對(duì)INTCON進(jìn)行修改之前,事先值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時(shí)到清0
                RETFIE;
               
;判斷是那一個(gè)產(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;清標(biāo)志位
;                BCF                INTCON,T0IF
                BCF                INTCON,T0IE;關(guān)定時(shí)期中斷
                MOVF        TEMP,0;
                MOVWF        TMR0;重新賦值
                BSF                INTCON,T0IE;開定時(shí)期中斷
                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)時(shí)
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)場(chǎng)               
LOOP        MOVF        PCLATH_TEMP,W;
                MOVWF        PCLATH;
                SWAPF        STEMP,0;
                MOVWF        STATUS;
                SWAPF        WTEMP;
                SWAPF        WTEMP,0;
                RETFIE               
;去抖程序,延時(shí)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
                               
;延時(shí)程序,延時(shí)約3MS,(10-20MS循環(huán)一次,六個(gè)數(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)左移計(jì)數(shù)器置8
                  CLRF                   BUFFER  ;        ;清除緩沖器
                  MOVF                   DIGHT,W  ;
                  MOVWF            BUFFER1   ;     
LOOP2                 
        RLF                BUFFER1,1    ;     ;二進(jìn)制數(shù)轉(zhuǎn)換成BCD碼(以便顯示)
                  RLF                      BUFFER,1;
                  DECFSZ           COUNTER,1;          ;左移8次
                  GOTO                   ADJUST    ;         ;
                  MOVF                   BUFFER,W;
                  MOVWF            DISPBUF ;
                  MOVF                DISPBUF,W;
                  RETURN        ;是否有進(jìn)位(即已達(dá)100),如已計(jì)數(shù)到100則
;                  SKPC                            ;從0開始再計(jì)數(shù)顯示(顯示00~99)
ADJUST                 

 MOVLW            3    ;           ;二進(jìn)制轉(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ò),侵刪)

南宫市| 龙川县| 溧阳市| 增城市| 偏关县| 宁波市| 阳泉市| 东台市| 深泽县| 建宁县| 庄河市| 阿拉尔市| 灵川县| 自治县| 伊宁市| 墨玉县| 贵溪市| 彰化市| 巴林右旗| 安福县| 屯昌县| 康平县| 榆林市| 宜良县| 乐平市| 财经| 新兴县| 太湖县| 渭源县| 永川市| 宿松县| 诸暨市| 鹤庆县| 阿拉尔市| 富顺县| 南华县| 临高县| 桐柏县| 嘉黎县| 平远县| 沙坪坝区|