Nghiên cứu, thiết kế, chế tạo điều tốc cho các trạm thủy điện

MỤC LỤC Trang Đặt vấn đề 1 Phần I Lý thuyết cơ bản của thiết bị điều tốc 3 I.1. Sự điều chỉnh tua bin và sự đièu chỉnh tua bin và phân loại máy điều. 3 I.1.1. Sơ l−ợc về lý thuyết về điều chỉnh tua bin thuỷ lực 3 I.1.2. Giới thiệu các loại máy điều tốc trong trạm thuỷ điện 5 I.2. NHU CầU CáC LOạI MáY đIềU TẩC TRONG TRạM THUÛ đIệN 9 I.3. XU H−ÍNG CHế TạO CáC LOạI MáY DIềU TẩC TRêN THế GIÍI 9 I.4 Chế tạo máy điều tốc ở Việt Nam 11 Phần II. Nghiên cứu, chế tạo điều tốc điều chỉnh l−u l−ợng và điều tốc điều chỉnh phụ tải 13 II.1 Nghiên cứu xử dụng các bộ vi xử lý (P), â thông dụng vào việc chế tạo máy điều tốc 13 II.1.1 Lựa chọn sử dụng vi xử lý 13 II.1.2. ứng dụng vi xử lý 8051 13 II.1.3 Nghiên cứu ứng dụng vi xử lý tại trung tâm nghiên cứu thuỷ điện nhỏ – Viện Khoa học Thuỷ lợi 15 II.1.4. Thông tin từ n−ớc ngoài 17 II.2. Nghiên cứu mở rộng bộ điều khiển điều tốc l−u l−ợng thành bộ điều khiển đa tác dụng 19 II.3. Xác định ph−ơng pháp điều chỉnh tua bin 20 II.3.1. Sơ đồ điều khiển 20 II.3.2. Sơ đồ khối chức năng 23 II.4 Thiết kế phần cứng 23 II.4.1 CPU 23 II.4.2 Khối hiển thị 24 II.4.3 Khối đo l−ờng tần số 25 II.4.4 Khối báo hiệu mực n−ớc 26 II.4.5 Tín hiệu đóng máy sự cố bên ngoài 26 II.4.6 Các công tác thiết lập giá trị vận hành 27 II.4.7 Khối điều khiển 27 II.4.8 Khối cấp nguồn 28 II.5. Xây dựng phần mềm điều khiển 28 II.5.1 Lựa chọn ngôn ngữ 28 II.5.2 Sơ đồ khối tính toán chính 29 II.6 Chế tạo hoàn chỉnh bộ điều tốc 37 II.7 Xây dựng qui trình vận hành, sửa chữa, bảo d−ỡng 38 II.8 Đề xuất nâng cao chất l−ợng thiết bị 38 II.9 Bản vẽ nguyên lý 39 Phần III Nghiên cứu bộ điều tốc điều khiển phụ tải 40 III.1 Tổng quan 40 III.1.1 Thông tin từ n−ớc ngoài 40 III.1.2 Lựa chọn ph−ơng án thiết kế 42 III.2 Thiết kế phần cứng 50 III.2.1 CPU 50 III.2.2 Khối đo l−ờng tần số 51 III.2.3 Công tác thiết lập giá trị vận hành 51 III.2.4 Khối điều khiển tải 53 III.2.5 Đièu khiển kiểu Rơle 53 III.2.6 Khối cấp nguồn 53 III.3 Xây dựng phần mềm điều khiển 54 III.3.1 Lựa chọn ngôn ngữ 54 III.3.2 Sơ đồ khối tính toán chính 54 III.4 Chế tạo hoàn chỉnh bộ điều khiển 59 III.5 Đề xuất nâng cao chất l−ợng thiết bị 60 III.6 Bản vẽ nguyên lý 61 Phụ lục I Phần mềm điều khiển l−u tốc điều chỉnh l−u l−ợng 63a Phụ lục II Phầm mềm điều khiển điều tốc điều chỉnh phu tải 102

pdf120 trang | Chia sẻ: lvcdongnoi | Lượt xem: 2746 | Lượt tải: 1download
Bạn đang xem trước 20 trang tài liệu Nghiên cứu, thiết kế, chế tạo điều tốc cho các trạm thủy điện, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
mmand X05af: ret ;============================================================= ;X05B0:Nap gia tri 1Ah vao cac o nho (23h),(22h),(21h),(20h) ; Khi hien thi, ROM 31Ah=00 -> Tat het cac LED 7 thanh ;============================================================= KhongHienSo: mov r0,#24h mov r2,#4 X05b4: dec r0 mov @r0,#1ah djnz r2,X05b4 ret ;============================================================== X05e6: ;Tien bo xung - Phuc vu X028b mov r2,#80h jb Acc.4, X05f1 mov r2,#60h jb Acc.5, X05f1 mov r2,#98h X05f1: ret ; 05f1 - 83 . ;=============================================================== ; Giam dan o nho chi ra trong R0, neu = 0 thi gan gia tri 1 ;=============================================================== X0617: mov a,r6 jb Acc.6, X062e ; d=0 - Trong luoi jb Acc.5, X062e ; Doc lap & x=0 Mode 1,2 mov a,r6 ; Doc lap & mode 3 swap a ; A=0D0N.0dxn anl a,#3 ; A=xn=11,10,01 add a,#0f8h mov r3,a ; R3=FBh,FAh,F9h mov r2,#6 X0626: call X073a jb Acc.7, X062e djnz r2,X0626 ret X062e: clr a ret X0661: mov a,r6 jb Acc.6, X066e ; Neu chay doc lap mov r0,#7eh mov a,@r0 jz X066e mov r1,#W_level mov @r1,#2 X066e: mov r0,#67h ret Nap1: mov @r0,#3 ; 3 -> (71h) mov r0,#28h ; mov @r0,#4 ; 4 -> (28h) inc r0 ; mov @r0,#5 ; 5 -> (29h) ret ; B¸o c¸o khoa häc §Ò tµi KC07- 04 80 ; X0689: mov r0,#Flags mov a,@r0 mov r0,#29h jb Acc.0, X0691 dec r0 X0691: inc @r0 setb f0 ret X0696: mov r0,#28h mov a,@r0 add a,#0fdh jc X06a3 inc r0 mov a,@r0 add a,#0fdh jnc X06b3 X06a3: mov a,r6 jb Acc.6, X06b3 mov r0,#6ah mov @r0,#0ah dec r0 jb Acc.5, X06b3 mov @r0,#6 dec r0 mov @r0,#0ch X06b3: ret ;(Quay tro lai X016f) X06b4: mov r2,#20h mov r3,#0e1h jb Acc.5, X06c2 mov r2,#0 jb Acc.4, X06c2 mov r2,#0eah dec r3 X06c2: ret ;============================================================== R3R2_Add_7978: ; Kiem tra o nho (79h.78h) so voi tri so R3.R2 mov r0,#78h mov a,@r0 add a,r2 inc r0 mov a,@r0 addc a,r3 ret ;=============================================================== ; Doan chuong trinh dong Role qua cong P1 ;=============================================================== Dong_Role: cjne R4,#1Dh,Next1 call Ngat_Role ; Ngat Toan bo role ajmp EndNext Next1: cjne R4,#69h,Next2 setb p2.4 ; Close ON clr p2.5 setb p3.4 ; Over ON clr p3.5 clr p2.6 ; Open OFF setb p2.7 setb p3.0 ; Sync OFF clr p3.1 ajmp EndNext Next2: cjne R4,#59h,Next3 B¸o c¸o khoa häc §Ò tµi KC07- 04 81 setb p2.4 ; Close ON clr p2.5 setb p3.5 ; Over OFF clr p3.4 clr p2.6 ; Open OFF setb p2.7 setb p3.0 ; Sync OFF clr p3.1 ajmp EndNext Next3: cjne R4,#95h,X06df setb p2.6 ; Open ON clr p2.7 clr p2.4 ; Close OFF setb p2.5 setb p3.0 ; Sync OFF clr p3.1 clr p3.4 ; Over Speed OFF setb p3.5 EndNext: nop nop djnz r3,Dong_Role djnz r2,Dong_Role ; R2=0A (X06e0) X06df: ret X06e0: mov r0,#1dh mov @r0,#0feh mov r0,#72h mov @r0,#0dch inc r0 mov @r0,#0dch mov r0,#2ah mov @r0,#8 mov r2,#0ah mov r0,#29h mov @r0,#5 ret X0700: mov r0,#38h mov r1,#36h call X074c jb Acc.7, X0711 mov r1,#38h mov r0,#36h call X074c jb Acc.7, X072e X0711: mov r0,#3ah mov r1,#3ch call SubR0_R1 call Cpl2Nor mov a,r2 rr a rr a nop anl a,#3fh mov r2,a jz X072e X0722: mov a,r7 ; R7 chua dia chi 69h hoac 6ah mov r0,a mov r3,#0fbh X0726: mov a,@r0 add a,r3 jnc X072e ; @R7 < 5 call DecToOne djnz r2,X0726 X072e: mov a,r7 B¸o c¸o khoa häc §Ò tµi KC07- 04 82 mov r0,a call DecToOne ; Giam noi dung @R7 ret X0735: call X0041 mov r2,a ret X073a: mov a,@r1 add a,@r0 mov r4,a inc r0 inc r1 mov a,@r1 addc a,@r0 mov r5,a inc r0 inc r1 mov a,r4 add a,r3 mov a,r5 addc a,#0ffh ret X074c: mov r2,#4 mov r3,#0fbh X0750: call X073a jb Acc.7, X0756 djnz r2,X0750 X0756: ret X0757: mov r2,#0beh mov r3,#0d8h call R3R2_Add_3F3E ; Neu Ts may phat > 39,8 thi bit 7=1 ret X0764: mov r2,#6 mov r3,#0ffh X0768: call X073a jb Acc.7, X078a djnz r2,X0768 mov r0,#34h mov r1,#3ch call SubR0_R1 call Cpl2Nor X0776: mov r0,#7bh mov a,@r0 anl a,#0f8h jz X077f call DecToOne X077f: mov r0,#7ch mov a,@r0 anl a,#0f8h jz X0788 call DecToOne X0788: djnz r2,X0776 X078a: ret ;============================================================== X078d: mov r0,#40h mov a,@r0 add a,r2 inc r0 mov a,@r0 addc a,#0 ret X0797: mov r0,#40h mov a,@r0 add a,r2 inc r0 mov a,@r0 addc a,#0ffh ret B¸o c¸o khoa häc §Ò tµi KC07- 04 83 Ngat_Role: clr p2.4 ; Close OFF setb p2.5 clr p2.6 ; Open OFF setb p2.7 setb p3.0 ; Sync OFF clr p3.1 clr p3.4 ; Over Speed OFF setb p3.5 nop nop ret ; Tong cong 16 chu ky may (8039) X07b0: mov r0,#1dh ; 2 ck mov @r0,#70h ; 2 ck (1Dh)=70h mov r2,#50h ; 2 ck X07b6: call Ngat_Role nop nop ; 16 + 4 =20 ck djnz r3,X07b6 djnz r2,X07b6 ret ;============================================================== ; Doc ROM ;=============================================================== ROM_MODE: mov a,r6 ; R6=0dxn0D0N swap a ; A =0D0N0dxn anl a,#7 ; A =00000dxn orl a,#38h ; A =00111dxn mov dptr,#ROM_DB ; Doc ROM tu 39h,3Ah,3Bh,3Dh,3Eh,3Fh movc a,@a+dptr ; FA(MODE3),FB(MODE2),FC(MODE1),FD(MODE3),B2(MODE2),10(MODE1) mov r0,#7ah mov @r0,#4 ; 4 -> (7ah) inc r0 ; mov @r0,a ; So doc tu rom -> (7Bh) inc r0 mov @r0,a ; So doc tu rom -> (7Ch) inc r0 mov @r0,a ; So doc tu rom -> (7Dh) ret X07e2: mov a,r6 jb Acc.0, X07ee ;Neu HOA thi ket thuc call ROM_MODE mov r0,#7ch mov @r0,#4 dec r0 mov @r0,#4 X07ee: mov r0,#7ah mov @r0,#4 ret X07f3: mov @r0,#2 ; r0 = 6ch or 6dh ; truoc khi goi doan nay hai op nay deu giam toi 1 mov a,@r1 ; r1 tro toi dia chi 70h or 71h anl a,#7 ; giu lai 3 bit cuoi mov @r1,a add a,#0fbh ; so sanh voi 5 (nho hon) jc X07fe inc @r1 X07fe: ret ;============================================================== XuLy: call X0083 ; 14 83 call Dem_Chu_Ky ; 14 60 call X0c00 ; 94 00 call Tinh_Tan_So ; 54 83 call X0b00 ; 74 00 B¸o c¸o khoa häc §Ò tµi KC07- 04 84 call ChuanBiHienThi ; 34 00 call X0a00 ; 54 00 call Tinh_PD ; 54 a0 call X0972 ; 34 72 nop nop ret ;==================================================================== X0083: mov r1,#Count ; 2Fh mov a,@r1 ; (Count) -> ACC nop anl a,#0fh ; Xet 4 bit cuoi jnz X0092 ; Neu 4 bit cuoi khac 0 mov r0,#50h ; Neu 4 bit cuoi bang 0 - Chia het cho 16 call DecToOne ; Giam o nho 50h sau 16 lan dem tan so inc r0 call DecToOne ; Giam o nho 51h sau 16 lan dem tan so X0092: ;call SW12ToR6 ; Dua gia tri bien SW12 -> ACC -> R6 mov r0,#SW12 mov a,@r0 mov r6,a ;ret mov r3,a ; R3 = SW12 mov r0,#Flags mov a,@r0 mov r7,a ; ret nop nop anl a,#64h ; Xet bit 6,5,2 jnz X00d9 ; 0 -> Ket thuc clr TR0 call Doc_Cong_Tac mov r0,#Flags mov a,@r0 jb Acc.7, X00af ; Neu bit 7 = 1, jb Acc.3, X00af ; Neu bit 3 = 0 (bang 1 sau khi da dao) mov a,r3 ; Neu bit 3 = 1 (bang 0 sau khi da dao), A=R3=SW12 xrl a,r6 ; R6=0dxn.0D0N XOR SW12 (=0dxn.0D0N) jb Acc.0, X00af ; =1-> N=0 (Cong tac co su thay doi o vi tri HOA) call X07b0 ; Neu khong doi-> Ngat ROLE trong R3*R2 lan =SW12*50h (0,075 ms) X00af: mov a,r2 ; Trong Doc_Cong_Tac r2=0000ldcn mov r0,#27h X07d2: jb Acc.1, X07dc ; Neu cong tac thay doi gia tri call DecToOne ; Neu co tin hieu CloseCommand thi giam o nho (27h) jnz X07de mov a,#2 orl a,r7 ; R7=Flags mov r7,a ; set bit 1 X07dc: mov a,#2 X07de: anl a,#7 ; lay 3 bit thap mov @r0,a nop mov a,R7 jb Acc.7, X00c2 mov a,r6 ; A=0dxn.0D0N anl a,#70h ; A=0dxn.0000 (Che do dieu tan - Normal) jb Acc.6, X00c0 ; d=1 -> Doc lap mov a,#50h ; Neu trong luoi ->A=0101.0000 ->Dieu tan, mode3, doclap X00c0: nop mov r6,a ; Nap A tro lai R6, =0dxn.0000 hoac 0101.0000 X00c2: mov r0,#7eh mov a,@r0 jnz X00cd ; (7Eh) FFh mov a,r6 ; Neu (7Eh)=FFh anl a,#45h ; A=0d00.0D0N jz X00d1 ; = 0 -> Normal + Luoi B¸o c¸o khoa häc §Ò tµi KC07- 04 85 X00cd: mov r0,#2dh ; Nguoc lai (2Dh)=1 mov @r0,#1 X00d1: mov r0,#SW12 mov a,r6 mov @r0,a ; R6 -> (SW12) mov r0,#Flags mov a,r7 mov @r0,a ; R7 -> Flags X00d9: ret ; End X0083 ;======================================================================== Dem_Chu_Ky: mov r1,#48h mov r2,#8 ; So lan lap cho XoaSoHienThi clr a ; A=00h XoaSoHienThi: mov @r1,a ; 00 -> (48h) inc r1 djnz r2,XoaSoHienThi ; Dien 00 vao (49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh) mov r0,#Count ; (2Fh) mov a,@r0 ; A=(Count) inc @r0 ; (Count)+1 anl a,#3 ; Lay 2 bit cuoi cua Count jnz Tieptuc2 ; Count khong chia het cho 4 khong KTLP call KiemTraLechPha ; 4 lan Dem_Chu_Ky, 1 lan KTLP Tieptuc2: clr f1 ; F1=0, Chua dem Tan so X0ee5: ; mov r0,#Flags mov a,@r0 jb Acc.7,TanSoMay ; Neu bit 7=1 chi kiem tra tan so may phat ; Neu bit 7 cua (Flags)=0 mov a,r6 ; Neu cong tac HOA khong o vi tri HOA nop jb Acc.0,TanSoMay ; chi kiem tra tan so may phat TanSoLuoi: setb p3.3 ; Cau hinh cong Input mov TL1,#0 mov TH1,#0 jnb p3.3,$ ; Neu luoi=0 thi cho khi luoi=1 jb p3.3,$ ; Neu luoi=1 thi cho khi luoi=0 call X0d00 ; Tre R2*0.250 ms = (3Fh)*0,250 ms mov @r0,#17h ; 17h ~ 23 ms, TS luoi qua thap -> Reset jnb p3.3,$ ; Neu luoi=0 thi cho khi luoi=1 jb p3.3,$ ; Neu luoi=1 thi cho khi luoi=0 setb TR1 ; Khoi dong Timer1 de dem tan so setb TR0 jnb p3.3,$ ; Neu luoi=0 thi cho khi luoi=1 jb p3.3,$ ; Neu luoi=1 thi cho khi luoi=0 clr TR1 ; Dung timer dem tan so clr a Wait4ChuKy: mov @r0,#17h ; 2Eh ~ 46 ms, TS luoi qua thap -> Reset jnb p3.3,$ ; Neu luoi=0 thi cho khi luoi=1 jb p3.3,$ ; Neu luoi=1 thi cho khi luoi=0 djnz R5,Wait4ChuKy ; R5 =4 trong X0D00 clr TR0 mov p0,#0ffh ; Tat den LED call X0d1e ; So dem duoc la gia tri 2 byte: R3R2 mov r5,#6 ; mov r0,#58h ; mov r1,#5ah ; mov r0,#5eh ; call NapR3R2ToR0 ; Tai dia chi 5Fh.5Eh chua gia tri 2 byte cua tan so luoi dien mov r0,#77h ; B¸o c¸o khoa häc §Ò tµi KC07- 04 86 call DecToOne mov r1,#LED1 X08ec: mov @r1,#1ah ; 1Ah -> LED1, khong hien so -> Nhap nhay so cuoi mov r0,#Flags mov a,@r0 jb acc.3,X08f6 ; neu bit Flags.3=0 thi thoi (HOA) call KhongHienSo ; Neu khong o che do HOA -> Tat het LED ( Nhap nhay?) X08f6: TanSoMay: mov TL1,#0 mov TH1,#0 setb p3.2 jnb p3.2,$ ; Cho den khi T1=1 (May phat) jb p3.2,$ ; Cho den khi T1=0 (May phat) call X0d00 ; (Trong doan nay stop Timer) mov @r0,#40h ; (Doan X0d3a cu)~ 14.5 Hz jnb p3.2,$ ; Cho den khi T1=1 (May phat) jb p3.2,$ ; Cho den khi T1=0 (May phat) setb TR1 setb TR0 mov @r0,#40h ; jnb p3.2,$ ; Cho den khi T1=1 (May phat) jb p3.2,$ ; Cho den khi T1=0 (May phat) clr TR1 ; Dung timer dem tan so clr a Wait4ChuKy2: mov @r0,#40h ; 45h ~ 14.5 Hz, TS luoi qua thap -> Reset jnb p3.2,$ ; Neu luoi=0 thi cho khi luoi=1 jb p3.2,$ ; Neu luoi=1 thi cho khi luoi=0 djnz R5,Wait4ChuKy2 ; R5 =4 trong X0D00 clr TR0 clr a mov p0,#0ffh ; Tat den LED call X0d1e mov r5,#0eh mov r0,#30h mov r1,#32h mov r0,#3eh call NapR3R2ToR0 cpl f1 ; F1=1 Dem xong tan so ret ; END OF Dem_Chu_Ky ;=================================================================== X0d00: mov a,3fh ; A=(3Fh) Byte cao cua so dem chu ky may phat mov r2,a ; Dua noi dung (3Fh) vao R2 X0d04: mov r1,#7Dh X0d06: djnz r1,X0d06 ; Tre 7Dh=125 x 2 chu ky=250chu ky= 0,250 ms djnz r2,X0d04 ; Tre R2 x 0,250 ms (50 Hz - R2=1Fh=31) mov r0,#Dsp_Count ; R0=(1Dh) mov r1,#1ah ; R1=1Ah mov r5,#4 ; R5=4 CLR TR0 ; Dung Timer call Ngat_Role clr a mov @r0,a ; 00 -> (Dsp_Count R5-rb1) ret ;============================================================== X0d1e N1: mov @r0,#0 ; 0 -> (1Dh) mov R3,TH1 mov R2,TL1 mov r3,a SETB tr0 ret ; R3.R2 = 1F40h (8000) N2: mov R3, #0Bh mov R2, #0DBh B¸o c¸o khoa häc §Ò tµi KC07- 04 87 mov a, TL1 add a,R2 mov a, TH1 addc a, R3 jb acc.7,N1 mov TH1,#0F4h mov TL1,#24h ret ;============================================================== ; Kiem tra do lech pha 2 may la (0,5 x R4) ms ;============================================================== So_Pha1: mov r4,#1 ; Lan dau R4=1 So_Pha: mov r1,#Dsp_Count ; mov @r1,#0d6h ; 1101.0110 -> (Dsp_Count) setb p3.2 ; (1Dh)=D6=214 setb p3.3 T0_Duong: mov a,@r1 ; jb acc.5,Ketthuc1 ; Neu (1D.5)=1, da qua 22 chu ky hien thi jb p3.3,T0_Duong ; (1Dh) = 1011.1111 = BFh= 191 T0_Am: mov a,@r1 ; den khi T0=0, kiemtra tiep jb acc.5,Ketthuc1 ; Neu (1D.5)=1 thi ket thuc, (Dsp_Count)=FAh jnb p3.3,T0_Am ; (1D.5)=0 -> Neu T0=0 tiep tuc kiem tra (1D.5) call Doi_nua_ms ; khi T0=1 doi sau 0,5*R4 ms jnb p3.3,Ketthuc2 ; jnt1 Neu T1=0 thi ket thuc, A=4Eh jb p3.3,$ ; Neu T1=1, (T0=1) cho doi call Doi_nua_ms ; khi T0=0, doi sau 0,5*R4 ms jb p3.2,Ketthuc2 ; jt1 Neu T1=1 thi ket thuc, A=4Eh ; T1 khong cham pha so voi T0 qua 0,5*r4 ms jnb p3.2,$ ; jnt1 Neu T1=0, cho den khi T1=1 call Doi_nua_ms ; Tre sau 0,5*R4 ms jnb p3.3,Ketthuc2 ; jnt0 Neu T0=0 thi ket thuc, A=4Eh jb p3.2,$ ; jt1 Neu T0=1 cho den khi T1=0 call Doi_nua_ms ; Doi 0,5*R4 ms clr a ; jnb p3.3,Ketthuc1 ; jnt0 Neu T0=0 thi ket thuc (Dsp_Count)=FAh ; T0 khong cham pha so voi T1 qua 0,5*r4 ms: A=0 Ketthuc2: mov a,#4eh ; Neu T0=1 thi ket thuc A=4Eh va (Dsp_Count)=FAh ; T0 cham pha so voi T1 qua 0,5*r4 ms: A=4Ef=0100 1110 Ketthuc1: mov @r1,#0fah ; Neu bit5 cua (Dsp_Count)=1 thi FAh=11111010 -> (Dsp_Count) ret ; Doi_nua_ms: mov a,r4 ; A=R4 1 ck rl a ; Neu R4<8F: A=R4*2 1 ck add a,r4 ; A=3*R4 1 ck mov r3,a ; R3=3*R4 1 ck Lap3: mov r2,#52h ; R2=82 2 ck djnz r2,$ ; X0eb2 82*2 ck = 164 ck djnz r3,Lap3 ; 2 ck ret ; ;==================================================== ; Kiem tra do lech pha ;==================================================== KiemTraLechPha: mov r0,#7eh ; R0=7Eh clr c mov a,@r0 ; (7Eh) -> A =3F=0011.1111 (Truoc khi goi KTLP) rlc a ; A*2=7E, C = bit MSB cua (7Eh)=0 mov @r0,a ; A=7E -> (7Eh) nop call So_Pha1 ; Kiem tra do lech pha 2 may < 0,5*R4 ms ; Neu lech pha lon hon 0,5*R4 ms A= 4E =0100 1110 B¸o c¸o khoa häc §Ò tµi KC07- 04 88 ; Neu lech pha nho hon 0,5*R4 ms A= 00 =0000 0000 jb acc.5,X0ef8 ; Neu ACC.5 = 1 (Truong hop f < 22 Hz) jb acc.6,KThuc_So_Lech ; Neu lech lon (A=4E -> ACC.6=1) -> Ket thuc inc @r0 ; Neu lech nho (A=0 -> ACC.6=0) mov a,@r0 ; (7Eh) -> A jnz Xoa_A ; Neu a0 (tuc la (7Eh) FF) thi xoa A=0 X0ef8: mov r0,#Flags ; Neu ACC=0, tuc ban dau (7Eh)=FF mov a,@r0 ; Dua (Flags) - >A orl a,#8 ; Bat bit thu 3 trong 2 t/hop: ACC.5=1 mov @r0,a ; Tan so < 22 Hz (Chu ky = 44 ms) Xoa_A: clr a KThuc_So_Lech: ret ;========================================================================== X0c00: mov a,r6 ; A=0dxn.0D0N -> N=1 Hoa dien jb Acc.0,X0c0b ; Neu Hoa X0e17: mov r4,#28h call Add_3F3E_E0C0 ; Cong gia tri 2 byte (3Fh.3Eh) voi E0C0h jb Acc.7,X0e1f ; Neu (3F.3E) khi cong voi E0C0h bit 7 bang 1 mov r4,#3ch ; f<= 50 Hz R4=28h X0e1f: nop ; ret f> 50 R4= 3Ch X0cf3: mov r0,#3eh mov r1,#3ch call SubR0_R1 ; Gia tri hien tai - Gia tri truoc do mov a,r2 add a,r4 mov a,r3 addc a,#0 ; (R3.R2) + R4 jb Acc.7,X0c0b ; bit 7 = 1 -> Delta F < +0,2 Hz mov r0,#7ah mov @r0,#4 X0c0b: ;call Flags2ACC mov r0,#Flags mov a,@r0 jb Acc.7,X0c16 mov r6,#70h ; R6=0111.0000 Dieu tan-mod1-doclap (Flags.7=0) mov r0,#68h nop X0c16: nop X0630: mov a,r6 anl a,#61h ; A=0dx0.000N xrl a,#20h ; A=0 khi d=0,x=1,N=0 (Luoi,khong HOA) jnz X065f ; Neu khong phai (Luoi,mode1&2,khong HOA) thi ket thuc mov r2,#65h mov r3,#0e1h mov a,r6 jb Acc.4,X0640 ; Mode1 R3R2=E165 - 1E9B: 51 Hz mov r2,#0fch ; Neu mode 2 R3R2=E10F - 1EF1: 52 Hz X0640: call R3R2_Add_3F3E jb Acc.7,X0656 mov r2,#50h ; Neu tan so nho hon mov r3,#0e0h mov a,r6 jb Acc.4,X064e ; thi neu mode 2 R3R2=E050 -1FB0:49 Hz mov r2,#72h ; Mode 1 R3R2=DF72 - 208E:48 Hz dec r3 X064e: call R3R2_Add_3F3E jb Acc.7,X065f mov r0,#2ah ; Neu Tan so nho hon mov @r0,#3 ; (2Ah)=3 X0656: mov r6,#30h ; R6=0011.0000 (Luoi-Mode1-Normal) mov r0,#69h mov @r0,#1 ; (69h)=1 inc r0 mov @r0,#1 ; (6Ah)=1 X065f: ;sel mb1 B¸o c¸o khoa häc §Ò tµi KC07- 04 89 ;ret mov a,r6 jb Acc.0, X0c2c jb Acc.6, X0c45 call Giam2Dh ; X0b85 xrl a,#8 jnz X0c35 mov r0,#68h mov @r0,#1 mov r0,#7ah mov @r0,#1 X0c2c: mov r0,#68h mov a,@r0 add a,#0fbh jnc X0c35 mov @r0,#4 X0c35: mov r0,#69h mov a,#1 nop mov @r0,a inc r0 ; 6Ah mov @r0,a mov r0,#7bh ; 7Bh mov @r0,a inc r0 ; 7Ch mov @r0,a X0e47: ;call X0e47 inc r0 ; 7Dh mov @r0,a mov r0,#2ah mov a,@r0 dec a jnz X0e53 mov r0,#2dh mov @r0,#1 X0e53: ret ; End X0C00 ;======================================================================= ; Doc ROM khi o che do doc lap ;======================================================================= X0c45: swap a ; A=R6 -> A=0D0N0dxn anl a,#7 ; A=00000dxn orl a,#38h ; A=00111dxn =3D - 3F mov dptr,#ROM_DB ; Doc ROM tu 3Dh,3Eh,3Fh movc a,@a+dptr mov r2,a mov r0,#7dh mov r3,#3 X0c50: mov a,r2 add a,@r0 jnc X0c57 mov @r0,#4 X0c57: dec r0 djnz r3,X0c50 ; Thuc hien 3 lan ret ;================================================================== Tinh_Tan_So: mov r0,#3eh mov r1,#48h ; Doi so dem tu 3F3E thanh Gia tri tan so * 100 call Chuky2TanSo ; Nap vao 49h.48h mov a,r6 jb Acc.0,X0a9f ; Neu khong hoa thi ket thuc mov r0,#5eh ; Neu hoa, tinh hieu tan so mov r1,#4ah call Chuky2TanSo ; Doi so dem tu 5F5E thanh gia tri tan so * 100 mov r0,#48h mov r1,#4ah call SubR0_R1 ; Hieu 2 tan so B¸o c¸o khoa häc §Ò tµi KC07- 04 90 call Cpl2Nor ; Doi sang dang binh thuong mov r0,#42h call NapR3R2ToR0 ; Nap gia tri hieu tan so vao 43h.42h (bit 16 chi dau) X0a9f: ret ; End TinhTanSo ;========================================================================== Chuky2TanSo: mov r2,#5ah mov r3,#62h mov r4,#2 ; Chu y : 2625A00h=40000000=1/0,000000025 mov r7,#18h X0bdd: ;call X0bdd ;ret mov r5,#0 ;======================================================== CplR0_To_R1: ;call CplR0_To_R1 mov a,@r0 cpl a add a,#1 mov @r1,a inc r0 inc r1 mov a,@r0 cpl a addc a,#0 mov @r1,a dec r0 dec r1 ;ret X0be1: clr c mov a,r2 rlc a mov r2,a mov a,r3 rlc a mov r3,a mov a,r4 rlc a mov r4,a mov a,r5 rlc a mov r5,a ;======================================================== R5R4_Add_R1: ; call R5R4_Add_R1 mov a,@r1 add a,r4 mov r4,a inc r1 mov a,@r1 addc a,r5 mov r5,a ;ret dec r1 inc r2 jc X0bf8 dec r2 ;======================================================== R5R4_Add_R0: ; call R5R4_Add_R0 mov a,@r0 add a,r4 mov r4,a inc r0 mov a,@r0 addc a,r5 B¸o c¸o khoa häc §Ò tµi KC07- 04 91 mov r5,a ;ret dec r0 X0bf8: djnz r7,X0be1 mov a,r2 mov @r1,a inc r1 mov a,r3 mov @r1,a ret ; End TinhTanSo ;======================================================================= X0b7f_j: jmp X0b7f ;======================================================================= X0b00: mov a,r6 anl a,#7Fh ; Xoa bit 7 mov r6,a mov r1,#44h mov @r1,#3eh inc r1 mov @r1,#1fh ; (45h.44h)=1F3Eh (50,01 Hz) mov r0,#Flags mov a,@r0 jb Acc.1,X0b65 jb Acc.7,X0b7f_j ; Ket thuc mov @r1,#1dh dec r1 mov @r1,#7ah ; (45h.44h)=1D7Ah ( 53 Hz) mov r0,#5eh call SubR0_R1 ; R3.R2=(5Fh.5Eh)-(45h.44h) jb Acc.7,X0b37 mov r1,#45h mov @r1,#23h dec r1 mov @r1,#93h ; R5.R4=2393h (43,9 Hz) mov r0,#5eh call SubR0_R1 ; R3.R2=(5Fh.5Eh)-(45h.44h) jb Acc.7,X0b37 mov r0,#5eh call NapR3R2FromR0 ; R3.R2=(5Fh.5Eh) mov r0,#44h call NapR3R2ToR0 ; (45h.44h)=(5Fh.5Eh) mov a,r6 orl a,#80h ; Bat bit 7 mov r6,a X0b37: mov a,r6 mov r0,#SW12 ; Nap R6 -> SW12 mov @r0,a jb Acc.0,X0b7f mov r2,#40h mov r3,#1fh jb Acc.6,X0b55 mov r0,#2dh mov a,@r0 dec a jnz X0b4d mov a,r6 jb Acc.2,X0b55 X0b4d: call Doc7Eh ; A=NOT(7Eh) jnz X0b55 mov r2,#69h mov r3,#1ch X0b55: mov r0,#44h call NapR3R2ToR0 ;(45h.44h)=1C69h (55Hz) hoac 1F40 (50Hz) mov a,r6 jb Acc.6,X0b7f ; B¸o c¸o khoa häc §Ò tµi KC07- 04 92 jb Acc.2,X0b7f mov r0,#W_level mov a,@r0 jb Acc.0,X0b7f X0b65: mov r0,#44h mov r2,#60h mov r3,#0ffh call Add_R2_R3 ;============================================================== CplR3R2: ;call CplR3R2 ; Lay so bu 2 cua (R3.R2) mov a,r2 cpl a add a,#1 mov r2,a mov a,r3 cpl a addc a,#0 mov r3,a ;ret call R3R2_Add_3F3E jb Acc.7, X0b7f mov r2,#0c0h mov r3,#1 mov r0,#3eh call Add_R2_R3 mov r0,#44h call NapR3R2ToR0 X0b7f: ret ; End X0B00 ;============================================================== ChuanBiHienThi: X0F22: ;call X0F22 , vi dang mb1) ; Tien bo xung mov a,r6 ; A=0dxn0D0N jb Acc.5,X0f30 mov r0,#26h call DecToOne ; X0e10 jnz X0f30 mov r0,#7bh mov @r0,#1 X0f30: mov r0,#Flags mov a,@r0 jb Acc.7,X0f3d mov a,r6 jb Acc.6,X0f3d mov r0,#2ah mov @r0,#0ah X0f3d: ;ret mov r0,#42h ; Chua chenh lech tan so luoi va may phat mov a,@r0 mov r2,a ; R2=(42h) inc r0 ; R0 =43h mov a,@r0 anl a,#7Fh mov r3,a ; Xoa bit dau jnz X0916 ; Neu 0 mov a,r2 ; Neu = 0 Kiem tra R2 co lon hon 2 khong add a,#0fdh jc X0916 mov r2,#0 ; Neu khong lon hon 4 -> Delta F < 0,02 mov @r0,#0 ; ->gan gia tri Delta F =0,00 X0916: mov a,r6 jb Acc.0,DoiHe ; N=1 HOA -> Hien thi chenh tan so (chi co 3 chu so) mov r0,#48h ; Neu khong phai HOA -> Hien thi tan so may phat call NapR3R2FromR0 ; R3.R2=(49h.48h) gia tri cua tan so may phat mov a,r6 ; a=0dxn.0D0N jb Acc.6,LamTron ; Chay doc lap d=1 -> Lam tron, hien thi 3 so jb Acc.2,DoiHe ; Neu chay trong luoi & Dieu toc-> Hien thi 4 chu so B¸o c¸o khoa häc §Ò tµi KC07- 04 93 LamTron: mov a,r2 ; Neu trong luoi & W_L -> Lam tron so add a,#5 ; + 5 vao so tan so may phat ( De lam tron) mov r2,a mov a,r3 addc a,#0 mov r3,a DoiHe: mov r0,#SoDonvi ;(SoDonvi=(4Dh)+10h (so co dau thap phan 310h-319h) mov @r0,#10h dec r0 ; R0=SoChuc (4Ch) Chia1000: mov a,r2 ; Cong R3.R2 + FC18h -> R3.R2 add a,#18h mov r2,a mov a,r3 addc a,#0fch ; FFFF-FC18=3E7h=999 mov r3,a jnc Hoiphucsodu1 ; Neu R3.R2 < 1000 thi khi cong FC18 khong co Carry inc @r0 ; Neu R3.R2 >= 1000, tang (So Chuc) jmp Chia1000 Hoiphucsodu1: inc r0 ; R0=SoDonvi(4Dh), Neu R3.R2 < 1000 mov a,r2 ; Cong R3.R2 +1000 nop add a,#0e8h mov r2,a mov a,r3 addc a,#3 mov r3,a ; R3.R2 +1000 (3E8h) -> R3.R2 Chia100: mov a,r2 ; Cong R3.R2 + FF9C -> R3.R2 add a,#9ch mov r2,a mov a,r3 addc a,#0ffh mov r3,a jnc Hoiphucsodu2 ; Neu R3.R2 < 100 thi khi cong voi FF9C khong co Carry inc @r0 ; Neu R3.R2 >=100, tang (So Don vi) jmp Chia100 Hoiphucsodu2: inc r0 ; R0=4Eh=So phan Chuc, Neu R3.R2 < 100 mov a,r2 add a,#64h ; Cong Byte thap R2 + 100 Chia10: add a,#0f6h jnc Hoiphucsodu3 ; Neu R2 < 10 thi khi cong voi F6 khong co Carry inc @r0 ; Neu R3.R2 >=10, tang (SophanChuc) jmp Chia10 Hoiphucsodu3: inc r0 ; R0=4Fh=So phan tram, ; Neu R2 < 10 add a,#0ah mov @r0,a ; (50h) ;ret ; Quay ve DoiHe mov a,r6 ; a=0dxn.0D0N jb Acc.0,HienSoHoa ; Neu che do HOA N=1 call Hien3Chuso jmp NapLED HienSoHoa: mov r0,#SoChuc ; Luc nay la Chuc cua Delta F mov a,@r0 jnz XetDau ; Neu tri so hang chuc 0 -> DeltaF > 10,00 Hz mov @r0,#1ah ; Neu Chuc = 0 -> 1Ah -> (SoChuc) -> tat LED4 (so chuc) XetDau: mov r1,#43h ; Byte cao cua Delta F mov a,@r1 jb Acc.7,NapLED ; Neu Delta F la so duong thi nap LED ngay B¸o c¸o khoa häc §Ò tµi KC07- 04 94 mov a,@r0 ; Neu la so am, xet tiep Delta F Chuc xrl a,#1ah ; (neu Chuc = 0 -> Chuc=1Ah(tat LED) -> (Chuc XOR jz DauTru ; Chuc = 0: Khong dich phai, hien dau (-)o LED4 call DichPhaiSoHienThi ; Neu Chuc 0 Dich chuyen du lieu DauTru: mov r0,#SoChuc ; SoChuc->SoDonvi->SophanChuc->SophanTram mov @r0,#42h ; ROM(442h)=20h -> Hien dau tru (-) o vi tri LED4 (Chuc) ;=================================================================== NapLED: mov r0,#SoChuc mov r1,#LED4 mov r2,#4 clr TR0 X0953: mov a,@r0 ; Nap cac gia tri (SoChuc),(SoDonvi), mov @r1,a ; (SophanChuc),(SophanTram) vao LEDs inc r0 inc r1 djnz r2,X0953 mov r0,#Count mov a,@r0 jb Acc.0,X0970 mov r1,#Flags mov a,@r1 jb Acc.7,X0970 jb Acc.1,X096a ; Neu bit Flags.7=1, xet bit 1=0 (binh thuong) mov r0,#LED4 ; Bit 1=1 -> CloseCommand hien nua tren so 8 (blink) mov @r0,#1bh ; ROM(31Bh)=72h=0111.0010=fgba -> Nua tren so 8 X096a: mov r0,#LED2 ; luc nay LED2 hien thi hang Donvi mov a,@r0 anl a,#0fh ; Lay 4 bit duoi -> Xoa dau (.) thap phan mov @r0,a X0970: setb TR0 ; Khoi dong Timer de hien thi ret ; End of ChuanBiHienThi ;============================================================= DichPhaiSoHienThi: mov r0,#SophanChuc mov r1,#SophanTram mov r2,#3 X0d76: mov a,@r0 mov @r1,a dec r0 dec r1 djnz r2,X0d76 ret ;============================================================ Hien3Chuso: ;call Hien3Chuso neu khong phai che do HOA mov r1,#SophanTram jb Acc.2,HienWL mov a,r6 jb Acc.6,X0f0c call DichPhaiSoHienThi ; Dich chuyen du lieu hien thi 3 chu so X0f0a: mov @r1,#1ah ; R1=So chuc khong hien X0f0c: ret ;=========================================================== HienWL: mov r0,#Count mov a,@r0 jb Acc.2,X0f0a call Doc7Eh ; A=NOT(7Eh) jz X0f1b mov a,r6 jb Acc.6,X0f0a X0f1b: mov r0,#W_level ; R0 = ul, Thap ul=11 -> 43h mov a,@r0 ; Trung binh ul=10 -> 42h orl a,#40h ; Cao ul=00 -> 40h mov @r1,a ; Chuan bi LED1 the hien Water Level ret ; Quay ve NapLED ;========================================================================== X0a00: mov a,r6 B¸o c¸o khoa häc §Ò tµi KC07- 04 95 anl a,#5 jz X0a12 ; Neu Dieu tan mov r0,#6ch mov @r0,#4 inc r0 mov @r0,#4 inc r0 mov @r0,#1 inc r0 mov @r0,#1 X0a12: mov r0,#6fh call DecToOne jz X0a24 call Add_3F3E_E0C0 ; Cong gia tri 2 byte (3Fh.3Eh) voi E0C0h jb Acc.7, X0a24 ; Neu Tanso > 50 Hz mov r0,#6fh mov @r0,#1 mov r0,#71h call DecToOne X0a24: mov r0,#6eh call DecToOne jz X0a37 call Add_3F3E_E0C0 ; Cong gia tri 2 byte (3Fh.3Eh) voi E0C0h jb Acc.7,X0a37 ; Neu Tanso < 50 Hz mov r0,#6eh mov @r0,#1 mov r0,#70h call DecToOne X0a37: mov r2,#0a2h mov r3,#0e0h call R3R2_Add_3F3E ; So sanh voi 49,8 Hz jb Acc.7,X0a47 ; Neu Tanso > 49,8 Hz mov r2,#6fh mov r3,#0e0h call R3R2_Add_3F3E ; So sanh voi 49,4 Hz jb Acc.7,X0a4b ; Neu Tanso > 49,4 Hz X0a47: mov r0,#6ch mov @r0,#3 X0a4b: mov r2,#0fh mov r3,#0e1h call R3R2_Add_3F3E ; So sanh voi 50,5 Hz jb Acc.7,X0a5b ; Neu Tanso > 50,5 Hz mov r2,#0deh mov r3,#0e0h call R3R2_Add_3F3E jb Acc.7,X0a5f ; Neu Tanso > 50,2 Hz X0a5b: mov r0,#6dh mov @r0,#3 X0a5f: mov r2,#44h mov r3,#0e3h call R3R2_Add_3F3E jb Acc.7,X0a6c ; Neu Tanso < 54,4 Hz mov a,#8 call Change_Flags ; Bat bit 3 cua Flags X0a6c: call Giam2Dh ; (X0b85) jz X0a74 mov r0,#72h mov @r0,#0ffh X0a74: nop ;jmp X0800 X0800: ;call Flags2ACC mov r0,#Flags mov a,@r0 mov r1,#73h jb Acc.1,X0809 mov @r1,#0ffh B¸o c¸o khoa häc §Ò tµi KC07- 04 96 X0809: mov a,@r0 ; R0=Flags jb Acc.7,X081b call Doc7Eh ; A=NOT(7Eh) jnz X081b mov a,r6 jb Acc.6,X081b ; (Doc lap) jb Acc.2,X082b ; Khong W_Level mov @r1,#0ffh dec r1 mov @r1,#0ffh X081b: mov r0,#2dh mov @r0,#1 mov r2,#90h mov r3,#0e2h ; E290 - 1D70:53 Hz call R3R2_Add_3F3E jb Acc.7,X0829 ; Neu tan so > 53 Hz jmp X0b9f ; Neu < 53 Hz X0829: jmp X0b92 X082b: mov r2,#58h mov r3,#0e1h ; E158 - 1EA8:51 Hz call R3R2_Add_3F3E jb Acc.7,X081b ; Neu tan so > 51 Hz jmp X0b9f ; Neu > 51 Hz X0b92: mov r0,#Flags mov a,@r0 jb Acc.4,X0b9f dec r0 ; Theo X081B R0=2Dh -> R0= 2Ch mov a,@r0 jnz X0b9f mov a,#80h call Change_Flags ; Bat bit 7 cua Flags X0b9f: mov r4,#80h call Doc7Eh ; A=NOT(7Eh) jnz X0bb0 mov a,r6 jb Acc.6,X0bb0 ; Doc lap jb Acc.0,X0bb0 ; hoa mov r4,#1 jb Acc.2,X0bb7 ; Wlevel mov r4,#0 X0bb0: mov r0,#50h mov @r0,#2 inc r0 mov @r0,#2 X0bb7: ;call Flags2ACC mov r0,#Flags mov a,@r0 jb Acc.1,X0bcb mov a,r4 jb Acc.0,X0bcb jnz X0bc4 call Giam2Dh ; X0b85 jnz X0bcb X0bc4: mov r1,#72h call Load_AC_to_R1 ; Nap ACh vao @R1, neu @R1=FF inc r1 call Load_AC_to_R1 ; Nap ACh vao @R1, neu @R1=FF X0bcb: ret ;========================================================================== Tinh_PD: mov r0,#3eh mov r1,#38h mov a,r6 nop jb Acc.0,X0aaa ; Neu hoa dien R1= 38h mov r1,#30h ; Neu Khong phai che do hoa R1=30h B¸o c¸o khoa häc §Ò tµi KC07- 04 97 X0aaa: call SubR0_R1 ; R2=(3Eh)-@R1 va R3=(3Fh)-@(R1+1) mov r0,#62h call NapR3R2ToR0 ; 63h.62h=3Fh.3Eh-39h.38h (Hoa) mov a,r6 ; 63h.62h=3Fh.3Eh-31h.30h (Khong hoa) jb Acc.0,X0ac4 mov r0,#5eh mov r1,#58h call SubR0_R1 ; R3.R2=(5Fh.5Eh)-(59h.58h) mov r0,#46h call NapR3R2ToR0 ; (47h.46h)=(5Fh.5Eh)-(59h.58h) mov r0,#62h mov r1,#46h call SubR0_R1 ; R3,R2=(63h.62h)-(47h.46h) X0ac4: mov r0,#40h call NapR3R2ToR0 ; (41h.40h)=(63h.62h)-(47h.46h) mov r0,#3eh call NapR3R2FromR0 ; R3,R2=(3Fh.3Eh) mov a,r6 mov r1,#6 jb Acc.0,X0add ; HOA R1=6 mov r1,#7 ; Khong HOA jb Acc.5,X0add ; Mode 1,2 R1=7 nop jb Acc.6,X0add ; Trong luoi mov r1,#7 ; Doc lap R1=7 nop nop X0add: mov r0,#62h call Add_R2_R3 ; R3.R2=R3.R2+(R0+1).R0 djnz r1,X0add mov r0,#64h call NapR3R2ToR0 ; (65h.64h)= ? call X0d7d mov r0,#64h mov r1,#44h call SubR0_R1 ; R3R2=(65h.64h)-(45h.44h) mov r0,#66h mov r1,#78h mov a,r2 mov @r0,a add a,#40h mov @r1,a inc r0 inc r1 mov a,r3 mov @r0,a addc a,#1fh mov @r1,a ret ; End of Tinh_PD ;================================================================ X0d7d: mov a,r6 jb Acc.0,X0d90 ; Neu HOA (N=1) thi Ret call Doc7Eh ; A=NOT(7Eh) mov r0,#2ch jnz X0d8e ; Neu A=NOT(7Eh) 0 -> (2Ch)=0 call DecToOne ; Neu a=0 tuc la (7Eh)=FF thi A=(2Ch)-1 jnz X0d90 ; Neu (2ch) 0 thi thoi mov a,#10h ; Neu A=0 (Luc nay (2Ch)=1) -> A=10h jmp Change_Flags ; Bat bit 4 cua Flags X0d8e: mov @r0,#0 X0d90: ret ;===================================================================== X0972: mov r0,#Flags mov a,@r0 anl a,#9bh ; And 1001.1011 ? mov @r0,a ; Xoa bit 2,5,6 cua Flags (lien quan X0092) B¸o c¸o khoa häc §Ò tµi KC07- 04 98 jb Acc.7,X097b jb Acc.1,X09b2 X097b: mov a,r6 jb Acc.0,X0981 ; N=0 Khong phai HOA jmp CheDoHOA ; Che do HOA ; X0981: mov a,r6 jb Acc.6,X09a8 ; Chay doc lap mov r2,#0fch mov r3,#0e1h X0eb7: jb Acc.2,X0ec6 ; call X0eb7 jb Acc.4,X0ec6 mov r2,#0a0h mov r3,#0e3h jb Acc.5,X0ec6 mov r2,#65h mov r3,#0e1h X0ec6: ;ret call R3R2_Add_3F3E jb Acc.7,X09a8 ; Neu Tan so may phat > cac gia tri tren thi X09a8 mov a,r6 ; Neu nho hon jb Acc.2,X09b6 ; Neu che do W_Lwvel - X09b6 call Giam2Dh ; Neu khong phai W_Level jnz X09b6 mov a,r6 ; Neu (2Dh)=0 jb Acc.5,X09a4 ; Neu mode 3 jb Acc.4,X09a4 ; Neu mode2 mov r2,#1dh ; Neu mode 1 R3R2=E01D - 49 Hz mov r3,#0e0h call R3R2_Add_3F3E jb Acc.7,X09b6 ; Neu tan so < 49 Hz X09a4: ;call X0cee ; Neu lon hon 4-> (7Ah) X0cee: mov r0,#7ah mov @r0,#4 ;ret jmp X09b6 X09a8: mov r2,#60h mov r3,#0e0h mov r4,#3ch call X0f3e jb Acc.7,X09b9 X09b2: mov a,#40h call Change_Flags ; Bat bit 6 cua Flags X09b6: ;call Flags2ACC mov r0,#Flags mov a,@r0 ret ;==================================================== X09b9: mov r2,#70h mov r3,#0e2h mov r4,#28h call X0f3e jb Acc.7,X09e1 mov r3,#0e5h mov r2,#0fh call R3R2_Add_6564 jb Acc.7,X09ce X09ce: mov r3,#0e4h X0857: mov r2,#19h ; Tien bo sung - Phuc vu X09CE mov a,r6 jb Acc.5,X085e ; Mode 1,2 R2=19h mov r2,#0ffh ; mode 3 R2=FF call R3R2_Add_3F3E jb Acc.7,X09b6 ;call X0d91 X0d91: mov r0,#34h B¸o c¸o khoa häc §Ò tµi KC07- 04 99 mov r1,#32h mov r5,#6 X0b8a: mov r4,#5 mov a,r6 jb Acc.5, X0b91 mov r4,#0ah X0b91: nop ;ret X09db: call X0da5 jb Acc.7,X09e3 djnz r5,X09db X09e1: jmp X09b2 X09e3: mov r0,#34h mov r1,#6 X09e7: mov r2,#0f5h mov r3,#0e5h call Add_R2_R3 inc r0 jb Acc.7,X09b6 djnz r1,X09e7 mov r0,#3eh mov r1,#3ch mov r4,#0f0h call X0d9a jb Acc.7,X09b2 X0c95: call Doc7Eh ; A=NOT(7Eh) jnz X0cd5 mov a,r6 jb Acc.6,X0cd5 jb Acc.2,X0ca4 mov r0,#W_level mov a,@r0 jb Acc.0,X0cd5 X0ca4: mov a,r6 swap a anl a,#3 mov r2,a rl a add a,r2 mov r0,#OpenRate ; Open Rate add a,@r0 add a,#0f7h jc X0cb3 clr a X0cb3: mov r0,#WL_Rate ; W_LRate rl a nop mov @r0,a mov r7,a jz X0cd5 ;call X0d91 mov r0,#34h mov r1,#32h mov r5,#6 ;ret X0cbd: mov a,#0d8h call X0d98 jb Acc.7,X0cd9 djnz r5,X0cbd mov r2,#8 mov r3,#0deh ; R3.R2=2270 X0cc9: call R3R2_Add_6564 jb Acc.7,X0cd5 mov r0,#Flags mov a,@r0 jb Acc.7,X0cd5 B¸o c¸o khoa häc §Ò tµi KC07- 04 100 orl a,#20h mov @r0,a X0cd5: mov r0,#Flags mov a,@r0 ret ;============================================================ X0cd9: mov r0,#34h mov r1,#32h mov r5,#6 ;ret X0cdb: mov a,#0e6h call X0d98 jb Acc.7,X0cd5 djnz r5,X0cdb mov r2,#7dh mov r3,#0dch X0d98: add a,r7 mov r4,a X0d9a: call SubR0_R1 inc r0 inc r1 mov a,r2 ; Cong 2 byte R3.R2 + R4 add a,r4 mov a,r3 addc a,#0ffh ret ;============================================================== X0da5: call SubR0_R1 inc r0 inc r1 mov a,r2 ; Cong 2 byte R3.R2 + R4 add a,r4 ; Sau do nghich dao gia tri mov a,r3 addc a,#0 ret ;============================================================== SubR0_R1: mov a,@r1 cpl a add a,#1 mov r2,a inc r1 mov a,@r1 cpl a addc a,#0 mov r3,a call Add_R2_R3 ret ;============================================================== Add_R2_R3: mov a,@r0 add a,r2 mov r2,a inc r0 mov a,@r0 addc a,r3 mov r3,a ret ;============================================================== Cpl2Nor: mov a,r3 ; Dua R3 vao A, cpl a ; Dao gia tri jb Acc.7,X0de4 ; Neu bit 7=1 ( bit 7 cua R3=0) -> Gia tri 2 byte trong R2 (L) ; va R3 (H) la so duong (+) thi ket thuc mov a,r2 ; Nguoc lai R2.R3 la so Am (-) B¸o c¸o khoa häc §Ò tµi KC07- 04 101 cpl a add a,#1 mov r2,a mov a,r3 cpl a addc a,#80h ; Tien hanh doi sang so duong, bat bit dau =1 (<0) mov r3,a X0de4: ret ;======================================================== NapR3R2ToR0: mov a,r2 ; R2=5Eh mov @r0,a inc r0 mov a,r3 mov @r0,a ret ;======================================================== NapR3R2FromR0: mov a,@r0 mov r2,a inc r0 mov a,@r0 mov r3,a ret ;============================================================== R3R2_Add_6564: mov r0,#64h mov a,@r0 add a,r2 inc r0 mov a,@r0 addc a,r3 ret ;============================================================== R3R2_Add_3F3E: mov r0,#3eh mov a,@r0 add a,r2 inc r0 mov a,@r0 addc a,r3 ret ;======================================================== DecToOne: mov a,@r0 ; X0610 dec a mov @r0,a jnz DecEnd ; inc @r0 ; DecEnd: ret ;================================================================== Load_AC_to_R1: mov a,@r1 cpl a jnz X0e45 mov @r1,#0ach X0e45: ret ;============================================================== Add_3F3E_E0C0: mov r0,#3eh mov a,@r0 add a,#0c0h inc r0 mov a,@r0 addc a,#0e0h ret ;===================================================================== Doc7Eh: mov r0,#7eh B¸o c¸o khoa häc §Ò tµi KC07- 04 102 mov a,@r0 cpl a ret ;================================================================= Giam2Dh: mov r0,#2dh mov a,@r0 dec a ret ;============================================================== Change_Flags: mov r0,#Flags orl a,@r0 mov @r0,a ret ;===================================================================== X0f3e: call R3R2_Add_3F3E jb Acc.7, X0f4f mov r0,#3ah mov r1,#38h mov r5,#3 X0f49: call X0da5 jb Acc.7, X0f4f djnz r5,X0f49 i X0f4f: ret ;===================================================================== ; HOA DIEN ;===================================================================== CheDoHOA: ;call Flags2ACC mov r0,#Flags mov a,@r0 nop jb Acc.4,X0f5d mov r0,#LED4 ; Neu bit 4 =1 mov @r0,#1fh ; ROM(31Fh)=53h=0101.0011=fbap - Dau cham hoi ? clr a ret ;=========================================================== X0f5d: mov r0,#2ah mov @r0,#8 mov r0,#40h call NapR3R2FromR0 ; R2=(40h), R3=(41h) call Cpl2Nor ; Doi dang so bu sang Binh thuong mov a,#0ceh add a,r2 mov a,r3 addc a,#0ffh jb Acc.6,X0f91 mov r0,#42h call NapR3R2FromR0 ; R2=(42h), R3=(43h) mov a,r2 add a,#0e8h mov a,r3 addc a,#0ffh jb Acc.6,X0f91 mov r0,#7ah mov @r0,#4 mov r0,#77h mov a,@r0 dec a jnz X0f91 mov r4,#2 call So_Pha ; 0f8a ( R4=2 - Tre pha 1 ms) jb Acc.5, X0f91 jnz X0f94 ; Ngoai bit 5, neu A 0 -> lech pha lon call Doc7Eh ; Doc 7Eh, dao gia tri ; A=NOT(7Eh) B¸o c¸o khoa häc §Ò tµi KC07- 04 103 X0f91: clr a ret X0f93: inc r4 X0f94: mov a,r4 add a,#0fbh ; (R4) + FBh=251 jc X0f91 call So_Pha ; Neu Carry=0 -> R4 <= 4, goi So_Pha jb Acc.5,X0f91 ; Sau khi so pha, neu bit 5 =1 (???) -> Xoa ACC jnz X0f93 ; Ngoai bit 5, neu A 0 -> lech pha lon, tang R4 cho toi 4 mov a,r4 ; Neu A=0, tuc la lech pha nho add a,#0fch ; A= (R4) + (FCh=252) jb Acc.7,X0fa6 ; Neu bit (A.7)=1, tuc la r4 < 4 mov r4,#3 ; Neu R4 >= 4, thi R4=3 X0fa6: dec r4 mov a,r4 dec a nop jnz X0f94 mov r4,#7 jmp HOA_DIEN Chuan_Bi_Hoa: mov r0,#2dh ; R0=2Dh mov @r0,#0bh ; 0Bh=0000.1011 -> (2Dh) mov a,r6 ; R6=0dxn.0D0N jb Acc.6,Doc_Lap ; d=1 -> day do = 5v-> Che do chay doc lap mov r0,#2ah ; Che do chay trong luoi mov @r0,#6 ; 6 -> (2Ah) =0000.0110 Doc_Lap: mov r0,#77h mov @r0,#10h ; 10h -> (77h) mov r0,#7eh mov @r0,#0ffh ; FFh -> (7Eh) ;========================================================== ; Doc cong tac xac dinh co o vi tri HOA khong ;========================================================== mov p1,#0ffh nop mov a,p1 jb Acc.0,Khong_Hoa ; Day Nau = 5 V -> Khong phai che do hoa dien jb Acc.1,Khong_Hoa ; Sau khi dao, neu P4.1=1 -> Closedown call So_Pha ; Con lai, chinh la HOA DIEN jz HOA_DIEN ; Neu do lech pha nho Khong_Hoa: djnz r5,Chuan_Bi_Hoa ; Lap lai cho toi khi xay ra ngat Timer, chuong trinh se mov r3,#9ch ; duoc re sang nhanh khac. Ngat_Role2: call Ngat_Role djnz r2,Ngat_Role2 djnz r3,Ngat_Role2 clr a ; ACC=0 ret ;================================================================== HOA_DIEN: mov r1,#1dh mov @r1,#0 ; 0 -> (1Dh), chuan bi cho lan goi So pha sau mov LED4,#1Ch ; H mov LED3,#0 ; O mov LED2,#0Ah ; A mov LED1,#1Dh ; ! mov r3,#8 DongMachHoa: setb p3.1 ; Sync ON clr p3.0 clr p2.4 ; Close OFF setb p2.5 clr p2.6 ; Open OFF B¸o c¸o khoa häc §Ò tµi KC07- 04 104 setb p2.7 clr p3.4 ; Over Speed OFF setb p3.5 djnz r2,DongMachHoa djnz r3,DongMachHoa ; Thuc hien Hoa R3 = 8 lan djnz r4,HOA_DIEN ; (Truoc doan nay R4=7) mov r4,#2 ; mov r5,#2 ; jmp Chuan_Bi_Hoa ; Kiem tra lai trang thai cong tac MODE end B¸o c¸o khoa häc §Ò tµi KC07- 04 105 PHỤ LỤC II PHẦN MỀM ĐIỀU KHIỂN ĐIỀU TỐC ĐIỀU CHỈNH PHỤ TẢI ;*********************************************** ;* Chuong trinh dieu chinh tan so luoi doc lap * ;* dung tai gia Dummy load * ;* Dung thuat toan dieu khien theo PI * ;**************** Byte Address ***************** frq_counter equ 50h frq_counter1 equ 51h frq_counter2 equ 52h Err_frq equ 53h Pre_alpha1 equ 54h Pre_alpha2 equ 55h delay_T equ 56h Temp1 equ 57h Temp2 equ 58h Temp3 equ 59h Kp equ 60h ; cac thong so bo dieu khien Ki equ 61h T equ 62h Dload1_alp1 equ 66h ; Gia tri alpha tai 1 Dload1_alp2 equ 67h Dload2_alp1 equ 68h ; Gia tri alpha tai 2 Dload2_alp2 equ 69h Ketqua_PI equ 6Ah Ketqua_P equ 6Bh Ketqua_I equ 6Ch TongSaiLech equ 6Dh pulse_width1 equ 70h pulse_width2 equ 71h ;**************** Bit Address ****************** F_level bit 20h B¸o c¸o khoa häc §Ò tµi KC07- 04 106 F_edge bit 21h F_open1 bit 22h F_open2 bit 23h F_level_ bit 24h F_edge_ bit 25h F_frq_c bit 26h F_result bit 27h Err_sign bit 28h F_cut1 bit 29h F_cut2 bit 2ah SignTong bit 2bh Sign_PI bit 2ch ;************************************************ ORG 0000h ljmp MainProg ORG 000bh ljmp Isr_Timer0 ORG 001bh ljmp Isr_Timer1 ;************************************************ ;Isr_Timer0: dem tan so ( Tan so ngat 0.125ms) ;************************************************ Isr_Timer0: push psw push acc push dph push dpl jb P3.2,continue00 jb F_level,continue01 setb F_level setb F_edge mov frq_counter1,frq_counter mov frq_counter,#00h B¸o c¸o khoa häc §Ò tµi KC07- 04 107 jnb F_frq_c,continue01 ; mov a,frq_counter1 jz continue01 clr F_frq_c setb F_result mov frq_counter2,frq_counter1 ajmp continue01 continue00: clr F_level continue01: jnb F_edge,continue02 clr c inc frq_counter jnc continue02 mov frq_counter,#255 continue02: jb F_cut1,continue04 mov a,frq_counter clr c subb a,Dload1_alp1 jnz continue03 setb F_open1 ajmp continue04 continue03: mov a,frq_counter clr c subb a,Dload1_alp2 jnz continue04 setb F_open1 ajmp continue05 continue04: jb F_cut2,continue06 mov a,frq_counter clr c subb a,Dload2_alp1 B¸o c¸o khoa häc §Ò tµi KC07- 04 108 jnz continue05 setb F_open2 ajmp continue06 continue05: jb F_cut2,continue06 mov a,frq_counter clr c subb a,Dload2_alp2 jnz continue06 setb F_open2 continue06: jnb F_open1,continue07 inc pulse_width1 clr c mov P2.5,c nop mov a,pulse_width1 cjne a,#2,continue07 nop setb c mov P2.5,c clr F_open1 mov pulse_width1,#00h continue07: jnb F_open2,Esc_Timer0 inc pulse_width2 clr c mov P2.6,c nop mov a,pulse_width2 cjne a,#2,Esc_Timer0 nop setb c mov P2.6,c clr F_open2 B¸o c¸o khoa häc §Ò tµi KC07- 04 109 mov pulse_width2,#00h Esc_Timer0: pop dpl pop dph pop acc pop psw reti ;================================================ ;Isr_Timer1: chu ky do tan so ( thoi gian 20ms) ;================================================ Isr_Timer1: mov TH1,#0B1h mov TL1,#0DFh push psw push acc push dph push dpl jnb F_result,delay_circ clr F_result mov a,frq_counter2 clr c subb a,#160 jc con00 mov Err_frq,a setb Err_sign ajmp con01 con00: mov a,#160 clr c subb a,frq_counter2 mov Err_frq,a clr Err_sign con01: lcall PI_controller delay_circ: B¸o c¸o khoa häc §Ò tµi KC07- 04 110 inc delay_T mov a,delay_T clr c subb a,T jnz Esc_Timer1 setb F_frq_c mov delay_T,#00 Esc_Timer1: pop dpl pop dph pop acc pop psw reti ;************************************************************************* ;PI_controller: ;************************************************************************* PI_controller: mov a, #16 clr c subb a,Err_frq jnc Err_adj mov Err_frq,#16 ajmp PI_tinhtoan Err_adj: mov a,Err_frq clr c subb a,#01 jc Err_nho jz Err_nho ajmp PI_tinhtoan Err_nho: ajmp Ket_thuc PI_tinhtoan: B¸o c¸o khoa häc §Ò tµi KC07- 04 111 mov r5,Kp mov a,#0 LapP: add a,Err_frq djnz r5,LapP mov Ketqua_P,a TinhTongSaiLech: mov a,TongSaiLech jb SignTong,TongDuong jb Err_sign,Tru1 ajmp Cong1 TongDuong: jnb Err_sign,Tru1 Cong1: clr c add a,Err_frq mov TongSaiLech,a clr c subb a,#24 jc Tran1 ajmp ThanhPhan_I Tran1: mov TongSaiLech,#24 ajmp ThanhPhan_I Tru1: clr c subb a,Err_frq jc DoiDauTong mov TongSaiLech,a ajmp ThanhPhan_I DoiDauTong: mov a,Err_frq subb a,TongSaiLech mov TongSaiLech,a cpl SignTong B¸o c¸o khoa häc §Ò tµi KC07- 04 112 ThanhPhan_I: mov r5,Ki mov a,#0 LapI: add a,TongSaiLech djnz r5,LapI mov Ketqua_I,a TongPI: mov a,Ketqua_P jb Err_sign,TruP CongP: clr Sign_PI jb SignTong,TruI ajmp CongI TruP: setb Sign_PI jnb SignTong,TruI CongI: clr c add a,Ketqua_I mov Ketqua_PI,a ajmp DieuKhien TruI: clr c subb a,Ketqua_I jc Doidau mov Ketqua_PI,a ajmp DieuKhien Doidau: mov a,Ketqua_I subb a,Ketqua_P mov Ketqua_PI,a cpl Sign_PI DieuKhien: B¸o c¸o khoa häc §Ò tµi KC07- 04 113 mov a,frq_counter2 mov Temp2,a mov Temp1,a mov a,Temp2 rrc a mov Temp3,a jb Err_sign,GiamTai2 TangTai1: mov a,Pre_Alpha1 clr c subb a,Ketqua_PI jc MoHoanToan1 mov Pre_Alpha1,a clr c subb a,#03 jc MoHoanToan1 ajmp TangTai2 MoHoanToan1: mov Pre_Alpha1,#3 TangTai2: clr F_Cut2 mov a,Temp3 clr c subb a,Pre_Alpha1 jc HetTangTai mov a,Pre_Alpha2 clr c subb a,Ketqua_PI jc MoHoanToan2 mov Pre_Alpha2,a clr c subb a,#03 jc MoHoanToan2 ajmp Alpha_charge B¸o c¸o khoa häc §Ò tµi KC07- 04 114 HetTangTai: mov Pre_Alpha2,Temp1 setb F_cut2 ajmp Alpha_charge MoHoanToan2: mov Pre_Alpha2,#3 ajmp Alpha_charge GiamTai2: clr F_cut2 mov a,Pre_Alpha2 clr c add a,KetQua_PI jc DongHoanToan2 mov Pre_Alpha2,a clr c subb a,Temp1 jnc DongHoanToan2 ajmp GiamTai1 DongHoanToan2: mov Pre_Alpha2,Temp1 setb F_cut2 GiamTai1: mov a,Pre_Alpha2 clr c subb a,Temp3 jc Alpha_charge mov a,Pre_Alpha1 clr c add a,KetQua_PI jc DongHoanToan1 mov Pre_Alpha1,a clr c B¸o c¸o khoa häc §Ò tµi KC07- 04 115 subb a,Temp1 jnc DongHoanToan1 clr F_cut1 ajmp Alpha_charge DongHoanToan1: mov Pre_Alpha1,Temp1 setb F_cut1 Alpha_charge: jb F_cut1,cont01 mov a,Pre_Alpha1 clr c add a,temp2 mov Dload1_alp2,a mov Dload1_alp1,Pre_Alpha1 cont01: jb F_cut2,Ket_thuc mov a,Pre_Alpha2 clr c add a,temp2 mov Dload2_alp2,a mov Dload2_alp1,Pre_Alpha2 ajmp Ket_thuc Ket_thuc: ret ;=============================================== ;Doc_Sw: ;=============================================== Doc_Sw: clr c mov P3.6,c mov P3.7,c nop nop B¸o c¸o khoa häc §Ò tµi KC07- 04 116 nop nop mov a,P1 cpl a add a,#1 mov T,a clr c mov P3.6,c setb c mov P3.7,c nop nop nop nop mov a,P1 cpl a add a,#1 mov Kp,a mov P0,a setb c mov P3.6,c clr c mov P3.7,c nop nop nop nop mov a,P1 cpl a mov Ki,a ret ;*********************************************** ; Main program ;*********************************************** MainProg: mov P2,#0 setb c mov P2.5,c ; Tat tat ca tai (Load-off) B¸o c¸o khoa häc §Ò tµi KC07- 04 117 mov P2.6,c mov P1,#0FFh mov frq_counter,#00h ; Khoi tao cac bien clr F_level ; Khoi tao cac flag clr F_edge clr F_result setb F_cut1 ; Cam tai setb F_cut2 ; setb F_frq_c ; Cho phep do tan so mov Pre_alpha1,#77 mov Pre_alpha2,#77 mov Dload1_alp1,#75 mov Dload1_alp2,#155 mov Dload2_alp1,#75 mov Dload2_alp2,#155 lcall Doc_sw mov IE,#8Ah ; Khoi tao ngat Timer 0, Timer 1 mov TMOD,#12h mov TH0,#131 ; Dinh timer0 0.125ms mov TL0,#131 mov TH1,#0B1h ; Dinh timer1 20ms mov TL1,#0DFh setb PT0 ; Uu tien ngat Timer0 clr PT1 setb TR0 setb TR1 ; Vong lap chuong trinh Mainloop: nop ljmp Mainloop End

Các file đính kèm theo tài liệu này:

  • pdfNghiên cứu, thiết kế, chế tạo điều tốc cho các trạm thủy điện.pdf