專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享
從全面的產(chǎn)品導(dǎo)入到強大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!
PIC16F73讀寫24C01的程序
;*****Start code
E2PROM_START
BSF PORTC,SDAT
BSF PORTC,SCLK
BSF STATUS,5
MOVLW DATA_OUT
MOVWF TRISC
BCF STATUS,5
NOP
NOP
NOP
NOP
NOP
BCF PORTC,SDAT
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTC,SCLK
NOP
NOP
NOP
NOP
RETURN
;*****Stop code
E2PROM_STOP
BCF PORTC,SCLK
BCF PORTC,SDAT
BSF STATUS,5
MOVLW DATA_OUT
MOVWF TRISC
BCF STATUS,5
NOP
NOP
NOP
NOP
BSF PORTC,SCLK
NOP
NOP
NOP
NOP
BSF PORTC,SDAT
NOP
NOP
NOP
NOP
BCF PORTC,SCLK
NOP
NOP
RETURN
;*****Byte out code
E2PROM_BYTE_OUT
MOVLW 08H
MOVWF E2PROM_cnt
BSF STATUS,5
MOVLW DATA_OUT
MOVWF TRISC
BCF STATUS,5
OUT_LOOP
BCF PORTC,SCLK
NOP
NOP
NOP
BTFSS E2PROM_data,7
GOTO PULL_DOWN_SDAT
BSF PORTC,SDAT
GOTO OUT_NEXT_BIT
PULL_DOWN_SDAT
BCF PORTC,SDAT
OUT_NEXT_BIT
RLF E2PROM_data,1
NOP
NOP
BSF PORTC,SCLK
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ E2PROM_cnt,1
GOTO OUT_LOOP
BCF PORTC,SCLK
BSF STATUS,5
MOVLW DATA_IN
MOVWF TRISC
BCF STATUS,5
NOP
NOP
BSF PORTC,SCLK
NOP
NOP
NOP
NOP
NOP
NOP
WAIT_ACK_LOOP
BTFSC PORTC,SDAT
GOTO WAIT_ACK_LOOP
BCF PORTC,SCLK
NOP
NOP
NOP
NOP
NOP
NOP
RETURN
;*****Byte in code
E2PROM_BYTE_IN
MOVLW 08H
MOVWF E2PROM_cnt
CLRF E2PROM_data
BSF STATUS,5
MOVLW DATA_IN
MOVWF TRISC
BCF STATUS,5
BCF STATUS,0
IN_LOOP
RLF E2PROM_data,1
BCF PORTC,SCLK
NOP
NOP
NOP
NOP
NOP
BSF PORTC,SCLK
NOP
NOP
NOP
BTFSS PORTC,SDAT
GOTO REC_DOWN_SDAT
BSF E2PROM_data,0
GOTO IN_NEXT_BIT
REC_DOWN_SDAT
BCF E2PROM_data,0
IN_NEXT_BIT
NOP
NOP
NOP
BCF PORTC,SCLK
NOP
NOP
NOP
DECFSZ E2PROM_cnt,1
GOTO IN_LOOP
NOP
NOP
NOP
RETURN
;*****Read code
READ_E2PROM
MOVLW 0A0H
MOVWF E2PROM_data
CALL E2PROM_START
CALL E2PROM_BYTE_OUT
MOVF E2PROM_addr,0
MOVWF E2PROM_data
CALL E2PROM_BYTE_OUT
MOVLW 0A1H
MOVWF E2PROM_data
CALL E2PROM_START
CALL E2PROM_BYTE_OUT
CALL E2PROM_BYTE_IN
CALL E2PROM_STOP
RETURN
;*****Write code
WRITE_E2PROM
MOVLW 0A0H
MOVWF E2PROM_data
CALL E2PROM_START
CALL E2PROM_BYTE_OUT
MOVF E2PROM_addr,0
MOVWF E2PROM_data
CALL E2PROM_BYTE_OUT
MOVF Need_write_data,0
MOVWF E2PROM_data
CALL E2PROM_BYTE_OUT
CALL E2PROM_STOP
RETURN