51微控制器簡易電子鐘設計組合語言編寫

2022-02-23 22:31:22 字數 7464 閱讀 9447

1樓:匿名使用者

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

關於51微控制器電子鐘硬體執行的問題

不知道你的數碼管顯示電路是怎麼連線的。通過什麼驅動。你這樣的情況原因基本有兩個 一個是電路板虛焊了,數碼管的不可靠導通。還有一個就是微控制器外圍電路 特別是電源和復位 有問題,造成微控制器不能可靠復位執行程式,有時正常有時不正常。你試試看將微控制器取下,接通電源看數碼管的顯示情況。再結合你的電路圖分...

51微控制器彙編控制流水燈,51微控制器中如何用組合語言編寫流水燈

用rl a 他是左移補零的,你rlc a 是把最高位放在psw的c中,再左移,c再放在最低位.而rl是不經過c的。左移後低位補零,你把rlc換成rl就可以了 org 0000h ljmp start org 0030h start mov a,0feh mov r2,8 output mov p1,...

51微控制器彙編指令mov和mov指令什麼區別聯絡

mov 是訪問片內的ram和sfr時用的 movx 是訪問片外的ram用的 還有一個movc,是訪問 rom時用的。51採用的哈佛結構,有許多的地址是重複的。比如說 一個地址是 0x88,在rom裡有這個地址,內部的ram裡有這個地址,sfr裡有這個地址,外部ram裡也有這個地上,究竟是訪問哪一個呢...