1樓:匿名使用者
start:
mov p3,#0ffh
mov dptr,#table
mov a,#0
mov r0,a
mov r1,a
mov r2,a
loop:
mov r3,#50
acall display
inc r0
cjne r0,#60,loop
mov r0,#0
inc r1
cjne r1,#60,loop
mov r1,#0
inc r2
cjne r2,#24,loop
mov r2,#0
ajmp loop
display:
mov a,r2
mov b,#10
div ab
movc a,@a+dptr
cpl a
mov p2,a
clr p3.7
acall delay
setb p3.7
mov a,b
movc a,@a+dptr
cpl a
mov p2,a
clr p3.6
acall delay
setb p3.6
mov a,#01000000b
mov p2,a
clr p3.5
acall delay
setb p3.5
mov a,r1
mov b,#10
div ab
movc a,@a+dptr
cpl a
mov p2,a
clr p3.4
acall delay
setb p3.4
mov a,b
movc a,@a+dptr
cpl a
mov p2,a
clr p3.3
acall delay
setb p3.3
mov a,#01000000b
mov p2,a
clr p3.2
acall delay
setb p3.2
mov a,r0
mov b,#10
div ab
movc a,@a+dptr
cpl a
mov p2,a
clr p3.1
acall delay
setb p3.1
mov a,b
movc a,@a+dptr
cpl a
mov p2,a
clr p3.0
acall delay
setb p3.0
djnz r3,display
retdelay:
mov r5,#100
del1: mov r6,#10
djnz r6,$
djnz r5,del1
rettable:
db 0c0h,0f9h,0a4h,0b0hdb 99h,92h,82h,0f8h
db 80h,90h,88h,82h
db 0c6h,0a1h,86h,8eh
end修改下就好
51微控制器簡易電子鐘設計。組合語言編寫
2樓:匿名使用者
keyval equ 30h
keytm equ 31h
keyscan equ 32h
dat equ 33h
scanled equ 39h
clk equ 77h
sec equ 78h
min equ 79h
hour equ 7ah
pause bit 00h
dot bit 01h
org 0000h
ljmp main
org 000bh
ljmp t0isr ;50ms定時
org 001bh
ljmp t1isr ;掃瞄顯示
org 0030h
main:
mov sp,#5fh
mov tmod,#11h
mov th0,#03ch
mov tl0,#0b0h
mov th1,#0ech
mov tl1,#078h
mov keyval,#0
mov scanled,#0
mov 33h,#10h
mov 34h,#10h
mov 35h,#10h
mov 36h,#10h
mov 37h,#10h
mov 38h,#10h
mov sec,#0
mov min,#0
mov hour,#0
mov clk,#0
clr pause
setb ea
setb et1
setb tr1
loop:
lcall keysel
mov a,keyval
cjne a,#0ffh,loop1
sjmp loop
loop1:
cjne a,#10,loop2 ;「on」啟動setb tr0
setb et0
setb pause
sjmp loop
loop2:
cjne a,#11,loop3 ;「=」清零mov sec,#0
mov min,#0
mov hour,#0
lcall dischg
sjmp loop
loop3:
cjne a,#15,loop4 ;「+」暫停clr tr0
clr et0
clr pause
sjmp loop
loop4:
cjne a,#14,loop5 ;「-」清顯示暫停mov 33h,#10h
mov 34h,#10h
mov 35h,#10h
mov 36h,#10h
mov 37h,#10h
mov 38h,#10h
clr tr0
clr et0
clr pause
sjmp loop
loop5:
cjne a,#10,loop6 ;數字鍵loop6:
jc loop7
ljmp loop
loop7:
jnb pause,loop8 ;暫停狀態可以輸入數字鍵ljmp loop
loop8:
mov 33h,34h
mov 34h,35h
mov 35h,36h
mov 36h,37h
mov 37h,38h
mov 38h,keyval
mov a,33h
swap a
orl a,34h
lcall bcdh
mov hour,a
mov a,35h
swap a
orl a,36h
lcall bcdh
mov min,a
mov a,37h
swap a
orl a,38h
lcall bcdh
mov sec,a
ljmp loop
;------------------
;bcd轉換為十六進製制
bcdh:
mov b,#10h
div ab
mov r7,b
mov b,#10
mul ab
add a,r7
ret;------------------
;十六進製制轉換為bcd
hbcd:
mov b,#10
div ab
swap a
orl a,b
ret;------------------
keysel:
mov keyval,#0
mov keyscan,#0efh
lcall getkey
mov a,keytm
jz keys1
mov keyval,a
sjmp keyrtn
keys1:
mov keyscan,#0dfh
lcall getkey
mov a,keytm
jz keys2
clr c
add a,#4
mov keyval,a
sjmp keyrtn
keys2:
mov keyscan,#0bfh
lcall getkey
mov a,keytm
jz keys3
clr c
add a,#8
mov keyval,a
sjmp keyrtn
keys3:
mov keyscan,#7fh
lcall getkey
mov a,keytm
jz keyrtn
clr c
add a,#12
mov keyval,a
keyrtn:
lcall chgkey
ret;--------------------getkey:
mov keytm,#0
mov a,keyscan
mov p3,a
nopmov a,p3
anl a,#0fh
xrl a,#0fh
jz nokey
mov r2,#10
lcall delay
mov a,p3
anl a,#0fh
xrl a,#0fh
jz nokey
mov a,p3
anl a,#0fh
mov r7,a
sf:mov a,p3
anl a,#0fh
xrl a,#0fh
jnz sf
mov a,r7
cjne a,#0eh,nk1
mov keytm,#1
sjmp nokey
nk1:
cjne a,#0dh,nk2
mov keytm,#2
sjmp nokey
nk2:
cjne a,#0bh,nk3
mov keytm,#3
sjmp nokey
nk3:
cjne a,#07h,nokey
mov keytm,#4
nokey: ret
;--------------------delay:
mov r3,#50
delay1:
mov r4,#100
djnz r4,$
djnz r3,delay1
djnz r2,delay
ret;--------------------t0isr:
push acc
clr tr0
mov th0,#3ch
mov tl0,#0b0h
setb tr0
inc clk
mov a,clk
cjne a,#20,t0isre
mov clk,#0
inc sec
mov a,sec
cjne a,#60,t0isre
mov sec,#0
inc min
mov a,min
cjne a,#60,t0isre
mov min,#0
inc hour
mov a,hour
cjne a,#24,t0isre
mov sec,#0
mov min,#0
mov hour,#0
t0isre:
lcall dischg
pop acc
reti
;--------------------dischg:
mov a,hour
lcall hbcd
push acc
anl a,#0fh
mov 34h,a
pop acc
anl a,#0f0h
swap a
mov 33h,a
mov a,min
lcall hbcd
push acc
anl a,#0fh
mov 36h,a
pop acc
anl a,#0f0h
swap a
mov 35h,a
mov a,sec
lcall hbcd
push acc
anl a,#0fh
mov 38h,a
pop acc
anl a,#0f0h
swap a
mov 37h,a
ret;--------------------t1isr:
push acc
clr tr1
mov th1,#0ech
mov tl1,#78h
setb tr1
mov dptr,#ledtab
t100:
mov r0,#dat
mov a,scanled
add a,r0
mov r0,a
mov a,scanled
jnz t101
mov p2,#01h
clr dot
sjmp t1dis
t101:
dec a
jnz t102
mov p2,#02h
setb dot
sjmp t1dis
t102:
dec a
jnz t103
mov p2,#04h
clr dot
sjmp t1dis
t103:
dec a
jnz t104
mov p2,#08h
setb dot
sjmp t1dis
t104:
dec a
jnz t105
mov p2,#10h
clr dot
sjmp t1dis
t105:
mov p2,#20h
clr dot
t1dis:
mov a,@r0
movc a,@a+dptr
jnb dot,t1dis1
orl a,#01h
t1dis1:
cpl a
mov p0,a
inc scanled
mov a,scanled
cjne a,#6,t1end
mov scanled,#0
t1end:
pop acc
reti
;--------------------chgkey:
mov a,keyval
jz kv16
dec a
jnz kv01
mov keyval,#7
retkv01:
dec a
jnz kv02
mov keyval,#4
retkv02:
dec a
jnz kv03
mov keyval,#1
retkv03:
dec a
jnz kv04
mov keyval,#10
retkv04:
dec a
jnz kv05
mov keyval,#8
retkv05:
dec a
jnz kv06
mov keyval,#5
retkv06:
dec a
jnz kv07
mov keyval,#2
retkv07:
dec a
jnz kv08
mov keyval,#0
retkv08:
dec a
jnz kv09
mov keyval,#9
retkv09:
dec a
jnz kv10
mov keyval,#6
retkv10:
dec a
jnz kv11
mov keyval,#3
retkv11:
dec a
jnz kv12
mov keyval,#11
retkv12:
dec a
jnz kv13
mov keyval,#12
retkv13:
dec a
jnz kv14
mov keyval,#13
retkv14:
dec a
jnz kv15
mov keyval,#14
retkv15:
dec a
jnz kv16
mov keyval,#15
retkv16:
mov keyval,#0ffh
ret;--------------------ledtab: db 0fch ;"0" 00hdb 60h ;"1" 01h
db 0dah ;"2" 02h
db 0f2h ;"3" 03h
db 66h ;"4" 04h
db 0b6h ;"5" 05h
db 0beh ;"6" 06h
db 0e0h ;"7" 07h
db 0feh ;"8" 08h
db 0f6h ;"9" 09h
db 0eeh ;"a" 0ah
db 3eh ;"b" 0bh
db 9ch ;"c" 0ch
db 7ah ;"d" 0dh
db 9eh ;"e" 0eh
db 8eh ;"f" 0fh
db 00h ;" " 10h
;--------------------end
微控制器中,怎樣設計鍵盤復合鍵,微控制器設計中乙個按鍵有多個功能是如何實現的
復合鍵就是給個按鍵標誌位,比如按下為1,沒按為0 如果 復合鍵為2 個以上功能 就要以0 1 2.賦值標誌。然後程式中判斷哪個值就轉哪個功能 鍵盤復合鍵,是要實現第二功能鍵嗎?就像電腦上的shift 鍵的功能嗎?這需要是矩陣鍵盤,獨立按鍵比較少就沒有什麼意義了。其實,與識別單鍵的原理是一樣的,只要識...
設計電子時鐘要用AT89S51微控制器的定時器實現,用4位數碼管顯示,用點的閃爍表示秒,我需要電路原理圖
用4位數碼管顯示,用點的閃爍表示秒,就是共有5位,7段 那麼用一整個pio口 8位 去對應7段資料,再用另外乙個pio口的部分 全部 管腳去構成個鍵盤,這個就是你需要畫的電路圖了 至於振盪電路 復位電路等幾乎是固定的結構形式,對應具體晶元就標註上對應的管腳序號就是了 1 基本要求 1 顯示準確的北京...
用51微控制器設計萬年曆高手幫忙,急
呵呵,看來對你來說是個麻煩事啊。做乙個完整的板子出來。要有 電路板 版微控制器 建議你出錢買乙個設計,10天你自己做比較困難 軟體好辦,網上都有現成的,關鍵是硬體啊,照樣焊也不一定好用啊,很難調啊 找做過的人幫忙吧 我給你一部分電路先 時間挺緊的,建議在高手的幫助指導下,趕緊先學習微控制器後再做。你...