các bác ơi ! ai ngon ASM sửa giúp cái code cho cái ! híc ! keil nó báo lỗi khai báo mà em ko biết sửa thế nào ! mong các pro giúp đỡ
; CHUONG TRINH CHO IC 89C51/52
; TRAN THANH QUANG 09CDT2 - DHBK DA NANG- 09CDT2 - 01675363461
tcon equ 88h ; dia chi cac thanh ghi va cac port
t2con equ c8h ;
tmod equ 89h ;
pcon equ 87h
tl0 equ 8ah;
tl1 equ 8bh
th0 equ 8ch
th1 equ 8dh
reap2l equ cah
reap2h equ cbh
tl2 equ cch
th2 equ cdh
sp equ 81h
ie equ a8h
ip equ b8h
p0 equ 80h
p1 equ 90h
p2 equ a0h
p3 equ b0h
b equ f0h;
pcon equ 87h
;--*-----*---------------MAIN-----------------*----*
org 0000h ; dia chi nap rom bat dau cua chuong trinh
ljmp begin
org 000bh ; dia chi nap rom bat dau cua chuong trinh con deo thoi gian
ljmp c_time
org 001bh ; dia chi nap rom bat dau cua chuong trinh con phim bam
ljmp get_key
org 002bh ; dia chi nap rom bat dau cua chuong trinh con hien thi
ljmp quet_hien_thi
org 0030h ; dia chi nap rom bat dau cua chuong trinh chinh
begin:
mov r0,#00h ;
mov r1,#00h ;
mov r2,#00h ;
mov r3,#00h ;
mov r4,#00h ;
mov r5,#00h ;
mov r6,#00h ; Dem 1/2 giay
mov r7,#00h ; Dem 1/20 giay
mov sp,#10h ; Dinh dia chi dau cua stack
mov 20h,#00h ; Byte chua phut
mov 21h,#00h ; Byte chua gio
mov 22h,#02h ; Byte chua thu
mov 23h,#00h ; Byte chua ngay
mov 24h,#00h ; Byte chua thang
mov 25h,#00h ; Byte chua nam
mov 26h,#00h ; Byte dem cho nut "lua_chon"
mov 27h,#00h ; Byte dem cho nut "chinh_tang"
mov 28h,#00h ; Byte chua chi so den nhay
mov 29h,#02h ; Byte chua chi so den duoc hien thi
mov 2ah,#00h ; Byte chua dia chi "byte nho gio co chuong"
mov tmod,#00010001b ;che do dinh thoi 16bit - bo dinh thoi 0 va 1
mov th0,#3ch ; Dat -50000 bo dinh thoi 0
mov tl0,#aeh ; Dat -50000 bo dinh thoi 0
mov th1,#f8h ; Dat -20000 bo dinh thoi 1 cho nut nhan
mov th1,#2fh ; Dat -20000 bo dinh thoi 1 cho nut nhan
mov rcap2h,#f6h ; Dat -25000 bo dinh thoi cho 2 hien thi
mov rcap2l,#38h ; Dat -25000 bo dinh thoi cho 2 hien thi
mov t2con,#00000100b ; Che do dinh thoi 16 bit bo dinh thoi 2
setb tcon.4 ; Cho phep bo dinh thoi 0
setb tcon.6 ; Cho pheo bo dinh thoi 1
mov ie,#aah ; Cho phep ngat - bo dinh thoi 0 va 1
mov ip,#02h ; Dat muc uu tien nhat cho dem thoi gian - cua bo dinh thoi toi 0
; Kiem tra xem mua nao
mov c,p2.6 ; Kiem tra bit p2.6
jc Chuong_mua_dong
;*********************mach vong mua he**********************
Chuong mua he:
lcall mua_he ; GOI CHUONG TRINH CON NAP GIO MUA HE
mov r0,30h ; Dat gia tri khoi dau vung chua gio hen do chuong
kt_chuong
kt_thu:
mov a,22h ;chuyen gia tri thanh ghi thu vao
cjne a,#08h, lap1 ; Khac chu nhat, nhay
setb p2.0 ; bang chu nhat, tat chuong
sjmp kt_thu
lap1:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#06h,lap2 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne,a#2dh,lap2 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap2:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#06h,lap3 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#39h,lap3 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
lap3:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#0dh,lap4 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#00h,lap4 ; So sanh phut, khong bang, nhay
lcall chuong_bao
loop: ; Vong lap kiem tra va so voi thoi gian dat truoc
mov a,@r0 ; chuyen gia tri o dia chi gian tiep vao a
inc ; Tang dia chi len
cjne a,21h,k_chuong ; So sanh gio, chua bang nhay
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep theo vao a
cjne a,20h,k_chuong ; So sanh phut, chua bang nhay
mov b,r0
jb f1h,ra_choi ; Bit= 1,nhay
vao hoc:
lcall chuong_vao
ljmp k_chuong
ra_choi:
lcall chuong_ra
k_chuong:
inc r0 ; Tang chi so hen gio
cjne r0,#58h,tiep_tuc ; Kiem tra den vung nho gio hen hay khong ?
mov r0,#30h ; Khoi tao lai r0 cho chu ky moi
tiep_tuc:
ljmp kt_chuong ; Nhay ve tiep tuc kiem tra
;*************** ; Mach vong mua dong ***************
chuong_mua_dong:
lcall mua_dong
mov r0,#30h ; Dat gia tri khoi dau vung chua hen gio do chuong
kt_chuong1: ; Vong lap lien tuc kiem tra co do chuong hay khong ?
kt_thu1:
mov a,22h ; Chuyen gia tri thanh ghi thu vao
cjne a,#08h,lap11 ; Khac chu nhat, nhay
setv p2.0 ; Bang chu nhat, tat chuong
sjmp kt_thu1
lap11:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#06h,lap21 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia ti thanh ghi chua phut vao
cjne,#2dh,lap21 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap21:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#06h,lap31 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#39h,lap31 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
lap31:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#0dh,lap41 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#00h,lap41 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap41:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#0dh,loop1 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a#05h,loop1 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
loop1: ; Vong lap kiem tra va so sanh voi thoi gian dat truoc
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep vao a
inc r0 ; Tang dia chia len
cjne a,21h,k_chuong1 ; So sanh gio, chua bang nhat
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep tiep theo vao a
cjne a,20h,k_chuong1 ; So sanh phut, chua bang nhay
mov b,r0
jb f1h,ra_choi1 ; Bit =1, nhay
vap_hoc1:
lcall chuong_vao
ljmp k_chuong1
ra_choi1:
lcall chuong_ra
k_chuong1:
inc r0 ; Tang chi so hen gio
cjne r0,#58h,tiep_tuc1 ; Kiem tra den cuoi vung nho hen gio hay khong
mov r0,#30h ; Khoi tao lai gia tri r0 cho chu ky moi
tiep_tuc1:
ljmp kt_chuong1 ; Nhay ve tiep tuc kiem tra
mua_he:
; gio buoi sang mua he
mov 30h,#07
mov 31h,#00
mov 32h,#07
mov 33h,#45
mov 34h,#07
mov 35h,#55
mov 36h,#08
mov 37h,#40
mov 38h,#08
mov 39h,#55
mov 3ah,#09
mov 3bh,#40
mov 3ch,#09
mov 3dh,#50
mov 3eh,#10
mov 3fh,#35
mov 40h,#10
mov 41h,#45
mov 42h,#11
mov 43h,#30
; Gio buoi chieu mua he
mov 44h,#13
mov 45h,#15
mov 46h,#14
mov 47h,#00
mov 48h,#14
mov 49h,#10
mov 4ah,#14
mov 4bh,#55
mov 4ch,#15
mov 4dh,#10
mov 4eh,#15
mov 4fh,#55
mov 50h,#16
mov 51h,#05
mov 52h,#16
mov 53h,#50
mov 54h,#17
mov 55h,#00
mov 56h,#17
mov 57h,#45
ret
mua_dong:
; Gio buoi sang mua dong
mov 30h,#07
mov 31h,#15
mov 32h,#08
mov 33h,#00
mov 34h,#08
mov 35h,#10
mov 36h,#08
mov 37h,#55
mov 38h,#09
mov 39h,#05
mov 3ah,#09
mov 3bh,#50
mov 3ch,#10
mov 3dh,#00
mov 3eh,#10
mov 3fh,#45
mov 40h,#10
mov 41h,#55
mov 42h,#11
mov 43h,#40
; Gio buoi chieu mua dong
mov 44h,#13
mov 45h,#00
mov 46h,#13
mov 47h,#45
mov 48h,#13
mov 49h,#55
mov 4ah,#14
mov 4bh,#40
mov 50h,#15
mov 51h,#50
mov 52h,#16
mov 53h,#35
mov 54h,#16
mov 55h,#17
mov 57h,#30
ret
; ****** Ket thuc viec nao gia tri hen gio *****;
chuong_bao:
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 2
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 3
clr p2.0
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2a ; Hoi 4
clr p2.0 ;
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2p ; Hoi 5
ret
chuong_truy_bai:
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 2
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2p ; Hoi 3
ret
chuong_vao ; keu chuong 2 hoi
clr p2.0 ; Keu chuong 2 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0 ; Tat chuong
lcall wait2p ; Doi 2 phut nua
ret
chuong_ra
clr p2.0 ; Keu chuong 2 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
ret
wait2s: ; Chuong trinh con doi 1,5s
mov a,r6 ; Chuyen gia tri thanh ghi dem giay vao a
add a,#3h ; Cong them 4 ( =4*1/2=2s )
waits:
cjne a,06h,waits ; Chua bang quay lai !
ret
wait2p: ; Chuong trinh con doi 2 phut
mov a,20h ; Chuyen gia tri thanh ghi dem phut vao a
add a,#1h ; Cong them 1
waitp:
cjne a,20h,waitp ; Chua bang quay lai !
ret
;CHUONG TRINH CON HIEN THI LED 7 THANH * 5 DEN LED
;BANG NGAT CUA BO DINH THOI 2 - T2CON
quet_hien_thi:
clr t2con.7 ; Xoa co ngat
mov 08h,r0
mov 09h,r1
mov 0ah,r2
mov 0bh,r3
mov 0ch,r4
mov 0dh,r5
mov 0eh,a ; Cat luon thanh chua a va thanh ghi b
mov 0fh,b
mov r0,29h ; Thanh ghi chi vi tri den duoc hien thi tai mot thoi diem
inc r0 ; Tang de chi sang den tiep theo
cjne r0,#06h,led
mov r0,#01h
led:
mov 29h,r0 ; Cat gia tri chi vi tri den hien thi
mov a,20h ; Tinh cac gia tri hien thi tren cac led vao trong cac r1->r5
mov b,#0ah ; b=10
div ab ; a chia b, gia tri phut
mov r1,b ; Phan hang truc
mov r2,a ; Phan hang don vi
mov a,21h
mov b,#0ah
div ab ; a chia b, gia tri gio
mov r3,b ; Phan hang chuc
mov r4,a ; Phan hang don vi
mov r5,22h ; Thanh ghi chua ngay
;*** Xet theo gia tri r0 de xem den nao duoc hien thi****
mov b,#00h
led1: cjne r0,#01h,led2 ;r0=1 thi,
mov r0,#28h
cjne @r0,#01h,n01
mov b,#01h
n01:
mov a,r1 ; Chuyen gia tri down vi phut ra den 7 thanh so 1
setb p2.5 ; Den 5 tat
lcall hien_thi
clr p2.1 ; Den 1 sang
ljmp end_hien_thi
led2:
cjne r0,#02h,led3 ; r0=2 thi,
mov r0,#28h
cjne @r0,#01h,n02
mov b,#01h
n02:
mov a,r2 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 2
setb p2.1 ; Den 1 tat
lcall hien_thi
clr p2.2 ; Den 2 sang
ljmp end_hien_thi
led3:
cjne r0,#03h,led4 ; r0=3 thi,
mov r0,#28h
cjne @r0,#02h,n03
mov b,#01h
n03:
mov a,r3 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 3
setb p2.1 ; Den 2 tat
lcall hien_thi
clr p2.3 ; Den 3 sang
ljmp end_hien_thi
led4:
cjne r0,#04h,led3 ; r0=4 thi,
mov r0,#28h
cjne @r0,#02h,n04
mov b,#01h
n04:
mov a,r4 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 4
setb p2.3 ; Den 3 tat
lcall hien_thi
clr p2.4 ; Den 4 sang
ljmp end_hien_thi
; Mach kiem tra va tat den so 4;
check: cjne r4,#00h,sang ; Neu gia tri hang chuc gio = 0
setb p2.4 ; Tat den so 4
ljmp end_hien_thi
sang: lcall hien_thi ; Neu =1 hoac 2 thi
clr p2.4 ; Den 4 sang
ljmp end_hien_thi
led5:
mov r0,#28h
cjne r0,#03h,n05 ; r0=5 thi,
mov b,#01h
n05:
mov a,r5 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 5
setb p2.4 ; Den 4 tat
lcall hien_thi
clr p2.5 ; Den 5 sang
end_hien_thi:
mov r0,08h ; Tra lai cac gia tri r0->r5 truoc khi goi ngat
mov r1,09h
mov r2,0ah
mov r3,0bh
mov r4,0ch
mov r5,0dh
mov a,0eh ; Tra lai cac gia tri thanh chua a va thanh ghi b
mov b,0fh
reti ; Ket thuc chuong trinh ngat quet hien thi
hien_thi: ; Chuong trinh hien thi cho mot LED
lcall chuyen_ma ; Goi chuong trinh chuyen ma BCD - 7 THANH
mov r0,b ; Cat t ghi a
mov b,a
mov a,r0
cjne a,#01h,khong_nhay ; So sanh kiem tra co phai hien thi trung den nhay
mov a,r7
anl a,#00000100b
cjne a,#00000100b, nhay
khonng_nhay:
mov p0,b
sjmp end_hien_thi
nhay:
mov p0,#ffh ; Den achung dffh, den kchung 00h
ret
; **************Chuong trinh nhan phim **************
get_ket:
mov th1,#f8h ; Khoi tao lai thanh ghi dinh thoi 1
mov tl1,#2fh
kt_nguon:
jb p1.0,binh_thuong
mov p0,#ffh
mov pcon,#01h ; Che do nguon giam
binh_thuong:
mov pcon,#00h
push 00h ; Cat gia tri trong thi ghi r0,a vao stack
mov r0,a
push 00h
jnb p3.2,lua_chon ; Bit =0, nhay
mov 26h,#00h ; Thanh ghi dem cho nut"lua_chon"
ljmp phim2
lua_chon:
mov r0,#26h
inc @r0
cjne @r0,#10h,end_get_key
mov r0,28h ; Thanh ghi chi so den nhay
inc @r0 ; Tang chi so den nhat -> Nhay sang den tiep theo
theo
cjne @0,#04h,end_get_key
mov @r0,#00h
ljmp end_get_key
phim2:
jnb p3.3,chinh_tang ; Bit =0, nhay
mov 27h,#00h ; Thanh ghi dem cho nut "chinh_tang"
ljmp end_get_key
chinh_tang:
mov r0,#27h ; CHuyen dia chi gian tiep vao r0; !!! Dang kiem tra
inc @r0 ; Tang gia tri trong dia chi do len
cjne @r0,10h,end_get_key ; Gia tri nay chua =10
inc 28h ; Tang gia tri thanh ghi chi so den nhay
djnz 28h,ld1 ; Giam, chua =0, nhay ve d1
ljmp end_get_key ; =0 nhay ve ket thuc
ld1:
djnz 28h,ld3 ; Tang den LED 1 - Hang don vi phut
mov a,20h ; Chuyen gia tri thanh ghi phut vao a
add a,#01h ; Cong them 1
cjne a,#3ch,m11 ; Chua = , quay lai
mov a,#00h ; =, dat =0
m11
mov 20h,a
mov 28h,#01h;
ljmp end_get_key
ld3
djnz 28h,ld5 ; Tang den LED 3 - Hang don vi gio
mov a,21h
add a,#01h
cjne a,#18h,m31 ; Chua =, quay lai
mov a,#00h ; =, dat =0
m31:
mov 21h,a
mov 28h,#02h
ljmp end_get_key
ld5:
mov a,22h ; Tang den LED 5 - Chua ngay
add a#01h
cjne a,#09h,m51
mov a,#02h ; =, dat =2
m51
mov 21h,a
mov 28h,#03h
ljmp end_get_key
end_get_key
pop 00h ; Lay lai cac gia tri truoc do cua r0 va a
mov a,r0
pop 00h
reti
;---- * CHUONG TRINH CON DEM THOI GIAN * -----
c_time: ; Duoc goi 20 lan moi giay
mov th0,#3ch ; Dat byte cao bo dinh thoi 0 ,-50000
mov tl0,#àh ; Dat byte thap bo dinh thoi 0
push 00h ; Cat gia tri thanh ghi r0
inc r7 ; Tang 1/20 giay
cjne r7,#0ah,end_time ; =10
mov r7,#00h ; Quay ve 0
cpl p2.7 ; Tao 2 cham sang nhay tren mat dong ho
inc r6 ; Tang 1/2 giay
cjne r6,#78h,end_time ; =120
mov r6,#00h ; Quay ve 00
mov r0,#20h ; Dia chi thanh ghi chua phut
inc @r0 ; Tang 1 phut
cjne @r0,#3ch,end_time ; =60,
mov @r0,#00h ; Quay ve 00
mov r0,21h ; Dia chi thanh ghi chua gio
inc @r0 ; Tang 1 gio
mov r6,#01h ; Bu 1h 0.5s*24=12s
cjne @r0,#18h,end_time ; =24
mov @r0,00h ; Quay ve 00
mov r0,#22h ; Dia chi thanh ghi chua ngay
inc @r0 ; Tang 1 ngay
mov r6,#11h ; Bu 1 ngay 8,5s
cjne @r0,#9h, end_time ; Den ngay thu 9
mov r6,#05h ; Bu 1 tuan 2,5s
mov @r0,#02h ; Quay ve thu 2
; Neu can thi dem them ngay, thang, nam
end_time:
pop 00h ; Lay ra
reti
; CHUONG TRINH CHUYEN DOI MA BCD - LED 7 THANH
chuyen_ma:
cjne a,#00h,so1 ; Khong bang nhay sang so 1
mov a,#c0h
sjmp end_cm
so1:
cjne a,#01h,so2 ; Khong bang nhay sang so 2
mov a,#f9h
sjmp end_cm
so2:
cjne a,#02h,so3 ; Khong bang nhay sang so 3
mov a,#a4h
sjmp end_cm
so3:
cjne a,#03h,so4 ; Khong bang nhay sang so 4
mov a,#b0h
sjmp end_cm
so4:
cjne a,#04h,so5 ; Khong bang nhay sang so 5
mov a,#99h
sjmp end_cm
so5:
cjne a,#05h,so6 ; Khong bang nhay sang so 6
mov a,#92h
sjmp end_cm
so6:
cjne a,#06h,so7 ; Khong bang nhay sang so 7
mov a,#82h
sjmp end_cm
so7:
cjne a,#07h,so8 ; Khong bang nhay sang so 8
mov a,#f8h
sjmp end_cm
so8:
cjne a,#08h,so9 ; Khong bang nhay sang so 9
mov a,#80h
sjmp end_cm
so9:
mov a,#90h
end_cm:
ret ; Quay tro lai chuong trinh
END ; Ket thuc hoan toan chuong trinh
; CHUONG TRINH CHO IC 89C51/52
; TRAN THANH QUANG 09CDT2 - DHBK DA NANG- 09CDT2 - 01675363461
tcon equ 88h ; dia chi cac thanh ghi va cac port
t2con equ c8h ;
tmod equ 89h ;
pcon equ 87h
tl0 equ 8ah;
tl1 equ 8bh
th0 equ 8ch
th1 equ 8dh
reap2l equ cah
reap2h equ cbh
tl2 equ cch
th2 equ cdh
sp equ 81h
ie equ a8h
ip equ b8h
p0 equ 80h
p1 equ 90h
p2 equ a0h
p3 equ b0h
b equ f0h;
pcon equ 87h
;--*-----*---------------MAIN-----------------*----*
org 0000h ; dia chi nap rom bat dau cua chuong trinh
ljmp begin
org 000bh ; dia chi nap rom bat dau cua chuong trinh con deo thoi gian
ljmp c_time
org 001bh ; dia chi nap rom bat dau cua chuong trinh con phim bam
ljmp get_key
org 002bh ; dia chi nap rom bat dau cua chuong trinh con hien thi
ljmp quet_hien_thi
org 0030h ; dia chi nap rom bat dau cua chuong trinh chinh
begin:
mov r0,#00h ;
mov r1,#00h ;
mov r2,#00h ;
mov r3,#00h ;
mov r4,#00h ;
mov r5,#00h ;
mov r6,#00h ; Dem 1/2 giay
mov r7,#00h ; Dem 1/20 giay
mov sp,#10h ; Dinh dia chi dau cua stack
mov 20h,#00h ; Byte chua phut
mov 21h,#00h ; Byte chua gio
mov 22h,#02h ; Byte chua thu
mov 23h,#00h ; Byte chua ngay
mov 24h,#00h ; Byte chua thang
mov 25h,#00h ; Byte chua nam
mov 26h,#00h ; Byte dem cho nut "lua_chon"
mov 27h,#00h ; Byte dem cho nut "chinh_tang"
mov 28h,#00h ; Byte chua chi so den nhay
mov 29h,#02h ; Byte chua chi so den duoc hien thi
mov 2ah,#00h ; Byte chua dia chi "byte nho gio co chuong"
mov tmod,#00010001b ;che do dinh thoi 16bit - bo dinh thoi 0 va 1
mov th0,#3ch ; Dat -50000 bo dinh thoi 0
mov tl0,#aeh ; Dat -50000 bo dinh thoi 0
mov th1,#f8h ; Dat -20000 bo dinh thoi 1 cho nut nhan
mov th1,#2fh ; Dat -20000 bo dinh thoi 1 cho nut nhan
mov rcap2h,#f6h ; Dat -25000 bo dinh thoi cho 2 hien thi
mov rcap2l,#38h ; Dat -25000 bo dinh thoi cho 2 hien thi
mov t2con,#00000100b ; Che do dinh thoi 16 bit bo dinh thoi 2
setb tcon.4 ; Cho phep bo dinh thoi 0
setb tcon.6 ; Cho pheo bo dinh thoi 1
mov ie,#aah ; Cho phep ngat - bo dinh thoi 0 va 1
mov ip,#02h ; Dat muc uu tien nhat cho dem thoi gian - cua bo dinh thoi toi 0
; Kiem tra xem mua nao
mov c,p2.6 ; Kiem tra bit p2.6
jc Chuong_mua_dong
;*********************mach vong mua he**********************
Chuong mua he:
lcall mua_he ; GOI CHUONG TRINH CON NAP GIO MUA HE
mov r0,30h ; Dat gia tri khoi dau vung chua gio hen do chuong
kt_chuong
kt_thu:
mov a,22h ;chuyen gia tri thanh ghi thu vao
cjne a,#08h, lap1 ; Khac chu nhat, nhay
setb p2.0 ; bang chu nhat, tat chuong
sjmp kt_thu
lap1:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#06h,lap2 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne,a#2dh,lap2 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap2:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#06h,lap3 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#39h,lap3 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
lap3:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#0dh,lap4 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#00h,lap4 ; So sanh phut, khong bang, nhay
lcall chuong_bao
loop: ; Vong lap kiem tra va so voi thoi gian dat truoc
mov a,@r0 ; chuyen gia tri o dia chi gian tiep vao a
inc ; Tang dia chi len
cjne a,21h,k_chuong ; So sanh gio, chua bang nhay
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep theo vao a
cjne a,20h,k_chuong ; So sanh phut, chua bang nhay
mov b,r0
jb f1h,ra_choi ; Bit= 1,nhay
vao hoc:
lcall chuong_vao
ljmp k_chuong
ra_choi:
lcall chuong_ra
k_chuong:
inc r0 ; Tang chi so hen gio
cjne r0,#58h,tiep_tuc ; Kiem tra den vung nho gio hen hay khong ?
mov r0,#30h ; Khoi tao lai r0 cho chu ky moi
tiep_tuc:
ljmp kt_chuong ; Nhay ve tiep tuc kiem tra
;*************** ; Mach vong mua dong ***************
chuong_mua_dong:
lcall mua_dong
mov r0,#30h ; Dat gia tri khoi dau vung chua hen gio do chuong
kt_chuong1: ; Vong lap lien tuc kiem tra co do chuong hay khong ?
kt_thu1:
mov a,22h ; Chuyen gia tri thanh ghi thu vao
cjne a,#08h,lap11 ; Khac chu nhat, nhay
setv p2.0 ; Bang chu nhat, tat chuong
sjmp kt_thu1
lap11:
mov a,21h ; Nao gia tri thanh ghi chua gio vao
cjne a,#06h,lap21 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia ti thanh ghi chua phut vao
cjne,#2dh,lap21 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap21:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#06h,lap31 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#39h,lap31 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
lap31:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#0dh,lap41 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a,#00h,lap41 ; So sanh phut, khong bang, nhay
lcall chuong_bao
lap41:
mov a,21h ; Nap gia tri thanh ghi chua gio vao
cjne a,#0dh,loop1 ; So sanh gio, khong bang, nhay
mov a,20h ; Nap gia tri thanh ghi chua phut vao
cjne a#05h,loop1 ; So sanh phut, khong bang, nhay
lcall chuong_truy_bai
loop1: ; Vong lap kiem tra va so sanh voi thoi gian dat truoc
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep vao a
inc r0 ; Tang dia chia len
cjne a,21h,k_chuong1 ; So sanh gio, chua bang nhat
mov a,@r0 ; Chuyen gia tri o dia chi gian tiep tiep theo vao a
cjne a,20h,k_chuong1 ; So sanh phut, chua bang nhay
mov b,r0
jb f1h,ra_choi1 ; Bit =1, nhay
vap_hoc1:
lcall chuong_vao
ljmp k_chuong1
ra_choi1:
lcall chuong_ra
k_chuong1:
inc r0 ; Tang chi so hen gio
cjne r0,#58h,tiep_tuc1 ; Kiem tra den cuoi vung nho hen gio hay khong
mov r0,#30h ; Khoi tao lai gia tri r0 cho chu ky moi
tiep_tuc1:
ljmp kt_chuong1 ; Nhay ve tiep tuc kiem tra
mua_he:
; gio buoi sang mua he
mov 30h,#07
mov 31h,#00
mov 32h,#07
mov 33h,#45
mov 34h,#07
mov 35h,#55
mov 36h,#08
mov 37h,#40
mov 38h,#08
mov 39h,#55
mov 3ah,#09
mov 3bh,#40
mov 3ch,#09
mov 3dh,#50
mov 3eh,#10
mov 3fh,#35
mov 40h,#10
mov 41h,#45
mov 42h,#11
mov 43h,#30
; Gio buoi chieu mua he
mov 44h,#13
mov 45h,#15
mov 46h,#14
mov 47h,#00
mov 48h,#14
mov 49h,#10
mov 4ah,#14
mov 4bh,#55
mov 4ch,#15
mov 4dh,#10
mov 4eh,#15
mov 4fh,#55
mov 50h,#16
mov 51h,#05
mov 52h,#16
mov 53h,#50
mov 54h,#17
mov 55h,#00
mov 56h,#17
mov 57h,#45
ret
mua_dong:
; Gio buoi sang mua dong
mov 30h,#07
mov 31h,#15
mov 32h,#08
mov 33h,#00
mov 34h,#08
mov 35h,#10
mov 36h,#08
mov 37h,#55
mov 38h,#09
mov 39h,#05
mov 3ah,#09
mov 3bh,#50
mov 3ch,#10
mov 3dh,#00
mov 3eh,#10
mov 3fh,#45
mov 40h,#10
mov 41h,#55
mov 42h,#11
mov 43h,#40
; Gio buoi chieu mua dong
mov 44h,#13
mov 45h,#00
mov 46h,#13
mov 47h,#45
mov 48h,#13
mov 49h,#55
mov 4ah,#14
mov 4bh,#40
mov 50h,#15
mov 51h,#50
mov 52h,#16
mov 53h,#35
mov 54h,#16
mov 55h,#17
mov 57h,#30
ret
; ****** Ket thuc viec nao gia tri hen gio *****;
chuong_bao:
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 2
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 3
clr p2.0
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2a ; Hoi 4
clr p2.0 ;
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2p ; Hoi 5
ret
chuong_truy_bai:
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 2
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2p ; Hoi 3
ret
chuong_vao ; keu chuong 2 hoi
clr p2.0 ; Keu chuong 2 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
clr p2.0 ; Keu chuong 3 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0 ; Tat chuong
lcall wait2p ; Doi 2 phut nua
ret
chuong_ra
clr p2.0 ; Keu chuong 2 hoi 4s, ngat 2s
lcall wait2s
lcall wait2s
setb p2.0
lcall wait2s ; Hoi 1
ret
wait2s: ; Chuong trinh con doi 1,5s
mov a,r6 ; Chuyen gia tri thanh ghi dem giay vao a
add a,#3h ; Cong them 4 ( =4*1/2=2s )
waits:
cjne a,06h,waits ; Chua bang quay lai !
ret
wait2p: ; Chuong trinh con doi 2 phut
mov a,20h ; Chuyen gia tri thanh ghi dem phut vao a
add a,#1h ; Cong them 1
waitp:
cjne a,20h,waitp ; Chua bang quay lai !
ret
;CHUONG TRINH CON HIEN THI LED 7 THANH * 5 DEN LED
;BANG NGAT CUA BO DINH THOI 2 - T2CON
quet_hien_thi:
clr t2con.7 ; Xoa co ngat
mov 08h,r0
mov 09h,r1
mov 0ah,r2
mov 0bh,r3
mov 0ch,r4
mov 0dh,r5
mov 0eh,a ; Cat luon thanh chua a va thanh ghi b
mov 0fh,b
mov r0,29h ; Thanh ghi chi vi tri den duoc hien thi tai mot thoi diem
inc r0 ; Tang de chi sang den tiep theo
cjne r0,#06h,led
mov r0,#01h
led:
mov 29h,r0 ; Cat gia tri chi vi tri den hien thi
mov a,20h ; Tinh cac gia tri hien thi tren cac led vao trong cac r1->r5
mov b,#0ah ; b=10
div ab ; a chia b, gia tri phut
mov r1,b ; Phan hang truc
mov r2,a ; Phan hang don vi
mov a,21h
mov b,#0ah
div ab ; a chia b, gia tri gio
mov r3,b ; Phan hang chuc
mov r4,a ; Phan hang don vi
mov r5,22h ; Thanh ghi chua ngay
;*** Xet theo gia tri r0 de xem den nao duoc hien thi****
mov b,#00h
led1: cjne r0,#01h,led2 ;r0=1 thi,
mov r0,#28h
cjne @r0,#01h,n01
mov b,#01h
n01:
mov a,r1 ; Chuyen gia tri down vi phut ra den 7 thanh so 1
setb p2.5 ; Den 5 tat
lcall hien_thi
clr p2.1 ; Den 1 sang
ljmp end_hien_thi
led2:
cjne r0,#02h,led3 ; r0=2 thi,
mov r0,#28h
cjne @r0,#01h,n02
mov b,#01h
n02:
mov a,r2 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 2
setb p2.1 ; Den 1 tat
lcall hien_thi
clr p2.2 ; Den 2 sang
ljmp end_hien_thi
led3:
cjne r0,#03h,led4 ; r0=3 thi,
mov r0,#28h
cjne @r0,#02h,n03
mov b,#01h
n03:
mov a,r3 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 3
setb p2.1 ; Den 2 tat
lcall hien_thi
clr p2.3 ; Den 3 sang
ljmp end_hien_thi
led4:
cjne r0,#04h,led3 ; r0=4 thi,
mov r0,#28h
cjne @r0,#02h,n04
mov b,#01h
n04:
mov a,r4 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 4
setb p2.3 ; Den 3 tat
lcall hien_thi
clr p2.4 ; Den 4 sang
ljmp end_hien_thi
; Mach kiem tra va tat den so 4;
check: cjne r4,#00h,sang ; Neu gia tri hang chuc gio = 0
setb p2.4 ; Tat den so 4
ljmp end_hien_thi
sang: lcall hien_thi ; Neu =1 hoac 2 thi
clr p2.4 ; Den 4 sang
ljmp end_hien_thi
led5:
mov r0,#28h
cjne r0,#03h,n05 ; r0=5 thi,
mov b,#01h
n05:
mov a,r5 ; Chuyen gia tri hang truc pht ra den led 7 thanh so 5
setb p2.4 ; Den 4 tat
lcall hien_thi
clr p2.5 ; Den 5 sang
end_hien_thi:
mov r0,08h ; Tra lai cac gia tri r0->r5 truoc khi goi ngat
mov r1,09h
mov r2,0ah
mov r3,0bh
mov r4,0ch
mov r5,0dh
mov a,0eh ; Tra lai cac gia tri thanh chua a va thanh ghi b
mov b,0fh
reti ; Ket thuc chuong trinh ngat quet hien thi
hien_thi: ; Chuong trinh hien thi cho mot LED
lcall chuyen_ma ; Goi chuong trinh chuyen ma BCD - 7 THANH
mov r0,b ; Cat t ghi a
mov b,a
mov a,r0
cjne a,#01h,khong_nhay ; So sanh kiem tra co phai hien thi trung den nhay
mov a,r7
anl a,#00000100b
cjne a,#00000100b, nhay
khonng_nhay:
mov p0,b
sjmp end_hien_thi
nhay:
mov p0,#ffh ; Den achung dffh, den kchung 00h
ret
; **************Chuong trinh nhan phim **************
get_ket:
mov th1,#f8h ; Khoi tao lai thanh ghi dinh thoi 1
mov tl1,#2fh
kt_nguon:
jb p1.0,binh_thuong
mov p0,#ffh
mov pcon,#01h ; Che do nguon giam
binh_thuong:
mov pcon,#00h
push 00h ; Cat gia tri trong thi ghi r0,a vao stack
mov r0,a
push 00h
jnb p3.2,lua_chon ; Bit =0, nhay
mov 26h,#00h ; Thanh ghi dem cho nut"lua_chon"
ljmp phim2
lua_chon:
mov r0,#26h
inc @r0
cjne @r0,#10h,end_get_key
mov r0,28h ; Thanh ghi chi so den nhay
inc @r0 ; Tang chi so den nhat -> Nhay sang den tiep theo
theo
cjne @0,#04h,end_get_key
mov @r0,#00h
ljmp end_get_key
phim2:
jnb p3.3,chinh_tang ; Bit =0, nhay
mov 27h,#00h ; Thanh ghi dem cho nut "chinh_tang"
ljmp end_get_key
chinh_tang:
mov r0,#27h ; CHuyen dia chi gian tiep vao r0; !!! Dang kiem tra
inc @r0 ; Tang gia tri trong dia chi do len
cjne @r0,10h,end_get_key ; Gia tri nay chua =10
inc 28h ; Tang gia tri thanh ghi chi so den nhay
djnz 28h,ld1 ; Giam, chua =0, nhay ve d1
ljmp end_get_key ; =0 nhay ve ket thuc
ld1:
djnz 28h,ld3 ; Tang den LED 1 - Hang don vi phut
mov a,20h ; Chuyen gia tri thanh ghi phut vao a
add a,#01h ; Cong them 1
cjne a,#3ch,m11 ; Chua = , quay lai
mov a,#00h ; =, dat =0
m11
mov 20h,a
mov 28h,#01h;
ljmp end_get_key
ld3
djnz 28h,ld5 ; Tang den LED 3 - Hang don vi gio
mov a,21h
add a,#01h
cjne a,#18h,m31 ; Chua =, quay lai
mov a,#00h ; =, dat =0
m31:
mov 21h,a
mov 28h,#02h
ljmp end_get_key
ld5:
mov a,22h ; Tang den LED 5 - Chua ngay
add a#01h
cjne a,#09h,m51
mov a,#02h ; =, dat =2
m51
mov 21h,a
mov 28h,#03h
ljmp end_get_key
end_get_key
pop 00h ; Lay lai cac gia tri truoc do cua r0 va a
mov a,r0
pop 00h
reti
;---- * CHUONG TRINH CON DEM THOI GIAN * -----
c_time: ; Duoc goi 20 lan moi giay
mov th0,#3ch ; Dat byte cao bo dinh thoi 0 ,-50000
mov tl0,#àh ; Dat byte thap bo dinh thoi 0
push 00h ; Cat gia tri thanh ghi r0
inc r7 ; Tang 1/20 giay
cjne r7,#0ah,end_time ; =10
mov r7,#00h ; Quay ve 0
cpl p2.7 ; Tao 2 cham sang nhay tren mat dong ho
inc r6 ; Tang 1/2 giay
cjne r6,#78h,end_time ; =120
mov r6,#00h ; Quay ve 00
mov r0,#20h ; Dia chi thanh ghi chua phut
inc @r0 ; Tang 1 phut
cjne @r0,#3ch,end_time ; =60,
mov @r0,#00h ; Quay ve 00
mov r0,21h ; Dia chi thanh ghi chua gio
inc @r0 ; Tang 1 gio
mov r6,#01h ; Bu 1h 0.5s*24=12s
cjne @r0,#18h,end_time ; =24
mov @r0,00h ; Quay ve 00
mov r0,#22h ; Dia chi thanh ghi chua ngay
inc @r0 ; Tang 1 ngay
mov r6,#11h ; Bu 1 ngay 8,5s
cjne @r0,#9h, end_time ; Den ngay thu 9
mov r6,#05h ; Bu 1 tuan 2,5s
mov @r0,#02h ; Quay ve thu 2
; Neu can thi dem them ngay, thang, nam
end_time:
pop 00h ; Lay ra
reti
; CHUONG TRINH CHUYEN DOI MA BCD - LED 7 THANH
chuyen_ma:
cjne a,#00h,so1 ; Khong bang nhay sang so 1
mov a,#c0h
sjmp end_cm
so1:
cjne a,#01h,so2 ; Khong bang nhay sang so 2
mov a,#f9h
sjmp end_cm
so2:
cjne a,#02h,so3 ; Khong bang nhay sang so 3
mov a,#a4h
sjmp end_cm
so3:
cjne a,#03h,so4 ; Khong bang nhay sang so 4
mov a,#b0h
sjmp end_cm
so4:
cjne a,#04h,so5 ; Khong bang nhay sang so 5
mov a,#99h
sjmp end_cm
so5:
cjne a,#05h,so6 ; Khong bang nhay sang so 6
mov a,#92h
sjmp end_cm
so6:
cjne a,#06h,so7 ; Khong bang nhay sang so 7
mov a,#82h
sjmp end_cm
so7:
cjne a,#07h,so8 ; Khong bang nhay sang so 8
mov a,#f8h
sjmp end_cm
so8:
cjne a,#08h,so9 ; Khong bang nhay sang so 9
mov a,#80h
sjmp end_cm
so9:
mov a,#90h
end_cm:
ret ; Quay tro lai chuong trinh
END ; Ket thuc hoan toan chuong trinh
Comment