This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;------------------------------------------ | |
; ================================== | |
; == 4x4按鍵與lcd應用 == | |
; == 2014/12/28 == | |
; == 蘇偉諺 4a037052 == | |
; ================================== | |
;------------------------------------------ | |
; | |
;於lcd的第一列顯示'0123456789abcdef'並利用4x4keyport按鍵,按下數字後其lcd上相對應的數字會往下跳至第二列 | |
lcd_rs equ p2.1 | |
lcd_enable equ p3.7 | |
lcd_bus equ p0 | |
keypor equ p2 | |
keyflag equ 20h.2 | |
scancode equ 33h | |
keyno equ 34h | |
org 00h | |
mov sp,#5fh | |
call initlcd | |
mov dptr,#str | |
call prtstring | |
again: call keyin | |
jnb keyflag,again | |
push acc;;;;;;;;;;;;;; | |
mov b,a | |
mov a,#1 | |
call goxy | |
mov a,#20h | |
call wrdr | |
mov a,#2 | |
call goxy | |
pop acc;;;;;;;;;;;;;; | |
mov dptr,#str;;;;;; | |
movc a,@a+dptr | |
call wrdr | |
jmp again | |
str: db '0123456789ABCDEF','$' | |
keyin: push 00 | |
push 01 | |
mov r0,#0 | |
mov scancode,#11111110b | |
keyrow: mov keyport,scancode | |
mov r7,#4 | |
call delay | |
mov a,keyport | |
mov r1,#4 | |
swap a | |
kcol: rrc a | |
jnc keypressed | |
inc r0 | |
djnz r1,kcol | |
mov a,scancode | |
rl a | |
mov scancode,a | |
jnb acc.4,nokey;;;;;;;;;;;;;;;;;;;; | |
jmp keyrow | |
nokey: clr keyflag | |
jmp keyend | |
keypressed: mo a,r0 | |
setb keyflag | |
keyend: pop 01 | |
pop 00 | |
ret | |
goxy: anl b,#00001111b | |
cjne a,#1,chk1 | |
mov a,b | |
add a,#10000000b;setb a.7 orl 10000000b | |
call wrir | |
ret | |
chk1: mov a,b | |
add a,#11000000b | |
call wrir | |
ret | |
prtstring: push acc | |
prtloop: clr a | |
movc a,@a+dptr | |
cjne a,#'$',next | |
jmp endprt | |
next: call wrdr | |
inc dptr | |
jmp prtloop | |
endprt: pop acc | |
ret | |
initlcd: mov a,#38h | |
call wrir | |
mov a,#0dh | |
call wrir | |
mov a,#06h | |
call wrir | |
clrlcd: mov a,#01h | |
call wrir | |
mov r7,#40;清除需延遲2ms | |
call delay | |
ret | |
delay: mov tmod,#00010001b | |
dloop: mov th0,#high(65536-50) | |
mov tl0,#low(65536-50) | |
setb tr0 | |
jnb tf0,$ | |
clr tr0 | |
clr tf0 | |
djnz r7,dloop | |
ret | |
wrir: setb lcd_enable | |
clr lcd_rs | |
mov lcd_bus,a | |
clr lcd_enable | |
mov r7,#1 | |
call delay | |
ret | |
wrdr: setb lcd_enable | |
setb lcd_rs | |
mov lcd_bus,a | |
clr lcd_enable | |
mov r7,#1 | |
call delay | |
ret | |
end |
沒有留言:
張貼留言
文章有誤或有問題麻煩您留言告知! 謝謝您~~