Using the 93LC56 and 93LC66
AN560
Using the 93LC56 and 93LC66
INTRODUCTION
The Microchip Technology Inc. 93LC56/66 are low-
power 3-wire non-volatile memories and are suitable for
many embedded system code and data storage applica-
tions. These devices are easily interfaced to most micro-
controllers in today's market place, but Microchip’s 8-bit
RISC series PIC16CXX offers the best code density of
any microcontroller on the market today. Using the
PIC16C54, the assembly programs contained in this
application note have been fully tested and provide the
correct timing and 3-wire sequences to fully operate the
93LC56/66 in a PIC16CXX-based embedded applica-
tion. The PIC16C54 was clocked at a 10MHz frequency.
This application note is intended to provide the engineer
with readily available stand-alone code modules to
accomplish all of the necessary functions to utilize these
devices in a low power application using the efficient
PIC16C54 microcontroller.
The 93 series of devices have essentially four I/O pins:
CS
CLK
DI
DO
Chip Select
Clock
Data In
Data Out
3-Wire Byte Write Program
– Delay Routine
– Start Bit Routine
– Bit Out Routine
– Transmit Data Routine
– Power-up Routine
– Erase/Write Enable Routine (EWEN)
– Byte Write Routine
– Erase/Write Disable Routine (EWDS)
3-Wire Byte Write with Data Polling Program
– Data Polling Delay Routine
– Start Bit Routine
– Bit Out Routine
– Transmit Data Routine
– Power-up Routine
– Erase/Write Enable Routine
– Write Routine
– Erase/Write Disable Routine (EWDS)
This series of devices use a series of commands to
accomplish the normal memory functions. These are
READ, WRITE, EWEN, ERASE, ERAL, WRAL, EWDS.
For a more detailed discussion of the function of these
devices reference the appropriate data sheet and AN536,
also published by Microchip Technology.
The following programs are included in this application
note and are fully functional stand-alone modules. They
are intended for use by those who are not already
familiar with interfacing a PIC16CXX microcontroller to
a 93 series device. For those with more experience,
please refer to application note AN530.
3-Wire Sequential Read Program
– Delay Routine
– Start Bit Routine
– Bit In Routine
– Receive Data Routine
– Bit Out Routine
– Transmit Data Routine
– Power-up Routine
– Read Routine
8
3-Wire Byte Read Program
– Start Bit Routine
– Receive Data Routine
– Bit Out Routine
– Transmit Data Routine
– Power-up Routine
– Read Routine
Author:
Bruce Negley
Memory Products Division
© 1994 Microchip Technology Inc.
DS00560D-page 1
8-99
Using the 93LC56 and 93LC66
16c5x/7x Cross-Assembler V4.12 Released
Line
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
PC
Opcode
LIST P=16C54,c=132
;****************************************************************
;
3-Wire Byte Read Program (80 bytes)
;
;
This program demonstrates how to interface a
;
Microchip PIC16C54 to a 93LC56 or 93LC66 Serial EE
;
device. This program will read 8 consecutive addresses
;
in the ‘random read’ mode. This means that the opcode
;
and address for each byte will be sent to the device.
;
This program will repeat forever.
;
;
Another, more efficient method of reading consecutive
;
addresses is called the ‘sequential read’ mode. This
;
involves sending the opcode and address for the first
;
byte to read, then continuing to provide clocks for the
;
next addresses. The device will automatically increment
;
the address. An example of the sequential read mode is
;
provided in the ‘3wseqr.asm’ file.
;
;
This program communicates to the serial EE in the
;
x16 mode, and ASSUMES THE USER HAS SET THE ORG PIN
;
ON THE DEVICE TO Vcc.
;
;
Timing is based on using the PIC16C54 in ‘XT’ mode
;
using a 4Mhz crystal. Clock speeds to the serial EE
;
will be approximately 50 kHz for this setup.
;
;
PIC16C54 to Serial EE Connections:
;
;
PIC16C54
Serial EE
;
——————
——————
;
Pin 10 (RB4) —> Chip Select
;
Pin 11 (RB5) —> Clock
;
Pin 12 (RB6) —> Data In
;
Pin 13 (RB7) —> Data Out
;
ORG = Vcc
;
;************************************************************
;
Register Assignments
;************************************************************
status equ
3h
; status register
port_a equ
5h
; port 5 (port_a)
port_b equ
6h
; port 6 (port b) comm lines to serial EE
eeprom equ
0ah
; bit buffer
addr
equ
0ch
; address register
datai
equ
0dh
; stored data input reg.
datao
equ
0eh
; stored data output reg.
txbuf
equ
10h
; transmit buffer
count
equ
11h
; bits transmitted so far
bits
equ
12h
; bits to transmit
bytcnt equ
13h
; byte counter for read routine
Mon Jun 06 10:49:10 1994
Page 2
Mon Jun 06 10:49:10 1994
Page 1
0003
0005
0006
000A
000C
000D
000E
0010
0011
0012
0013
16c5x/7x Cross-Assembler V4.12 Released
Line
0052
0053
0054
0055
0056
0057
0058
0059
0060
PC
Opcode
0015
0016
0017
0018
0007
0006
loops
equ
15h
; delay loop counter
loops2 equ
16h
; delay loop counter
hbyte
equ
17h
; high byte for input data
lbyte
equ
18h
; low byte for input data
;************************************************************
;
Bit Assignments
;************************************************************
di
equ
7
; eeprom input
do
equ
6
; eeprom output
DS00560D-page 2
© 1994 Microchip Technology Inc.
8-100
Using the 93LC56 and 93LC66
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0007
0006
0005
0004
datout equ
7
; data out line (port_b)
datin
equ
6
; data in line (port_b)
sclk
equ
5
; clock line (port_b)
chpsel equ
4
; chip select line (port_b)
;
;*************************************************************
org
01ffh
begin
goto
PWRUP
; set the reset vector
org
000h
goto
PWRUP
;
;**************************************************************
;
Start Bit Subroutine
;
this routine generates a start bit
;
(Chip select and DI high when clock goes high)
;**************************************************************
BSTART
bcf
port_b,datin
; set datain and chipselect lines
bcf
port_b,chpsel ; low just to check operation
bcf
port_b,sclk
; make sure clock starts low too.
nop
;
bsf
port_b,chpsel ; set chip select line high
bsf
port_b,datin
; set data in line high
nop
bsf
port_b,sclk
; set the clock line high to
; generate the start bit
nop
nop
bcf
port_b,sclk
; set clock low again
retlw
0
;
;**************************************************************
;
BITIN routine reads one bit of data from the
;
serial EE device and stores it in ‘di’
;**************************************************************
BITIN
bsf
eeprom,di
; assume input bit is high
bsf
port_b,sclk
; set clock line high
nop
;
btfss
port_b,datout ; read the data bit
bcf
eeprom,di
; input bit was low
Mon Jun 06 10:49:10 1994
Page 3
01FF
0000
0000
0A33
0000
0A33
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
04C6
0486
04A6
0000
0586
05C6
0000
05A6
0000
0000
04A6
0800
000D
000E
000F
0010
0011
05EA
05A6
0000
07E6
04EA
16c5x/7x Cross-Assembler V4.12 Released
Line
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
PC
0012
0013
Opcode
04A6
0800
bcf
retlw
port_b,sclk
0
; set clock line low
;
;
8
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
006D
0C08
0031
0403
036D
090D
040D
06EA
050D
02F1
0A18
0800
;****************************************************************
;
Receive data routine
;
This routine reads one byte of data from the part
;
into the ‘datai’ register.
;****************************************************************
RX
clrf
datai
; clear input buffer
movlw
.8
; set # bits to 8
movwf
count
bcf
status,0
; make sure carry bit is low
RXLP
rlf
datai
; rotate the buffer left 1 bit
call
BITIN
; read 1 bit
bcf
datai,0
; assume the input bit was low
btfsc
eeprom,di
; check the bit
bsf
datai,0
; set high if neccessary
decfsz count
; 8 bits done?
goto
RXLP
; no, do another
retlw
0
© 1994 Microchip Technology Inc.
DS00560D-page 3
8-101
Using the 93LC56 and 93LC66
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
;
;*************************************************************
;
BITOUT routine
;
This routine takes one bit of data in ‘do’ and
;
transmits it to the serial EE device
;*************************************************************
BITOUT
btfss
eeprom,do
; check state of data bit
goto
bitlow
; low, goto bitlow
bsf
port_b,datin
; high, set datain high
goto
clkout
; and clock it
;
bitlow
bcf
port_b,datin
; output a logic low
clkout
bsf
port_b,sclk
; set clock line high
nop
bcf
port_b,sclk
; return clock line low
retlw
0
;
;****************************************************************
;
Transmit Data Subroutine
;
This routine takes the byte of data stored in the
;
‘datao’ register and transmits it to the serial EE device.
;****************************************************************
TX
movf
bits,w
; set the number of bits to xmit
movwf
count
;
TXLP
bcf
eeprom,do
; assume bit 7 is low
Mon Jun 06 10:49:10 1994
Page 4
0020
0021
0022
0023
0024
0025
0026
0027
0028
07CA
0A24
05C6
0A25
04C6
05A6
0000
04A6
0800
0029
002A
0212
0031
002B
04CA
16c5x/7x Cross-Assembler V4.12 Released
Line
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
PC
002C
002D
002E
002F
0030
0031
0032
Opcode
06F0
05CA
0920
0370
02F1
0A2B
0800
btfsc
bsf
call
rlf
decfsz
goto
retlw
txbuf,7
eeprom,do
BITOUT
txbuf
count
TXLP
0
;
;
;
;
;
;
;
is bit 7 clear?
no, set data bit =1
transmit 1 bit to serial EE
rotate txbuf left
all bits done?
no, do another bit
yes, jump out
0033
0034
0035
0036
0037
0C00
0005
0065
0C80
0006
;
;****************************************************************
;
POWER-UP ROUTINE
;
This is the program entry point, which in this case simply
;
sets the port_a I/O lines and directs control to the
;
read routine.
;*****************************************************************
PWRUP
;
movlw
b’00000000'
tris
port_a
; set port_a as all output
clrf
port_a
; all lines low
movlw
tris
b’10000000'
port_b
0038
0039
0C00
002C
; set RB7 as input, rest output;
;
;
Fall through and do the read
;
;*********************************************************************
;
READ ROUTINE
;
This routine reads 8 consecutive addresses in
;
random mode starting at address 0. This is done in
;
x16 mode and will repeat forever.
;*********************************************************************
READ
;
movlw
.0
; set starting address to 00
movwf
addr
;
DS00560D-page 4
© 1994 Microchip Technology Inc.
8-102
Using the 93LC56 and 93LC66
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
003A
003B
003C
003D
003E
003F
0040
0041
0042
0043
0044
0045
0046
0047
0C08
0033
0901
0C02
0032
0C80
0030
0929
0C08
0032
020C
0030
0929
0914
rbyte
movlw
movwf
call
movlw
movwf
movlw
movwf
call
movlw
movwf
movf
movwf
call
call
.8
bytcnt
BSTART
.2
bits
b’10000000'
txbuf
TX
.8
bits
addr,w
txbuf
TX
RX
;
;
;
;
;
;
;
;
;
;
;
;
;
;
set number of addresses to
read as 8
generate the start bit
set # bits to 2
get opcode (10b)
into output buffer
and transmit it
set number of bits to 8
get the address
into the output buffer
and transmit it
; read the high byte
Mon Jun 06 10:49:10 1994
Page 5
16c5x/7x Cross-Assembler V4.12 Released
Line
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
PC
0048
0049
004A
004B
004C
004D
004E
004F
0050
0051
Opcode
020D
0037
0914
020D
0037
0486
02AC
02F3
0A3C
0A38
0000
movf
movwf
call
movf
movwf
bcf
incf
decfsz
goto
goto
END
datai,w
hbyte
RX
datai,w
hbyte
port_b,chpsel
addr
bytcnt
rbyte
READ
; move input data to w
; xfer it to high byte
; read the low byte
; move input data to w
; xfer it to low byte
; clear the chip select line
;
;
;
;
add 1 to the address
have all bytes been read?
no, read another byte
yes, start over
8
© 1994 Microchip Technology Inc.
DS00560D-page 5
8-103