How to read eeprom M27C64A with pic18f4520, should i enable and disable the chip enable as well as output enable inside the loop while increasing the address?

Can someone suggest me some code or ideas.


The eeprom has the following data from 0x00 address

x"7F" , x"97" , x"AF" , x"C5" , x"D8" , x"E8" , x"F4" , x"FB" , x"FE" , x"FB" , x"F4" , x"E8" , x"D8" , x"C5" , x"AF" , x"97" , x"7F" , x"67" , x"4F" , x"39" , x"26" , x"16" , x"0A" , x"03" , x"00" , x"03" , x"0A" , x"16" , x"26" , x"39" , x"4F" , x"67"


include "P18F4520.inc"

var1 res 1
var2 res 1
var3 res 1
address res 1
firstadd res 1
lastadd res 1
outreg res 1
savedWREG res 1

org 0
goto main

org 100
clrf PORTA
clrf TRISA  ;address
clrf PORTC
clrf TRISC  ;enable
setf TRISB  ;input
clrf PORTD
clrf TRISD  ;output
movlw 0x00
movwf firstadd
movlw 0x1f
movwf lastadd

movff firstadd,address

movff address,PORTA
clrf PORTC  ;out enable
call delay
movff PORTB,outreg
movff outreg,PORTD
setf PORTC  ;out disable
incf address
movf lastadd,W
cpfslt address
goto repeat
goto loop

movwf savedWREG
movlw 0x0C
movwf var1

decfsz var1
goto delayloop
movf savedWREG,W



  • 1
    \$\begingroup\$ It's an EPROM, not an EEPROM! Read details are in the data sheet. \$\endgroup\$ – Leon Heller Nov 28 '11 at 19:22

The easiest way of wiring the chip would be to wire D0-D7 to one I/O port (in order), A0-A7 to another (likewise), and A8-A12 to bits 0-5 of a third I/O port, and /CS to a free pin somewhere. To read an address, make sure the TRIS of the D0-D7 port is set to 0xFF, and then write the LSB of the desired address to the A0-A7 port and the MSB to the A8-A12 port. Set the /CS pin low (if it's on the same I/O port as A8-A12, one can set it low in the same operation that writes those bits). To fetch the data, read the I/O port to which D0-D7 are connected. When not reading an EPROM location, set /CS high. Most EPROMs (including any that call themselves 2764, 27C64, or any other such thing) won't care if /CS is left between bytes but there are some other EPROMS (e.g. 87C64 if memory serves) which are similar to the 27C64 except that they require that /CS go high between bytes.

This approach will use up lots of I/O pins, but will allow fast access to any desired byte of memory. Other approaches may be used to trade off I/O pins for access speed. What are your actual requirements?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.