專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享
從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!
提供新的芯片及解決方案,提升客戶產(chǎn)品競爭力
提供最新的單片機(jī)資訊,行業(yè)消息以及公司新聞動態(tài)
十年單片機(jī)開發(fā)方案公司深圳英銳恩分享PIC單片機(jī)控制LED點(diǎn)陣顯示屏。
本實(shí)驗(yàn)在proteus軟件上模擬完成。
實(shí)驗(yàn)器件:20片8X8LED點(diǎn)陣顯示屏,10片74LS164移位寄存器,10片74LS273數(shù)據(jù)鎖存器,2片74LS138譯碼器,1片PIC16F877A單片機(jī)。
proteus元件庫中中沒有16X80點(diǎn)陣顯示屏,所以用20片8X8LED點(diǎn)陣屏拼裝而成。
10片74LS164移位寄存器和10片74LS273數(shù)據(jù)鎖存器用于傳送和保存一行數(shù)據(jù)。
2片74LS138構(gòu)成4選16譯碼器用于行選。
DELAY_REG EQU 0x20
LINE_NUM EQU 0x21 ;行號
BYTE_NUM EQU 0x22 ;字節(jié)號
WORD_NUM EQU 0x23 ;字號
;字號X32 + 行號X2 + 字節(jié)號 得查表偏移量。
BYTE_BIT_COUNT EQU 0x24 ;一個(gè)字節(jié)的位數(shù),移位時(shí)用
SER EQU 0x07
SCK EQU 0x00
RCK EQU 0x01
;**********************************************************************
ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
retfie ; return from interrupt
main
; remaining code goes here
BSF STATUS,RP0
CLRF TRISB
CLRF TRISC
CLRF TRISD
BCF STATUS,RP0
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF LINE_NUM
MAIN_LOOP:
CALL LOAD_A_LINE ;加載一行
MOVF LINE_NUM,W ;行選
MOVWF PORTC
BSF PORTB,RCK ;將一行數(shù)據(jù)送入鎖存器
NOP
NOP
BCF PORTB,RCK
CALL DELAY ;延時(shí)
INCF LINE_NUM ;下一行
BCF LINE_NUM,4 ;一共16行,模16
GOTO MAIN_LOOP
;加載一行
LOAD_A_LINE:
CLRF WORD_NUM ;字號清零
LOAD_A_WORD:
CLRF BYTE_NUM ;字節(jié)號清零
LOAD_A_BYTE:
BCF STATUS,C ;清除C標(biāo)志位,為移位乘2做準(zhǔn)備
RLF LINE_NUM,W ;每個(gè)字一行占兩個(gè)字節(jié),所以乘2
ADDWF WORD_NUM,W ;下面WORD_NUM每次加32,不用再乘
ADDWF BYTE_NUM,W ;行號X2 + 字號X32 + 字節(jié)號
CALL ENCODE ;查表,取出對應(yīng)的字節(jié)
MOVWF PORTD
MOVLW D'8'
MOVWF BYTE_BIT_COUNT ;一個(gè)字節(jié)有8位
LOAD_A_BIT:
BSF PORTB,SCK ;將PORTD最高位送入移位寄存器
NOP
NOP
BCF PORTB,SCK
RLF PORTD ;移位,準(zhǔn)備將下一位送入移位寄存器
DECFSZ BYTE_BIT_COUNT ;循環(huán)8次
GOTO LOAD_A_BIT
INCF BYTE_NUM
BTFSS BYTE_NUM,1 ;BYTE_NUM==2?一行有兩個(gè)字節(jié)
GOTO LOAD_A_BYTE
MOVLW D'32'
ADDWF WORD_NUM ;一個(gè)字32個(gè)字節(jié),每次加32,使用時(shí)不用再乘32
MOVF WORD_NUM,W
SUBLW D'160'
BTFSS STATUS,Z ;WORD_NUM==160?5個(gè)字160個(gè)字節(jié)
GOTO LOAD_A_WORD
RETURN
;延時(shí)
DELAY:
DECFSZ DELAY_REG
GOTO DELAY
RETURN
ENCODE:
ADDWF PCL
DT 0x3F,0xF8,0x21,0x08,0x29,0x28,0x25,0x48,0x25,0x88,0x3F,0xF8,0x01,0x00,0x01,0x00,
DT 0x3F,0xF8,0x01,0x00,0xFF,0xFE,0x00,0x00,0x48,0x84,0x44,0x42,0x84,0x42,0x00,0x00
DT 0x02,0x00,0x02,0x40,0x02,0x20,0x02,0x20,0x7F,0xFE,0x02,0x80,0x02,0x90,0x02,0x90,
DT 0x04,0xA0,0x04,0xC0,0x08,0x80,0x09,0x80,0x12,0x82,0x20,0x82,0x40,0x7E,0x00,0x00
DT 0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40,0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40,
DT 0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00
DT 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80,
DT 0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04
DT 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,
DT 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00
END
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
list p=16f877A ; list directive to define processor
#include ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
源程序:
(圖文源網(wǎng)絡(luò),侵刪)