Hola muy buenas, veran mi caso es que tengo que ir almacenando datos obtenidos en el PIC en una EEPROM, para ello voy a utilizar la EEPROM 25LC1024,aqui os dejo el enlace del datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/22064A.pdf y el PIC que voy a utilizar es el 16C74. Quiero usar el protocolo SPI pues es más rapido, ya que usaré para mi PIC un cristal de 20 MHz. He conseguido un codigo de microchip pero a la hora de probarlo no me funciona. Las conexiones que hago estan en este enlace:
http://ww1.microchip.com/downloads/en/AppNotes/00966A.pdfLes pongo el codigo que pone en la pagina pero es que no me funciona, aver si alguien me puede decir en que stoy fallando, por otra parte hay un codigo de un delay que no se para que se usa.
Saludos
LIST P=16C74
#include <p16c74a.inc>
; Port C pin descriptions
; SCK bit = 3
; SDI bit = 4
; SDO bit = 5
; CS_ bit = 7
;
;
;*******************RAM register definitions**********************
w equ 1
f equ 0
rxdata equ 20h
txdata equ 21h
addr equ 22h
loops equ 23h
outbyte equ 24h
temp1 equ 25h
temp2 equ 26h
;*******************Bit definitions*******************************
CS_ equ 7
;*******************Include file**********************************
;*****************************************************************
org 0x000 ; set the reset vector
goto start ; go to the beginning of main
;!!!!!!!!!!!!!!!!!!!!!!Begin Main Program!!!!!!!!!!!!!!!!!!!!!!!!!
start
clrf PORTC
BSF STATUS,RP0 ; initialize portc to 0
movlw 0x10 ; all bits are outputs except SDI
movwf TRISC ; move the value to TRIS portc
BCF STATUS,RP0
bsf PORTC,CS_ ; make the chip select is high
clrf PIE1 ; disable peripheral interrupts
clrf INTCON ; disables all interrupts
clrf SSPCON ; clear SSP control register
movlw 0x31 ; set up spi port, SPI master,
movwf SSPCON ; clk/16, ckp=1 (mode 1,1)
BSF STATUS,RP0
clrf SSPSTAT ; clear SSP status register
movlw 0x80 ; set up spi port, SPI master,
movwf SSPSTAT ; cke = 0 (mode 1,1)
BCF STATUS,RP0
movlw 0x55 ; put starting address 55 in
movwf addr ; addr for later use
;Send the write enable sequence (WREN)
bcf PORTC,CS_ ; clear the chip select (active)
movlw 0x06 ; load WREN sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
bsf PORTC,CS_ ; set the chip select line
;Send the read status register sequence (RDSR)
bcf PORTC,CS_ ; clear the chip select line
movlw 0x05 ; load RDSR sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load up zero to send
movwf outbyte ; store in RAM location outbyte
call output ; read the data in status reg.
bsf PORTC,CS_ ; set the chip select line
;Send the write sequence (WRITE)
bcf PORTC,CS_ ; clear the chip select line
movlw 0x02 ; load WRITE sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
; Enviamos direccion 00055
movlw 0x00 ; load high address byte
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load high address byte
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movf addr,W ; move the address into w
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
; Enviamos dato
movlw 0xAA ; load data AA into w
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
bsf PORTC,CS_ ; set the chip select line
;Perform data polling (RDSR bit 0)
polling
bcf PORTC,CS_ ; clear the chip select line
movlw 0x05 ; load RDSR sequence
movwf outbyte ; store in RAM location outbyte
call output ; read the data in status reg.
movlw 0x00 ; load up zero to send
movwf outbyte ; store in RAM location outbyte
call output ; read the data in status reg.
bsf PORTC,CS_ ; set the chip select line
btfsc rxdata,0 ; test the WIP bit in status reg.
goto polling ; WIP set, loop until WIP clear
bsf PORTC,CS_ ; Set the CS line
;Send read sequence (READ), read address 0x55
bcf PORTC,CS_ ; clear the chip select line
movlw 0x03 ; load READ sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load high address byte
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load high address byte
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movf addr,W ; move the address into w
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load high address byte
movwf outbyte ; store in RAM location outbyte
call output ; call output to read 1 byte
bsf PORTC,CS_ ; set the chip select line
;Send the write enable sequence (WREN)
bcf PORTC,CS_ ; clear the chip select (active)
movlw 0x06 ; load WREN sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
bsf PORTC,CS_ ; set the chip select line
;Send the read status register sequence (RDSR)
bcf PORTC,CS_ ; clear the chip select line
movlw 0x05 ; load RDSR sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load up zero to send
movwf outbyte ; store in RAM location outbyte
call output ; read the data in status reg.
bsf PORTC,CS_ ; set the chip select line
;Send the write disable sequence (WRDI)
bcf PORTC,CS_ ; clear the chip select (active)
movlw 0x04 ; load WRDI sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
bsf PORTC,CS_ ; set the chip select line
;Send the read status register sequence (RDSR)
bcf PORTC,CS_ ; clear the chip select line
movlw 0x05 ; load RDSR sequence
movwf outbyte ; store in RAM location outbyte
call output ; call the SPI output routine
movlw 0x00 ; load up zero to send
movwf outbyte ; store in RAM location outbyte
call output ; read the data in status reg.
;*******Go back to main routine*********************************
goto start
;*******************SPI output subroutine***********************
output
movf outbyte,W ; move outbyte into w
movwf SSPBUF ; place data in send buffer
loop1
BSF STATUS,RP0
btfss SSPSTAT,BF ; has data been received?
goto loop1 ; loop if not received yet
BCF STATUS,RP0
movf SSPBUF,W ; empty the receive buffer
movwf rxdata ; put received byte into rxdata
retlw 0 ; return from subroutine
; 250 x 400nS x 50 = 5mS (plus overhead)
delay
movlw 0x32 ; move 50 decimal into w
movwf temp1 ; move 50 decimal into temp1
dec1
movlw 0xFA ; move 250 decimal into w
movwf temp2 ; move 250 decimal into temp2
dec2
decfsz temp2,1 ; decrement temp2, skip if zero
goto dec2 ; goto decrement 2 if not zero
decfsz temp1,1 ; decrement temp1, skip if zero
goto dec1 ; goto decrement 1 if not zero
retlw 0 ; return both locations = 0
END