我是使用MICROCHIP放在網路上的程式
寫入時可以確定是我寫入的DATA
我是用示波器測量出波型
在讀取時我發現讀出的數值也正確
可是我不知道它將讀出的值放在哪裡
由程式的語法得知,他把資料放在datai 的位置
可是我把datai位置的資料叫出來,發現是不對的
想請問是否讀取錯誤
以下是MICROCHIP的程式
PIC10F202 and
; the PIC12F675 are supported by this code.
LIST P=12F675 ; This can be either 10F202 or 12F675
; GPIO pin descriptions
; SDA bit = 0
; SCL bit = 1
;
; 4MHz internal oscillator is being used, thus each instruction
; cycle = 1000 ns
;
;*******************Include file**********************************
; Include the appropriate header file, only one will be selected
IFDEF __10F202
include "p10f202.inc" ; This is the include file for a PIC10F202
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
ENDIF
IFDEF __12F675
include "p12f675.inc" ; This is the include file for a PIC12F675
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _CPD_OFF
ENDIF
errorlevel -302 ; Suppress message 302 from list file
;*****************************************************************
org 0x000 ; Set the reset vector
goto start ; Go to the beginning of main
;*******************Macro definitions*****************************
IFDEF __10F202
SETTRIS macro ; Macro to set TRIS reg. on PIC10F202
tris GPIO ; Copy value to TRIS reg.
endm
ENDIF
IFDEF __12F675
SETTRIS macro ; Macro to set TRISIO reg. on PIC12F675
banksel TRISIO ; Select Bank 1
movwf TRISIO ; Copy value to TRISIO reg.
banksel GPIO ; Select Bank 0
endm
ENDIF
;*******************Begin Main Program****************************
include "i2c_routines.inc" ; This is the I2C code
start
bsf GPIO,SCL ; Set SCL high
movlw SDA_IN ; Configure SDA to be an input
SETTRIS ; Copy value to TRISB register
goto BYTEREAD ; Call byte read routine
;*******************Byte read test subroutine*********************
; This routine tests the byte read feature
; of the serial EEPROM device. It will read
; 16 bytes of data from the device starting at
; address 0x50, 1 byte at a time.
;*****************************************************************
BYTEREAD
movlw .16
movwf bytecount ; Initialize counter to 16 bytes
movlw 0x50
movwf address ; Initialize byte address to 0x50
rxbyte
call BSTART ; Generate start bit
; Now send the control byte
; for a write, to set address
movlw WRITE_ADDR
movwf datao ; Copy control byte to buffer
call TX ; Output control byte to device
; Next, the address pointer
movf address,W ; Copy address to WREG
movwf datao ; Copy address to buffer
call TX ; Output address to device
call BSTART ; Generate another start bit
; to switch to read mode
movlw READ_ADDR
movwf datao ; Copy control byte to buffer
call TX ; Output control byte to device
; Finally, read the data byte
bcf buffer,ACKB ; Select to send NO ACK bit
call RX ; Input data from device
call BSTOP ; Generate stop bit
incf address,F ; Increment address pointer
decfsz bytecount,F ; Check if finished looping
goto rxbyte ; Continue looping
goto BYTEREAD
END