專(zhuān)注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開(kāi)發(fā)工具、應(yīng)用測(cè)試 完善的開(kāi)發(fā)代碼案例庫(kù)分享
從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無(wú)限潛能!
十年專(zhuān)注單片機(jī)方案開(kāi)發(fā)的方案公司英銳恩,分享用1個(gè)口做兩個(gè)數(shù)碼管的動(dòng)態(tài)顯示。英銳恩現(xiàn)提供服務(wù)產(chǎn)品涉及主控芯片:8位單片機(jī)、16位單片機(jī)、32位單片機(jī)及各類(lèi)運(yùn)算放大器等。
================================== ;定時(shí)器:用BIN轉(zhuǎn)換BCD后顯示 ;================================== LIST P=16C54 include cblock 8h Y1 Y2 BIN_L GE SHI TEMP YY_1 YY_2 YY_3 endc #define OUT PORTA,1 #define INT_JIA PORTA,0 #define INT_JIAN PORTA,2 #define XUAN_TONG PORTA,3 #define INT_OK PORTB,0 ORG 1FFH GOTO START ORG 00H START: CLRF GE CLRF SHI CLRF Y1 CLRF Y2 CLRF TEMP CLRF YY_1 CLRF YY_2 CLRF YY_3 MOVLW B'00000101' TRIS PORTA MOVLW 01H TRIS PORTB ;---按鍵全松開(kāi)才能往下跳------- OF_ANJIAN: BCF OUT CALL XIAN_OF BTFSS INT_JIA GOTO OF_ANJIAN BTFSS INT_JIAN GOTO OF_ANJIAN BTFSS INT_OK GOTO OF_ANJIAN ;=============================== ;---按鍵檢測(cè)-------------------- AN_JIAN: ;---如果TEMP為0,則變OF--------- MOVF TEMP,F SKPNZ GOTO CE_OF ;---轉(zhuǎn)入倒計(jì)程序----------------- BTFSS INT_OK GOTO _DAOJI ;---時(shí)間設(shè)定----------------------- CALL DISP INCF YY_1 MOVF YY_1,W XORLW .10 ;按一時(shí)間去按鍵檢測(cè) SKPZ GOTO AN_JIAN CLRF YY_1 ; BTFSC INT_JIA GOTO DE_C CALL DISP BTFSC INT_JIA GOTO DE_C MOVF TEMP,W ;TEMP是直接顯示到 XORLW .100 ;數(shù)碼管的數(shù)據(jù) SKPZ GOTO
================================== ;定時(shí)器:用BIN轉(zhuǎn)換BCD后顯示 ;================================== LIST P=16C54 include cblock 8h Y1 Y2 BIN_L GE SHI TEMP YY_1 YY_2 YY_3 endc #define OUT PORTA,1 #define INT_JIA PORTA,0 #define INT_JIAN PORTA,2 #define XUAN_TONG PORTA,3 #define INT_OK PORTB,0 ORG 1FFH GOTO START ORG 00H START: CLRF GE CLRF SHI CLRF Y1 CLRF Y2 CLRF TEMP CLRF YY_1 CLRF YY_2 CLRF YY_3 MOVLW B'00000101' TRIS PORTA MOVLW 01H TRIS PORTB ;---按鍵全松開(kāi)才能往下跳------- OF_ANJIAN: BCF OUT CALL XIAN_OF BTFSS INT_JIA GOTO OF_ANJIAN BTFSS INT_JIAN GOTO OF_ANJIAN BTFSS INT_OK GOTO OF_ANJIAN ;=============================== ;---按鍵檢測(cè)-------------------- AN_JIAN: ;---如果TEMP為0,則變OF--------- MOVF TEMP,F SKPNZ GOTO CE_OF ;---轉(zhuǎn)入倒計(jì)程序----------------- BTFSS INT_OK GOTO _DAOJI ;---時(shí)間設(shè)定----------------------- CALL DISP INCF YY_1 MOVF YY_1,W XORLW .10 ;按一時(shí)間去按鍵檢測(cè) SKPZ GOTO AN_JIAN CLRF YY_1 ; BTFSC INT_JIA GOTO DE_C CALL DISP BTFSC INT_JIA GOTO DE_C MOVF TEMP,W ;TEMP是直接顯示到 XORLW .100 ;數(shù)碼管的數(shù)據(jù) SKPZ GOTO {D_L_技術(shù)支持_內(nèi)容瀏覽}3 GOTO CE_OF GOTO {D_L_技術(shù)支持_內(nèi)容瀏覽}2 INCF TEMP DE_C: BTFSC INT_JIAN GOTO AN_JIAN CALL DISP BTFSC INT_JIAN GOTO AN_JIAN MOVF TEMP,W SKPZ GOTO {D_L_技術(shù)支持_內(nèi)容瀏覽}2 GOTO CE_OF DECF TEMP GOTO AN_JIAN ;---等待按鍵松開(kāi)---------------- CE_OF: BCF OUT CALL XIAN_OF BTFSS INT_JIA GOTO CE_OF BTFSS INT_JIAN GOTO CE_OF BTFSS INT_OK GOTO CE_OF ;---再次檢測(cè)按鍵--------------- JIAN_OF: CLRF TEMP CALL XIAN_OF BTFSS INT_JIA ;檢測(cè)加按鍵 GOTO JIA_TEMP
BTFSS INT_JIAN ;檢測(cè)減按鍵 GOTO JIAN_TEMP BTFSS INT_OK ;檢測(cè)確認(rèn)鍵 GOTO _ON GOTO JIAN_OF ;---從OF變01---------------- JIA_TEMP: INCF TEMP GOTO AN_JIAN ;---從OF變99----------------- JIAN_TEMP: MOVLW .99 MOVWF TEMP GOTO AN_JIAN ;---OF變ON----------------- _ON: BSF OUT CALL XIAN_ON BTFSS INT_OK GOTO _ON CALL XIAN_ON CALL XIAN_ON CALL XIAN_ON ;去抖動(dòng) CALL XIAN_ON BTFSS INT_OK GOTO _ON ;---ON變OF------------------ _ON_1: CALL XIAN_ON BTFSC INT_OK GOTO _ON_1 CALL XIAN_ON CALL XIAN_ON CALL XIAN_ON ;去抖動(dòng) CALL XIAN_ON BTFSC INT_OK GOTO _ON_1 GOTO CE_OF ;===倒計(jì)程序段============= _DAOJI: BSF OUT CALL DISP BTFSS INT_OK GOTO _DAOJI CALL DISP CALL DISP CALL DISP BTFSS INT_OK GOTO _DAOJI ;---暫停(返回時(shí)間設(shè)定)----------- _DAOJI_1: BTFSS INT_OK GOTO OF_ANJIAN CALL DISP CALL DISP BTFSS INT_OK GOTO OF_ANJIAN ;------------------- CALL DISP MOVF TEMP,F SKPNZ GOTO START INCF YY_2 MOVF YY_2,W XORLW .4 SKPZ GOTO _DAOJI_1 CLRF YY_2 INCF YY_3 MOVF YY_3,W XORLW .8 SKPZ GOTO _DAOJI_1 CLRF YY_3 DECF TEMP GOTO
_DAOJI_1 ;========================== DISP: ;---二進(jìn)制轉(zhuǎn)BCD碼---------- CLRF SHI CLRF GE MOVF TEMP,W MOVWF BIN_L MOVF BIN_L,F SKPNZ GOTO XIAN_SHU SHI_: MOVLW .10 SUBWF BIN_L,W SKPC GOTO GE_ MOVWF BIN_L INCF SHI GOTO SHI_ GE_: MOVF BIN_L,W MOVWF GE ;---轉(zhuǎn)換完立即顯示--------- XIAN_SHU: BCF XUAN_TONG MOVF GE,W ANDLW 0FH CALL TABEL MOVWF PORTB CALL DELAY MOVLW B'00001101' TRIS PORTA BSF XUAN_TONG MOVF SHI,W ANDLW 0FH CALL TABEL MOVWF PORTB MOVLW B'00000101' TRIS PORTA CALL DELAY RETLW
00H ;========================== XIAN_OF: MOVF TEMP,F SKPZ GOTO XIAN_SHU MOVLW 087H MOVWF PORTB BCF XUAN_TONG CALL DELAY ; MOVLW B'00001101' TRIS PORTA ; MOVLW 041H MOVWF PORTB MOVLW B'00000101' TRIS PORTA BSF XUAN_TONG CALL DELAY RETLW 00H ;========================== XIAN_ON: MOVLW 044H MOVWF PORTB BCF XUAN_TONG CALL DELAY ; MOVLW B'00001101' TRIS PORTA ; MOVLW 041H MOVWF PORTB MOVLW B'00000101' TRIS PORTA BSF
XUAN_TONG CALL DELAY ; RETLW 00H ;================================= DELAY: MOVLW 70H MOVWF Y1 DECFSZ Y1 GOTO $-1 RETLW 00H ;============================ TABEL: ADDWF PCL,F RETLW 040H RETLW 07DH RETLW 022H RETLW 028H RETLW 01DH RETLW 088H RETLW 080H RETLW 06DH RETLW 000H RETLW 008H ;============================= END
(文源網(wǎng)絡(luò),侵刪)