本帖最后由 loyou1993 于 2012-11-16 13:23 编辑
位操作不是不行,但需要注意外部电路设计不当造成的读-修改-写现象,根据编写代码的通用原则,要尽量降低软件和硬件的耦合度,尽量降低彼此之间的互相作用,根据这个原则,那么最好的方式显然就是使用这个IO输出 ...
yewuyi 发表于 2012-11-16 10:25 多谢版主,试过了,可惜还是不行!贴下代码!SEGDATA EQU 20H
SEGWELA EQU 21H
N0 EQU 23H
N1 EQU 24H
COUNT EQU 25H
SEG_COUNT EQU 26H
TMP595 EQU 27H
;※※※※※※※※程序开始※※※※※※※※
ORG 00H
GOTO STATR
;※※※※※※※※段选表※※※※※※※※※
TABLE1
ADDWF PCL,1
RETLW 3FH
RETLW 06H
RETLW 5BH
RETLW 4FH
RETLW 66H
RETLW 6DH
RETLW 7DH
;※※※※※※※※位选表※※※※※※※※※
TABLE2
ADDWF PCL,1
RETLW 7FH
RETLW 0BFH
RETLW 0DFH
RETLW 0EFH
RETLW 0F7H
RETLW 0FBH
;※※※※※※※※程序初始化※※※※※※※
STATR
BSF STATUS,RP0
BCF STATUS,RP1
CLRF OPTION_REG
MOVLW 06H
MOVWF ADCON1
CLRF TRISA
BCF STATUS,RP0BCF STATUS,RP1MOVLW 00H
MOVWF PORTA
MOVLW 0FH
MOVWF SEGDATA
CLRF SEGWELA
CLRF SEG_COUNT
;※※※※※※※※主程序※※※※※※※※※
MAIN
CALL TIME2
CALL SEG_display
INCF SEG_COUNT
MOVF SEG_COUNT,W
SUBLW 06H
BTFSS STATUS,Z
CLRF SEG_COUNT
GOTO MAIN
;※※※※※※数码管显示程序※※※※※※※ SEG_display
MOVLW SEG_COUNT
CALL TABLE1
MOVWF SEGDATA
CALL SEG_d595
MOVLW SEG_COUNT
CALL TABLE2
MOVWF SEGWELA
CALL SEG_w595
RETURN
;※※※※※※段选595送数据※※※※※※※SEG_d595
MOVLW 8
MOVWF COUNT
BCF STATUS,C LOOP
BCF TMP595,2
MOVLW TMP595
MOVWF PORTA
NOP
RLF SEGDATA,F
BTFSS STATUS,C
CALL TMP595_0
BTFSC STATUS,C
CALL TMP595_1
BSF TMP595,2
MOVLW TMP595
MOVWF PORTA
DECFSZ COUNT,F
GOTO LOOP
BCF TMP595,1
MOVLW TMP595
MOVWF PORTA
BSF TMP595,1
MOVLW TMP595
MOVWF PORTA
RETURN
TMP595_0
BCF TMP595,0
MOVLW TMP595
MOVWF PORTA
RETURN TMP595_1
BSF TMP595,0
MOVLW TMP595
MOVWF PORTA
RETURN
;※※※※※※位选595送数据※※※※※※※SEG_w595
MOVLW 8
MOVWF COUNT
BCF STATUS,C
LOOP1
BCF TMP595,5
MOVLW TMP595
MOVWF PORTA
NOP
RLF SEGDATA,F
BTFSS STATUS,C
CALL TMP595_00
BTFSC STATUS,C
CALL TMP595_11
BSF TMP595,5
MOVLW TMP595
MOVWF PORTA
DECFSZ COUNT,F
GOTO LOOP1
BCF TMP595,4
MOVLW TMP595
MOVWF PORTA
BSF TMP595,4
MOVLW TMP595
MOVWF PORTA
RETURN
TMP595_00
BCF TMP595,3
MOVLW TMP595
MOVWF PORTA
RETURN
TMP595_11
BSF TMP595,3
MOVLW TMP595
MOVWF PORTA
RETURN
;※※※※※※※※延时2ms※※※※※※※※
TIME2
MOVLW 0XFC
MOVWF N1
MOVLW 0X5B
MOVWF N0
INCFSZ N0
GOTO $-1
INCFSZ N1
GOTO $-5
RETURN
;※※※※※※※※程序结束※※※※※※※※
END |