list p=16C57 INCLUDE "d:piclibp16c5x.inc" ;************************************************** VAR0 EQU 08H VAR1 EQU 09H
;**************************************************
TRISC_RD EQU 0BFH ;read rom data TRISC_WR EQU 03FH ;write rom data
COMM_WR EQU 0A0H COMM_RD EQU 0A1H
#DEFINE PC_SDA PORTC,7 #DEFINE PC_SCL PORTC,6 ;**************************************************
ORG 0000H GOTO RESET
ROM_START: MOVLW TRISC_RD TRIS 7 CALL NOP_4 BTFSS PC_SDA GOTO START_ERR MOVLW TRISC_WR TRIS 7 CALL NOP_4 BSF PC_SDA CALL NOP_4 BSF PC_SCL CALL NOP_4 BCF PC_SDA CALL NOP_4 BCF PC_SCL CALL NOP_4 BTFSC PC_SDA GOTO ROM_START RETLW 00H
RESET: CALL ROM_START
WR_COM: MOVLW 08H MOVWF VAR0 MOVLW COMM_WR MOVWF VAR1 CALL WR_LOOP
MOVLW 00H MOVWF VAR1 MOVLW 08H MOVWF VAR0 CALL WR_LOOP
CALL ROM_START MOVLW 08H MOVWF VAR0 MOVLW COMM_RD MOVWF VAR1 CALL WR_LOOP MOVLW 08H MOVWF VAR1
READ1: MOVLW TRISC_RD TRIS 7 READ2: BSF PC_SCL RLF VAR0 BSF VAR0,0 BTFSS PC_SDA BCF VAR0,0 BCF PC_SCL DECF VAR1 SKPZ GOTO READ2
MOVLW TRISC_WR TRIS 7 BSF PC_SDA CALL NOP_4 BSF PC_SCL CALL NOP_4 BCF PC_SCL
CALL ROM_STOP GOTO $
ROM_STOP: BCF PC_SDA MOVLW TRISC_WR TRIS 7 BSF PC_SCL CALL NOP_4 BSF PC_SDA CALL NOP_4 RETLW 00H
START_ERR: NOP NOP GOTO ROM_START
NOP_4: RETURN
WR_LOOP: RLF VAR1 MOVLW TRISC_WR TRIS 7 BTFSC STATUS,C BSF PC_SDA BTFSS STATUS,C BCF PC_SDA CALL NOP_4 BSF PC_SCL CALL NOP_4 DECF VAR0 SKPZ GOTO WR_LOOP
BSF PC_SCL CALL NOP_4 BCF PC_SCL RETLW 00H END
谁有的话,发一个给我吧, chqy326@163.com |