?? chinese_led.asm
字號:
;********************************************************************************
;* *
;* File : 擴(kuò)展板漢字LED.asm *
;* Function : 點(diǎn)陣漢字LED顯示練習(xí) 兩個漢字顯示 *
;* Date : 2006-09-18 *
;* Version : 1.0 *
;* *
;* Author : 開關(guān)電源 hongtusy@163.com *
;* Company : 電子信息技術(shù)咨詢網(wǎng) http://www.itsn.cn *
;* *
;****************************描述與記事******************************************
;擴(kuò)展實(shí)驗(yàn)板的AVR程序,使用595驅(qū)動點(diǎn)陣漢字LED的練習(xí)。
;記事:本程序旨在對漢字LED驅(qū)動的理解與演示,程序適合初學(xué)者使用。
;描述:74HC595是串行輸入,并行輸出帶鎖存器的有較大驅(qū)動能力的芯片。驅(qū)動電流可達(dá)70mA。內(nèi)部有移位和輸出兩個寄存器。
;在SRCLK串行時鐘上升沿,數(shù)據(jù)經(jīng)SER移位進(jìn)入,或經(jīng)QH’輸出。在RCLK上升沿,數(shù)據(jù)進(jìn)入并行輸出寄存器。
;SRCLK’和OE’分別是復(fù)位和允許輸出控制,分別接電源和地。
;除了系統(tǒng)復(fù)位SW3-8外其余平撥開關(guān)需要關(guān)閉
;接線定義:PD4=數(shù)據(jù),PD5=RCLK并行輸出時鐘,PD6=SRCLK串行時鐘,PD7=OE,PD0=A,PD1=B,PD2=C,PD3=D
;********************************************************************************
.include"8535def.inc" ;定義頭文件。
.org 0x0000 ;指定開始地址。
rjmp reset ;轉(zhuǎn)移到“RESET”句。
.org 0x0010
reset: ldi r16,high(ramend)
out sph,r16
ldi r16,low(ramend)
out spl,r16
;---------以上是定義堆棧指針-----------
ldi r16,0xff ;加載立即數(shù)作數(shù)據(jù)方向參數(shù)。
out ddrd,r16 ;PD口為輸出,595的輸入控制部分,只使用末3位
;------------------------------------------
;-------------------------滾動顯示4個漢字,修改指針r7---------------------------
star: ldi r16,32 ;顯示歡迎
mov r6,r16
ldi r16,0
mov r7,r16 ;指針
bbb: rcall display1
inc r7
inc r7
dec r6
dec r6
mov r16,r6
cpi r16,0 ;與立即數(shù)0比較,由于CPI指令只允許R16至R31。
brne bbb ;不為0,繼續(xù)發(fā)送下一列。
rjmp star
;---r4為真正的指針------r7放的是備份的指針----r5為顯示次數(shù)指針---------
display1: ldi r16,5 ;顯示x次作為一屏畫面。調(diào)節(jié)滾動速度。
aaa: mov r4,r7 ;重新賦值給指針
rcall display ;顯示
dec r5
mov r16,r5
cpi r16,0
brne aaa
ret
;------------------------顯示以屏畫面子程序--------------------------------
;--輸入?yún)?shù):表格指針。-------------------
display: sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
cbi portd,1 ;B
cbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
cbi portd,1 ;B
cbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
sbi portd,1 ;B
cbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
sbi portd,1 ;B
cbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
cbi portd,1 ;B
sbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
cbi portd,1 ;B
sbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
sbi portd,1 ;B
sbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
sbi portd,1 ;B
sbi portd,2 ;C
sbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
;-------------------
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
cbi portd,1 ;B
cbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
cbi portd,1 ;B
cbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
sbi portd,1 ;B
cbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
sbi portd,1 ;B
cbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi 0x12,7 ;OE=1,消隱
cbi 0x12,0 ;A
cbi 0x12,1 ;B
sbi 0x12,2 ;C
cbi 0x12,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
cbi portd,1 ;B
sbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
cbi portd,0 ;A
sbi portd,1 ;B
sbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
sbi portd,7 ;OE=1,消隱
sbi portd,0 ;A
sbi portd,1 ;B
sbi portd,2 ;C
cbi portd,3 ;D
rcall out_595
rcall del
cbi portd,7 ;OE=1,輸出
rcall londel
ret
;-------------顯示子程序--行數(shù)據(jù)已經(jīng)在R0,R1,R2,R3中了。-----------
out_595: rcall cabiao ;首先生成最新的數(shù)據(jù)。
mov r17,r3 ;行數(shù)據(jù)到顯示緩存,先送最末位的數(shù)據(jù)。
rcall wr_595 ;移位輸出
mov r17,r2
rcall wr_595
mov r17,r1
rcall wr_595
mov r17,r0
rcall wr_595
sbi 0x12,5 ;并行輸出鎖存器rclk=1,portd=0x12,上升沿移位
nop
nop
cbi 0x12,5 ;rclk=0,portd=0x12
ret
;------查表取碼程序,初始值在r4(指針)中,結(jié)果在R0,R1,R2,R3中---------
;工作原理;首先將表格首地址放到16位寄存器Z中,然后把要查表顯示的數(shù)據(jù)個數(shù)(當(dāng)前是第幾個)(即R6的值)和
;Z相加,結(jié)果仍放到Z中,然后使用LPM命令,將數(shù)據(jù)存儲器的內(nèi)容讀入到指定的寄存器中。注意只可以讀到字地址。
cabiao: ldi zh, high(Table_1<<1);初始化Z指針
ldi zl, low(Table_1<<1)
clc ;清進(jìn)位標(biāo)志c
add r30,r4 ;r4中放的是要顯示的數(shù)據(jù)個數(shù)的初始值,處理低字節(jié)數(shù)據(jù)
clr r16 ;r16清0
adc r31,r16 ;處理高字節(jié)數(shù)據(jù),帶C加。
lpm r0,z ;從程序存儲器中裝入Z指針(r31:r30)指向的常量
inc r4 ;加1得到下一個字節(jié)數(shù)據(jù)
ldi zh, high(Table_1<<1); 初始化Z指針
ldi zl, low(Table_1<<1)
clc ;清進(jìn)位標(biāo)志c
add r30,r4 ;r4中放的是要顯示的數(shù)據(jù)個數(shù)的初始值,處理低字節(jié)數(shù)據(jù)
clr r16 ;r16清0
adc r31,r16 ;處理高字節(jié)數(shù)據(jù),帶C加。
lpm r1,z ;從程序存儲器中裝入Z指針(r31:r30)指向的常量
ldi r16,63
add r4,r16 ;新的指針,中間加了31,實(shí)際就是獲得了下一個字的地址。
;---------------------------------
ldi zh, high(Table_1<<1)
ldi zl, low(Table_1<<1)
clc
add r30,r4
clr r16
adc r31,r16
lpm r2,z
inc r4
ldi zh, high(Table_1<<1)
ldi zl, low(Table_1<<1)
clc
add r30,r4
clr r16
adc r31,r16
lpm r3,z
ldi r16,63
sub r4,r16 ;得到正確的下個地址指針。
ret
;-------移位寄存器接收數(shù)據(jù),數(shù)據(jù)在r17中--------------
wr_595: ldi r16,0x08 ;8位數(shù)據(jù)
wr0: ror r17 ;帶C循環(huán)左移。高位先出。
brbc 0,w0 ;若C為0跳轉(zhuǎn),輸出0。
rjmp w1 ;否則肯定為1,輸出1。
w0: sbi 0x12,4 ;I/Oout=0,輸出0。portd=0x12
rjmp wr1 ;轉(zhuǎn)移
w1: cbi 0x12,4 ;I/Oout=1,輸出1。portd=0x12
nop
wr1: sbi 0x12,6 ;srclk=1,portd=0x12,上升沿移位
nop
cbi 0x12,6 ;srclk=0,portd=0x12
dec r16 ;寄存器減1
cpi r16,0 ;與立即數(shù)0比較
brne wr0 ;不為0,繼續(xù)發(fā)送下一位。
ret
;#################短延遲程序##################
del: ldi r16,0x01f
Loop1: dec r16 ;減一操作。算術(shù)運(yùn)算指令
brne Loop1 ;條件跳轉(zhuǎn),不相等跳轉(zhuǎn),就是新TEMP不等于舊REMP轉(zhuǎn)移,否則繼續(xù)往下執(zhí)行
nop
ret
;###################鉗套的延遲程序################
londel: ldi r17,0x03
Loop2: rcall del
rcall del
dec r17
brne Loop2
ret
Table_1:
;歡
.db 0x00,0x80,0x00,0x80,0xFC,0x80,0x05,0xFE,0x85,0x04,0x4A,0x48,0x28,0x40,0x10,0x40
.db 0x18,0x40,0x18,0x60,0x24,0xA0,0x24,0x90,0x41,0x18,0x86,0x0E,0x38,0x04,0x00,0x00
;迎
.db 0x01,0x00,0x21,0x10,0x19,0x18,0x0D,0x10,0x09,0x20,0x01,0x04,0x7F,0xFE,0x04,0x40
.db 0x04,0x40,0x04,0x40,0x04,0x40,0x08,0x42,0x08,0x42,0x10,0x42,0x20,0x3E,0x40,0x00
;--------
;迎
.db 0x40,0x00,0x21,0x80,0x36,0x7C,0x24,0x44,0x04,0x44,0x04,0x44,0xE4,0x44,0x24,0x44
.db 0x25,0x44,0x26,0x54,0x24,0x48,0x20,0x40,0x20,0x40,0x50,0x00,0x8F,0xFE,0x00,0x00
;臨
.db 0x01,0x00,0x09,0x80,0x09,0x00,0x49,0xFE,0x4A,0x20,0x4A,0x10,0x4C,0x10,0x49,0x04
.db 0x49,0xFE,0x49,0x24,0x49,0x24,0x49,0x24,0x49,0x24,0x09,0xFC,0x09,0x04,0x00,0x00
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -