Phần chương trình viết trên vi xử lý

Chia sẻ: Mr Mai | Ngày: | Loại File: PDF | Số trang:110

0
319
lượt xem
99
download

Phần chương trình viết trên vi xử lý

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tài liệu tham khảo môn công nghệ thông tin dành cho những bạn yêu thích lập trình máy tính,với chương trình viết trên vi xử lý,giup các bạn hiểu thêm về kỹ thuật lập trình.

Chủ đề:
Lưu

Nội dung Text: Phần chương trình viết trên vi xử lý

  1. Chinh sua boi: nguyenvanbientbd47@gmail.com PHAÀN CHÖÔNG TRÌNH VIEÁT TREÂN VI XÖÛ LYÙ
  2. 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
  3. 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:
  4. 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
  5. 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
  6. 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************************************** ;------------------------------------------------------
  7. 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
  8. 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
  9. 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
  10. 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
  11. Chinh sua boi: nguyenvanbientbd47@gmail.com XRL OUT_ST,#00H MOV TEMP1,#00H MOV TEMP2,#00H MOV DPTR,#0000H ;X CHUA DIA CHI HIEN TAI QUET_LAI: MOVX A,@DPTR CJNE A,Z,BLOI INC Z INC DPTR LCALL DE_CODE JNB KT,QUET_LAI CLR LOI CLR KT MOV DX,#0 SJMP RA BLOI: SETB LOI RA: RET ;******************************************* ;CHUONG TRINH CON NHAN DANG MA LENH ;ma lenh chuong trinh tu F0-->FC ;******************************************* DE_CODE: MOVX A,@DPTR CJNE A,#0F0H,LAM2 LCALL COM_AND SJMP DONE LAM2:CJNE A,#0F1H,LAM3 LCALL COM_OR SJMP DONE LAM3:CJNE A,#0F2H,LAM4 LCALL COM_NAND SJMP DONE LAM4:CJNE A,#0F3H,LAM5 LCALL COM_NOR SJMP DONE LAM5:CJNE A,#0F4H,LAM6 LCALL COM_NOT SJMP DONE LAM6:CJNE A,#0F5H,LAM7 LCALL COM_SR SJMP DONE LAM7:CJNE A,#0F6H,LAM8 LCALL COM_ON SJMP DONE LAM8:CJNE A,#0F7H,LAM9 LCALL COM_OFF SJMP DONE LAM9:CJNE A,#0F8H,LAM10 LCALL COM_PULSE SJMP DONE LAM10:CJNE A,#0F9H,LAM11 LCALL COM_RET SJMP DONE LAM11:CJNE A,#0FAH,LAM12 LCALL COM_COUNT SJMP DONE LAM12:CJNE A,#0FBH,LAM13 LCALL COM_MOV SJMP DONE LAM13:CJNE A,#0FDH,LAM14 LCALL CLOCK_ON
  12. Chinh sua boi: nguyenvanbientbd47@gmail.com SJMP DONE LAM14:CJNE A,#0FEH,LAM15 LCALL CLOCK_OFF SJMP DONE LAM15:CJNE A,#0FFH,LAM16 LCALL CLOCK_SET SJMP DONE LAM16:CJNE A,#0D0H,LAM17 LCALL MOV_EXT SJMP DONE LAM17: CJNE A,#0FCH,DONE SETB KT DONE: RET ;******************************************* ;chuong trinh con lenh OR ;******************************************* COM_OR: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP5 CLR TAM1 SJMP FR1 NIP5: LCALL GOI_MA MOV TAM1,C FR1: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP6 CLR TAM2 SJMP FR2 NIP6: LCALL GOI_MA MOV TAM2,C FR2: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP7 CLR C SJMP FR3 NIP7: LCALL GOI_MA FR3: ORL C,TAM1 ORL C,TAM2 MOV TAM3,C INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP8 LCALL XUAT_TB SJMP QUIT1 NIP8: LCALL OUTPUT QUIT1:INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL RET ;******************************************* ;CHUONG TRINH CON LENH AND ;******************************************* COM_AND: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP1 SETB TAM1 SJMP FOR1 NIP1:LCALL GOI_MA MOV TAM1,C
  13. Chinh sua boi: nguyenvanbientbd47@gmail.com FOR1: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP2 SETB TAM2 SJMP FOR2 NIP2: LCALL GOI_MA MOV TAM2,C FOR2: INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP3 SETB C SJMP FOR3 NIP3: LCALL GOI_MA FOR3: ANL C,TAM1 ANL C,TAM2 MOV TAM3,C INC DPTR MOVX A,@DPTR CJNE A,#78H,NIP4 LCALL XUAT_TB SJMP QUIT NIP4: LCALL OUTPUT QUIT: INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL RET ;******************************************** ;CHUONG TRINH CON LENH NAND ;******************************************** COM_NAND: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP1 SETB TAM1 SJMP FUR1 SKP1: LCALL GOI_MA MOV TAM1,C FUR1: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP2 SETB TAM2 SJMP FUR2 SKP2: LCALL GOI_MA MOV TAM2,C FUR2: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP3 SETB C SJMP FUR3 SKP3: LCALL GOI_MA FUR3: ANL C,TAM1 ANL C,TAM2 CPL C MOV TAM3,C INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP4 LCALL XUAT_TB SJMP QUITT SKP4: LCALL OUTPUT QUITT: INC DPTR
  14. Chinh sua boi: nguyenvanbientbd47@gmail.com MOV TEMP1,DPH MOV TEMP2,DPL RET ;******************************************** ;CHUONG TRINH CON LENH NOR ;********************************************* COM_NOR: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP5 CLR TAM1 SJMP FRR1 SKP5: LCALL GOI_MA MOV TAM1,C FRR1: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP6 CLR TAM2 SJMP FRR2 SKP6: LCALL GOI_MA MOV TAM2,C FRR2: INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP7 CLR C SJMP FRR3 SKP7: LCALL GOI_MA FRR3: ORL C,TAM1 ORL C,TAM2 CPL C MOV TAM3,C INC DPTR MOVX A,@DPTR CJNE A,#78H,SKP8 LCALL XUAT_TB SJMP QUITT1 SKP8: LCALL OUTPUT QUITT1: INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL RET ;**************************************************** ;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 CJNE A,#100,ABB ABB: JNC SS MOV VAR1,A SJMP DEN
  15. Chinh sua boi: nguyenvanbientbd47@gmail.com SS: PUSH 01H MOV R1,A MOV VAR1,@R1 POP 01H DEN: JNB TAM1,NHAY1 MOV R2,VAR2 INC R2 CJNE R2,#100,NHAY2 MOV VAR2,#0 lcall trave MOV A,VAR3 INC A CJNE A,VAR1,NHAY3 MOV VAR3,#0 lcall trave SETB TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,HA LCALL XUAT_TB SJMP TANG HA: LCALL OUTPUT SJMP TANG NHAY1: MOV VAR2,#0 MOV VAR3,#0 lcall trave CLR TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,HA1 LCALL XUAT_TB SJMP TANG HA1: LCALL OUTPUT SJMP TANG NHAY2: MOV VAR2,R2 lcall trave INC DPTR SJMP TANG NHAY3: MOV VAR3,A lcall trave INC DPTR TANG: INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL RET ;*********************************************************** ;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
  16. Chinh sua boi: nguyenvanbientbd47@gmail.com MOV TAM1,C INC DPTR MOVX A,@DPTR CJNE A,#100,ABC ABC: JNC SAS MOV VAR1,A SJMP TIEPP SAS: PUSH 01H MOV R1,A MOV VAR1,@R1 POP 01H TIEPP: JB TAM1,NHAY4 MOV R2,VAR2 INC R2 CJNE R2,#100,NHAY5 MOV VAR2,#0 LCALL TRAVE MOV A,VAR3 INC A CJNE A,VAR1,NHAY6 MOV VAR3,#0 CLR TAM3 lcall trave INC DPTR MOVX A,@DPTR CJNE A,#78H,HAN LCALL XUAT_TB SJMP TANG1 HAN: LCALL OUTPUT SJMP TANG1 NHAY4: MOV VAR2,#0 MOV VAR3,#0 LCALL TRAVE SETB TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,HAN1 LCALL XUAT_TB SJMP TANG1 HAN1: LCALL OUTPUT SJMP TANG1 NHAY5: MOV VAR2,R2 LCALL TRAVE INC DPTR SJMP TANG1 NHAY6: MOV VAR3,A LCALL TRAVE INC DPTR TANG1: INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL RET ;****************************************************** ;CHUONG TRINH CON PULSE_DELAY ;:bit phat hien canh len cua pulse_delay ;:bit trang thai cua pulse_delay ;******************************************************
  17. Chinh sua boi: nguyenvanbientbd47@gmail.com COM_PULSE: INC DPTR MOVX A,@DPTR LCALL GOI_MA MOV TAM1,C INC DPTR MOVX A,@DPTR LCALL GOI_MA MOV TAM2,C JB TAM2,RSET INC DBITC LCALL NHAN_BIT JNB TAM1,LUU1 JB TAM4,KXET MOV C,TAM1 MOV TAM4,C LCALL TRA_BIT INC DBITC LCALL NHAN_BIT CPL TAM4 LCALL TRA_BIT MOV C,TAM4 MOV TAM3,C INC DPTR MOVX A,@DPTR CJNE A,#78H,OUTTO LCALL XUAT_TB SJMP TOUT OUTTO: LCALL OUTPUT SJMP TOUT RSET: INC DBITC INC DBITC CLR TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,EXT LCALL XUAT_TB SJMP TOUT EXT: LCALL OUTPUT SJMP TOUT LUU1: MOV C,TAM1 MOV TAM4,C LCALL TRA_BIT INC DBITC INC DPTR SJMP TOUT KXET: INC DBITC INC DPTR TOUT: INC DPTR MOV TEMP1,DPH 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 ;*****************************************************************
  18. Chinh sua boi: nguyenvanbientbd47@gmail.com COM_RET: INC DX LCALL DEMTR INC DPTR MOVX A,@DPTR LCALL GOI_MA MOV TAM1,C INC DPTR MOVX A,@DPTR LCALL GOI_MA MOV TAM2,C INC DPTR MOVX A,@DPTR CJNE A,#100,FBI FBI: JNC GMC MOV VAR1,A SJMP CHINH GMC: PUSH 01H MOV R1,A MOV VAR1,@R1 POP 01H CHINH: JB TAM2,RESET2 INC DBITC LCALL NHAN_BIT JB TAM4,DEML ;BIT=1:DEM CHUA XONG;BIT=0:DEM XONG INC DBITC LCALL NHAN_BIT JNB TAM1,LUU2 JB TAM4,BQUA MOV C,TAM1 MOV TAM4,C LCALL TRA_BIT DEC DBITC SETB TAM4 LCALL TRA_BIT DEML: MOV R2,VAR2 INC R2 CJNE R2,#100,NHAY7 MOV VAR2,#0 LCALL TRAVE MOV A,VAR3 INC A CJNE A,VAR1,NHAY8 MOV VAR3,#0 LCALL TRAVE CLR TAM4 ;DA DEM XONG LCALL TRA_BIT INC DBITC SETB TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,OUTTO1 LCALL XUAT_TB SJMP NDD OUTTO1:LCALL OUTPUT SJMP NDD NHAY7:INC DBITC MOV VAR2,R2 LCALL TRAVE INC DPTR
  19. Chinh sua boi: nguyenvanbientbd47@gmail.com SJMP NDD NHAY8:INC DBITC MOV VAR3,A LCALL TRAVE INC DPTR SJMP NDD RESET2:INC DBITC INC DBITC MOV VAR2,#0 MOV VAR3,#0 LCALL TRAVE CLR TAM3 INC DPTR MOVX A,@DPTR CJNE A,#78H,OUTTO2 LCALL XUAT_TB SJMP NDD OUTTO2:LCALL OUTPUT SJMP NDD LUU2: MOV C,TAM1 MOV TAM4,C LCALL TRA_BIT INC DPTR SJMP NDD BQUA: INC DPTR NDD: INC DPTR MOV TEMP1,DPH MOV TEMP2,DPL 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 LCALL GOI_MA MOV TAM2,C INC DPTR MOVX A,@DPTR CJNE A,#100,ABD ABD: JNC SS2 MOV VAR1,A SJMP JUMP SS2: PUSH 01H MOV R1,A MOV VAR1,@R1 POP 01H JUMP: JB TAM2,RESET3 INC DBITC
Đồng bộ tài khoản