Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 110 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
110
Dung lượng
265,75 KB
Nội dung
Chinh sua boi: nguyenvanbientbd47@gmail.com PHAÀN CHÖÔNG TRÌNH VIEÁT TREÂN VI XÖÛ LYÙ Chinh sua boi: nguyenvanbientbd47@gmail.com ;;;;;;;;;;;;;;;;CHÖÔNG TRÌNH VIEÁT CHO PLC NEÀN;;;;;;;;;;;;;;;;;; ;VIET NGAY 04/11/2000 ;CHUONG TRINH CHO PHEP GIAO TIEP VOI BOARD GIAO DIEN VA MAY TINH ;O CHE DO SLAVE VA IO PLC O CHE DO MASTER ;DIEU KHIEN BANG SWITCH CHON MODE HOAT DONG ;********************************************************* ;- Chuong trinh nhan phat du lieu tu port noi tiep ; voi toc do 9600 1 start bit ,1 stop bit,bit thu 9 ;- Chuong trinh viet theo kieu ngat.Cu 1S goi 10 byte ; du lieu den Slave , nhan ve 10 byte ;- Byte dau tien la byte dia chi, 8 byte du lieu, byte ; cuoi cung la 0DH ; Neu byte thu 10 khong phai la 0DH thi bao loi ;- Vung dem thu bat dau tu 50H ;- Vung dem phat bat dau tu 60H ;********************************************************* ; CHUONG TRINH CHO MASTER CO DIA CHI 00H ; CHUONG TRINH CHO SLAVER CO DIA CHI 01H ;++++++++++++++++++KHAI BAO CAC BIEN VA HANG++++++++++++++ ;********************************************************* ;NGO VAO:lay gia tri tu byte dem thu chep vao IN_ST ; IN_ST EQU 22H ;BYTE TRANG THAI NGO VAO IN1 BIT 10H ;BIT=1:DONG,BIT=0:NGAT IN2 BIT 11H IN3 BIT 12H IN4 BIT 13H IN5 BIT 14H IN6 BIT 15H ;********************************************************* ;NGO RA :xuat ra OUT_ST roi chep vao byte dem phat ; OUT_ST EQU 23H ;BYTE TRANG THAI NGO RA OUT1 BIT 18H ;BIT=1:DONG,BIT=0:NGAT OUT2 BIT 19H OUT3 BIT 1AH OUT4 BIT 1BH LOI BIT 1FH ;********************************************************** dcMas EQU 00H dcSle EQU 01H DCMPLC EQU 02H DCSPLC EQU 03H demt EQU 50H demp EQU 60H bien1 EQU 5EH bien2 EQU 5FH bien3 EQU 5CH bien4 EQU 5BH ;chua d/c Slave bien5 EQU 5AH ;chua THOI GIAN CHO count EQU 10000 chon1 EQU 2 chon2 EQU 1 th EQU 1 ; RUN BIT P3.4 ;LED RUN NAP BIT P3.5 ;LED NAP PRO_G BIT P3.3 ;CONG TAC NAP CHUONG TRINH RUN_G BIT P3.2 ;CONG TAC CHAY CHUONG TRINH TAM1 BIT 00H ;BIT TAM NGO VAO Chinh sua boi: nguyenvanbientbd47@gmail.com TAM2 BIT 01H ;BIT TAM NGO VAO TAM3 BIT 02H ;BIT TAM DE XUAT NGO RA CO_1 BIT 03H ; CO_2 BIT 04H ; CO_T1 BIT 05H ; CO_T2 BIT 06H ; CO_L1 BIT 07H ; KT BIT 08H ;CO KET THUC (LENH END) CO_3 BIT 09H ;BIT PHAT HIEN START CO_X BIT 0AH ;co bao che do quet va che do load CO_TAM1 BIT 0BH CO_TAM2 BIT 0CH TAM4 BIT 0DH CO_L2 BIT 0EH CO_S1 BIT 0FH CO_S2 BIT 20H ; FLOAT EQU 3FH ;byte tam Z EQU 3EH ;BYTE TAM CHUA DIA CHI KHOI VAR1 EQU 3DH ;BIEN LUU TRU DU LIEU CUA TIMER,COUNTER VAR2 EQU 3CH ;BIEN XU LY CUA TIMER,COUNTER VAR3 EQU 3BH ; DX EQU 3AH ;BIEN DEM TIMER TEMP EQU 39H TEMP1 EQU 38H ;LUU DIA CHI KHOI(DPH) TEMP2 EQU 37H ;LUU DIA CHI KHOI(DPL) RISE EQU 36H ;chua dung REPL EQU 35H ;byte tam BITH EQU 34H ;byte cao cua data pointer dung cho dem bit BITL EQU 33H ;byte thap cua data pointer dung cho dem bit LUU_B EQU 32H ;byte luu bit tam BCAO EQU 31H ;DIA CHI DAU VUNG CHO TIMER,COUNTER BTHAP EQU 30H ; STEP1 EQU 40H ;luu tru byte tam cua chuong trinh dem bit STEP2 EQU 41H ; DBITC EQU 42H ;bien tang bit DMT EQU 43H ;DEM NEN EQU 44H ; FIRSTH EQU 45H ;BIEN LUU DIA CHI RAM DAU TIEN CUA DATA PLC FIRSTL EQU 46H ; GIAY EQU 47H PHUT EQU 48H GIO EQU 49H THU EQU 4AH NGAY EQU 4BH THANG EQU 4CH NAM EQU 4DH COMP1 EQU 4EH COMP2 EQU 4FH CHU_X EQU 78H ; ORG 0000H LJMP BEGIN ORG 000BH LJMP T0ISR ORG 0023H LJMP SPISR ORG 30H BEGIN: Chinh sua boi: nguyenvanbientbd47@gmail.com ;________________________________________________ ;DOAN CHUONG TRINH RESET CAC GIA TRI BAN DAU ;********** START ***************************** CLR F0 CLR CO_1 CLR CO_2 CLR CO_L1 CLR CO_L2 CLR CO_T1 CLR CO_T2 CLR KT ;XOA BIT KET THUC CLR CO_X CLR P2.5 MOV FIRSTH,#00H MOV FIRSTL,#00H MOV DPTR,#0400H MOV BCAO,DPH MOV BTHAP,DPL MOV DPTR,#0100H MOV BITH,DPH MOV BITL,DPL ; ; MOV DPTR,#1E00H ;BYTE 1E00H O RAM NGOAI LUU ANH OUTPUT MOV IN_ST,#00H MOV OUT_ST,#00H MOV R0,#DEMT MOV DBITC,#0 MOV DX,#0 MOV Z,#50H ;Z CHUA MA TB ; MOV bien1,#0 MOV bien2,#chon1 MOV bien3,#chon2 MOV bien4,#0 MOV bien5,#chon1 ; MOV A,87H ;TOC DO 19200 SETB ACC.7 MOV 87H,A ; MOV SCON,#11110000B MOV TMOD,#21H MOV TH1,#-3 SETB TR1 SETB IP.1 MOV IE,#92H SETB TF0 ;************ END ****************************** ;*********************************************** ; DOAN CHUONG TRINH CHINH ; DOAN CHUONG TRINH NAY LUON ; QUET CHOUNG TRINH SAU 1MS ;**************** START ************************ XET: JNB F0,$ CLR F0 JNB PRO_G,STOP_CT JNB RUN_G,CHAY_CT SETB RUN ;DEN SANG O CHE DO LOAD SETB NAP Chinh sua boi: nguyenvanbientbd47@gmail.com LCALL GT_PRG MOV IN_ST,#00H MOV OUT_ST,#00H MOV DPTR,#1E00H ;RESET LAI ANH OUTPUT MOV A,#00H MOVX @DPTR,A SJMP XET CHAY_CT: CLR RUN ;DEN SANG O CHE DO RUN SETB NAP LCALL GT_IO SJMP XET STOP_CT: CLR NAP ;DEN SANG CHE DO LOAD SETB RUN MOV IN_ST,#00H MOV OUT_ST,#00H MOV DPTR,#1E00H ;RESET LAI ANH OUTPUT MOV A,#00H MOVX @DPTR,A SJMP XET ;****************************************************************** ;CHUONG TRINH CON GIAO TIEP VOI BOARD GIAO DIEN ; VA MAY TINH,LUC NAY PLC DANG O CHE DO SLAVE ;******************************************************************* GT_PRG: JNB CO_1,XETT CLR CO_1 LCALL ANSWER SETB SM2 SETB TI XETT: JNB CO_2,ZCX CLR CO_2 ZCX: RET ;************************************************** ;CHUONG TRINH CON GIAO TIEP VOI IO PLC ;************************************************** GT_IO: MOV DPTR,#1E00H ;LAY ANH OUTPUT TU RAM MOVX A,@DPTR MOV OUT_ST,A LCALL MAU ;LAY MAU PHAT LCALL CHO_NHAN ;CHO NHAN DU 3 BYTE MOV R1,#DEMT MOV IN_ST,@R1 ;LAY ANH INPUT TU BUFFER RECEIVE LCALL QUETCT MOV R1,#DEMP MOV @R1,OUT_ST ;XUAT ANH OUTPUT VAO BUFFER TRANSMIT MOV DPTR,#1E00H ;LUU ANH OUTPUT VAO RAM MOV A,OUT_ST MOVX @DPTR,A RET ;**************************************** ; Chuong trinh tao ngat 1mS ;**************START********************* T0ISR: PUSH ACC MOV CO_T1,C SETB F0 CLR TR0 Chinh sua boi: nguyenvanbientbd47@gmail.com MOV TH0,#HIGH(-count) MOV TL0,#LOW(-count) SETB TR0 POP ACC MOV C,CO_T1 RETI ;***************END*********************** ; ;***************************************** ;DOAN CHUONG TRINH CON NGAT CONG NOI TIEP ;************ START ********************** SPISR: PUSH ACC MOV CO_T2,C JNB PRO_G,SPIC JNB RUN_G,NGAT_S JNB RI,SPI1 LCALL CTNHANS SJMP SPIC SPI1: LCALL CTRUYENS SJMP SPIC NGAT_S: JNB RI,SPI2 LCALL CTNHANM SJMP SPIC SPI2: LCALL CTRUYENM SPIC: POP ACC MOV C,CO_T2 RETI ;**************END*************************************** ;;******************************************************* ; CHUONG TRINH NHAN 10 BYTE,CHE DO SLAVE ;**************START************************************* CTNHANS: JNB RI,$ CLR RI JNB RB8,CNT1S MOV A,SBUF CJNE A,#dcSle,CNTCS CLR SM2 MOV R0,#demt SJMP CNTCS CNT1S: MOV A,SBUF CJNE R0,#demt+8,CNT2S SETB SM2 CJNE A,#0DH,CNT3S LCALL ST_START LCALL KT_END SETB CO_1 SJMP CNTCS CNT2S: MOV @R0,A INC R0 SJMP CNTCS CNT3S: SETB CO_L1 CNTCS: RET ;************END************************************** ; Chinh sua boi: nguyenvanbientbd47@gmail.com ;CT CON CHEP DU LIEU VUA NHAN DUOC VAO VUNG DEMP ; ANSWER: PUSH 00H PUSH 01H MOV R1,#DEMP MOV R0,#DEMT WRITE: MOV A,@R0 MOV @R1,A INC R0 INC R1 CJNE R0,#DEMT+8,WRITE POP 01H POP 00H RET ;********************************************* ; CHUONG TRINH TRUYEN 10 BYTE,CHE DO SLAVE ;**************START************************** CTRUYENS: JNB TI,$ CLR TI mov A,bien1 cjne A,#10,ctrS mov bien1,#0 sjmp ctrcS ctrS: INC bien1 MOV A,bien1 CJNE A,#1,CTR1S SETB TB8 MOV SBUF,#dcMas MOV R0,#demp SJMP CTRCS CTR1S: CJNE A,#10,CTR2S CLR TB8 MOV SBUF,#0DH SETB CO_2 SJMP CTRCS CTR2S: CLR TB8 MOV A,@R0 MOV SBUF,A INC R0 CTRCS: RET ;************END********************************* ;************************************************ ;CHUONG TRINH CON NHAN CHUOI START ;NEU NHAN DUOC CHUOI START THI KHONG GHI VAO RAM ;NOI MA BAT DAU LAI TU DIA CHI 80H ;************************************************ ST_START: PUSH 00H PUSH ACC MOV R0,#DEMT MOV A,@R0 CJNE A,#53H,QQQ INC R0 MOV A,@R0 Chinh sua boi: nguyenvanbientbd47@gmail.com CJNE A,#74H,QQQ INC R0 MOV A,@R0 CJNE A,#61H,QQQ INC R0 MOV A,@R0 CJNE A,#72H,QQQ INC R0 MOV A,@R0 CJNE A,#74H,QQQ SETB CO_3 QQQ: JB CO_3,MMM ;CO_3=1 KHI START MOV R0,#DEMT MOV DPH,FIRSTH ;LAY DIA CHI TRONG RAM MOV DPL,FIRSTL ; UUU: MOV A,@R0 ;LAY DATA TU VUNG DEM THU MOVX @DPTR,A ;GHI VAO RAM 8K NOP INC R0 INC DPTR CJNE R0,#DEMT+8,UUU MOV FIRSTH,DPH ;LUU DIA CHI TRONG RAM MOV FIRSTL,DPL ; SJMP QQC MMM: MOV FIRSTH,#00H ;DAT LAI VUNG NHO DAU MOV FIRSTL,#00H CLR CO_3 QQC: POP ACC POP 00H RET Chinh sua boi: nguyenvanbientbd47@gmail.com ;************************************************* ;CHUONG TRINH CON KIEM TRA CHUOI END(MA LA FCH) ;************************************************* KT_END: PUSH ACC push 00H MOV R0,#DEMT MOV A,@R0 CJNE A,#45H,KKK INC R0 MOV A,@R0 CJNE A,#4EH,KKK INC R0 MOV A,@R0 CJNE A,#44H,KKK SETB CO_X SETB TI MOV 60H,#00H ;RESET LAI DIA CHI DAU VUNG DEM PHAT SETB RUN ;DEN SANG MAU VANG SETB NAP KKK: POP 00H POP ACC RET ;****************************************** ; CHUONG TRINH NHAN 3 BYTE,CHE DO MASTER ;**************START*********************** CTNHANM: JNB RI,$ CLR RI JNB RB8,CNT1 MOV A,SBUF CJNE A,#DCMPLC,CNTC CLR SM2 MOV R0,#demt SJMP CNTC CNT1: MOV A,SBUF CJNE R0,#demt+1,CNT2 SETB SM2 CJNE A,#0DH,CNT3 SETB CO_1 SJMP CNTC CNT2: MOV @R0,A INC R0 SJMP CNTC CNT3: SETB CO_L1 CNTC: RET ;************END************************ ;************************************************* ; CHUONG TRINH TRUYEN 1 BYTE,CHE DO MASTER ;**************START**************************** CTRUYENM: JNB TI,$ CLR TI mov A,bien1 cjne A,#3,ctr3 mov bien1,#0 sjmp ctrc ctr3: INC bien1 MOV A,bien1 Chinh sua boi: nguyenvanbientbd47@gmail.com CJNE A,#1,CTR1 SETB TB8 MOV SBUF,#DCSPLC MOV R0,#demp SJMP CTRC CTR1: CJNE A,#3,CTR2 CLR TB8 MOV SBUF,#0DH SETB CO_2 SJMP CTRC CTR2: CLR TB8 MOV A,@R0 MOV SBUF,A INC R0 CTRC: RET ;************END************************ ;***************************************** ; CHUONG TRINH TAO MAU 1S ;****************START******************** MAU: DJNZ bien2,MAUC MOV bien2,#chon1 DJNZ bien3,MAUC MOV bien3,#chon2 INC bien4 MOV A,bien4 CJNE A,#th+1,MAU1 MOV bien4,#1 MAU1: SETB SM2 SETB TI MAUC: RET ;*****************END*************************** ;*********************************************** ; CHUONG TRINH CHO NHAN DU LIEU ;*****************START************************* CHO_NHAN: JNB CO_2,CANC JNB CO_1,CAN1 CLR CO_1 CLR CO_2 MOV bien5,#chon1 SJMP CANC CAN1: DJNZ bien5,CANC CLR CO_2 SETB CO_L1 CANC: RET ;*******************END**************************** ;********************************************** ;CHUONG TRINH CON QUET CHUONG TRINH TRONG RAM ;NGOAI VOI DIA CHI BAT DAU LA 0000H ;********************************************** QUETCT: MOV DBITC,#0 MOV DX,#0 MOV Z,#50H ;Z CHUA MA TB [...]... A,THANG ;CAI DAT THANG MOVX @DPTR,A NOP MOV DPTR,#1FFFH MOV A,NAM ;CAI DAT NAM MOVX @DPTR,A Chinh sua boi: nguyenvanbientbd47@gmail.com NOP MOV DPTR,#1FF8H ;KHONG CHO PHEP CAI DAT MOV A,#00H MOVX @DPTR,A NOP POP DPL POP DPH MOV IE,#92H ;CHO PHEP NGAT MOV TEMP1,DPH MOV TEMP2,DPL RET ;***************************************************************** ;CHUONG TRINH CON LENH MOVX ;*****************************************************************... TRA_BIT: PUSH DPL PUSH DPH PUSH ACC MOV CO_TAM1,C MOV A,DBITC MOV B,#8 DIV AB MOV LUU_B,A MOV STEP1,B ;STEP1 LUU VI TRI BIT CAN DICH LAN 1 INC LUU_B MOV DPH,BITH MOV DPL,BITL ZXC1: INC DPTR DJNZ LUU_B,ZXC1 MOVX A,@DPTR MOV FLOAT,A ;LUU BYTE CAN DICH CLR C MOV A,#8 SUBB A,STEP1 MOV STEP2,A ;STEP2 LUU VI TRI DICH LAN 2 MOV A,FLOAT RRC A AGAIN1:RRC A DJNZ STEP1,AGAIN1 MOV C,TAM4 AGAIN2:RRC A DJNZ STEP2,AGAIN2... MOV TEMP2,DPL RET ;**************************************************************** ;CHUONG TRINH CON RETTENTIVE ON _DELAY ;VAR1:byte dem chua gia tri dat cua on_delay timer ;VAR1,VAR2:byte dem co danh cho on_delay ;bit phat hien canh len ;bit phat hien dem xong chua;0:CHUA XONG,1:XONG ROI ;***************************************************************** Chinh sua boi: nguyenvanbientbd47@gmail.com COM_RET:... ;********************************************************* ;CHUONG TRINH CON COUNTER ;byte du lieu co the lay tu M1 >M16(70H ->7FH) ;hoac co the lay truc tiep tu #00 >#99 ;VAR1:byte dem chua gia tri dat cua COUNTER ;VAR2:byte dem co danh cho COUNTER ;TAM4:bit phat hien canh len cua counter ;**************************************************** COM_COUNT: INC DX LCALL DEMTR INC DPTR MOVX A,@DPTR LCALL GOI_MA MOV TAM1,C INC DPTR MOVX A,@DPTR... ;CHUONG TRINH CON LENH CLOCK SET ;****************************************************** CLOCK_SET: INC DPTR LCALL COPY_TIME ;CHEP DU LIEU PUSH DPH PUSH DPL MOV IE,#00H ;CAM CAC NGAT MOV DPTR,#1FF8H ;CHO PHEP CAI DAT MOV A,#10000000B MOVX @DPTR,A MOV DPTR,#1FF9H MOV A,GIAY ;CAI DAT GIAY MOVX @DPTR,A NOP MOV DPTR,#1FFAH MOV A,PHUT ;CAI DAT PHUT MOVX @DPTR,A NOP MOV DPTR,#1FFBH MOV A,GIO ;CAI DAT GIO... ;**************************************************** ;CHUONG TRINH CON ON DELAY ;byte du lieu co the lay tu M1 >M16(70H ->7FH) ;hoac co the lay truc tiep tu #00 >#99 ;VAR1:byte dem chua gia tri dat cua on_delay timer ;VAR2,VAR3:byte dem co danh cho on_delay ;**************************************************** COM_ON: inc DX ;dem timer lcall DEMTR INC DPTR ;DOC NGO VAO MOVX A,@DPTR LCALL GOI_MA MOV TAM1,C INC DPTR ;DOC BYTE DU LIEU MOVX A,@DPTR... A,@DPTR ADD A,R3 XCH A,R6 ADDC A,R2 XCH A,R6 ;R6 LA BYTE CAO MOV R7,A ;R7 LA BYTE THAP MOV COMP1,R6 MOV COMP2,R7 ; -ket thuc phep cong thi R6:high va R5:low -PUSH DPH ;CAT DPTR TRONG CHU KY QUET PLC PUSH DPL ; CJNE R2,#49H,TEST_INR CJNE R4,#49H,TEST_EX ; RAM NOI >RAM NOI MOV A,R3 MOV R0,A MOV A,R5 MOV R1,A IN_L: MOV A,@R0 MOV @R1,A INC R0 INC R1 MOV A,R0 CJNE A,COMP2,IN_L SJMP... A,@DPTR MOV VAR2,A INC DPTR MOVX A,@DPTR MOV VAR3,A POP ACC POP DPH POP DPL RET ;************************************************************ ;CHUONG TRINH CON TRA BYTE,MOI LAN TRA 2 BYTE ;SO TT BYTE CHO BOI DBC ;*************************************************************** TRAVE: PUSH DPL PUSH DPH PUSH ACC MOV A,DX MOV B,#2 MUL AB DEC A MOV REPL,A MOV DPL,BTHAP MOV DPH,BCAO GROW1: INC DPTR DJNZ... ;************************************************ NHAN_BIT: PUSH DPL PUSH DPH PUSH ACC MOV CO_TAM1,C Chinh sua boi: nguyenvanbientbd47@gmail.com CLR C MOV A,DBITC MOV B,#8 DIV AB MOV LUU_B,A MOV STEP1,B ;STEP1 LUU VI TRI BIT CAN DICH INC LUU_B MOV DPH,BITH MOV DPL,BITL ZXC: INC DPTR DJNZ LUU_B,ZXC MOVX A,@DPTR PUSH ACC RRC A AGAIN:RRC A DJNZ STEP1,AGAIN MOV TAM4,C ;TAM4 CHUA BIT CAN LAY POP ACC MOVX @DPTR,A MOV... ;*********************************************************** ;CHUONG TRINH CON OFF_DELAY ;byte du lieu co the lay tu M1 >M16(70H ->7FH) ;hoac co the lay truc tiep tu #00 >#99 ;VAR1:byte dem chua gia tri dat cua OFF_delay timer ;VAR2,VAR3:byte dem co danh cho OFF_delay ;********************************************************** COM_OFF: INC DX lcall demtr INC DPTR MOVX A,@DPTR LCALL GOI_MA Chinh sua boi: nguyenvanbientbd47@gmail.com MOV TAM1,C INC DPTR . CHÖÔNG TRÌNH VIEÁT TREÂN VI XÖÛ LYÙ Chinh sua boi: nguyenvanbientbd47@gmail.com ;;;;;;;;;;;;;;;;CHÖÔNG TRÌNH VIEÁT CHO PLC NEÀN;;;;;;;;;;;;;;;;;; ;VIET NGAY 04/11/2000 ;CHUONG TRINH CHO PHEP. DCMPLC EQU 02H DCSPLC EQU 03H demt EQU 50H demp EQU 60H bien1 EQU 5EH bien2 EQU 5FH bien3 EQU 5CH bien4 EQU 5BH ;chua d/c Slave bien5 EQU 5AH ;chua THOI GIAN CHO count EQU 10000 chon1. ;byte cao cua data pointer dung cho dem bit BITL EQU 33H ;byte thap cua data pointer dung cho dem bit LUU_B EQU 32H ;byte luu bit tam BCAO EQU 31H ;DIA CHI DAU VUNG CHO TIMER,COUNTER BTHAP EQU 30H ;