cac anh tim loi chuong trinh giup em voi :tai sai cai counter no ko chiu dem len ji ca toan hien so 0 khong a
ORG 0000H ;chan p3.4 la chan nhan xung ngo vao
;DINH NGHIA: ;phan dinh nghia cac bien trong chuong trinh
DON_VI EQU 120
CHUC EQU 121
TRAM EQU 123
NGAN EQU 124
SO_DEM EQU 125
;----------------------------
LJMP MAIN
ORG 001BH
LJMP NGAT_TIMER1 ;su dung timer1 de tao ngat
ORG 0030H ;su dung timer0 de lam bo dem xung ngo vao
MAIN:
;sau mot khoang thoi gian nhat dinh thi tao
;ngat 1 lan ,moi ngat xay ra se lay noi dung
;cua bo dem COUNTER_0 de hien thi ra led 7 doan
MOV DPTR,#MALED
MOV TMOD,#00100110B
MOV TH1,#3CH
MOV TL1,#AFH
MOV TH0,#0
MOV IE,#88H ;cho phep ngat timer 1
SETB TR1
SETB TR0
SETB P3.4 ;xung vao tai chan p3.4
AGAIN:
CALL CHAY_LED
sJMP AGAIN
CHAY_LED:
GIAI_MA: ;phan giai ma de tim ra so de hien thi
MOV A,SO_DEM
MOV B,#10
DIV AB
MOV DON_VI,B
MOV B,#10
DIV AB
MOV CHUC,B
MOV TRAM,A
HIEN_THI:
;-------------------------
MOV A,TRAM ;hien thi so hang tram
MOVC A,@A+DPTR
MOV P1,A
CLR P0.0
CALL DELAY
SETB P0.0
CALL DELAY
;------------------------
MOV A,CHUC ;hien thi so hang chuc
MOVC A,@A+DPTR
MOV P1,A
CLR P0.1
CALL DELAY
SETB P0.1
CALL DELAY
;-----------------------
MOV A,DON_VI ;hien thi so hang don vi
MOVC A,@A+DPTR
MOV P1,A
CLR P0.2
CALL DELAY
SETB P0.2
CALL DELAY
;-------------------------
RET
;---------------------------
NGAT_TIMER1: ;chuong trinh ngat cho timer 1
MOV A,TL0
MOV SO_DEM,A
CLR TR1
CLR TF1
RETI
;--------------------------
DELAY: ;chuong trinh delay
MOV R0 ,#200
here: DJNZ R0 ,here
RET
;----------------------------
;ma hien thi cho led 7 doan
MALED:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
ORG 0000H ;chan p3.4 la chan nhan xung ngo vao
;DINH NGHIA: ;phan dinh nghia cac bien trong chuong trinh
DON_VI EQU 120
CHUC EQU 121
TRAM EQU 123
NGAN EQU 124
SO_DEM EQU 125
;----------------------------
LJMP MAIN
ORG 001BH
LJMP NGAT_TIMER1 ;su dung timer1 de tao ngat
ORG 0030H ;su dung timer0 de lam bo dem xung ngo vao
MAIN:
;sau mot khoang thoi gian nhat dinh thi tao
;ngat 1 lan ,moi ngat xay ra se lay noi dung
;cua bo dem COUNTER_0 de hien thi ra led 7 doan
MOV DPTR,#MALED
MOV TMOD,#00100110B
MOV TH1,#3CH
MOV TL1,#AFH
MOV TH0,#0
MOV IE,#88H ;cho phep ngat timer 1
SETB TR1
SETB TR0
SETB P3.4 ;xung vao tai chan p3.4
AGAIN:
CALL CHAY_LED
sJMP AGAIN
CHAY_LED:
GIAI_MA: ;phan giai ma de tim ra so de hien thi
MOV A,SO_DEM
MOV B,#10
DIV AB
MOV DON_VI,B
MOV B,#10
DIV AB
MOV CHUC,B
MOV TRAM,A
HIEN_THI:
;-------------------------
MOV A,TRAM ;hien thi so hang tram
MOVC A,@A+DPTR
MOV P1,A
CLR P0.0
CALL DELAY
SETB P0.0
CALL DELAY
;------------------------
MOV A,CHUC ;hien thi so hang chuc
MOVC A,@A+DPTR
MOV P1,A
CLR P0.1
CALL DELAY
SETB P0.1
CALL DELAY
;-----------------------
MOV A,DON_VI ;hien thi so hang don vi
MOVC A,@A+DPTR
MOV P1,A
CLR P0.2
CALL DELAY
SETB P0.2
CALL DELAY
;-------------------------
RET
;---------------------------
NGAT_TIMER1: ;chuong trinh ngat cho timer 1
MOV A,TL0
MOV SO_DEM,A
CLR TR1
CLR TF1
RETI
;--------------------------
DELAY: ;chuong trinh delay
MOV R0 ,#200
here: DJNZ R0 ,here
RET
;----------------------------
;ma hien thi cho led 7 doan
MALED:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
Comment