Đồ án Rơle số bảo vệ cách điện

MỤC LỤC MỤC LỤC 1 CHƯƠNG I. ĐẶT VẤN ĐỀ VÀ VÀ NHIỆM VỤ THƯ 3 I. Đặt vấn đề 3 II. Các nhiệm vụ , chức năng của rơle số bảo vệ cách điện: 3 III.Nhiệm vụ cụ thể của Rơle số bảo vệ cách điện cho một động cơ tại nhà máy phân đạm Hà Bắc 4 CHƯƠNG 2:TỔNG QUAN VỀ RƠLE SỐ 5 I. Tổng quan về sự phát triển của Rơle số 5 II. Các chức năng của rơle số 6 2.1 .Chức năng đo lường : 6 2.2. Chức năng lấy mẫu và canh sự cố 7 2.3. Chức năng bảo vệ rơle và ghi chép sự cố 7 2.4. Chức năng chống sự cố 7 2.5. Chức năng tự động đóng lại 8 2.6. Chức năng giao tiếp với người dùng 8 III. Các chủng loại Rơle thành bộ ngày nay 8 3.1.Đường đây truyền tải 8 3.2. Đường dây phân phối 9 3.3. Bảo vệ mỏy biến ỏp 9 3.4. Bảo vệ môtơ 9 CHƯƠNG 3: THIẾT KẾ TỔNG QUÁT 10 I.Phương hướng giải quyết vấn đề 10 II.Giới thiệu về một số vi mạch dựng trong thiết bị 16 2.1 Vi điều khiển 89C52 16 2.3 Đồng hồ thời gian thực DS12887 34 CHƯƠNG 4:TÍNH TOÁN THIẾT KẾ CHI TIẾT 41 I.Tớnh toỏn thiết kế mạch đo: 41 II .Mạch số hoỏ: 43 III. Hiển thị kết quả đo: 45 IV. Bàn phím chức năng 49 V. EEPRROM 53 VI. Ghộp nối mỏy tớnh. 53 CHƯƠNG 5. THIẾT KẾ PHẦN MỀM 56 I. Lưu đồ thuật toán cho vi điều khiển: 56 1. Lưu đồ thuật toán cho chương trỡnh khởi tạo: 56 2. Lưu đồ chương trỡnh phục vụ ngắt phớm: 57 3. Lưu đồ chương trỡnh phục vụ phớm FUNC: 58 4. Lưu đồ chương trỡnh phục vụ phớm INC: 59 6. Lưu đồ chương trỡnh phục vụ phớm OK: 61 7. Chương trỡnh phục vụ ngắt RTC 62 8. Chương trỡnh phục vụ ngắt truyền tin 63 II.thiết kế giao diện trờn PC bằng Visual Basic: 1. Giao diện 2. lưu đồ chương trỡnh nhận bản tin của mỏy tớnh CHƯƠNG 6: CHẠY THỬ, ĐÁNH GIÁ KẾT QUẢ PHỤ LỤC: I. Chương trỡnh phần mềm cho vi điều khiển của Rơle số bảo vệ cách điện. II. Chương trỡnh phần mềm cho Giao diện trờn PC với rơle cách điện. III. Tài liệu tham khảo. Lời nói đầu: Ngày nay, sự phát triển của công nghệ vi điện tử, kỹ thuật vi xử lý đó tạo ra những bước ngoặt cho quá trỡnh tự động hoá sản xuất cũng như các hoạt động xó hội khỏc. Điều này đó mang lại những lợi ớch to lớn: mở rộng chức năng của hệ thống, nâng cao độ tin cậy, giảm giá thành sản phẩm. Tuy nhiên, việc triển khai ứng dụng những tiến bộ nói trên vào nước ta cũn nhiều hạn chế. Việc nghiờn cứu thiết kế những thiết bị sử dụng những tiến bộ này là cần thiết. Em thực hiện đồ án nghiên cứu và thiết kế Rơle số bảo vệ cách điện sử dụng Vi điều khiển với sự hướng dẫn của PGS. Nguyễn Bỡnh Thành và ThS.Trần Văn Tuấn. Nhằm mục đích khẳng lại định những kiến thức lý thuyết đó học bằng thực tế nõng cao kỹ năng kinh nghiệm thiết kế. Do thời gian ngắn và kinh nghiệm bản thõn cũn hạn chế nờn đề tài chắc chắn không tránh khỏi những thiếu sót, rất mong được sự góp ý từ phớa thầy cụ và cỏc bạn. Em xin chân thành cảm ơn sự giúp đỡ tận tỡnh của cỏc thầy, cụ trong bộ mụn và cỏc bạn đó giỳp em hoàn thành đồ án.

doc124 trang | Chia sẻ: lvcdongnoi | Ngày: 14/06/2013 | Lượt xem: 2155 | Lượt tải: 2download
Bạn đang xem nội dung tài liệu Đồ án Rơle số bảo vệ cách điện, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
tam chan ra data 922 0623 C295 clr Clock ;xoa tam chan ra clock 923 0625 C3 clr C 924 0626 7E04 mov r6,#04h ;so digit duoc dua ra LED 925 Next_Byte: 926 0628 7F08 mov r7,#08h ;so lan quay bit trong acc 927 062A E7 mov a,@r1 928 062B 09 inc r1 929 Next_Bit: 930 062C 33 rlc a 931 062D 9296 mov Data,C ;dua data ra P2.4 (noi voi chan D of 4094) 932 062F D295 setb Clock ;dung xung clk (Chan Clk of 4094) 933 0631 00 nop ;tao do rong xung clk 934 0632 00 nop 935 0633 C295 clr Clock ;ha xung clock 936 0635 00 nop 937 0636 DFF4 djnz r7,Next_Bit ;Dua ra het 1 digit(8 bit) thi 938 ;chuyen sang digit tiep theo 939 0638 DEEE djnz r6,Next_Byte ;Dua ra het 4 digit thi dung 940 063A 22 ret 941 ;==================================================== 942 BCDto7thanh: 943 063B E50C mov a,digit4 944 063D 12065F lcall Trabang 945 0640 F50C mov digit4,a 946 947 0642 E50B mov a,digit3 948 0644 12065F lcall Trabang 949 0647 F50B mov digit3,a 950 951 0649 E50A mov a,digit2 952 064B 12065F lcall Trabang 953 064E F50A mov digit2,a 954 955 0650 E509 mov a,digit1 956 0652 12065F lcall Trabang 957 0655 F509 mov digit1,a 958 959 0657 E508 mov a,digit0 960 0659 12065F lcall Trabang 961 065C F508 mov digit0,a 962 065E 22 ret 963 ;======================== 964 Trabang: 965 065F C083 push dph 966 0661 C082 push dpl 967 0663 90066C mov dptr,#Table 968 0666 93 movc a,@a+dptr 969 0667 D082 pop dpl 970 0669 D083 pop dph 971 066B 22 ret 972 Table: 973 066C C0 db 0C0h ; 0 974 066D F9 db 0F9h ; 1 975 066E A4 db 0A4h ; 2 976 066F B0 db 0B0h ; 3 977 0670 99 db 99h ; 4 978 0671 92 db 92h ; 5 979 0672 82 db 82h ; 6 980 0673 F8 db 0F8h ; 7 981 0674 80 db 80h ; 8 982 0675 90 db 90h ; 9 983;============================================ 984 ;=================================================== 985 ;CHUONG TRINH PHUC VU NGAT PHIM 986 ;Thuc hien thay doi cac thong so cac che do chay cua role 987 ;Ghi lai cac thong so do vao RAM cua RTC 988 ;Doc CSDL trong EEPROM 989 ;====================================== 990 KEY_Srv: 991 0676 C2AF clr EA ;cam cac ngat khac 992 0678 7414 mov a,#20 ;tre 15ms de chong nhieu phim 993 067A 12100B lcall delay_ms 994 ;doc ma phim: 995 067D D290 setb p1.0 996 067F D291 setb p1.1 997 0681 E590 mov a,p1 998 0683 5403 anl a,#03h 999 ;giai ma phim: 1000 0685 B40005 cjne a,#00h,notfunc 1001 0688 1206AA lcall funckey 1002 068B 8016 sjmp kt 1003 notfunc: 1004 068D B40105 cjne a,#01h,notinc 1005 0690 120B04 lcall inckey 1006 0693 800E sjmp kt 1007 notinc: 1008 0695 B40205 cjne a,#02h,notdec 1009 0698 120C35 lcall deckey 1010 069B 8006 sjmp kt 1011 notdec: 1012 069D B40303 cjne a,#03h,kt 1013 06A0 120D67 lcall okkey 1014 kt: 1015 06A3 90400C mov dptr,#400ch 1016 06A6 E0 movx a,@dptr ;doc thanh ghi C de xoa co UF o RTC. 1017 06A7 D2AF setb EA 1018 06A9 32 reti 1019 ;================================ 1020 funckey: 1021 06AA 74FF mov a,#255 ;tre 255ms de chong nhieu phim 1022 06AC 12100B lcall delay_ms 1023 06AF 7401 mov a,#ClearDsp 1024 06B1 120E61 lcall writecommand 1025 1026 06B4 056C inc func_reg 1027 06B6 E56C mov a,func_reg 1028 1029 06B8 B40C07 cjne a,#0ch,not_run 1030 06BB 756C01 mov func_reg,#01h 1031 06BE 120708 lcall run 1032 06C1 22 ret 1033 not_run: 1034 06C2 B40204 cjne a,#02h,not_stop 1035 06C5 120749 lcall stop 1036 06C8 22 ret 1037 not_stop: 1038 06C9 B40304 cjne a,#03h,not_sethour 1039 06CC 12075D lcall sethour 1040 06CF 22 ret 1041 not_sethour: 1042 06D0 B40404 cjne a,#04h,not_setmin 1043 06D3 12079A lcall setmin 1044 06D6 22 ret 1045 not_setmin: 1046 06D7 B40504 cjne a,#05h,not_setday 1047 06DA 1207D9 lcall setday 1048 06DD 22 ret 1049 not_setday: 1050 06DE B40604 cjne a,#06h,not_setmonth 1051 06E1 120815 lcall setmonth 1052 06E4 22 ret 1053 not_setmonth: 1054 06E5 B40704 cjne a,#07h,not_setyear 1055 06E8 120853 lcall setyear 1056 06EB 22 ret 1057 not_setyear: 1058 06EC B40804 cjne a,#08h,not_setmode 1059 06EF 120890 lcall setmode 1060 06F2 22 ret 1061 not_setmode: 1062 06F3 B40904 cjne a,#09h,not_setU0 1063 06F6 1208EB lcall setU0 1064 06F9 22 ret 1065 not_setU0: 1066 06FA B40A04 cjne a,#0ah,not_setRp 1067 06FD 12093E lcall setRp 1068 0700 22 ret 1069 not_setRp: 1070 0701 B40B03 cjne a,#0bh,Ignore 1071 0704 120988 lcall xemsuco 1072 Ignore: 1073 0707 22 ret 1074;=============================== 1075 run: 1076 0708 D201 setb runf 1077 070A 7400 mov a,#00h 1078 070C 120E57 lcall placecursor 1079 070F 120EA4 lcall prtLCD 1080 0712 46312052 db "F1 Run Rcd= ",0h 756E2052 63643D20 20202020 20202020 00 1081 0727 7440 mov a,#40h 1082 0729 120E57 lcall placecursor 1083 072C 120EA4 lcall prtLCD 1084 072F 20202020 db " - - ",0h ; Vd:"10:25 14-02-04 " 20202020 2D20202D 20202020 20202020 00 1085 1086 0744 90400C mov dptr,#400ch 1087 0747 E0 movx a,@dptr ;doc thanh ghi C de xoa co UF. 1088 0748 22 ret 1089 ;=================================== 1090 stop: 1091 0749 C201 clr runf 1092 074B 7400 mov a,#00h 1093 074D 120E57 lcall placecursor 1094 0750 120EA4 lcall prtLCD 1095 0753 46322020 db "F2 Stop",0h 53746F70 00 1096 075C 22 ret 1097 ;================================== 1098 sethour: 1099 075D 7400 mov a,#00h 1100 075F 120E57 lcall placecursor 1101 0762 120EA4 lcall prtLCD 1102 0765 46332053 db "F3 Set hour:",0h 65742068 6F75723A 00 1103 Hiengio: 1104 0772 7440 mov a,#40h 1105 0774 120E57 lcall placecursor 1106 0777 120EA4 lcall prtLCD 1107 077A 20486F75 db " Hour= ? ",0h 723D2020 203F2020 20202020 20202020 00 1108 078F 7447 mov a,#47h 1109 0791 120E57 lcall placecursor 1110 0794 E55C mov a,hour_reg 1111 0796 120EBA lcall Hien_2digit 1112 0799 22 ret 1113 ;========================== 1114 setmin: 1115 079A 7400 mov a,#00h 1116 079C 120E57 lcall placecursor 1117 079F 120EA4 lcall prtLCD 1118 07A2 46342053 db "F4 Set minute:",0h 6574206D 696E7574 653A00 1119 Hienphut: 1120 07B1 7440 mov a,#40h 1121 07B3 120E57 lcall placecursor 1122 07B6 120EA4 lcall prtLCD 1123 07B9 204D696E db " Min= ? ",0h 3D202020 3F202020 20202020 20202020 00 1124 07CE 7446 mov a,#46h 1125 07D0 120E57 lcall placecursor 1126 07D3 E55B mov a,min_reg 1127 07D5 120EBA lcall Hien_2digit 1128 07D8 22 ret 1129 ;========================== 1130 setday: 1131 07D9 7400 mov a,#00h 1132 07DB 120E57 lcall placecursor 1133 07DE 120EA4 lcall prtLCD 1134 07E1 46352053 db "F5 Set day:",0h 65742064 61793A00 1135 Hienngay: 1136 07ED 7440 mov a,#40h 1137 07EF 120E57 lcall placecursor 1138 07F2 120EA4 lcall prtLCD 1139 07F5 20446179 db " Day= ? ",0h 3D202020 3F202020 20202020 20202020 00 1140 080A 7446 mov a,#46h 1141 080C 120E57 lcall placecursor 1142 080F E55D mov a,day_reg 1143 0811 120EBA lcall Hien_2digit 1144 0814 22 ret 1145 ;================================ 1146 setmonth: 1147 0815 7400 mov a,#00h 1148 0817 120E57 lcall placecursor 1149 081A 120EA4 lcall prtLCD 1150 081D 46362053 db "F6 Set month:",0h 6574206D 6F6E7468 3A00 1151 Hienthang: 1152 082B 7440 mov a,#40h 1153 082D 120E57 lcall placecursor 1154 0830 120EA4 lcall prtLCD 1155 0833 204D6F6E db " Month= ? ",0h 74683D20 20203F20 20202020 20202020 00 1156 0848 7448 mov a,#48h 1157 084A 120E57 lcall placecursor 1158 084D E55E mov a,month_reg 1159 084F 120EBA lcall Hien_2digit 1160 0852 22 ret 1161;================================ 1162 setyear: 1163 0853 7400 mov a,#00h 1164 0855 120E57 lcall placecursor 1165 0858 120EA4 lcall prtLCD 1166 085B 46372053 db "F7 Set year:",0h 65742079 6561723A 00 1167 Hiennam: 1168 0868 7440 mov a,#40h 1169 086A 120E57 lcall placecursor 1170 086D 120EA4 lcall prtLCD 1171 0870 20596561 db " Year= ? ",0h 723D2020 203F2020 20202020 20202020 00 1172 0885 7447 mov a,#47h 1173 0887 120E57 lcall placecursor 1174 088A E55F mov a,year_reg 1175 088C 120EBA lcall Hien_2digit 1176 088F 22 ret 1177 ;=========================== 1178 setmode: 1179 0890 7401 mov a,#ClearDsp 1180 0892 120E61 lcall writecommand 1181 1182 0895 904010 mov dptr,#4010h 1183 0898 E0 movx a,@dptr 1184 0899 13 rrc a 1185 089A 9202 mov mode,c 1186 1187 089C 7400 mov a,#00h 1188 089E 120E57 lcall placecursor 1189 08A1 120EA4 lcall prtLCD 1190 08A4 46382053 db "F8 Set mode:",0h 6574206D 6F64653A 00 1191 Hienmode: 1192 08B1 7442 mov a,#42h 1193 08B3 120E57 lcall placecursor 1194 08B6 200219 jb mode,doclap 1195 08B9 120EA4 lcall prtLCD 1196 08BC 20436861 db " Chay theo? ",0h 79207468 656F3F20 20202020 20202020 00 1197 08D1 22 ret 1198 doclap: 1199 08D2 120EA4 lcall prtLCD 1200 08D5 20436861 db " Chay doc lap? ",0h 7920646F 63206C61 703F2020 20202020 00 1201 08EA 22 ret 1202 ;========================= 1203 setU0: 1204 08EB 904011 mov dptr,#4011h 1205 08EE E0 movx a,@dptr 1206 08EF F562 mov U0hi,a 1207 08F1 A3 inc dptr 1208 08F2 E0 movx a,@dptr 1209 08F3 F563 mov U0lo,a 1210 1211 08F5 20023F jb mode,chay_doclap 1212 08F8 7400 mov a,#00h 1213 08FA 120E57 lcall placecursor 1214 08FD 120EA4 lcall prtLCD 1215 0900 46392053 db "F9 Set U0:",0h 65742055 303A00 1216 HienU0: 1217 090B 7440 mov a,#40h 1218 090D 120E57 lcall placecursor 1219 0910 120EA4 lcall prtLCD 1220 0913 2055303D db " U0= V? ",0h 20202020 20202056 3F202020 20202020 00 1221 0928 856273 mov bytehi,U0hi 1222 092B 856372 mov bytelo,U0lo 1223 092E 120EF9 lcall hextodec 1224 0931 7F45 mov r7,#45h 1225 0933 120ED9 lcall display5d 1226 0936 22 ret 1227 chay_doclap: 1228 0937 756C0B mov func_reg,#0bh 1229 093A 020988 ljmp xemsuco 1230 093D 22 ret 1231 ;======================== 1232 setRp: 1233 093E 904013 mov dptr,#4013h 1234 0941 E0 movx a,@dptr 1235 0942 F560 mov Rphi,a 1236 0944 A3 inc dptr 1237 0945 E0 movx a,@dptr 1238 0946 F561 mov Rplo,a 1239 1240 0948 7400 mov a,#00h 1241 094A 120E57 lcall placecursor 1242 094D 120EA4 lcall prtLCD 1243 0950 46313020 db "F10 Set Rp:",0h 53657420 52703A00 1244 HienRp: 1245 095C 7440 mov a,#40h 1246 095E 120E57 lcall placecursor 1247 0961 120EA4 lcall prtLCD 1248 0964 2052703D db " Rp= k? ",0h 20202020 2020206B 3F202020 20202020 00 1249 0979 856073 mov bytehi,Rphi 1250 097C 856172 mov bytelo,Rplo 1251 097F 120EF9 lcall hextodec 1252 0982 7F45 mov r7,#45h 1253 0984 120ED9 lcall display5d 1254 0987 22 ret 1255 ;=========================== 1256 xemsuco: 1257 0988 7400 mov a,#00h 1258 098A 120E57 lcall placecursor 1259 098D 120EA4 lcall prtLCD 1260 0990 20205072 db " Press inc key or",0h 65737320 696E6320 6B657920 6F7200 1261 09A3 7440 mov a,#40h 1262 09A5 120E57 lcall placecursor 1263 09A8 120EA4 lcall prtLCD 1264 09AB 64656320 db "dec key to see fault",0h 6B657920 746F2073 65652066 61756C74 00 1265 09C0 74C8 mov a,#200 1266 09C2 12100B lcall delay_ms 1267 09C5 74C8 mov a,#200 1268 09C7 12100B lcall delay_ms 1269 09CA 74C8 mov a,#200 1270 09CC 12100B lcall delay_ms 1271 09CF 74C8 mov a,#200 1272 09D1 12100B lcall delay_ms 1273 09D4 74C8 mov a,#200 1274 09D6 12100B lcall delay_ms 1275 1276 09D9 904015 mov dptr,#4015h 1277 09DC E0 movx a,@dptr 1278 09DD F56A mov fpt_hi,a 1279 09DF A3 inc dptr 1280 09E0 E0 movx a,@dptr 1281 09E1 F56B mov fpt_lo,a 1282 1283 09E3 856A73 mov XH,fpt_hi 1284 09E6 856B72 mov XL,fpt_lo 1285 09E9 757700 mov YH,#00h 1286 09EC 757608 mov YL,#08h 1287 09EF 120FF7 lcall sub16 1288 09F2 857B6A mov fpt_hi,ZH 1289 09F5 857A6B mov fpt_lo,ZL 1290 1291 09F8 1209FF lcall Doc_CSDL 1292 1293 09FB 120A35 lcall HienCSDL 1294 09FE 22 ret 1295 ;========================= 1296 Doc_CSDL: 1297 09FF C0A0 push P2 1298 0A01 7C02 mov r4,#2 1299 Doclai: 1300 0A03 7B08 mov r3,#08h 1301 0A05 856AA0 mov p2,fpt_hi 1302 0A08 A86B mov r0,fpt_lo 1303 0A0A 790B mov r1,#digit3 1304 loop2: 1305 0A0C E2 movx a,@r0 1306 0A0D F7 mov @r1,a 1307 0A0E 09 inc r1 1308 0A0F 08 inc r0 1309 0A10 B80002 cjne r0,#00h,Ro_notfull 1310 0A13 05A0 inc P2 1311 Ro_notfull: 1312 0A15 DBF5 djnz r3,loop2 1313 0A17 00 nop 1314 0A18 DCE9 djnz r4,Doclai 1315 0A1A 850B5B mov min_reg,digit3 1316 0A1D 850C5C mov hour_reg,digit4 1317 0A20 850D5D mov day_reg,digit5 1318 0A23 850E5E mov month_reg,digit6 1319 0A26 850F5F mov year_reg,digit7 1320 0A29 851064 mov Rcdhi,digit8 1321 0A2C 851165 mov Rcdlo,digit9 1322 0A2F 851259 mov Ghichu,digit10 1323 0A32 D0A0 pop P2 1324 0A34 22 ret 1325 ;========================== 1326 HienCSDL: 1327 0A35 7401 mov a,#ClearDsp 1328 0A37 120E61 lcall writecommand 1329 0A3A 120EA4 lcall prtLCD 1330 0A3D 20203A20 db " : - - ",0h 20202020 2D20202D 20202020 20202020 00 1331 0A52 7440 mov a,#40h 1332 0A54 120E57 lcall placecursor 1333 0A57 120EA4 lcall prtLCD 1334 0A5A 5263643D db "Rcd= ",0h 20202020 20202020 20202020 20202020 00 1335 1336 0A6F 7400 mov a,#00h ;Hien thi gio hien tai 1337 0A71 120E57 lcall placecursor ;tren LCD 1338 0A74 E55C mov a,hour_reg 1339 0A76 120EBA lcall Hien_2digit 1340 1341 0A79 7403 mov a,#03h ;Hien thi phut hien tai 1342 0A7B 120E57 lcall placecursor ;tren LCD 1343 0A7E E55B mov a,min_reg 1344 0A80 120EBA lcall Hien_2digit 1345 1346 0A83 7406 mov a,#06h ;Hien thi ngay hien tai 1347 0A85 120E57 lcall placecursor ;tren LCD 1348 0A88 E55D mov a,day_reg 1349 0A8A 120EBA lcall Hien_2digit 1350 1351 1352 0A8D 7409 mov a,#09h ;Hien thi thang hien tai 1353 0A8F 120E57 lcall placecursor ;tren LCD 1354 0A92 E55E mov a,month_reg 1355 0A94 120EBA lcall Hien_2digit 1356 1357 0A97 740C mov a,#0ch ;Hien thi nam hien tai 1358 0A99 120E57 lcall placecursor ;tren LCD 1359 0A9C E55F mov a,year_reg 1360 0A9E 120EBA lcall Hien_2digit 1361 1362 0AA1 755A44 mov vitriLCD,#44h ;vi tri can hien tren LCD 1363 0AA4 12042D lcall HienRcd ;goi chuong trinh hien thi Rcd len LCD va LED 1364 1365 0AA7 856A73 mov bytehi,fpt_hi 1366 0AAA 856B72 mov bytelo,fpt_lo 1367 0AAD 120EF9 lcall hextodec 1368 0AB0 7F0F mov r7,#0fh 1369 0AB2 120ED9 lcall display5d 1370 0AB5 744A mov a,#4ah 1371 0AB7 120E57 lcall placecursor 1372 0ABA A859 mov r0,Ghichu 1373 0ABC B8010F cjne r0,#01h,noAT 1374 0ABF 120EA4 lcall prtLCD 1375 0AC2 20202053 db " SAFE ",0h 41464520 202000 1376 0ACD 22 ret 1377 noAT: 1378 0ACE B8020F cjne r0,#02h,noCB 1379 0AD1 120EA4 lcall prtLCD 1380 0AD4 20205741 db " WARNING ",0h 524E494E 472000 1381 0ADF 22 ret 1382 noCB: 1383 0AE0 B8030F cjne r0,#03h,noSCD 1384 0AE3 120EA4 lcall prtLCD 1385 0AE6 4641554C db "FAULT STOP",0h 54205354 4F5000 1386 0AF1 22 ret 1387 noSCD: 1388 0AF2 B8040E cjne r0,#04h,noSCC 1389 0AF5 120EA4 lcall prtLCD 1390 0AF8 4641554C db "FAULT RUN ",0h 54205255 4E2000 1391 noSCC: 1392 0B03 22 ret 1393;=============================== 1394;============================== 1395 inckey: 1396 0B04 E56C mov a,func_reg 1397 ;kiem tra xem o function nao 1398 0B06 B40304 cjne a,#03h,no_inchour 1399 0B09 120B45 lcall inchour 1400 0B0C 22 ret 1401 no_inchour: 1402 0B0D B40404 cjne a,#04h,no_incmin 1403 0B10 120B53 lcall incmin 1404 0B13 22 ret 1405 no_incmin: 1406 0B14 B40504 cjne a,#05h,no_incday 1407 0B17 120B61 lcall incday 1408 0B1A 22 ret 1409 no_incday: 1410 0B1B B40604 cjne a,#06h,no_incmonth 1411 0B1E 120B6F lcall incmonth 1412 0B21 22 ret 1413 no_incmonth: 1414 0B22 B40704 cjne a,#07h,no_incyear 1415 0B25 120B7D lcall incyear 1416 0B28 22 ret 1417 no_incyear: 1418 0B29 B40804 cjne a,#08h,no_incmode 1419 0B2C 120B8B lcall incmode 1420 0B2F 22 ret 1421 no_incmode: 1422 0B30 B40904 cjne a,#09h,no_incU0 1423 0B33 120B91 lcall incU0 1424 0B36 22 ret 1425 no_incU0: 1426 0B37 B40A04 cjne a,#0ah,no_incRp 1427 0B3A 120BC2 lcall incRp 1428 0B3D 22 ret 1429 no_incRp: 1430 0B3E B40B03 cjne a,#0bh,Ign_inc 1431 0B41 120BF3 lcall nextfault 1432 Ign_inc: 1433 0B44 22 ret 1434 ;======================= 1435 inchour: 1436 0B45 055C inc hour_reg 1437 0B47 E55C mov a,hour_reg 1438 0B49 B41803 cjne a,#24,hienho 1439 0B4C 755C00 mov hour_reg,#0 1440 hienho: 1441 0B4F 120772 lcall Hiengio 1442 0B52 22 ret 1443 ;======================== 1444 incmin: 1445 0B53 055B inc min_reg 1446 0B55 E55B mov a,min_reg 1447 0B57 B43C03 cjne a,#60,hienmi 1448 0B5A 755B00 mov min_reg,#0 1449 hienmi: 1450 0B5D 1207B1 lcall Hienphut 1451 0B60 22 ret 1452 ;========================== 1453 incday: 1454 0B61 055D inc day_reg 1455 0B63 E55D mov a,day_reg 1456 0B65 B42003 cjne a,#32,hienda 1457 0B68 755D01 mov day_reg,#1 1458 hienda: 1459 0B6B 1207ED lcall Hienngay 1460 0B6E 22 ret 1461 ;=========================== 1462 incmonth: 1463 0B6F 055E inc month_reg 1464 0B71 E55E mov a,month_reg 1465 0B73 B40D03 cjne a,#13,hienmon 1466 0B76 755E01 mov month_reg,#1 1467 hienmon: 1468 0B79 12082B lcall Hienthang 1469 0B7C 22 ret 1470 ;========================== 1471 incyear: 1472 0B7D 055F inc year_reg 1473 0B7F E55F mov a,year_reg 1474 0B81 B46403 cjne a,#100,hienye 1475 0B84 755F00 mov year_reg,#0 1476 hienye: 1477 0B87 120868 lcall Hiennam 1478 0B8A 22 ret 1479 ;============================ 1480 incmode: 1481 0B8B B202 cpl mode 1482 0B8D 1208B1 lcall Hienmode 1483 0B90 22 ret 1484 ;============================ 1485 incU0: 1486 0B91 856273 mov XH,U0hi ;Moi lan nhan phim inc U0 duoc tang 1487 0B94 856372 mov XL,U0lo ;1V (ta phai su dung chuong trinh 1488 0B97 757700 mov YH,#00h ;add16 vi U0 chua trong 2 byte) 1489 0B9A 757601 mov YL,#01h 1490 0B9D 120FE7 lcall add16 1491 0BA0 857B62 mov U0hi,ZH ;Luu ket qua Z->U0 1492 0BA3 857A63 mov U0lo,ZL 1493 1494 0BA6 857B73 mov XH,ZH ;kiem tra xem U0 da tang qua gia 1495 0BA9 857A72 mov XL,ZL ;tri max chua 1496 0BAC 757701 mov YH,#01h ;(max of U0 =500V =>01F4h) 1497 0BAF 7576F5 mov YL,#0F5h 1498 0BB2 120FF7 lcall sub16 1499 0BB5 200006 jb ZOV,okinc_U0 ;Neu da lon hon gia tri max thi dua 1500 0BB8 756200 mov U0hi,#00h ;ve gia tri min(min of U0=250V=>00FAh) 1501 0BBB 7563FA mov U0lo,#0FAh 1502 okinc_U0: 1503 0BBE 12090B lcall HienU0 ;Sau khi tang xong goi chuong trinh hien 1504 0BC1 22 ret ;thi U0 len LCD 1505 1506 ;============================= 1507 incRp: 1508 0BC2 856073 mov XH,Rphi ;Moi lan nhan phim inc Rp duoc tang 1509 0BC5 856172 mov XL,Rplo ;1k (ta phai su dung chuong trinh 1510 0BC8 757700 mov YH,#00h ;add16 vi Rp chua trong 2 byte) 1511 0BCB 757601 mov YL,#01h 1512 0BCE 120FE7 lcall add16 1513 0BD1 857B60 mov Rphi,ZH ;Luu ket qua Z->Rp 1514 0BD4 857A61 mov Rplo,ZL 1515 1516 0BD7 857B73 mov XH,ZH ;kiem tra xem Rp da tang qua gia 1517 0BDA 857A72 mov XL,ZL ;tri max chua 1518 0BDD 757703 mov YH,#03h ;(max of Rp =1000k =>03E8h) 1519 0BE0 7576E9 mov YL,#0E9h 1520 0BE3 120FF7 lcall sub16 1521 0BE6 200006 jb ZOV,okinc_Rp ;Neu da lon hon gia tri max thi dua 1522 0BE9 756002 mov Rphi,#02h ;ve gia tri min(min of Rp =600k =>0258h) 1523 0BEC 756158 mov Rplo,#58h 1524 okinc_Rp: 1525 0BEF 12095C lcall HienRp ;Sau khi tang xong goi chuong trinh hien 1526 0BF2 22 ret ;thi Rp len LCD 1527 ;============================= 1528 nextfault: 1529 0BF3 856A73 mov XH,fpt_hi 1530 0BF6 856B72 mov XL,fpt_lo 1531 0BF9 757700 mov YH,#00h 1532 0BFC 757608 mov YL,#08h 1533 0BFF 120FE7 lcall add16 1534 0C02 857B6A mov fpt_hi,ZH 1535 0C05 857A6B mov fpt_lo,ZL 1536 1537 0C08 857B73 mov XH,ZH ;kiem tra xem fpt da tang qua gia 1538 0C0B 857A72 mov XL,ZL ;tri max chua 1539 0C0E 75778F mov YH,#8fh 1540 0C11 7576FF mov YL,#0ffh 1541 0C14 120FF7 lcall sub16 1542 0C17 200006 jb ZOV,okinc_fpt 1543 0C1A 756A80 mov fpt_hi,#80h 1544 0C1D 756B00 mov fpt_lo,#00h 1545 okinc_fpt: 1546 0C20 856A73 mov bytehi,fpt_hi 1547 0C23 856B72 mov bytelo,fpt_lo 1548 0C26 120EF9 lcall hextodec 1549 0C29 7F0E mov r7,#0eh 1550 0C2B 120ED9 lcall display5d 1551 1552 0C2E 1209FF lcall Doc_CSDL 1553 1554 0C31 120A35 lcall HienCSDL 1555 0C34 22 ret 1556 ;============================== 1557 deckey: 1558 0C35 E56C mov a,func_reg 1559 ;kiem tra xem o function nao: 1560 1561 0C37 B40304 cjne a,#03h,no_dechour 1562 0C3A 120C76 lcall dechour 1563 0C3D 22 ret 1564 no_dechour: 1565 0C3E B40404 cjne a,#04h,no_decmin 1566 0C41 120C85 lcall decmin 1567 0C44 22 ret 1568 no_decmin: 1569 0C45 B40504 cjne a,#05h,no_decday 1570 0C48 120C93 lcall decday 1571 0C4B 22 ret 1572 no_decday: 1573 0C4C B40604 cjne a,#06h,no_decmonth 1574 0C4F 120CA1 lcall decmonth 1575 0C52 22 ret 1576 no_decmonth: 1577 0C53 B40704 cjne a,#07h,no_decyear 1578 0C56 120CAF lcall decyear 1579 0C59 22 ret 1580 no_decyear: 1581 0C5A B40804 cjne a,#08h,no_decmode 1582 0C5D 120CBD lcall decmode 1583 0C60 22 ret 1584 no_decmode: 1585 0C61 B40904 cjne a,#09h,no_decU0 1586 0C64 120CC3 lcall decU0 1587 0C67 22 ret 1588 no_decU0: 1589 0C68 B40A04 cjne a,#0ah,no_decRp 1590 0C6B 120CF4 lcall decRp 1591 0C6E 22 ret 1592 no_decRp: 1593 0C6F B40B03 cjne a,#0bh,Ign_dec 1594 0C72 120D25 lcall backfault 1595 Ign_dec: 1596 0C75 22 ret 1597 ;=========================== 1598 1599 dechour: 1600 0C76 155C dec hour_reg 1601 0C78 E55C mov a,hour_reg 1602 0C7A B4FF02 cjne a,#255,hienh 1603 0C7D 7417 mov a,#23 1604 hienh: 1605 0C7F F55C mov hour_reg,a 1606 0C81 120772 lcall Hiengio 1607 0C84 22 ret 1608 ;========================== 1609 decmin: 1610 0C85 155B dec min_reg 1611 0C87 E55B mov a,min_reg 1612 0C89 B4FF03 cjne a,#255,hienm 1613 0C8C 755B3B mov min_reg,#59 1614 hienm: 1615 0C8F 1207B1 lcall Hienphut 1616 0C92 22 ret 1617 ;============================ 1618 decday: 1619 0C93 155D dec day_reg 1620 0C95 E55D mov a,day_reg 1621 0C97 B40003 cjne a,#00h,hiend 1622 0C9A 755D1F mov day_reg,#31 1623 hiend: 1624 0C9D 1207ED lcall Hienngay 1625 0CA0 22 ret 1626 ;============================ 1627 decmonth: 1628 0CA1 155E dec month_reg 1629 0CA3 E55E mov a,month_reg 1630 0CA5 B40003 cjne a,#00h,hienmo 1631 0CA8 755E0C mov month_reg,#12 1632 hienmo: 1633 0CAB 12082B lcall Hienthang 1634 0CAE 22 ret 1635 ;========================== 1636 decyear: 1637 0CAF 155F dec year_reg 1638 0CB1 E55F mov a,year_reg 1639 0CB3 B4FF03 cjne a,#255,hieny 1640 0CB6 755F63 mov year_reg,#99 1641 hieny: 1642 0CB9 120868 lcall Hiennam 1643 0CBC 22 ret 1644 ;============================ 1645 decmode: 1646 0CBD B202 cpl mode 1647 0CBF 1208B1 lcall Hienmode 1648 0CC2 22 ret 1649 ;============================ 1650 decU0: 1651 0CC3 856273 mov XH,U0hi ;Moi lan nhan phim dec U0 duoc giam 1652 0CC6 856372 mov XL,U0lo ;1V (ta phai su dung chuong trinh 1653 0CC9 757700 mov YH,#00h ;sub16 vi U0 chua trong 2 byte) 1654 0CCC 757601 mov YL,#01h 1655 0CCF 120FF7 lcall sub16 1656 0CD2 857B62 mov U0hi,ZH ;Luu ket qua Z->U0 1657 0CD5 857A63 mov U0lo,ZL 1658 1659 0CD8 857B73 mov XH,ZH ;kiem tra xem U0 da giam qua gia 1660 0CDB 857A72 mov XL,ZL ;tri min chua 1661 0CDE 757700 mov YH,#00h ;(min of U0=250V=>00FAh) 1662 0CE1 7576FA mov YL,#0FAh 1663 0CE4 120FF7 lcall sub16 1664 0CE7 300006 jnb ZOV,okdec_U0 ;Neu da nho hon gia tri min thi dua 1665 0CEA 756201 mov U0hi,#01h ;ve gia tri max(max of U0 =500V =>01F4h) 1666 0CED 7563F4 mov U0lo,#0F4h 1667 okdec_U0: 1668 0CF0 12090B lcall HienU0 ;Sau khi giam xong goi chuong trinh hien 1669 0CF3 22 ret ;thi U0 len LCD 1670 1671 ;======================================= 1672 decRp: 1673 0CF4 856073 mov XH,Rphi ;Moi lan nhan phim dec Rp duoc giam 1674 0CF7 856172 mov XL,Rplo ;1k (ta phai su dung chuong trinh 1675 0CFA 757700 mov YH,#00h ;sub16 vi Rp chua trong 2 byte) 1676 0CFD 757601 mov YL,#01h 1677 0D00 120FF7 lcall sub16 1678 0D03 857B60 mov Rphi,ZH ;Luu ket qua Z->Rp 1679 0D06 857A61 mov Rplo,ZL 1680 1681 0D09 857B73 mov XH,ZH ;kiem tra xem Rp da giam qua gia 1682 0D0C 857A72 mov XL,ZL ;tri min chua 1683 0D0F 757702 mov YH,#02h ;(min of Rp =600k =>0258h) 1684 0D12 757658 mov YL,#58h 1685 0D15 120FF7 lcall sub16 1686 0D18 300006 jnb ZOV,okdec_Rp ;Neu da nho hon gia tri min thi dua 1687 0D1B 756003 mov Rphi,#03h ;ve gia tri max(max of Rp =1000k =>03E8h) 1688 0D1E 7561E8 mov Rplo,#0E8h 1689 okdec_Rp: 1690 0D21 12095C lcall HienRp ;Sau khi giam xong goi chuong trinh hien 1691 1692 0D24 22 ret ;thi Rp len LCD 1693 ;========================== 1694 backfault: 1695 0D25 856A73 mov XH,fpt_hi 1696 0D28 856B72 mov XL,fpt_lo 1697 0D2B 757700 mov YH,#00h 1698 0D2E 757608 mov YL,#08h 1699 0D31 120FF7 lcall sub16 1700 0D34 857B6A mov fpt_hi,ZH 1701 0D37 857A6B mov fpt_lo,ZL 1702 1703 0D3A 857B73 mov XH,ZH ;kiem tra xem fpt da giam qua gia 1704 0D3D 857A72 mov XL,ZL ;tri min chua 1705 0D40 757780 mov YH,#80h 1706 0D43 757600 mov YL,#00h 1707 0D46 120FF7 lcall sub16 1708 0D49 300006 jnb ZOV,okdec_fpt 1709 0D4C 756A8F mov fpt_hi,#8fh 1710 0D4F 756BFF mov fpt_lo,#0ffh 1711 okdec_fpt: 1712 0D52 856A73 mov bytehi,fpt_hi 1713 0D55 856B72 mov bytelo,fpt_lo 1714 0D58 120EF9 lcall hextodec 1715 0D5B 7F4D mov r7,#4dh 1716 0D5D 120ED9 lcall display5d 1717 1718 0D60 1209FF lcall Doc_CSDL 1719 1720 0D63 120A35 lcall HienCSDL 1721 0D66 22 ret 1722 ;========================= 1723 ;========================= 1724 okkey: 1725 0D67 E56C mov a,func_reg 1726 ;kiem tra xem o function nao: 1727 1728 0D69 B40304 cjne a,#03h,no_okhour 1729 0D6C 120DA8 lcall okhour 1730 0D6F 22 ret 1731 no_okhour: 1732 0D70 B40404 cjne a,#04h,no_okmin 1733 0D73 120DBA lcall okmin 1734 0D76 22 ret 1735 no_okmin: 1736 0D77 B40504 cjne a,#05h,no_okday 1737 0D7A 120DCC lcall okday 1738 0D7D 22 ret 1739 no_okday: 1740 0D7E B40604 cjne a,#06h,no_okmonth 1741 0D81 120DDE lcall okmonth 1742 0D84 22 ret 1743 no_okmonth: 1744 0D85 B40704 cjne a,#07h,no_okyear 1745 0D88 120DF0 lcall okyear 1746 0D8B 22 ret 1747 no_okyear: 1748 0D8C B40804 cjne a,#08h,no_okmode 1749 0D8F 120E02 lcall okmode 1750 0D92 22 ret 1751 no_okmode: 1752 0D93 B40904 cjne a,#09h,no_okU0 1753 0D96 120E15 lcall okU0 1754 0D99 22 ret 1755 no_okU0: 1756 0D9A B40A04 cjne a,#0ah,no_okRp 1757 0D9D 120E2B lcall okRp 1758 0DA0 22 ret 1759 no_okRp: 1760 0DA1 B40B03 cjne a,#0bh,Ign_ok 1761 0DA4 120E41 lcall ok_fpt 1762 Ign_ok: 1763 0DA7 22 ret 1764 ;======================== 1765 ;======================== 1766 okhour: 1767 0DA8 904004 mov dptr,#4004h 1768 0DAB E55C mov a,hour_reg 1769 0DAD F0 movx @dptr,a 1770 1771 0DAE 744F mov a,#4fh 1772 0DB0 120E57 lcall placecursor 1773 0DB3 120EA4 lcall prtLCD 1774 0DB6 4F4B00 db "OK",0h 1775 0DB9 22 ret 1776 ;========================== 1777 okmin: 1778 0DBA 904002 mov dptr,#4002h 1779 0DBD E55B mov a,min_reg 1780 0DBF F0 movx @dptr,a 1781 1782 0DC0 744F mov a,#4fh 1783 0DC2 120E57 lcall placecursor 1784 0DC5 120EA4 lcall prtLCD 1785 0DC8 4F4B00 db "OK",0h 1786 0DCB 22 ret 1787 ;========================= 1788 okday: 1789 0DCC 904007 mov dptr,#4007h 1790 0DCF E55D mov a,day_reg 1791 0DD1 F0 movx @dptr,a 1792 1793 0DD2 744F mov a,#4fh 1794 0DD4 120E57 lcall placecursor 1795 0DD7 120EA4 lcall prtLCD 1796 0DDA 4F4B00 db "OK",0h 1797 0DDD 22 ret 1798 ;========================== 1799 okmonth: 1800 0DDE 904008 mov dptr,#4008h 1801 0DE1 E55E mov a,month_reg 1802 0DE3 F0 movx @dptr,a 1803 1804 0DE4 744F mov a,#4fh 1805 0DE6 120E57 lcall placecursor 1806 0DE9 120EA4 lcall prtLCD 1807 0DEC 4F4B00 db "OK",0h 1808 0DEF 22 ret 1809 ;========================== 1810 okyear: 1811 0DF0 904009 mov dptr,#4009h 1812 0DF3 E55F mov a,year_reg 1813 0DF5 F0 movx @dptr,a 1814 1815 0DF6 744F mov a,#4fh 1816 0DF8 120E57 lcall placecursor 1817 0DFB 120EA4 lcall prtLCD 1818 0DFE 4F4B00 db "OK",0h 1819 0E01 22 ret 1820 ;=========================== 1821 okmode: 1822 0E02 904010 mov dptr,#4010h 1823 0E05 A202 mov c,mode 1824 0E07 33 rlc a 1825 0E08 F0 movx @dptr,a 1826 1827 0E09 744F mov a,#4fh 1828 0E0B 120E57 lcall placecursor 1829 0E0E 120EA4 lcall prtLCD 1830 0E11 4F4B00 db "OK",0h 1831 0E14 22 ret 1832 ;=========================== 1833 okU0: 1834 0E15 904011 mov dptr,#4011h 1835 0E18 E562 mov a,U0hi 1836 0E1A F0 movx @dptr,a 1837 1838 0E1B A3 inc dptr 1839 0E1C E563 mov a,U0lo 1840 0E1E F0 movx @dptr,a 1841 1842 0E1F 744F mov a,#4fh 1843 0E21 120E57 lcall placecursor 1844 0E24 120EA4 lcall prtLCD 1845 0E27 4F4B00 db "OK",0h 1846 0E2A 22 ret 1847 ;============================== 1848 okRp: 1849 0E2B 904013 mov dptr,#4013h 1850 0E2E E560 mov a,Rphi 1851 0E30 F0 movx @dptr,a 1852 1853 0E31 A3 inc dptr 1854 0E32 E561 mov a,Rplo 1855 0E34 F0 movx @dptr,a 1856 1857 0E35 744F mov a,#4fh 1858 0E37 120E57 lcall placecursor 1859 0E3A 120EA4 lcall prtLCD 1860 0E3D 4F4B00 db "OK",0h 1861 0E40 22 ret 1862 ;================================== 1863 ok_fpt: 1864 0E41 904015 mov dptr,#4015h ;giu trong RTC 1865 0E44 E56A mov a,fpt_hi 1866 0E46 F0 movx @dptr,a 1867 0E47 A3 inc dptr 1868 0E48 E56B mov a,fpt_lo 1869 0E4A F0 movx @dptr,a 1870 1871 0E4B 7452 mov a,#52h 1872 0E4D 120E57 lcall placecursor 1873 0E50 120EA4 lcall prtLCD 1874 0E53 4F4B00 db "OK",0h 1875 0E56 22 ret 1876 ;=================================== 1877 ;===================================== 1878 ;subroutine placecursor 1879 ;Input: Accumulator indicates the position of cursor 1880 ;the first small line :00h -> 27h 1881 ;the second small line : 40h -> 67h 1882 ;Output: None 1883 ;=================================== 1884 placecursor: 1885 0E57 C0E0 push acc 1886 0E59 4480 orl a,#80h 1887 0E5B 120E61 lcall writecommand 1888 0E5E D0E0 pop acc 1889 0E60 22 ret 1890 ;=================================== 1891 ;subroutine writecommand 1892 ;(Write Command to 8 bit LCD Module) 1893 ;Input: A = Command Byte 1894 ;Call OutPort function to write 1895 ;=================================== 1896 writecommand: 1897 0E61 C2A5 clr LCD_E 1898 0E63 C2A4 clr LCD_RS 1899 0E65 C2B5 clr LCD_RW 1900 0E67 F580 mov p0,a 1901 0E69 00 nop 1902 0E6A D2A5 setb LCD_E 1903 0E6C 00 nop 1904 0E6D 00 nop 1905 0E6E 00 nop 1906 0E6F C2A5 clr LCD_E 1907 0E71 120E75 lcall busyflag 1908 0E74 22 ret 1909 ;============================================== 1910 ;subroutine busyflag 1911 ;After each read write operation,Busy Flag (DB7) need to check. 1912 ;The next operation can be only executed when BF bit was cleared 1913 ;Subroutin Tests BF bit until BF bit clear 1914 ;============================================= 1915 busyflag: 1916 0E75 C0E0 push acc 1917 0E77 D2B5 setb LCD_RW 1918 0E79 C2A4 clr LCD_RS 1919 0E7B C2A5 clr LCD_E 1920 B_Flag: 1921 0E7D 7580FF mov p0,#0ffh 1922 0E80 00 nop 1923 0E81 D2A5 setb LCD_E 1924 0E83 00 nop 1925 0E84 00 nop 1926 0E85 00 nop 1927 0E86 E580 mov a,p0 1928 0E88 C2A5 clr LCD_E 1929 0E8A 20E7F0 jb ACC.7,B_Flag 1930 0E8D D0E0 pop acc 1931 0E8F 22 ret 1932 ;=============================================== 1933 ;subroutine writedata 1934 ;(Write Data to 8 bit LCD) 1935 ;Input: A = Character to write (ascii code) 1936 ;Call OutPort function to write 1937 ;=============================================== 1938 writedata: 1939 0E90 C2A5 clr LCD_E 1940 0E92 D2A4 setb LCD_RS 1941 0E94 C2B5 clr LCD_RW 1942 0E96 F580 mov p0,a 1943 0E98 00 nop 1944 0E99 D2A5 setb LCD_E 1945 0E9B 00 nop 1946 0E9C 00 nop 1947 0E9D 00 nop 1948 0E9E C2A5 clr LCD_E 1949 0EA0 120E75 lcall busyflag 1950 0EA3 22 ret 1951 ; *************************** PRINT LCD ******************** 1952 ; subroutine prtLCD 1953 ; takes the string immediately following the call and 1954 ; displays on the LCD. the string is read with the 1955 ; mov a, @a+dptr 1956 ; instruction. thus, the string is in data memory. since 1957 ; the string immediately follows code, the microcontroller 1958 ; is used with overlapping code and data memories (the von 1959 ; Newman architecture). string must be terminated with a 1960 ; null (0). upon termination this routine jumps to the 1961 ; instruction immediately following the string. 1962 ; input : none 1963 ; output : none 1964 ; destroys : acc, dptr 1965 ; ********************************************************* 1966 prtLCD: 1967 0EA4 D083 pop dph 1968 0EA6 D082 pop dpl 1969 prtNext: 1970 0EA8 7400 mov a,#00h 1971 0EAA 93 movc a,@a+dptr 1972 0EAB B40002 cjne a,#0,chrOK 1973 0EAE 8007 sjmp retPrtLCD 1974 chrOK: 1975 1976 0EB0 120E90 lcall writedata 1977 0EB3 A3 inc dptr 1978 0EB4 020EA8 ljmp prtNext 1979 retPrtLCD: 1980 0EB7 7401 mov a,#1h 1981 0EB9 73 jmp @a+dptr 1982 ;=============================== 1983 ;subroutine Hien_2digit 1984 ;Doi so chua trong a sang ASCII 1985 ;va hien thi no tren LCD 1986 ;input a 1987 ;output hien Dg1,Dg2 len LCD 1988 ;=============================== 1989 Hien_2digit: 1990 0EBA C0F0 push b 1991 0EBC 75F00A mov b,#10 1992 0EBF 84 div ab 1993 0EC0 4430 orl a,#30h 1994 0EC2 120E90 lcall writedata 1995 0EC5 E5F0 mov a,b 1996 0EC7 4430 orl a,#30h 1997 0EC9 120E90 lcall writedata 1998 0ECC D0F0 pop b 1999 0ECE 22 ret 2000 ;========================================== 2001 ;subroutine display5d & 3digit 2002 ;hien thi len LCD chu so 5 digit BCD dat o 5 o nho 2003 ;digit4, digit3, digit2, digit1, digit0 2004 ;cac thanh ghi duoc dung r0, r1, r7, acc 2005 ;input : digit4, digit3, digit2, digit1, digit0 2006 ; : chua ma BCD so can hien 2007 ; : r7 = vi tri con tro LCD tren dong (tu 00h - 39h) 2008 ;============================================ 2009 display3d: 2010 0ECF EF mov a,r7 2011 0ED0 120E57 lcall placecursor 2012 0ED3 7903 mov r1,#3 2013 0ED5 780A mov r0,#digit2 2014 0ED7 8008 sjmp chua_hien 2015 display5d: 2016 0ED9 EF mov a,r7 2017 0EDA 120E57 lcall placecursor 2018 0EDD 7905 mov r1,#5 2019 0EDF 780C mov r0,#digit4 2020 chua_hien: 2021 0EE1 E6 mov a,@r0 2022 0EE2 B4000A cjne a,#00h,hiendigit 2023 0EE5 18 dec r0 2024 0EE6 19 dec r1 2025 0EE7 0F inc r7 2026 0EE8 EF mov a,r7 2027 0EE9 120E57 lcall placecursor 2028 0EEC B901F2 cjne r1,#1,chua_hien 2029 hiendigit: 2030 0EEF E6 mov a,@r0 2031 0EF0 4430 orl a,#30h 2032 0EF2 120E90 lcall writedata 2033 0EF5 18 dec r0 2034 0EF6 D9F7 djnz r1,hiendigit 2035 0EF8 22 ret 2036 ;=========================================== 2037 ;subroutine hextodec 2038 ;input : bytelo,bytehi 2039 ;output : Digit4,Digit3,Digit2,Digit1,Digit0 2040 ;=========================================== 2041 hextodec: 2042 0EF9 857373 mov XH,bytehi 2043 0EFC 857272 mov XL,bytelo 2044 0EFF 757700 mov YH,#00h 2045 0F02 75760A mov YL,#0ah 2046 0F05 120F9A lcall DIV16 2047 0F08 857A08 mov digit0,Z0 2048 0F0B 857D73 mov XH,Z3 2049 0F0E 857C72 mov XL,Z2 2050 0F11 120F9A lcall DIV16 2051 0F14 857A09 mov digit1,Z0 2052 0F17 857D73 mov XH,Z3 2053 0F1A 857C72 mov XL,Z2 2054 0F1D 120F9A lcall DIV16 2055 0F20 857A0A mov digit2,Z0 2056 0F23 857D73 mov XH,Z3 2057 0F26 857C72 mov XL,Z2 2058 0F29 120F9A lcall DIV16 2059 0F2C 857A0B mov digit3,Z0 2060 0F2F 857D73 mov XH,Z3 2061 0F32 857C72 mov XL,Z2 2062 0F35 120F9A lcall DIV16 2063 0F38 857A0C mov digit4,Z0 2064 0F3B 22 ret 2065 ;============================================ 2066 ; subroutine mul16 2067 ; Multiply two 16-Bit Unsigned Words 2068 ; Z(Z3:Z2:Z1:Z0) = X(XH:XL) * Y(YH:YL) 2069 ; input: XH, XL, YH, YL 2070 ; output: Z3, Z2, Z1, Z0 2071 ; Z3 is the most significant byte. 2072 ; Z0 is the least significant byte. 2073 ; lcall: BMW 2074 ; destroys: a, b, c 2075 ;============================================= 2076 mul16: 2077 0F3C C0E0 push acc 2078 0F3E C0F0 push b 2079 0F40 120F78 lcall bmw ; XL * Y(YH:YL) 2080 0F43 E57C mov a,Z2 2081 0F45 C0E0 push acc ; push Z2_1 2082 0F47 E57B mov a,Z1 2083 0F49 C0E0 push acc ; push Z1_1 2084 0F4B E57A mov a,Z0 2085 0F4D C0E0 push acc ; push Z0_1 2086 0F4F 857372 mov XL,XH ; put XH in XL 2087 0F52 120F78 lcall bmw ; XH * Y(YH:YL) 2088 0F55 857AF0 mov b,Z0 ; save Z0_2 in b register 2089 0F58 D0E0 pop acc ; recall Z0_1 2090 0F5A F57A mov Z0,a ; *************** Z0 = Z0_1 2091 0F5C D0E0 pop acc ; Z1_1 2092 0F5E 25F0 add a,b ; a = Z1_1 + Z0_2 2093 0F60 857BF0 mov b,Z1 ; save Z1_2 in b register 2094 0F63 F57B mov Z1,a ; *************** Z1 = a 2095 0F65 D0E0 pop acc ; Z2_1 2096 0F67 35F0 addc a,b ; a = zl2_1 + zh1_2 + c 2097 0F69 857CF0 mov b,Z2 ; save Z2_2 in b register 2098 0F6C F57C mov Z2,a ; *************** Z2 = a 2099 0F6E E4 clr a ; acc = 0 2100 0F6F 35F0 addc a,b ; a = 0 + Z2_2 + c 2101 0F71 F57D mov Z3,a ; Z3 = a 2102 0F73 D0F0 pop b 2103 0F75 D0E0 pop acc 2104 0F77 22 ret 2105 ;======================================= 2106 ; subroutine bmw 2107 ; Z(Z2:Z1:Z0) = XL * Y(YH:YL) 2108 ; input: XL, YH,,YL 2109 ; output: Z(Z2:Z1:Z0) 2110 ; Z2 is the most significant byte. 2111 ; Z0 is the least significant. 2112 ; destroys: a, b, r0, c 2113 ;======================================= 2114 bmw: 2115 0F78 C0D0 push psw 2116 0F7A 75D000 mov psw,#0 2117 0F7D E572 mov a,XL 2118 0F7F 8576F0 mov b,YL 2119 0F82 A4 mul ab 2120 0F83 F57A mov Z0,a 2121 0F85 C0F0 push b 2122 0F87 E572 mov a,XL 2123 0F89 8577F0 mov b,YH 2124 0F8C A4 mul ab 2125 0F8D D000 pop 0 2126 0F8F 28 add a,r0 2127 0F90 F57B mov Z1,a 2128 0F92 E4 clr a 2129 0F93 35F0 addc a,b 2130 0F95 F57C mov Z2,a 2131 0F97 D0D0 pop psw 2132 0F99 22 ret 2133 2134 ;================================================================= 2135 ;subroutine div16 2136 ; Z = X / Y 2137 ; input : X:(XH,XL); Y:(YH,YL) 2138 ; output : Z3,Z2 hold high and low bytes of the quotient 2139 ; Z1,Z0 hold high and low bytes of the remainder 2140 ; ZOV is set if Y=0, i.e., the result is out of range. 2141 ; calls : sub16 2142 ; destroys: a, r0, r1, r2, r3, r7, flags 2143 ;================================================================== 2144 div16: 2145 0F9A E577 mov a,YH ;get divisor high byte 2146 0F9C 4576 orl a,YL ;OR with low byte 2147 0F9E 7003 jnz div_OK ;divisor OK if not 0 2148 0FA0 D200 setb ZOV ;else, overflow 2149 0FA2 22 ret 2150 div_OK: 2151 0FA3 A973 mov r1,XH ;store dividend in r1, r0 2152 0FA5 A872 mov r0,XL 2153 0FA7 757300 mov XH,#0 ;clear partial remainder 2154 0FAA 757200 mov XL,#0 2155 0FAD 7B00 mov r3,#0 ;clear partial quotient 2156 0FAF 7A00 mov r2,#0 2157 0FB1 7F10 mov r7,#16 ;set loop count 2158 div_loop: 2159 0FB3 C3 clr C ;clear carry flag 2160 0FB4 E8 mov a,r0 ;shift the highest bit of the dividend... 2161 0FB5 33 rlc a ; ... into... 2162 0FB6 F8 mov r0,a 2163 0FB7 E9 mov a,r1 2164 0FB8 33 rlc a 2165 0FB9 F9 mov r1,a 2166 0FBA E572 mov a,XL ; ... the lowest bit of the partial ... 2167 0FBC 33 rlc a ; ... remainder 2168 0FBD F572 mov XL,a 2169 0FBF E573 mov a,XH 2170 0FC1 33 rlc a 2171 0FC2 F573 mov XH,a 2172 0FC4 120FF7 lcall sub16 ; attempt to subtract to see if the... 2173 ; ... partial remainder is as large or... 2174 ; ... larger than the divisor.; 2175 2176 0FC7 A200 mov c,ZOV ; get subtraction external borrow 2177 0FC9 B3 cpl c ;complement external borrow; 2178 0FCA 5006 jnc div_1 2179 0FCC 857B73 mov XH,ZH 2180 0FCF 857A72 mov XL,ZL 2181 div_1: 2182 0FD2 EA mov a,r2 ; add result bit to partial quotient 2183 0FD3 33 rlc a 2184 0FD4 FA mov r2,a 2185 0FD5 EB mov a,r3 2186 0FD6 33 rlc a 2187 0FD7 FB mov r3,a 2188 0FD8 DFD9 djnz r7,div_loop 2189 0FDA 8B7D mov Z3,r3 ; put quotient in Z3, and Z2 2190 0FDC 8A7C mov Z2,r2 2191 0FDE 85737B mov Z1,XH ; get remainder, saved before the... 2192 0FE1 85727A mov Z0,XL ; last subtraction 2193 0FE4 C200 clr ZOV ; divisor is not 0 2194 0FE6 22 ret 2195 ;======================================================== 2196 ; subroutine ADD16 2197 ; input : X (XH:XL),Y:(YH:YL) 2198 ; output: Z (ZH:ZL),ZOV 2199 ; Z=X+Y. 2200 ; destroys: a, flags 2201 ;================================================================= 2202 add16: 2203 0FE7 C3 clr c 2204 0FE8 E572 mov a,XL ; load X low byte into accumulator 2205 0FEA 2576 add a,YL ; add Y low byte 2206 0FEC F57A mov ZL,a ; put result in Z low byte 2207 0FEE E573 mov a,XH ; load X high byte into accumulator 2208 0FF0 3577 addc a,YH ; add Y high byte with the carry from low ... 2209 ; ... byte operation 2210 0FF2 F57B mov ZH,a ; save result in Z high byte 2211 0FF4 9200 mov ZOV,C ; set ZOV if external carry 2212 0FF6 22 ret 2213 ;=================================================== 2214 ;subroutine sub16 2215 ; Z(ZH,ZL) = X(XH,XL) - Y(YH,YL) 2216 ; if (Y > X) 2217 ; ZOV = 1 2218 ;=================================================== 2219 sub16: 2220 0FF7 C0E0 push acc 2221 0FF9 E572 mov a,XL ; load X low byte into accumulator 2222 0FFB C3 clr c ; clear carry flag 2223 0FFC 9576 subb a,YL ; subract Y low byte 2224 0FFE F57A mov ZL,a ; put result in Z low byte 2225 1000 E573 mov a,XH ; load X high byte into accumulator 2226 1002 9577 subb a,YH ; subtract Y high byte with the borrow ... 2227 ; ... from low byte operation 2228 1004 F57B mov ZH,a ; save result in Z high byte 2229 1006 9200 mov ZOV,c ; set ZOV id an external borrow is produced 2230 1008 D0E0 pop acc 2231 100A 22 ret 2232 ;============================ 2233 ;subroutine delay_ms 2234 ;delay time 1 milisecond 2235 ;100h-a6h=5a=90 2236 ;90x11=990 milisecond 2237 ;input acc= milisecond delay 2238 ;============================ 2239 delay_ms: 2240 100B C0E0 push acc 2241 100D 74A6 mov a,#0a6h 2242 dilp: 2243 100F 04 inc a 2244 1010 00 nop 2245 1011 00 nop 2246 1012 00 nop 2247 1013 00 nop 2248 1014 00 nop 2249 1015 00 nop 2250 1016 00 nop 2251 1017 00 nop 2252 1018 70F5 jnz dilp 2253 101A 00 nop 2254 101B 00 nop 2255 101C 00 nop 2256 101D D0E0 pop acc 2257 101F D5E0E9 djnz acc,delay_ms 2258 1022 22 ret 2259 ;==================================================================== 2260 ; subroutine div32 2261 ; 32-Bit Unsigned Division 2262 ; 2263 ; input: internal registers X3, X2, X1, and X0 hold the 32-bit 2264 ; unsigned dividend. similarly, internal registers Y1 and 2265 ; Y0 hold the high and low bytes of the unsigned divisor. 2266 ; 2267 ; output: internal registers Z5, Z4, Z3, and Z2 hold the 32-bit 2268 ; quotient of Z=X / Y. internal registers Z1 and Z0 hold 2269 ; the high and low bytes of the remainder. addressible bit 2270 ; ZOV is set if Y=0, i.e., the result is out of range. 2271 ; 2272 ; internal registers PR3, PR2, PR1, and PR0 store the 2273 ; partial remainder. r5, r4, r3, and r2 hold the partially 2274 ; computed quotient. 2275 ; 2276 ; calls: SUB32 2277 ; destroys: a, r2, r3, r4, r5, r7, flags 2278 ;==================================================================== 2279 div32: 2280 1023 E577 mov a, Y1 ; get divisor high byte 2281 1025 4576 orl a, Y0 ; OR with low byte 2282 1027 7003 jnz div32_OK ; divisor OK if not 0 2283 1029 D200 setb ZOV ; else, overflow 2284 102B 22 ret 2285 div32_OK: 2286 102C 757800 mov Y2, #0 ; high 16 bits of Y is 0 2287 102F 757900 mov Y3, #0 2288 1032 857571 mov PR3, X3 ; store dividend 2289 1035 857470 mov PR2, X2 2290 1038 85736F mov PR1, X1 2291 103B 85726E mov PR0, X0 2292 103E 757500 mov X3, #0 ; clear partial remainder 2293 1041 757400 mov X2, #0 2294 1044 757300 mov X1, #0 2295 1047 757200 mov X0, #0 2296 104A 7D00 mov r5, #0 2297 104C 7C00 mov r4, #0 2298 104E 7B00 mov r3, #0 ; clear partial quotient 2299 1050 7A00 mov r2, #0 2300 1052 7F20 mov r7, #32 ; set loop count 2301 2302 div32_loop: 2303 1054 C3 clr C ; clear carry flag 2304 1055 E56E mov a, PR0 ; shift the highest bit of the dividend... 2305 1057 33 rlc a ; ... into... 2306 1058 F56E mov PR0, a 2307 105A E56F mov a, PR1 2308 105C 33 rlc a 2309 105D F56F mov PR1, a 2310 105F E570 mov a, PR2 2311 1061 33 rlc a 2312 1062 F570 mov PR2, a 2313 1064 E571 mov a, PR3 2314 1066 33 rlc a 2315 1067 F571 mov PR3, a 2316 2317 1069 E572 mov a, X0 ; ... the lowest bit of the partial ... 2318 106B 33 rlc a ; ... remainder 2319 106C F572 mov X0, a 2320 106E E573 mov a, X1 2321 1070 33 rlc a 2322 1071 F573 mov X1, a 2323 1073 E574 mov a, X2 2324 1075 33 rlc a 2325 1076 F574 mov X2, a 2326 1078 E575 mov a, X3 2327 107A 33 rlc a 2328 107B F575 mov X3, a 2329 2330 107D 1210B0 lcall SUB32 ; attempt to subtract to see if the... 2331 ; ... partial remainder is as large or... 2332 ; ... larger than the divisor. 2333 2334 1080 A200 mov C, ZOV ; get subtraction external barrow 2335 1082 B3 cpl C ; complement external barrow 2336 1083 500C jnc div32_1 2337 1085 857D75 mov X3, Z3 2338 1088 857C74 mov X2, Z2 2339 108B 857B73 mov X1, Z1 2340 108E 857A72 mov X0, Z0 2341 div32_1: 2342 2343 1091 EA mov a, r2 ; add result bit to partial quotient 2344 1092 33 rlc a 2345 1093 FA mov r2, a 2346 1094 EB mov a, r3 2347 1095 33 rlc a 2348 1096 FB mov r3, a 2349 1097 EC mov a, r4 2350 1098 33 rlc a 2351 1099 FC mov r4, a 2352 109A ED mov a, r5 2353 109B 33 rlc a 2354 109C FD mov r5, a 2355 2356 109D DFB5 djnz r7, div32_loop 2357 2358 109F 8D7F mov Z5, r5 ; put quotient in Z3, and Z2 2359 10A1 8C7E mov Z4, r4 2360 10A3 8B7D mov Z3, r3 2361 10A5 8A7C mov Z2, r2 2362 10A7 85737B mov Z1, X1 ; get remainder, saved before the... 2363 10AA 85727A mov Z0, X0 ; last subtraction 2364 10AD C200 clr ZOV ; divisor is not 0 2365 10AF 22 ret 2366;========================================================= 2367 ;subroutine sub32 2368 ;32 bit unsigned subtraction 2369 ;input: internal register X3, X2 , X1 ,X0 and Y3 ,Y2 ,Y1 ,Y0 hold the 32 bit 2370 ; unsigned intergers 2371 ;output:internal register Z3, Z2, Z1 and Z0 hold the result Z=X-Y. 2372 ;destroy : a, flag 2373 ; if Y > X then ZOV = 1 2374;=================================================== 2375 sub32: 2376 10B0 E572 mov a,X0 2377 10B2 C3 clr c 2378 10B3 9576 subb a,Y0 2379 10B5 F57A mov Z0,a 2380 10B7 E573 mov a,X1 2381 10B9 9577 subb a,Y1 2382 10BB F57B mov Z1,a 2383 10BD E574 mov a,X2 2384 10BF 9578 subb a,Y2 2385 10C1 F57C mov Z2,a 2386 10C3 E575 mov a,X3 2387 10C5 9579 subb a,Y3 2388 10C7 F57D mov Z3,a 2389 10C9 9200 mov ZOV,c 2390 10CB 22 ret 2391 ;===================================== 2392 tre_800ms: 2393 10CC 74FF mov a,#0ffh ;tre 0.8ms chong nhieu o 2394 10CE 12100B lcall delay_ms ; mach khi power on 2395 10D1 74FF mov a,#0ffh 2396 10D3 12100B lcall delay_ms 2397 10D6 74FF mov a,#0ffh 2398 10D8 12100B lcall delay_ms 2399 10DB 22 ret II. Tài liệu tham khảo. 1- Dallas Maxim DS12887 Real Time Clock Maxim-ic com/errata. 2- Kỹ thuật đo lường các đại lượng vật lý 1,2 Phạm Thượng Hàn. 3- MCS-51 Family Mcrocontrollers architectual overview 4- Programming and interfacing the 8051 Microcontroller Sencer Yeralan Ashutosh Ahluwalia 5- MCS51 microcontroller family user’s manual INTEL: www.intel.com. 6- Sơ đồ chân linh kiện bán dẫn Dương Minh Trí. 7- Giáo trình Vật liệu điện Nguyễn Thế Thắng. 8- Kỹ thuật ghép nối máy tính Ngô Diên Tập. Frame bản tin trong truyền thông giữa rơle với máy tính: “#” Địa chỉ máy nhận bản tin Mã lệnh(đọc/viết) Mã bản tin Nội dung bản tin nếu là lệnh viết “/” “#” 01 04 03 “/” “#” 01 04 05 “/” “#” 01 04 06 “/”

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

  • docRơle số bảo vệ cách điện.doc