十年專注單片機方案開發的方案公司英銳恩,分享用1個口做兩個數碼管的動態顯示。英銳恩現提供服務產品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。
================================== ;定時器:用BIN轉換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 ;---按鍵全松開才能往下跳------- 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 ;=============================== ;---按鍵檢測-------------------- AN_JIAN: ;---如果TEMP為0,則變OF--------- MOVF TEMP,F SKPNZ GOTO CE_OF ;---轉入倒計程序----------------- BTFSS INT_OK GOTO _DAOJI ;---時間設定----------------------- CALL DISP INCF YY_1 MOVF YY_1,W XORLW .10 ;按一時間去按鍵檢測 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 ;數碼管的數據 SKPZ GOTO
================================== ;定時器:用BIN轉換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 ;---按鍵全松開才能往下跳------- 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 ;=============================== ;---按鍵檢測-------------------- AN_JIAN: ;---如果TEMP為0,則變OF--------- MOVF TEMP,F SKPNZ GOTO CE_OF ;---轉入倒計程序----------------- BTFSS INT_OK GOTO _DAOJI ;---時間設定----------------------- CALL DISP INCF YY_1 MOVF YY_1,W XORLW .10 ;按一時間去按鍵檢測 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 ;數碼管的數據 SKPZ GOTO {D_L_技術支持_內容瀏覽}3 GOTO CE_OF GOTO {D_L_技術支持_內容瀏覽}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_技術支持_內容瀏覽}2 GOTO CE_OF DECF TEMP GOTO AN_JIAN ;---等待按鍵松開---------------- 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 ;---再次檢測按鍵--------------- JIAN_OF: CLRF TEMP CALL XIAN_OF BTFSS INT_JIA ;檢測加按鍵 GOTO JIA_TEMP
BTFSS INT_JIAN ;檢測減按鍵 GOTO JIAN_TEMP BTFSS INT_OK ;檢測確認鍵 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 ;去抖動 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 ;去抖動 CALL XIAN_ON BTFSC INT_OK GOTO _ON_1 GOTO CE_OF ;===倒計程序段============= _DAOJI: BSF OUT CALL DISP BTFSS INT_OK GOTO _DAOJI CALL DISP CALL DISP CALL DISP BTFSS INT_OK GOTO _DAOJI ;---暫停(返回時間設定)----------- _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: ;---二進制轉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 ;---轉換完立即顯示--------- 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
(文源網絡,侵刪)