MCS 51微控制器 1 利用定時器 數碼管實現秒錶(時分秒都要有)。2 實現可調日曆

2022-04-11 23:38:24 字數 7212 閱讀 6064

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

retkeysel:

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

retgetkey:

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

rett0isr:

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

rett1isr:

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

retledtab: 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 ;" " 10hend

51微控制器的位定址區問題,MCS 51微控制器內部RAM中 單元為位定址區,其位地址範圍為

51單片bai機的位定址區問題書上寫著du位定址zhi區是20h 2fh,位地址00h 7fh,這不是超過dao這個位定址區了嘛內,這兩容個區域是什麼意思的?是這樣的,請你參考 51微控制器的位定址區問題書上寫著位定址區是20h 2fh 這裡的20h 2fh指的是片內ram低128位元組的 20h儲...

MCS 51微控制器有幾個工作暫存器?如何選擇

作暫存器有4組,每組都是8個工作暫存器r0 r7,通過psw中的rs1 rs0兩位來選擇使用哪一組,如果不選,預設是選擇第0組。rs1rs0組合為00時,選中第0組工作暫存器,r0 r7地址為00h 07h rs1rs0組合為01時,選中第1組工作暫存器,r0 r7地址為08h 0fh rs1rs0...

主流C51微控制器編譯器比對,在MCS 51微控制器中怎麼用CJNE指令比較兩數大小

int short 的大小是因機器而異嘛 準確點應該是編譯器 你都說了人家規定的是 最小 為16位,又不是隻能是16位,也沒有說兩者應該相等 事實上是short不超過int就ok啦 所以當然可以short型別為半個機器字長,而int型別則為一個機器字長的啦。c 標準規定了每個算術型別的最小儲存空間,...