採用微控制器控制的時鐘計時器的設計內容 以MCS 51微控制器為核心,設計並製作時鐘計時器,用6位LED數碼管

2022-02-03 00:45:03 字數 7469 閱讀 1402

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

微控制器中定時器的時鐘與系統時鐘有什麼關係

微控制器的定時器可bai以使用 系統時du鍾,也可以使用zhi外接的dao晶震,如果使用系統時鐘專,系統的時鐘決屬定指令週期,經過分頻 比如4分頻 定時器計一個數要的時間就便成指令週期乘以4。使用內部時鐘還是外部時鐘 幾分頻就取決於各晶片的配置字。可以這樣理解,定時器是copy 一個bai可程式設計...

微控制器鎖存器和譯碼器的原理,51微控制器中LS138譯碼器的原理

譯碼器一般用來io口擴充套件,比如38譯碼器,用3個io口當8個io來使用,因為它輸出只有一路有效 鎖存器是用來儲存維持狀態的,io口複用電路上用的多,通過使能腳來切換 鎖存器和譯碼器,不是微控制器。鎖存器和譯碼器的原理很簡單,看看 數位電子技術 即可。鎖存器和譯碼器屬於數位電路,與微控制器並不屬於...

怎麼不用微控制器之類的控制直流減速電機,直接實現小車的差速轉彎

讓兩個電機的轉速不一樣就可以實現轉彎。先測出直走時前輪的pwm,再根據需要改變pwm的值,看它怎麼轉彎的,這些都是慢慢試出來的 微控制器三輪小車怎樣控制車輪差速使轉彎最快!微控制器是不能直接使用在變速上的。和直流減速電機有什麼區別,我想用微控制器來控制,不 步進電機與直流電機在電機學裡完全就屬於不同...