Không biết vì sao em chỉ dùng ngắt int0 chỉ được 1 lần.
Code:
SCL BIT P3.0 SDA BIT P3.1 DULIEU EQU 50H ADD_DATA EQU 54H GIO EQU 51H PHUT EQU 52H GIAY EQU 53H ORG 00H LJMP MAIN ORG 0013H CHINH_GIO: JNB P3.2,OUTH MOV A,GIO MOV DULIEU,GIO CALL HIENTHI_H CALL CHECK SJMP CHINH_GIO OUTH: MOV ADD_DATA,#02H CALL SEND_DATA JNB P3.2,$ sjmp CHINH_PHUT CHECK: JB P1.0,CHECK2 JNB P1.0,$ INC GIO SJMP CHECK CHECK2: JB P1.1,EXIT JNB P1.1,$ DEC GIO EXIT: RET CHINH_PHUT: JNB P3.2,OUTP MOV A,PHUT MOV DULIEU,PHUT CALL HIENTHI_P CALL CHECKP SJMP CHINH_PHUT OUTP: MOV ADD_DATA,#01H CALL SEND_DATA JNB P3.2,$ sjmp CHINH_GIAY CHECKP: JB P1.0,CHECKP2 JNB P1.0,$ INC PHUT SJMP CHECKP CHECKP2: JB P1.1,EXIT JNB P1.1,$ DEC PHUT RET CHINH_GIAY: JNB P3.2,OUTS MOV A,GIAY MOV DULIEU,GIAY CALL HIENTHI_S CALL CHECKS SJMP CHINH_GIAY OUTS: MOV ADD_DATA,#00H CALL SEND_DATA RETI CHECKS: JB P1.0,CHECKS2 JNB P1.0,$ INC GIAY SJMP CHECKS CHECKS2: JB P1.1,EXIT JNB P1.1,$ DEC GIAY RET ORG 40H MAIN: MOV IE,#10000100b WAIT: CALL HIEN_NORMAL SJMP WAIT HIEN_NORMAL: CALL HIEN_S CALL HIEN_P CALL HIEN_H RET HIEN_S: MOV ADD_DATA,#00H CALL READ_DATA MOV GIAY,DULIEU CALL HIENTHI_S RET HIEN_P: MOV ADD_DATA,#01H CALL READ_DATA MOV PHUT,DULIEU CALL HIENTHI_P RET HIEN_H: MOV ADD_DATA,#02H CALL READ_DATA MOV GIO,DULIEU CALL HIENTHI_H RET SEND_DATA: CALL START MOV A,#0D0H CALL SEND SETB SCL CLR SCL MOV A,ADD_DATA CALL SEND SETB SCL CLR SCL MOV A,DULIEU CALL SEND SETB SCL CLR SCL CALL STOP RET READ_DATA: CALL START MOV A,#0D0H CALL SEND SETB SCL CLR SCL MOV A,ADD_DATA CALL SEND SETB SCL CLR SCL CALL STOP CALL START MOV A,#0D1H CALL SEND SETB SCL CLR SCL CALL RECIVE SETB SCL CLR SCL CALL STOP RET SEND: MOV R1,#8 LOOP: RLC A MOV SDA,C SETB SCL CLR SCL DJNZ R1,LOOP RET RECIVE: MOV R1,#8 CLR A LOOP1: MOV C,SDA SETB SCL CLR SCL RLC A DJNZ R1,LOOP1 MOV DULIEU,A RET START: SETB SDA SETB SCL NOP CLR SDA NOP CLR SCL RET STOP: CLR SCL CLR SDA NOP SETB SCL NOP SETB SDA RET HIENTHI_S: MOV P2,#00000000B SWAP A ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.0 CALL DELAY CLR P2.0 MOV A,DULIEU ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.1 CALL DELAY CLR P2.1 RET HIENTHI_P: MOV P2,#00000000B SWAP A ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.2 CALL DELAY CLR P2.2 MOV A,DULIEU ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.3 CALL DELAY CLR P2.3 RET HIENTHI_H: MOV P2,#00000000B SWAP A ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.4 CALL DELAY CLR P2.4 MOV A,DULIEU ANL A,#00001111B MOV DPTR,#MALED ; MOVC A,@A+DPTR MOV P0,A SETB P2.5 CALL DELAY CLR P2.5 RET DELAY: MOV R1,#99 DJNZ R1,$ RET MALED: DB 40H,79H,24H,30H,19H,12H,02H,78H,00H,10H,21H,08H,11H,7FH,46H,48H END
Comment