單片機開發方案商深圳英銳恩分享PS7219的PIC單片機接口程序。
Copyright (c) 1998, MICROCHIP Technology Inc
TITLE "PS7219 TEST" ;標題
LIST P=16C711 ;處理器為PIC16C711單片機
#INCLUDE P16c711.INC
TIMER1 EQU H'000C' ;定義延時寄存器
TIMER2 EQU H'000D'
SENT_ADDRESS EQU H'000E' ;定義發送地址寄存器
SENT_DATA EQU H'000F' ;定義發送數據寄存器
LED1 EQU H'0010'
LED2 EQU H'0011'
LED3 EQU H'0012'
LED4 EQU H'0013'
LED5 EQU H'0014'
LED6 EQU H'0015'
LED7 EQU H'0016'
LED8 EQU H'0017'
COUNT EQU H'0018'
NO_OP EQU 0X00 ;定義控制寄存器
DIGIT1 EQU 0X01
DIGIT2 EQU 0X02
DIGIT3 EQU 0X03
DIGIT4 EQU 0X04
DIGIT5 EQU 0X05
DIGIT6 EQU 0X06
DIGIT7 EQU 0X07
DIGIT8 EQU 0X08
DECODE EQU 0X09
INTSEN EQU 0X0A
SCAN EQU 0X0B
SHUT EQU 0X0C
FLASH EQU 0X0D
DISPLAY EQU 0X0F
LOAD EQU 0 ;通訊引腳定義
DOUT EQU 1
CLK EQU 2
ORG 0
GOTO START ;程序開始
ORG H'0010'
;*************************
; 延時子程序
;*************************
T1
MOVLW 33 ;延時子程序T1
MOVWF TIMER1
DEL_LOP
CLRWDT
DECFSZ TIMER1,1
GOTO DEL_LOP
RETURN
T2
MOVLW 0X04 ;延時子程序T2
MOVWF TIMER1
MOVLW 0XFF
LOOP2
MOVWF TIMER2
LOOP1
CLRWDT
DECFSZ TIMER2,1
GOTO LOOP1
DECFSZ TIMER1,1
GOTO LOOP2
RETURN
SEND
MOVLW 8 ;數據傳送子程序SEND
MOVWF COUNT
BCF PORTA,LOAD ;初始化LOAD引腳
CALL T1
SET_LP1
BCF STATUS,C ;發送8位地址
BSF PORTA,CLK
RLF SENT_ADDRESS,1
BCF PORTA,DOUT
BTFSC STATUS,C
BSF PORTA,DOUT
BCF PORTA,CLK
CALL T1 ;調用延時子程序T1
DECFSZ COUNT,1 ;COUNT減一為1零則結束傳送
GOTO SET_LP1
BSF PORTA,CLK
MOVLW 8
MOVWF COUNT
BSF PORTA,LOAD
SET_LP2
BCF STATUS,C ;發送8位數據
BSF PORTA,CLK
RLF SENT_DATA,1
BCF PORTA,DOUT
BTFSC STATUS,C
BSF PORTA,DOUT
BCF PORTA,CLK
CALL T1 ;調用延時子程序T1
DECFSZ COUNT,1 ;COUNT減一為零則結束傳送
GOTO SET_LP2
BSF PORTA,CLK
CALL T1
BSF PORTA,LOAD
BSF PORTA,DOUT
RETURN ;子程序返回
START
BSF STATUS,RP0 ;主程序
MOVLW 0X18
MOVWF TRISA
MOVLW 0XFF
MOVWF TRISB
BCF STATUS,RP0
CALL T1
CALL T1
MOVLW 0X12
MOVWF PORTA
BCF PORTA,LOAD
CON_COM
CALL T1 ;初始化PS7219內部RAM
MOVLW 0X0A ;設置亮度為最亮
MOVWF SENT_ADDRESS
MOVLW 0X0F
MOVWF SENT_DATA
CALL SEND ;調用串行通訊子程序
CALL T1
MOVLW 0X0B ;設置掃描界線為8位
MOVWF SENT_ADDRESS
MOVLW 0X07
MOVWF SENT_DATA
CALL SEND ;調用串行通訊子程序
CALL T1
MOVLW 0X09 ;設置每位譯碼方式為BCD譯碼
MOVWF SENT_ADDRESS
MOVLW 0XFF
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X0C ;設置工作方式為正常
MOVWF SENT_ADDRESS
MOVLW 0X01
MOVWF SENT_DATA
CALL SEND
LED_CON
CALL T1 ;LED顯示控制部分
MOVLW 0X01 ;LED1顯示為1
MOVWF SENT_ADDRESS
MOVLW 0X01
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X02 ;LED2顯示為2
MOVWF SENT_ADDRESS
MOVLW 0X02
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X03 ;LED3顯示為3
MOVWF SENT_ADDRESS
MOVLW 0X03
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X04 ;LED4顯示為4
MOVWF SENT_ADDRESS
MOVLW 0X04
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X05 ;LED5顯示為5
MOVWF SENT_ADDRESS
MOVLW 0X05
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X06 ;LED6顯示為6
MOVWF SENT_ADDRESS
MOVLW 0X06
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X07 ;LED7顯示為7
MOVWF SENT_ADDRESS
MOVLW 0X07
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X08 ;LED8顯示為8
MOVWF SENT_ADDRESS
MOVLW 0X08
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X0F ;進入測試模式
MOVWF SENT_ADDRESS
MOVLW 0X01
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X0F ;退出測試模式
MOVWF SENT_ADDRESS
MOVLW 0X00
MOVWF SENT_DATA
CALL SEND
CALL T1
MOVLW 0X0D ;使能8位LED閃爍
MOVWF SENT_ADDRESS
MOVLW 0XFF
MOVWF SENT_DATA
CALL SEND
FINISH CLRWDT ;清Watch Dog
GOTO FINISH
END ;結束