電子時鐘程式(微控制器組合語言編寫,不要C語言)

2022-02-06 20:25:06 字數 7469 閱讀 8046

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

PIC微控制器c語音變成組合語言,微控制器大神進,如何將C語言變

有個組合語言轉換器 你自己找找 這個轉化也不是很精確 很容易是自己迷糊,建議還是用c好,現在還用彙編 out了 如何用keil uvision2把c語言的微控制器程式轉換為組合語言 彙編是不可能用軟體自動轉成c語言的,想轉成c就自己寫,反正是自己的程式,程式流程內是不用變容的。keil uvisio...

微控制器組合語言兩數比較大小,51微控制器用組合語言怎麼程式設計幾個有符號數的比較大小

微控制器有比較指令cmp的嗎,請回答者再看看書吧。可以用cjne指令,它有比較功能,如cjne a,data,label 當a data時,進製位置一,就可以判斷了。程式如下 clr c 先把進製位清零,以防誤判cjne a,data,no equ 不等則轉到no equ,相等則直接順序執行 執行相...

51微控制器倒序指令組合語言,51微控制器的指令是組合語言嗎

func 版 mov r0,0 權 mov r7,8 loop rlc a xch a,r0 rrc a xch a,r0 djnz r7,loop mov a,r0ret 51微控制器的指令是組合語言嗎?組合語言 assembly language 是一種用於電子計算機 微處理器版 微控制器或其他...