KunNguyen
$Include(reg52.inc)
org 0000H ;Vector reset
ljmp Init ;nhay toi chuong trinh khoi tao
org 002BH ;Vector ngat TRANT/C2
ljmp INT2 ;ctcpvn tran T2
kqdo EQU 50H
tic1 equ 55h
tic2 equ 51h
D0 EQU 52H
D1 EQU 53H
D2 EQU 54H
XL EQU 64H
XH EQU 56H
Z0 EQU 57H
Z1 EQU 58H
Z2 EQU 59H
Z3 EQU 5AH
TANG EQU 64H
NUM EQU 65H
modereg equ 45h
TREN equ 42h
DUOI1 equ 48h
incdec equ 44h
RD_ADC BIT P3.5
WR_ADC BIT P3.6
INTR BIT P3.7
adc equ p1
kq equ 40h
org 100
Init:
clr EA ;cam ngat
mov SP,#2FH ;khoi tao ngan sap sep
mov T2CON,#00H ;T2 lam viec
mov TL2,#0EFH ;auto_reload
mov RCAP2L,TL2 ;chu ki ngat la 10ms
mov TH2,#0D8H
mov RCAP2H,TH2
mov ie,#20h
clr p0.2
clr p0.3
MOV TIC1,#0
MOV TIC2,#0
MOV TANG,#0
mov TREN,#30
mov DUOI1,#20
setb ET2 ;cho phep T2 ngat
setb TR2 ;cho phÐp T2 chay
mov modereg,#3
setb EA ;cho phep cac ngat
here:
sjmp here ;doi ngat
;==================================
int_ext0:
mov SP,#2FH ;khëi t¹o ng¨n xÕp
setb IT0 ;®Æt ng¾t ngoµi INT0
setb EX0 ;cho phÐp ng¾t ngoµiINT0
SETB EX0 ;CHO PHEP NGAT NGOAI
SETB IT0
jnb p0.4,MENU1 ; kiem tra phim MENU co dc an khong
jnb p0.5,TANG1 ; kiem tra phim TANG co dc an khong
jnb p0.6,GIAM1 ; kiem tra phim GIAM co dc an khong
jnb p0.7,OK1 ; kiem tra phim OK co dc an khong
ajmp ReIntEx
MENU1: ;phim menu
acall MENU
ajmp ReIntEx
TANG1:
acall TANGA
ajmp ReIntEx
GIAM1:
acall GIAM
ajmp ReIntEx
OK1:
acall OK
ReIntEx:
sjmp int_ext0
clr tcon.0
;===================================================================================
MENU:
djnz modereg,testmode
mov modereg,#3
SETB P3.0
CALL disInc
testmode:
mov a,modereg
cjne a,#2,Testmode2
CLR P3.0
mov IncDec,DUOI1 ;chuyen gia tri den do ban phim va0 thanh ghi indec(thanh ghi tang giam)
ajmp disInc ;goi den ct hienn thi
TestMode2:
cjne a,#1,CHUYENDEN2
CLR P3.0
mov IncDec,TREN ;chuyen gia tri den vang ban phim va0 thanh ghi indec(thanh ghi tang giam)
ajmp disInc ;goi den ct hien thi
CHUYENDEN2:
mov IncDec,#0
ajmp disInc
TANGA:
mov a,modereg ;Chuong trinh con phuc vu phim TANG
cjne a,#3,contInc
contInc:
inc IncDec ;ko cho phep tang den 100
mov a,IncDec
cjne a,#100,disInc
mov IncDec,#99 ;n
jmp disInc
GIAM: ; C
mov a,modereg
cjne a,#3,contDec
contDec:
Dec IncDec
mov a,IncDec
cjne a,#0H,disInc
mov IncDec,#99
jmp DisInc
OK:
mov a,modereg
cjne a,#3,luutren
jmp ENDOK
luutren:
cjne a,#2,luuduoi
mov DUOI1,IncDec
jmp DisInc
luuduoi:
cjne a,#1,endok1
mov TREN,IncDec
jmp DisInc
endok1:
ENDOK:
mov ip,#20h
CALL INT2
SJMP ENDOK
RET
int_ext01: CALL int_ext0
RET
disInc:
MOV R1,#30
LABER:
call delay10ms ;tre 100 ms tranh rung phim
DJNZ R1,LABER
thanhQ:
jnb p0.4,int_ext01 ; kiem tra phim MENU co dc an khong
jnb p0.5,int_ext01
jnb p0.6,int_ext01
jnb p0.7,int_ext01
clr p3.3
clr p3.4
mov a,IncDec ; chuyen gia tri tang vao a
acall BCD
acall DisSegm1
MOV R7,#20 ;tao tre 1s de nhin led 7thanhC
TIEP:
clr p3.4
acall Delay10ms
DJNZ R7,TIEP
clr p3.3
acall DisSegm2
MOV R7,#20
TIEP111:
acall Delay10ms
DJNZ R7,TIEP111
sjmp thanhQ
;===
DELAY10ms: MOV R2,#5; 10
DL3: MOV R3,#250; 1
DL2: NOP ; 1
NOP ; 1
DJNZ R3,DL2 ; 2
DJNZ R2,DL3 ; 2
RET
;==============================
INT2:
CLR TR2
jnb p0.4,int_ext01
CALL DODAC
call TINHTOAN5
call kiemtranguongduoi
call kiemtranguongtren
CALL HIENTHI
SJMP INT2
RETI
;-============================
;CHUOG TRINH DO NHIET DO TU ADC
;==========================
DODAC:;mov p1,#0ffh
CLR WR_ADC ; YEU CAU CHUYEN DOI
SETB WR_ADC
WAIT:
JB INTR,WAIT; DOI CHO DEN KHI CHUYEN DOI XONG---INTR = 0
CLR RD_ADC ; YEU CAU DUA DU LIEU TU THANH GHI RA NGOAI CUA ADC 0804
MOV kq,ADC; DOC GIU LIEU TU ADC VAO VI DIEU KHIEN
SETB RD_ADC
;===============================
TINHTOAN5:
mov a,kq
bcd:
clr c
mov b,#10
div ab
mov z2,b
mov b,#10
div ab
mov z1,b
mov z0,a
;==============================
kiemtranguongduoi:
MOV A,kq
CLR C
SUBB A,DUOI1
JC BATDEN
JB p0.2,KIEMTRALAN2 ;KTRA XEM TRUOC DO DEN SANG KO
JMP THOATLUON ;KHONG PHAI THI THOAT LUON
BATDEN:
SETB p0.2
JMP THOATLUON
KIEMTRALAN2:
CLR C
MOV A,kq
SUBB A,DUOI1
CJNE A,#0,THOATLUON
CLR p0.2
THOATLUON:
RET
kiemtranguongtren:
MOV A,Kq
CLR C
SUBB A,tren
JC KT1 ; TRU DI DAI THAP NEU CO =1 KT TIEP XEM TB CO NAM DUOI DAI DO
SJMP KT2 ;KO FAI KT XEM TB NAM TREN DAI DO
KT1:
MOV A,Kq
CLR C
SUBB A,TREN
JC BATLOSUOI ; TB NAM DUOI DAI DO BAT LO SUOI
SJMP TATHET ; KO FAI THI TB NAM TRONG DAI DO
KT2:
MOV A,Kq
CLR C
SUBB A,TREN
JNC BATQUAT ; CO C =0 CHUNG TO TB NAM TREN DAI DO BAT QUAT
SJMP TATHET ;K0 FAI CHUNG TO TB NAM TRONG DAI DO
BATLOSUOI:
;SETB P3.4
CLR P0.3
SJMP THOAT1
BATQUAT:
SETB P0.3
;CLR P3.4
SJMP THOAT1
TATHET:
mov a,Kq
CLR C
SUBB A,tren
CJNE A,#0,THOAT1 ;
CLR P0.3
;CLR P3.4
THOAT1:
RET
;----------------------
HIENTHI:
INC TIC1
MOV A,TIC1
CJNE A,#1,LABER1
disSegm1:
mov a,Z2 ;che bit cao
clr p3.4 ;cho phep D0 sang
acalldisplay ; goi den chuong trinh hien thi
setb P3.1
LABER1:
CJNE A,#2,LABER2
disSegm2:
mov a,Z1
clr p3.1
acalldisplay
setb P3.3
;----------------------
LABER2:
CJNE A,#3,LABER3
MOV TIC1,#0
disSegm3:
mov a,Z0
clr P3.3
acalldisplay
setb P3.4
;-------------------------
LABER3:
RET
display:
mov dptr,#seg
movc a,@a+dptr
mov p2,a ; dua du lieu ra p2 voi chot p0.0
seg:
db 40H,79H,24H,30h,19h,12h,02h,78h,00h,00010000b
end
Bạn đang đọc truyện trên: Truyen247.Pro