Share code cho các bác. Không biết share link có bị xem là spam không nhỉ? Mới bị xóa nick do hiểu lầm. Hình dung lương lớn không up được và cũng hơi lười viết https://www.facebook.com/%C4%90I%E1%...meline/?ref=hl
Trang file của mình. Tất cả code và hình mình đã úp lên trang face.
Lai không up được file hex và rar rồi. copy dán vậy.
S1 EQU 80H
S2 EQU 81H
S3 EQU 'C'
S4 EQU 'D'
S5 EQU 'E'
S6 EQU 'F'
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++
;PHAN DINH NGHIA CHO UNG DUNG DIEU KHIEN HE THONG
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
;DINH NGHIA DE TRUY XUAT NVMROM
NVMCON EQU 0CEH ;REGISTER CONTROL DATA ROM
NVMDATA EQU 0CFH ;CHUA DATA ROM
NVMADDRL EQU 0C6H ;CHUA DIA CHI BYTE DATA ROM
ADDP0 EQU 00H ;DIA CHI PAGE 0
ADDP1 EQU 10H ;
ADDP2 EQU 20H ;
ADDP3 EQU 30H ;
ADDP4 EQU 40H ;
ADDP5 EQU 50H ;
ADDP6 EQU 60H ;
ADDP7 EQU 70H ;DIA CHI PAGE7
EERBIT EQU 80H ;BIT DIEU KHIEN XOA PAGE
EWRBIT EQU 40H ;BIT DIEU KHIEN GHI DATA
;------------------------------------------------
;DINH NGHIA PHUC VU UNG DUNG
;------------DINH NGHIA PHUNG CUNG ---------
SPEAKER BIT P3.7
;TRAIN_CODE BIT P1.1 ;DU PHONG
GEAR BIT P1.7 ;CHAN 18
IRINPUT BIT P3.2 ;NGAT NGOAI 1, CHAN VAO HONG NGOAI
SWING_OUT BIT P3.0 ;CHAN 2
COOL_OUT BIT P3.1 ;CHAN 3
SO1 BIT P3.3 ;CHAN 7
SO2 BIT P3.4 ;CHAN 8
SO3 BIT P3.5 ;CHAN 9
LA BIT P1.0
LB BIT P1.1
LC BIT P1.2
LD BIT P1.3
L_E BIT P1.4
LF BIT P1.5
LG BIT P1.6
LH BIT P1.7 ;GEAR
L1 BIT P2.0
L2 BIT P2.1
;----------DINH NGHIA CAC CO -------------
MODE_ON1 BIT 7FH ;2FH
ON_FLAG BIT 7EH
OFF_FLAG BIT 7DH
MODE_FLAG BIT 7CH
SYNC BIT 7BH
HEG_FLAG BIT 7AH
SOSAFLAG BIT 79H
LOCK BIT 78H
S_LAG EQU 2EH
KE_M BIT 77H ;2EH
dg_flag BIT 76H
GEAR_M BIT 75H
swing_M bit 74h
cool_M bit 73h
mode_M bit 72h
time_M BIT 71H
DOT BIT 70H
co_dong_bo bit 20h.0
;----------DINH NGHIA CAC HANG SO---
IP0H EQU 0B7H ;THANH GHI UU TIEN NGAT0 CAO NHAT
IP0 EQU 0B8H ;THANH GHI UU TIEN NGAT0 CAO HON
IP1H EQU 0F7H ;THANH GHI UU TIEN NGAT1 CAO NHAT
IP1 EQU 0F8H ;THANH GHI UU TIEN NGAT1 CAO HON
SB0 EQU 01H
SB1 EQU 02H
SB2 EQU 04H
SB3 EQU 08H
SB4 EQU 10H
SB5 EQU 20H
SB6 EQU 40H
SB7 EQU 80H
soso_mk equ 5 ;so byte luu eprom
TG_TIME EQU R6
;HOWBYTE EQU 4 ;GIA TRI TOI UU IT BI GIAI MA NHAM PHIM 9BYTE
;----------DINH NGHIA CAC BIEN--KO DUOC TRUNG CAC VUNG RAM BIEN KHAC TRONG CHUONG TRINH
TERAM EQU 30H ;TU 30H - 3FH, 2 BYTE RAM
TEROM EQU 40H ;TU 40H - 4FH, 2 BYTE RAM
SOBIT EQU 50H
TEMP EQU 51H
SOBYTE EQU 52H
COUNT_1S EQU 53H
COUNT_15P EQU 54H
COUNT_P EQU 55H
COUNT_M EQU 56H
COUNT_MS EQU 57H
COUNT_M1 EQU 58H
COUNT_M2 EQU 59H
bien_1 equ 5AH
bien_2 equ 5BH
bien_3 equ 5CH
bien_DV equ 5DH
bien_HC equ 5EH
dia_chi_song_mang1 equ 60h ;4 byte nay phai dat dia chi lien tuc nhau
dia_chi_song_mang2 equ 61h ;
time_delay1 equ 62h ;
time_delay2 equ 63h ;
data_song_mang1 equ 5Fh
data_song_mang2 equ 68h
dem_sm_1 equ 69h
dem_sm_2 equ 65h
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++
;DINH NGHIA XONG CHO PHAN DK HE THONG
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
;BAT DAU
;================================================= ====
ORG 00H
SJMP START
ORG 0003H ;DIA CHI NGAT NGOAI 0
; LJMP READ_IR
ORG 000BH ;VECTO NGAT TIMER0 cho hien thi led
; ORG 0013H ;DIA CHI NGAT NGOAI 1
; LJMP
ORG 001BH ;VECTO NGAT TIMER1
; ORG 30H ;BAT DAU CHUONG TRINH, CAU HINH KERNEL
START: ;--------------CONFIG INITIAL
clr co_dong_bo
clr SPEAKER
setb gear
main:
mov time_delay1,#0 ;duoc thay the cho dien tro RC cua PT2272
mov time_delay2,#1 ;gia tri dau tien phai la 1
jnb gear,do_tim_cai_dia_chi_rc
ACALL LOAD_ADD
sjmp check_lenh_dk
;==============================================
do_tim_cai_dia_chi_rc:
inc time_delay1 ;mo phong dieu chinh bang soft = tuong duong thay doi RC tren chan 15-16 pt2272
mov r6,time_delay1
cjne r6,#0,tim_bit_sync
mov r6,time_delay2
cjne r6,#6,tangtime2 ;gioi han de tim nhanh hon,bo gi tri lon ko can thiet
mov time_delay2,#1 ;gia tri dau tien phai la 1
sjmp tim_bit_sync
tangtime2:
inc time_delay2
;----------------------do dong bo dau
tim_bit_sync:
acall do_bit_dong_bo
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;do tim tho bit sync ban dau.tim duoc tiep tuc hieu chinh tinh de tim ra RC toi uu nhat.
cpl so3 ;sang lien tuc bao hieu da do duoc dia chi va rc
;----------------------het dong bo dau
acall lay_data_frame ;test nhan du lieu de hieu chinh RC neu chua dung RC
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;neu ko nhan dien duoc cac bit du lieu thi thuc hien dieu chinh RC tiep cho den khi ok
;----------------------dong bo cuoi
acall do_bit_dong_bo ;test lai bit dong bo cuoi frame
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;neu ko nhan dien duoc bit sync thi thuc hien dieu chinh RC cho den khi nao ok
;---------------------het dong bo cuoi
;===============================================
check_lenh_dk:
setb gear ;len 1 de quet phim
jb gear,check_lenh_dk1 ;bam nut luu dia chi song mang va rc
mov dia_chi_song_mang1,dem_sm_1 ;luu 8 bit dia chi1 de khoi bi ghi de boi 4 bit data con lai
mov dia_chi_song_mang2,dem_sm_2 ;luu 8 bit dia chi2 de khoi bi ghi de boi 4 bit data con lai
acall SAVE_ADD
cpl so3 ;bao hieu da luu
jnb gear,$ ;chong lap
check_lenh_dk1:
mov data_song_mang1,#0 ;xoa con tro thu data trong song mang
mov data_song_mang2,#0 ;
;----------------------
;----------------------dong bo start
acall do_bit_dong_bo
jnb co_dong_bo,check_lenh_dk ;neu ko nhan dien duoc bit sync thi bat dau thuc hien nhan 1 4word khac
;----------------------het dong bo start
acall lay_data_frame ;loc lay noi dung trong chuoi 4word
jnb co_dong_bo,check_lenh_dk ;bi loi; neu ko nhan dien duoc bit thi bat dau thuc hien nhan 1 4word khac
;----------------------dong bo end
acall do_bit_dong_bo
jnb co_dong_bo,check_lenh_dk ;neu ko nhan dien duoc bit sync thi bat dau thuc hien nhan 1 4word khac
;----------------------dong bo end
;co the chen vao o day nhieu frame de tao mot goi data nhieu byte hon ma ko bi loss.
;---------------------------
cpl so3 ;nhap nhay lien tuc neu nhan lien tuc phim de bao hieu dia chi va rc chinh xac
mov a,dem_sm_1 ;
cjne a,dia_chi_song_mang1,check_lenh_dk ;so sanh dia chi song mang
mov a,dem_sm_2 ;
cjne a,dia_chi_song_mang2,check_lenh_dk ;so sanh dia chi song mang
mov a,data_song_mang1 ;lay data
swap a
; xrl a,#0ffh ;not trang thai a
orl a,#0f0h ;che 1/2 byte cao
mov p1,a ;xuat 4bit data ra 1/2 byte thap cua p1
cpl so2 ;bao hieu da nhan duoc mot frame hop le hoan chinh
acall delay_n
anl p1,#00h
; anl p1,#0ffh
sjmp check_lenh_dk
;================================================
;-------------------
do_bit_dong_bo:
clr co_dong_bo
acall lay_mau_1bit
cjne a,#01h,sai_tro_ve ;neu khac thi sai nhan dang, quay ve tang thoi delay lay mau time_delay
mov b,#23 ;dieu chinh trong khoang tu 1-24;thoi gian check 3 muc thap bit sync
check_muc_tiep2:
mov bien_1,time_delay1
check_22:
jb IRINPUT,sai_tro_ve
djnz bien_1,check_22 ;kiem tra du 8 lan
djnz b,check_muc_tiep2
setb co_dong_bo
sai_tro_ve:
ret
;------------------
lay_data_frame: ;bat dau lay dia chi song mang
mov b,#12
lay_du_4_word:
acall lay_mau_1bit ;lay mau de tim 1 bit
acall check_4word ;kiem tra 1 bit co hop le, dong thoi doi doi bit de don gian hon trong viec xu li
jnb co_dong_bo,sai_lai_tu_dau ;neu ko nhan dien duoc bit thi bat dau thuc hien nhan 1 4word khac
mov r7,b
cjne r7,#5,lay_tiep ;kiem tra neu du 8 bit dia chi thi luu
mov dem_sm_1,data_song_mang1 ;luu 8 bit dia chi1 de khoi bi ghi de boi 4 bit data con lai
mov dem_sm_2,data_song_mang2 ;luu 8 bit dia chi2 de khoi bi ghi de boi 4 bit data con lai
mov data_song_mang1,#0
; mov data_song_mang2,#0
lay_tiep:
djnz b,lay_du_4_word
sai_lai_tu_dau:
ret
;-------------------
lay_mau_1bit:
clr a
mov bien_1,#8
jnb IRINPUT,$ ;scan ngo vao
lay_mau_xung:
acall delay_laymau ;tre voi gia tri thuoc tg time_delay
mov c,IRINPUT ;lay mau
rrc a ;dua vao a
djnz bien_1,lay_mau_xung ;kiem tra du 8 lan
jb IRINPUT,$ ;wait de dong bo lai cho lay mau bit tiep theo; lenh nay rat quang trong.
ret
;-------------------
check_4word:
cjne a,#11h,bit_1 ;neu la bit 1
mov a,data_song_mang1
clr c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
clr c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit 0
bit_1: cjne a,#77h,bit_f
mov a,data_song_mang1
setb c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
setb c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit 1
bit_f: cjne a,#71h,khong_phai_bit
mov a,data_song_mang1
clr c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
setb c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit float
du_bit:
setb co_dong_bo
ret
khong_phai_bit:
clr co_dong_bo
ret
;---------------------------------------------
;---------------------delay rc de lay mau
delay_laymau:
mov 2bh,time_delay2 ;2 neu thach anh 12, 4 neu thach anh 24 ;he so tang len neu RC qua lon
dl_1: mov 2ah,time_delay1 ;doi voi RC=4.7Momh thi trong khoang tu 140-150 la toi uu
djnz 2ah,$
djnz 2bh,dl_1
ret
;================================================= =
SAVE_ADD:
MOV NVMADDRL,#ADDP0 ;00H
CALL XOAROM ;TRUOC KHI GHI PHAI XOA TRUOC NVMROM
MOV SOBYTE,#soso_mk ;HOWBYTE
MOV R0,#dia_chi_song_mang1 ;TERAM ;DIA CHI DAU VUNG RAM
MOV NVMADDRL,#ADDP0 ;DIA CHI NVMROM, DUNG LENH NAY TRUOC KHI GOI TRINH CON N
CALL GHIROM
RET
;---------------------------------------------------
LOAD_ADD:
MOV SOBYTE,#soso_mk ;HOWBYTE
MOV R1,#dia_chi_song_mang1 ;TEROM ;DIA CHI DAU VUNG RAM CHUA NOI DUNG DOC DUOC TU NVMROM
MOV DPL,#ADDP0 ;DIA CHI NVMROM,;TRUOC KHI GOI DA CO LENH NAY
MOV DPH,#0FCH ;
CALL DOCROM
RET
;-------------------====================================
;------------------------
XOAROM: ;XOA PAGE 0
; MOV NVMADDRL,#ADDP0 ;TRUOC KHI GOI DA CO LENH NAY
MOV NVMCON,#EERBIT ;SETB EER BIT 0CEH
RET
;-----------
GHIROM:
GHITIEP:
MOV NVMDATA,@R0 ;GHI DATA
MOV NVMCON,#EWRBIT ;SETB EWR BIT DE CHOT DATA
INC NVMADDRL ;tang dia cho ROM
INC R0 ;Tang vi tri data muon lay de ghi vao ROM
DJNZ SOBYTE,GHITIEP
ACALL BUZZER ;KEU DE CHI THI OK
RET
;-----------
DOCROM:
DOCTIEP:
CLR A
MOVC A,@A+DPTR
MOV @R1,A
INC DPTR
INC R1
DJNZ SOBYTE,DOCTIEP
RET
;================================================= ==========
delay_n:
mov r4,#255
DELAY:
dd2: mov r5,#255
djnz r5,$
djnz r4,dd2
RET
;=================
BUZZER:
SETB SPEAKER
MOV R4,#100
CALL DELAY
CLR SPEAKER
RET
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++
end
Trang file của mình. Tất cả code và hình mình đã úp lên trang face.
Lai không up được file hex và rar rồi. copy dán vậy.
S1 EQU 80H
S2 EQU 81H
S3 EQU 'C'
S4 EQU 'D'
S5 EQU 'E'
S6 EQU 'F'
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++
;PHAN DINH NGHIA CHO UNG DUNG DIEU KHIEN HE THONG
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
;DINH NGHIA DE TRUY XUAT NVMROM
NVMCON EQU 0CEH ;REGISTER CONTROL DATA ROM
NVMDATA EQU 0CFH ;CHUA DATA ROM
NVMADDRL EQU 0C6H ;CHUA DIA CHI BYTE DATA ROM
ADDP0 EQU 00H ;DIA CHI PAGE 0
ADDP1 EQU 10H ;
ADDP2 EQU 20H ;
ADDP3 EQU 30H ;
ADDP4 EQU 40H ;
ADDP5 EQU 50H ;
ADDP6 EQU 60H ;
ADDP7 EQU 70H ;DIA CHI PAGE7
EERBIT EQU 80H ;BIT DIEU KHIEN XOA PAGE
EWRBIT EQU 40H ;BIT DIEU KHIEN GHI DATA
;------------------------------------------------
;DINH NGHIA PHUC VU UNG DUNG
;------------DINH NGHIA PHUNG CUNG ---------
SPEAKER BIT P3.7
;TRAIN_CODE BIT P1.1 ;DU PHONG
GEAR BIT P1.7 ;CHAN 18
IRINPUT BIT P3.2 ;NGAT NGOAI 1, CHAN VAO HONG NGOAI
SWING_OUT BIT P3.0 ;CHAN 2
COOL_OUT BIT P3.1 ;CHAN 3
SO1 BIT P3.3 ;CHAN 7
SO2 BIT P3.4 ;CHAN 8
SO3 BIT P3.5 ;CHAN 9
LA BIT P1.0
LB BIT P1.1
LC BIT P1.2
LD BIT P1.3
L_E BIT P1.4
LF BIT P1.5
LG BIT P1.6
LH BIT P1.7 ;GEAR
L1 BIT P2.0
L2 BIT P2.1
;----------DINH NGHIA CAC CO -------------
MODE_ON1 BIT 7FH ;2FH
ON_FLAG BIT 7EH
OFF_FLAG BIT 7DH
MODE_FLAG BIT 7CH
SYNC BIT 7BH
HEG_FLAG BIT 7AH
SOSAFLAG BIT 79H
LOCK BIT 78H
S_LAG EQU 2EH
KE_M BIT 77H ;2EH
dg_flag BIT 76H
GEAR_M BIT 75H
swing_M bit 74h
cool_M bit 73h
mode_M bit 72h
time_M BIT 71H
DOT BIT 70H
co_dong_bo bit 20h.0
;----------DINH NGHIA CAC HANG SO---
IP0H EQU 0B7H ;THANH GHI UU TIEN NGAT0 CAO NHAT
IP0 EQU 0B8H ;THANH GHI UU TIEN NGAT0 CAO HON
IP1H EQU 0F7H ;THANH GHI UU TIEN NGAT1 CAO NHAT
IP1 EQU 0F8H ;THANH GHI UU TIEN NGAT1 CAO HON
SB0 EQU 01H
SB1 EQU 02H
SB2 EQU 04H
SB3 EQU 08H
SB4 EQU 10H
SB5 EQU 20H
SB6 EQU 40H
SB7 EQU 80H
soso_mk equ 5 ;so byte luu eprom
TG_TIME EQU R6
;HOWBYTE EQU 4 ;GIA TRI TOI UU IT BI GIAI MA NHAM PHIM 9BYTE
;----------DINH NGHIA CAC BIEN--KO DUOC TRUNG CAC VUNG RAM BIEN KHAC TRONG CHUONG TRINH
TERAM EQU 30H ;TU 30H - 3FH, 2 BYTE RAM
TEROM EQU 40H ;TU 40H - 4FH, 2 BYTE RAM
SOBIT EQU 50H
TEMP EQU 51H
SOBYTE EQU 52H
COUNT_1S EQU 53H
COUNT_15P EQU 54H
COUNT_P EQU 55H
COUNT_M EQU 56H
COUNT_MS EQU 57H
COUNT_M1 EQU 58H
COUNT_M2 EQU 59H
bien_1 equ 5AH
bien_2 equ 5BH
bien_3 equ 5CH
bien_DV equ 5DH
bien_HC equ 5EH
dia_chi_song_mang1 equ 60h ;4 byte nay phai dat dia chi lien tuc nhau
dia_chi_song_mang2 equ 61h ;
time_delay1 equ 62h ;
time_delay2 equ 63h ;
data_song_mang1 equ 5Fh
data_song_mang2 equ 68h
dem_sm_1 equ 69h
dem_sm_2 equ 65h
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++
;DINH NGHIA XONG CHO PHAN DK HE THONG
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
;BAT DAU
;================================================= ====
ORG 00H
SJMP START
ORG 0003H ;DIA CHI NGAT NGOAI 0
; LJMP READ_IR
ORG 000BH ;VECTO NGAT TIMER0 cho hien thi led
; ORG 0013H ;DIA CHI NGAT NGOAI 1
; LJMP
ORG 001BH ;VECTO NGAT TIMER1
; ORG 30H ;BAT DAU CHUONG TRINH, CAU HINH KERNEL
START: ;--------------CONFIG INITIAL
clr co_dong_bo
clr SPEAKER
setb gear
main:
mov time_delay1,#0 ;duoc thay the cho dien tro RC cua PT2272
mov time_delay2,#1 ;gia tri dau tien phai la 1
jnb gear,do_tim_cai_dia_chi_rc
ACALL LOAD_ADD
sjmp check_lenh_dk
;==============================================
do_tim_cai_dia_chi_rc:
inc time_delay1 ;mo phong dieu chinh bang soft = tuong duong thay doi RC tren chan 15-16 pt2272
mov r6,time_delay1
cjne r6,#0,tim_bit_sync
mov r6,time_delay2
cjne r6,#6,tangtime2 ;gioi han de tim nhanh hon,bo gi tri lon ko can thiet
mov time_delay2,#1 ;gia tri dau tien phai la 1
sjmp tim_bit_sync
tangtime2:
inc time_delay2
;----------------------do dong bo dau
tim_bit_sync:
acall do_bit_dong_bo
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;do tim tho bit sync ban dau.tim duoc tiep tuc hieu chinh tinh de tim ra RC toi uu nhat.
cpl so3 ;sang lien tuc bao hieu da do duoc dia chi va rc
;----------------------het dong bo dau
acall lay_data_frame ;test nhan du lieu de hieu chinh RC neu chua dung RC
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;neu ko nhan dien duoc cac bit du lieu thi thuc hien dieu chinh RC tiep cho den khi ok
;----------------------dong bo cuoi
acall do_bit_dong_bo ;test lai bit dong bo cuoi frame
jnb co_dong_bo,do_tim_cai_dia_chi_rc ;neu ko nhan dien duoc bit sync thi thuc hien dieu chinh RC cho den khi nao ok
;---------------------het dong bo cuoi
;===============================================
check_lenh_dk:
setb gear ;len 1 de quet phim
jb gear,check_lenh_dk1 ;bam nut luu dia chi song mang va rc
mov dia_chi_song_mang1,dem_sm_1 ;luu 8 bit dia chi1 de khoi bi ghi de boi 4 bit data con lai
mov dia_chi_song_mang2,dem_sm_2 ;luu 8 bit dia chi2 de khoi bi ghi de boi 4 bit data con lai
acall SAVE_ADD
cpl so3 ;bao hieu da luu
jnb gear,$ ;chong lap
check_lenh_dk1:
mov data_song_mang1,#0 ;xoa con tro thu data trong song mang
mov data_song_mang2,#0 ;
;----------------------
;----------------------dong bo start
acall do_bit_dong_bo
jnb co_dong_bo,check_lenh_dk ;neu ko nhan dien duoc bit sync thi bat dau thuc hien nhan 1 4word khac
;----------------------het dong bo start
acall lay_data_frame ;loc lay noi dung trong chuoi 4word
jnb co_dong_bo,check_lenh_dk ;bi loi; neu ko nhan dien duoc bit thi bat dau thuc hien nhan 1 4word khac
;----------------------dong bo end
acall do_bit_dong_bo
jnb co_dong_bo,check_lenh_dk ;neu ko nhan dien duoc bit sync thi bat dau thuc hien nhan 1 4word khac
;----------------------dong bo end
;co the chen vao o day nhieu frame de tao mot goi data nhieu byte hon ma ko bi loss.
;---------------------------
cpl so3 ;nhap nhay lien tuc neu nhan lien tuc phim de bao hieu dia chi va rc chinh xac
mov a,dem_sm_1 ;
cjne a,dia_chi_song_mang1,check_lenh_dk ;so sanh dia chi song mang
mov a,dem_sm_2 ;
cjne a,dia_chi_song_mang2,check_lenh_dk ;so sanh dia chi song mang
mov a,data_song_mang1 ;lay data
swap a
; xrl a,#0ffh ;not trang thai a
orl a,#0f0h ;che 1/2 byte cao
mov p1,a ;xuat 4bit data ra 1/2 byte thap cua p1
cpl so2 ;bao hieu da nhan duoc mot frame hop le hoan chinh
acall delay_n
anl p1,#00h
; anl p1,#0ffh
sjmp check_lenh_dk
;================================================
;-------------------
do_bit_dong_bo:
clr co_dong_bo
acall lay_mau_1bit
cjne a,#01h,sai_tro_ve ;neu khac thi sai nhan dang, quay ve tang thoi delay lay mau time_delay
mov b,#23 ;dieu chinh trong khoang tu 1-24;thoi gian check 3 muc thap bit sync
check_muc_tiep2:
mov bien_1,time_delay1
check_22:
jb IRINPUT,sai_tro_ve
djnz bien_1,check_22 ;kiem tra du 8 lan
djnz b,check_muc_tiep2
setb co_dong_bo
sai_tro_ve:
ret
;------------------
lay_data_frame: ;bat dau lay dia chi song mang
mov b,#12
lay_du_4_word:
acall lay_mau_1bit ;lay mau de tim 1 bit
acall check_4word ;kiem tra 1 bit co hop le, dong thoi doi doi bit de don gian hon trong viec xu li
jnb co_dong_bo,sai_lai_tu_dau ;neu ko nhan dien duoc bit thi bat dau thuc hien nhan 1 4word khac
mov r7,b
cjne r7,#5,lay_tiep ;kiem tra neu du 8 bit dia chi thi luu
mov dem_sm_1,data_song_mang1 ;luu 8 bit dia chi1 de khoi bi ghi de boi 4 bit data con lai
mov dem_sm_2,data_song_mang2 ;luu 8 bit dia chi2 de khoi bi ghi de boi 4 bit data con lai
mov data_song_mang1,#0
; mov data_song_mang2,#0
lay_tiep:
djnz b,lay_du_4_word
sai_lai_tu_dau:
ret
;-------------------
lay_mau_1bit:
clr a
mov bien_1,#8
jnb IRINPUT,$ ;scan ngo vao
lay_mau_xung:
acall delay_laymau ;tre voi gia tri thuoc tg time_delay
mov c,IRINPUT ;lay mau
rrc a ;dua vao a
djnz bien_1,lay_mau_xung ;kiem tra du 8 lan
jb IRINPUT,$ ;wait de dong bo lai cho lay mau bit tiep theo; lenh nay rat quang trong.
ret
;-------------------
check_4word:
cjne a,#11h,bit_1 ;neu la bit 1
mov a,data_song_mang1
clr c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
clr c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit 0
bit_1: cjne a,#77h,bit_f
mov a,data_song_mang1
setb c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
setb c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit 1
bit_f: cjne a,#71h,khong_phai_bit
mov a,data_song_mang1
clr c
rrc a
mov data_song_mang1,a
mov a,data_song_mang2
setb c
rrc a
mov data_song_mang2,a
sjmp du_bit ;la bit float
du_bit:
setb co_dong_bo
ret
khong_phai_bit:
clr co_dong_bo
ret
;---------------------------------------------
;---------------------delay rc de lay mau
delay_laymau:
mov 2bh,time_delay2 ;2 neu thach anh 12, 4 neu thach anh 24 ;he so tang len neu RC qua lon
dl_1: mov 2ah,time_delay1 ;doi voi RC=4.7Momh thi trong khoang tu 140-150 la toi uu
djnz 2ah,$
djnz 2bh,dl_1
ret
;================================================= =
SAVE_ADD:
MOV NVMADDRL,#ADDP0 ;00H
CALL XOAROM ;TRUOC KHI GHI PHAI XOA TRUOC NVMROM
MOV SOBYTE,#soso_mk ;HOWBYTE
MOV R0,#dia_chi_song_mang1 ;TERAM ;DIA CHI DAU VUNG RAM
MOV NVMADDRL,#ADDP0 ;DIA CHI NVMROM, DUNG LENH NAY TRUOC KHI GOI TRINH CON N
CALL GHIROM
RET
;---------------------------------------------------
LOAD_ADD:
MOV SOBYTE,#soso_mk ;HOWBYTE
MOV R1,#dia_chi_song_mang1 ;TEROM ;DIA CHI DAU VUNG RAM CHUA NOI DUNG DOC DUOC TU NVMROM
MOV DPL,#ADDP0 ;DIA CHI NVMROM,;TRUOC KHI GOI DA CO LENH NAY
MOV DPH,#0FCH ;
CALL DOCROM
RET
;-------------------====================================
;------------------------
XOAROM: ;XOA PAGE 0
; MOV NVMADDRL,#ADDP0 ;TRUOC KHI GOI DA CO LENH NAY
MOV NVMCON,#EERBIT ;SETB EER BIT 0CEH
RET
;-----------
GHIROM:
GHITIEP:
MOV NVMDATA,@R0 ;GHI DATA
MOV NVMCON,#EWRBIT ;SETB EWR BIT DE CHOT DATA
INC NVMADDRL ;tang dia cho ROM
INC R0 ;Tang vi tri data muon lay de ghi vao ROM
DJNZ SOBYTE,GHITIEP
ACALL BUZZER ;KEU DE CHI THI OK
RET
;-----------
DOCROM:
DOCTIEP:
CLR A
MOVC A,@A+DPTR
MOV @R1,A
INC DPTR
INC R1
DJNZ SOBYTE,DOCTIEP
RET
;================================================= ==========
delay_n:
mov r4,#255
DELAY:
dd2: mov r5,#255
djnz r5,$
djnz r4,dd2
RET
;=================
BUZZER:
SETB SPEAKER
MOV R4,#100
CALL DELAY
CLR SPEAKER
RET
;+++++++++++++++++++++++++++++++++++++++++++++++++ ++++
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++
end