Sunday, June 14, 2009

Serial EEPROM








Serial EEPROMs come in three main flavors and variety of sizes. The 93XXX devices are the easiest to interface to microcontroller PIC16F84/A.

The 93C46 is a small non volatile memory peripheral chip. It is organized as 64 registers of 16 bits each. The programming voltage and write timing are developed on-chip. The self timed write cycle takes about 10 miliseconds.

All communication with the 93C64 begins with sending 9 instruction bits. The first bit ( MSB ) is a logic “1” start bit. The remaining 8 bits may be an op code or an op code and address combination. If the operation is a write operation, 16 data bits follow the instruction bits, MSB first.


This chip have control line as follow :

  1. Serial data In
  2. Serial Data Out
  3. Clock
  4. Chip Select

Some use rules are :

  1. A register must be erased ( all 1’s ) before it can be written to. The chip has a built in auto erase cycle which takes place when a write is called for.
  2. The chip select pin ( CS ) must be brought low for a minimum of 1 microsecond between consecutive instruction cycles to synchronize the internal logic of the device
  3. For read operations, a dummy “0” precedes the 16 data bits. Data is shifted out MSB first.
  4. Completion of an erase cycle or write cycle to an individual memory location takes about 10 milliseconds. The serial data output ( DO ) pin may also be used as a status pin during the self timing phase of these operation to indicate the status of the device.

On completion of erase or write, CS is brought low briefly. After that, DO will be low until the operation is complete. When DO goes high again, the device is no longer busy and is accessible for other operations.




;=======93C46.ASM===================================4/26/97==

list p=16f84a

__config h'3ff1'

radix hex

;------------------------------------------------------------

; cpu equates (memory map)

status equ 0x03

porta equ 0x05

portb equ 0x06

cook equ 0x0c

hibyte equ 0x0d

count equ 0x0e

address equ 0x0f

data_hi equ 0x10

data_lo equ 0x11

temp equ 0x12

trisa equ 0x85

trisb equ 0x86

;------------------------------------------------------------

; bit equates

rp0 equ 5

;------------------------------------------------------------

org 0x000

;

start bsf status,rp0 ;switch to bank 1

movlw b'00000001' ;bit 0 = input

movwf trisa

movlw b'00000000' ;outputs

movwf trisb

bcf status,rp0 ;switch back to bank 0

bcf porta,1 ;initialize

bcf porta,2 ;initialize

bcf porta,3 ;initialize

movlw 0x00 ;00000000

movwf portb ;LEDs off

movlw 0x00 ;define test address

movwf address

movlw 0x80 ;define test hi byte

movwf data_hi

movlw 0x0f ;define test lo byte

movwf data_lo

call write ;write subroutine

call read ;read subroutine

movf cook,w ;get lo byte

movwf portb ;display via LEDs

circle goto circle ;done

;------------------------------------------------------------

ewen movlw 0x30 ;ewen op code

movwf cook ;to cook

bsf porta,1 ;send start bit

bsf porta,2 ;shift

bcf porta,2

call sendbits ;send ewen op code

return

;------------------------------------------------------------

ewds movlw 0x00 ;ewds op code

movwf cook ;to cook

bsf porta,1 ;send start bit

bsf porta,2 ;shift

bcf porta,2

call sendbits ;send ewds op code

return

;------------------------------------------------------------

write bsf porta,3 ;cs high

call ewen ;erase/write enable

bcf porta,3 ;cs low

nop ;1 microsecond min

bsf porta,3 ;cs high

movf address,w ;get address

movwf cook ;store in cook

bcf cook,7 ;op code

bsf cook,6 ;ms 2 bits

bsf porta,1 ;send start bit

bsf porta,2 ;shift

bcf porta,2

call sendbits ;send address

movf data_hi,w ;get data hi

movwf cook

call sendbits ;send data hi

movf data_lo,w ;get data lo

movwf cook

call sendbits ;send data lo

bcf porta,3 ;cs low

nop ;1 microsecond min

bsf porta,3 ;cs high

ecycle2 btfss porta,0 ;erase cycle complete?

goto ecycle2 ;not yet

bcf porta,3 ;cs low

nop ;1 microsecond min

call ewds ;yes, erase/write disable

bcf porta,3 ;cs low

nop ;1 microsecond min

return

;------------------------------------------------------------

read bsf porta,3 ;cs high

movf address,w ;get address

movwf cook

bsf cook,7 ;op code

bcf cook,6 ;ms 2 bits

bsf porta,1 ;send start bit

bsf porta,2 ;shift

bcf porta,2

call sendbits ;send address

call getprom ;shift hi 8 bits out of eeprom

movf cook,w ;hi byte result in hibyte

movwf hibyte

call getprom ;shift lo 8 bits out of eeprom

bcf porta,3 ;cs low

nop ;1microsecond min

return ;exit sub with lo byte in cook

;------------------------------------------------------------

sendbits movlw 0x08 ;count=8

movwf count

sbit call sendbit ;send 1 bit

decfsz count,f ;done?

goto sftcook ;no

return ;yes

sftcook rlf cook,f ;shift cook left

goto sbit ;again

;------------------------------------------------------------

sendbit bcf porta,1 ;default

btfsc cook,7 ;test cook bit 7

bsf porta,1 ;bit is set

shift1 bsf porta,2 ;shift

bcf porta,2

return

;------------------------------------------------------------

getprom movlw 0x08 ;count=8

movwf count

shift2 bsf porta,2 ;shift

bcf porta,2

movf porta,w ;read port A

movwf temp ;store copy

rrf temp,f ;rotate bit into carry flag

rlf cook,f ;rotate carry flag into cook

decfsz count,f ;decrement counter

goto shift2

return ;done

;------------------------------------------------------------

end

;------------------------------------------------------------

;at device program time, select:

; code protection off

; watchdog timer disabled (default is enabled)

; standard crystal XT (using 4 MHz osc for test)

; power-up timer on

;============================================================

;------------------------------------------------------------

erase bsf porta,3 ;cs high

call ewen ;erase/write enable

bcf porta,3 ;cs low

nop ;1 microsecond min

bsf porta,3 ;cs high

movf address,w ;get address

movwf cook ;store in cook

bsf cook,7 ;op code

bsf cook,6 ;ms 2 bits

bsf porta,1 ;send start bit

bsf porta,2 ;shift

bcf porta,2

call sendbits ;send address

bcf porta,3 ;cs low

nop ;1 microsecond min

bsf porta,3 ;cs high

ecycle1 btfss porta,0 ;erase cycle complete?

goto ecycle1 ;not yet

bcf porta,3 ;cs low

nop ;1microsecond min

call ewds ;yes, erase/write disable

bcf porta,3 ;cs low

nop ;1microsecond min

return; NOP are use to ensure that the 93C64 chip’s timing requirement are met.

Source : pic’n up the pace


Download PDF




No comments: