Nguyên văn bởi dedodi
Xem bài viết
đây là sơ đồ mạch của khối thu-phát hồng ngoại
Chú thích code:
Port segment cua LED 7 doan (A,B,C,D,E,F,G,P) nối với P0 sao cho A,B,C,...F,point ứng với P0.0...P0.7
Cac pin 7SEG1 (hàng chục) va 7SEG2 (hàng đơn vị) dùng để kích trans A1015 cấp VCC cho 2 con LED 7 đoạn
; Chuc nang cua chuong trinh: Dem so lan co vat the chan ngan LED thu va LED phat, roi hien thi tren LED 7 doan
; Ket noi day:
; LED hong ngoai:
; * Control cua module LED hong ngoai ----> P1.5 cua 8051
; * OUT cua module LED hong ngoai ----> P3.2 cua 8051
; LED 7 doan :
; * Port segment cua LED 7 doan (A,B,C,D,E,F,G,P) ----> Port 0 cua 8051
; * Cac pin 7SEG1 (hàng chục) va 7SEG2 (hàng đơn vị) cua LED 7 doan ----> P1.7 va P1.6 cua 8051
; Luu y:
; * Gat 8 cong tac (mau do hong) qua ON de mo nguon cac LED 7 doan
; * Co the dieu chinh bien tro tinh chinh (mau xanh duong) cua module LED hong ngoai de thay doi khoang thoi gian gian cach
; giua 2 lan dem so lan co vat the chan ngan LED thu va LED phat
; * Phai de module LED hong ngoai lam viec trong moi truong hoan toan toi de co nguon phat hong ngoai nao khac ngoai LED phat
; de qua trinh so lan co vat the chan ngan LED thu va LED phat dien ra binh thuong
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0_ISR
ORG 0003H
LJMP E0_ISR
ORG 001BH
LJMP T1_ISR
ORG 0030H
MAIN: MOV TMOD, #12H
MOV TH0,#(-12) ; Clock=38Khz
SETB TR0
SETB EA
SETB ET0
SETB EX0
SETB IT0
CLR P1.4
MOV R7,#0
MOV R5,#50
LOOP: MOV A,R7
MOV B,#10
DIV AB
MOV DPTR,#LUT
MOVC A,@A+DPTR
MOV P0,A
CLR P1.7
SETB P1.6
ACALL DELAY
MOV A,B
MOV DPTR,#LUT
MOVC A,@A+DPTR
MOV P0,A
CLR P1.6
SETB P1.7
ACALL DELAY
SJMP LOOP
RET
T0_ISR: CPL P1.5
RETI
E0_ISR: INC R7
CJNE R7,#20,TIEP
ACALL TIEPTUC
TIEP: CJNE R7,#40,TIEP1
ACALL TIEPTUC
TIEP1: CJNE R7,#60,TIEP2
ACALL TIEPTUC
TIEP2: CJNE R7,#80,TIEP3
ACALL TIEPTUC
TIEP3: CJNE R7,#100,EXIT
MOV R7,#0
ACALL TIEPTUC
EXIT: RETI
DELAY: MOV R6,#200
DJNZ R6,$
RET
TIEPTUC: SETB P1.4
SETB ET1
MOV TH1,#HIGH(-50000)
MOV TL1,#LOW(-50000)
SETB TR1
RET
T1_ISR: DJNZ R5,THOAT
CLR P1.4
CLR ET1
CLR TR1
MOV R5,#50
THOAT: RETI
LUT: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
; Ket noi day:
; LED hong ngoai:
; * Control cua module LED hong ngoai ----> P1.5 cua 8051
; * OUT cua module LED hong ngoai ----> P3.2 cua 8051
; LED 7 doan :
; * Port segment cua LED 7 doan (A,B,C,D,E,F,G,P) ----> Port 0 cua 8051
; * Cac pin 7SEG1 (hàng chục) va 7SEG2 (hàng đơn vị) cua LED 7 doan ----> P1.7 va P1.6 cua 8051
; Luu y:
; * Gat 8 cong tac (mau do hong) qua ON de mo nguon cac LED 7 doan
; * Co the dieu chinh bien tro tinh chinh (mau xanh duong) cua module LED hong ngoai de thay doi khoang thoi gian gian cach
; giua 2 lan dem so lan co vat the chan ngan LED thu va LED phat
; * Phai de module LED hong ngoai lam viec trong moi truong hoan toan toi de co nguon phat hong ngoai nao khac ngoai LED phat
; de qua trinh so lan co vat the chan ngan LED thu va LED phat dien ra binh thuong
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0_ISR
ORG 0003H
LJMP E0_ISR
ORG 001BH
LJMP T1_ISR
ORG 0030H
MAIN: MOV TMOD, #12H
MOV TH0,#(-12) ; Clock=38Khz
SETB TR0
SETB EA
SETB ET0
SETB EX0
SETB IT0
CLR P1.4
MOV R7,#0
MOV R5,#50
LOOP: MOV A,R7
MOV B,#10
DIV AB
MOV DPTR,#LUT
MOVC A,@A+DPTR
MOV P0,A
CLR P1.7
SETB P1.6
ACALL DELAY
MOV A,B
MOV DPTR,#LUT
MOVC A,@A+DPTR
MOV P0,A
CLR P1.6
SETB P1.7
ACALL DELAY
SJMP LOOP
RET
T0_ISR: CPL P1.5
RETI
E0_ISR: INC R7
CJNE R7,#20,TIEP
ACALL TIEPTUC
TIEP: CJNE R7,#40,TIEP1
ACALL TIEPTUC
TIEP1: CJNE R7,#60,TIEP2
ACALL TIEPTUC
TIEP2: CJNE R7,#80,TIEP3
ACALL TIEPTUC
TIEP3: CJNE R7,#100,EXIT
MOV R7,#0
ACALL TIEPTUC
EXIT: RETI
DELAY: MOV R6,#200
DJNZ R6,$
RET
TIEPTUC: SETB P1.4
SETB ET1
MOV TH1,#HIGH(-50000)
MOV TL1,#LOW(-50000)
SETB TR1
RET
T1_ISR: DJNZ R5,THOAT
CLR P1.4
CLR ET1
CLR TR1
MOV R5,#50
THOAT: RETI
LUT: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
Comment