NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
AN530 93CX6 PIC16C5X 93C46/56/66 93LC46/56/66 93LCXX 93CXX S93C46 S93LC46 - Datasheet Archive
Interfacing 93CX6 Serial EEPROMs to PIC16C5X Microcontrollers Authors: Stan D'Souza Microchip Technology Inc. Bob Ward Microchip
AN530 AN530 Interfacing 93CX6 93CX6 Serial EEPROMs to PIC16C5X PIC16C5X Microcontrollers Authors: Stan D'Souza Microchip Technology Inc. Bob Ward Microchip Technology Inc. FIGURE 1: PIC16C5X PIC16C5X x x x x x x x x Microchip Technology Inc.'s popular 93C46/56/66 93C46/56/66 and 93LC46/56/66 93LC46/56/66 Serial EEPROMs feature a three/four wire serial interface bus. The attractive price and simple interface make it the ideal device for additional memory space. This application note is intended for design engineers who wish to incorporate a pre-packaged serial EEPROM interface driver into their application. Note: The four command/data passing registers have to be defined consecutively in order for the FSR to access them successfully in the program execution. © 1999 Microchip Technology Inc. NC 7 x CS >CLK ORG 6 DI Note 1 DO 4 MCLR VCC 20 pF 16 OSC1 40 MHz RTCC 17 Note 1: FOR 93LCXX 93LCXX For 16-bit data word connect to VCC For 8-bit data word connect to GND FIGURE 2: 3-WIRE CONNECTION PIC16C5X PIC16C5X x x x x x x x x 6 7 8 9 10 11 12 13 x An example interface driver is listed in Appendix A. A flow diagram is given in Figure 2. The interface driver is written to minimize both overhead to the calling program as well as the program space necessary for its inclusion into the user's code. The driver has been written as a generic driver to service all 93 Series Serial EEPROMs made by Microchip. Processor resources which must be made available to the driver prior to being called are: 3. RA0 RA1 RA2 RA3 1 2 3 4 20 pF THE SOFTWARE CONNECTION Two levels of processor stack. Six register locations (four for command/data passing and two for software counters). The File Select Register (FSR), which is used to pass a command/data string pointer to the driver. 3 RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 93CXX 93CXX 17 18 1 2 OSC2 THE HARDWARE CONNECTION 1. 2. 6 7 8 9 10 11 12 13 x INTRODUCTION A typical 4-wire hardware connection is illustrated in Figure 1 and a typical 3-wire connection is illustrated in Figure 2. Since all I/O ports on the PIC16C5X PIC16C5X are configurable as input and/or output, a 3-wire interface makes optimum utilization of the I/O pins by having a common connection for the DI and DO lines of the Serial EEPROM. The port pin on the PIC16C5X PIC16C5X connected to these pins, has a default setting as an output and is configured, when needed, as an input during program execution. 4-WIRE CONNECTION 3 RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RA0 RA1 RA2 RA3 MCLR OSC1 93CXX 93CXX 17 18 1 2 x 4 1 2 3 4 10K NC 7 x CS >CLK VCC ORG 6 DI Note 1 DO VCC 16 20 pF 40 MHz RTCC OSC2 17 20 pF Note 1: FOR 93LCXX 93LCXX For 16-bit data word connect to VCC For 8-bit data word connect to GND The user should take the following steps when using the routines provided in Appendix A. A) B) Specify and define a 3-/4-wire interface by defining the common connection to the DI/DO lines and setting the equate 'wire3' TRUE or FALSE (4-wire is automatically assumed if 3-wire is false). Specify and define if 16-bit or 8-bit data organization is used, by setting equate 'org8' TRUE or FALSE. DS00530F-page 1 AN530 AN530 FIGURE 3: FLOW CHART Inc. FSR to Register Containing 1st write byte Call dout8, output 1st byte Start 8 bit mode? Transfer location of register `cmd' to FSR Y N Inc. FSR to Register Containing 2nd write byte Select device, clock out start bit Call dout8, output 2nd byte Call doutxx, clock out xx bits of cmd/addr N Write or erase? time Y Erase? Y N Read? Y Inc. FSR to Register Receiving 1st byte Call rdychk wait for rdy status within allocated time Y Call din8, input 1st byte De-select device N EWEN? (erase all) N ERAL? (erase all) Y Y Compute completion status (error/no_error) and return N N WRAL? (write all) 8 bit mode? Y Inc. FSR to Register Receiving 2nd byte N Call din8, input 2nd byte De-select device Return with no error DS00530F-page 2 © 1999 Microchip Technology Inc. AN530 AN530 C) The user should assemble the source file by specifying which type of serial EEPROM is being used. This is done by defining the equate S93C46 S93C46, S93LC46 S93LC46, etc., as TRUE. Only one device can be TRUE, the rest have to be defined FALSE. D) The user would invoke the driver as follows: 1. Load the register defined as 'cmd' with the 93CX6 93CX6 Command Opcode (only the four upper bits are used in this register; see Figure 3). 2. If necessary, load the register defined 'addr' with the lower 8/7/6 bit address of the location. 3. If necessary, load the 9th bit of the address as bit 3 of the register defined as 'cmd' (Figure 3). Note: 4. If necessary, load the register defined as 'highb' and 'lowb' with the 16 bits of data, the most significant byte loaded in 'highb'. In 8 bit mode, 'highb' should be loaded with the 8 bit data. Note: 5. 6. READ, WRITE and ERASE commands need to have an address associated with the command and the 9th bit of the address is only required when using the 93C56/66 93C56/66 or 93LC56/66 93LC56/66 devices in the 8 bit mode (ORG tied to GND). Only the WRITE and WRAL commands require data to be loaded in the 'highb', 'lowb' locations. Call the driver sub-routine 'see'. Upon completion, the driver will return a completion status in the W register FIGURE 4: 7. (error/no error). Only commands requiring a status check are capable of returning a valid error/no error status, in all other cases a no error is returned. If the READ command is executed, the 16/8 bit data will be loaded in the 'highb' and 'lowb' registers, where 'highb' contains the MSB in the 16 bit mode and 8 bit data in the 8-bit mode. The Example interface assumes a 4 MHz oscillator clock which gives us a 1 µS instruction cycle. If a higher clock speed is used, additional NOPs have to be included in the code in order to meet the minimum clock speed requirements of the 93 Series Serial EEPROMs (see data sheet for further details). Listing in Appendix B is for an interface to 93C46 93C46 Serial EEPROM only. SUMMARY The 93 Series Serial EEPROMs are a simple and versatile method of increasing read/write memory capability in a PIC16C5X PIC16C5X application. The 'generic' code in Appendix A makes it easy to incorporate in any PIC16C5X PIC16C5X application. Any of the 93 Series Serial EEPROMs can be applied, while at the same time using a minimal amount of I/O, code and RAM resources. Code size: 6 bytes of RAM. Appendix A listing: 127 bytes program code (max.) 100 bytes program code (min.) Appendix B listing: 86 bytes program code `CMD', `ADDR', DATA BYTE DEFINITION Bit7 Bit6 Bit5 Bit4 Bit3 Command Register (cmd) MSB of address in 8-bit mode for 93C56/66 93C56/66 (if necessary) LSB of 4-bit opcode 3rd bit of opcode 2nd bit of opcode MSB of 4-bit opcode A7 A6 A5 A4 A3 A2 A1 A0 Command Register (cmd) MSB of address in 8-bit mode for 93C56/66 93C56/66 (if necessary) LSB of 4-bit opcode 3rd bit of opcode 16-Bit Mode high b 8 Bit Mode high b D15 D8 D7 D7 D0 D0 low b © 1999 Microchip Technology Inc. DS00530F-page 3 AN530 AN530 Please check the Microchip Worldwide Website at www.microchip.com for the latest version of the source code. APPENDIX A: 93XCXX 93XCXX.ASM MPASM 01.40 Released LOC OBJECT CODE VALUE 000001FF 000001FF 0000 0000 0000 0A7B 00000001 00000000 00000001 00000000 00000000 00000000 00000000 00000001 00000000 00000001 00000000 DS00530F-page 4 93XCXX 93XCXX.ASM 1-16-1997 13:13:47 PAGE 1 LINE SOURCE TEXT 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 TITLE "R/W EEPROM" LIST P = 16C54 16C54 ;Serial Eprom interface to PIC16C5X PIC16C5X. ; ; ; Program: 93XCXX 93XCXX.ASM ; Revision Date: 8/26/92 ; 10/31/92 Comments clarified REV 2.0 ; 1-13-97 Compatibility with MPASMWIN 1.40 ; ;* ; ;Define Equates: ; PIC54 PIC54 EQU 1FFH ; PAGE ; ORG 0 START goto main ;run test program ; PAGE ; TRUE EQU 1 FALSE EQU 0 F EQU 1 S93C46 S93C46 EQU FALSE S93LC46 S93LC46 EQU FALSE S93C56 S93C56 EQU FALSE S93LC56 S93LC56 EQU FALSE S93C66 S93C66 EQU TRUE S93LC66 S93LC66 EQU FALSE wire3 equ TRUE ; for four-wire setup equate to FALSE org8 EQU FALSE ; IF S93LC46 S93LC46 IF org8 LC468 LC468 EQU TRUE XC46 EQU FALSE H16 EQU FALSE H8 EQU FALSE ELSE LC468 LC468 EQU FALSE XC46 EQU TRUE H16 EQU FALSE H8 EQU FALSE ENDIF ELSE ENDIF IF S93C46 S93C46 LC468 LC468 EQU FALSE XC46 EQU TRUE H16 EQU FALSE H8 EQU FALSE ENDIF © 1999 Microchip Technology Inc. AN530 AN530 00000001 00000000 00000000 00000000 00000000 00000002 00000003 00000004 00000005 0000001A 0000001B 0000001B 0000001C 0000001C 0000001D 0000001D 0000001E 0000001E 0000001F 0000001F 0000001E 0000001E 0000001F 0000001F 00000000 00000002 00000002 00000001 00000001 00000003 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 © 1999 Microchip Technology Inc. IF H8 H16 LC468 LC468 XC46 H16 H8 LC468 LC468 XC46 S93C56 S93C56 + S93C66 S93C66 + S93LC56 S93LC56 + S93LC66 S93LC66 IF org8 EQU TRUE EQU FALSE EQU FALSE EQU FALSE ELSE EQU TRUE EQU FALSE EQU FALSE EQU FALSE ENDIF ELSE ENDIF ;* ;* Register Assignments * ;* indir equ 0 pc status fsr serial equ equ equ equ 2 3 4 5 cmd equ 1a addr highb equ equ 1b 1c lowb equ 1d cnthi equ 1e cnt equ 1f temp_cmd equ temp_addr equ 1e 1f ;Use this register as source/destination ;for indirect addressing. ;PIC Program Counter. ;PIC Status Register. ;File Select Register. ;Port used for 93CX6 93CX6 control. ;The following four registers must be ;located consecutively in memory. ;This register contains the 4 bit ;command op code for 93CX6 93CX6 as follows: ;bit 7 msb of command op code ;bit 6 next bit of op code ;bit 5 next bit of op code ;bit 4 lsb of op code ;bit 3 A8 of address in case of ;56/66 in 8 bit mode. ;memory address of lower 7/8 bits ;Used in read/write routines to store the ;upper byte of a 16 bit data word, ;or the data in a 8 bit data word ;Used in read/write routines to store the ;lower byte of a 16 bit data word, ;or not used in 8 bit data word. ;Used as the upper byte of a sixteen bit ;loop counter in RDYCHK routine. ;Used as the lower byte of a sixteen bit ;loop counter in RDYCHK routine, and ;elswhere as an eight bit counter. ;doubles as a temp register for cmd ;doubles as a temp register for addr ;* ;* Bit Assignments: The following assignments are for 3-wire. For ;* 4-wire assign din and dout to seperate pins. carry zflag equ equ 0 2 ;Carry Flag of Status Register. ;Zero Flag of Status Register. cs din dout clock equ equ equ equ 2 1 1 3 ;Port ;Port ;Port ;Port pin pin pin pin tied tied tied tied to to to to CS on 93CX6 93CX6. DI on 93CX6 93CX6. 3-wire DO on 93CX6 93CX6. 3-wire CLK on 93CX6 93CX6. ;* DS00530F-page 5 AN530 AN530 00000000 00000001 00000020 00000080 00000040 000000C0 000000C0 00000030 00000000 00000020 00000010 DS00530F-page 6 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 ;* General Assignments * ;* no_err err1 tries equ equ equ 0 1 20 read write erase ewen ewds eral wral equ equ equ equ equ equ equ b'10000000' b'01000000' b'11000000' b'00110000' b'00000000' b'00100000' b'00010000' ;After issuing a WRITE, ERASE, ERAL, or WRAL ;command, the approximate number of machine ;cycles X 256 to wait for the RDY status. ;This value must be adjusted for operating ;frequencies other than 4 MHz. ;read command op code ;write command op code ;erase command op code ;erase enable command op code ;erase disable command op code ;erase all command op code ;write all command op code ;* ;* Macro Definitions * ;* sel dsel MACRO bsf ENDM MACRO bcf serial,cs ;Selects the 93CX6 93CX6 device. ;Chip Select (CS) = `1' to select ;the device serial,cs ;De-select the 93CX6 93CX6 device. ;Chip Select (CS) = `0' to de-select ;the device. serial,din ;Issue the Start Bit to the 93CX6 93CX6. ;Start Bit = `1'. ;Clock it out. ENDM strtbt clkit MACRO bsf clkit ENDM MACRO bsf nop bcf ENDM serial,clock ;Clocks a serial data bit into or out ;of the 93CX6 93CX6 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. serial,clock ;Clock (CLK) = `0'. ; PAGE ;* ;* DOUTx * ;* ;doutxx, outputs up to 11 bits of op code/data, depending on whether ;a 46/56/66 serial eeprom is being used. The number of bits over 8 are ;saved in the cmd register and the rest in the addr register. Before ;calling this routine the cmd and the addr registers should be loaded ;as follows: ;cmd reg.bits 7|6|5|4|3|2|1|0 ;-|-|-|-|-|-|-|-| ; X|X|X|X|X|X|X|Y| -> not used ; X|X|X|X|X|X|Y|X| -> mot used ; X|X|X|X|X|Y|X|X| -> not used ; X|X|X|X|Y|X|X|X| -> 9th bit of address if necessary ; X|X|X|Y|X|X|X|X| -> lsb of command op code © 1999 Microchip Technology Inc. AN530 AN530 0001 0001 0002 0003 0004 0360 0425 0603 0525 0005 0565 0006 0000 0007 0465 0008 0008 0009 000A 000B 0360 0425 0603 0525 000C 0565 000D 0000 000E 0465 000F 02A4 0010 0010 0C08 0011 003F 0012 0425 0013 0360 0014 0603 0015 0525 0016 0565 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 M M M M M M M M M M 00210 00211 00212 00213 00214 00215 00216 00217 M M M M M M M M M M 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 M M M © 1999 Microchip Technology Inc. ; X|X|Y|X|X|X|X|X| -> 3rd bit of command op code ; X|Y|X|X|X|X|X|X| -> 2nd bit of command op code ; Y|X|X|X|X|X|X|X| -> msb of command op code ; ;addr reg. 6/7/8 bits of address if necessary. IF dout11 H8 bcf serial,din rlf indir btfsc status,carry bsf serial,din clkit ENDIF IF H16+H8 dout10 rlf indir, F bcf serial,din btfsc status,carry bsf serial,din clkit bsf serial,clock nop serial,clock nop bcf incf ENDIF dout8 movlw movwf ; d_o_8 bcf ;rotate thru carry ;set output to 0 ;set? ;else set output to 1 ;clk data ;of the 93CX6 93CX6 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. bcf serial,clock ENDIF IF H8+H16+LC468 LC468 dout9 rlf indir, F bcf serial,din btfsc status,carry bsf serial,din clkit bsf ;rotate thru carry ;set? ;yes, set output to 1 ;clk data ;Clock (CLK) = `0'. ;rotate thru carry ;set output to 0 ;set? ;else set output to 1 ;clk data ;of the 93CX6 93CX6 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. serial,clock fsr, F ;Clock (CLK) = `0'. ;inc pointer 8 cnt ;Initialize loop counter. serial,din ;Assume that the bit to be transfered ;is a '0'. Hence, de-assert DI. rlf indir, F ;Rotate the actual bit to be ;transferred into the carry bit. btfsc status,carry ;Test the carry, if our assumption was ;correct, skip the next instruction. bsf serial,din ;No, actual bit was a `1'. Assert DI. clkit ;Clock the 93CX6 93CX6. ;of the 93CX6 93CX6 device. bsf serial,clock ;Clock (CLK) = `1'. DS00530F-page 7 AN530 AN530 0017 0000 0018 0019 001A 001B 001C 001D 0465 02FF 0A12 0360 0425 0800 001E 001E 0C02 001F 0005 0020 0C08 0021 003F 0022 0022 0360 0023 0400 0024 0565 0025 0000 0026 0465 0027 0625 0028 0500 0029 02FF 002A 0A22 002B 0C00 002C 0005 002D 0800 DS00530F-page 8 M M M M M M M 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 M M M M M M M M M M 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 nop bcf decfsz goto rlf bcf retlw ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. serial,clock cnt, F d_o_8 indir, F serial,din no_err ;Clock (CLK) = `0'. ;Repeat until cnt = 0. ;Cnt still > 0. ;Restore register to its original condition. ;make sure din is low ;Exit with good status. ;* ;* DIN8 * ;* ;Din8 will input 8 bits of data from the ;93CX6 93CX6. Before calling this routine, ;the FSR must point to the register ;being used to hold the incomming data. din8 IF wire3 ;set up the RA1 as a input before proceeding movlw b'00000010' ;set up porta tris serial ; ENDIF movlw 8 ;Initialize loop counter. movwf cnt ; d_i_8 rlf indir, F bcf indir,0 clkit bsf serial,clock nop ;Make room for the incomming bit in the ;destination register. ;Assume that the incomming bit is a `0' and ;clear the LSB of the destination register. ;Clock a bit in the 93CX6 93CX6. ;of the 93CX6 93CX6 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. bcf btfsc serial,clock serial,dout bsf indir,0 decfsz cnt, F goto d_i_8 IF wire3 ;setup RA1 back to output movlw 0 tris serial ENDIF retlw no_err ;Clock (CLK) = `0'. ;Test the incomming bit, if our assumption ;was correct, skip the next instruction. ;No, actual bit is a `1'. Set the LSB of ;the destination register. ;Repeat until cnt = 0. ;Cnt still > 0. ;set RA1 as output ; / ;Exit with good status. ;* ;* RDYCHK * ;* ;Rdychk will read the 93CX6 93CX6 READY/BUSY status ;and wait for RDY status within the alloted ;number of processor cycles. If RDY status ;is not present after this set period, the ;routine will return with an error status. © 1999 Microchip Technology Inc. AN530 AN530 002E 002E 0C02 002F 0005 0030 0C20 0031 003E 0032 007F 0033 0445 0034 0545 0035 0625 0036 0A3E 0037 02FF 0038 0A35 0039 02FE 003A 0A35 003B 0C00 003C 0005 003D 0801 003E 003E 0C00 003F 0005 0040 0800 0041 0041 021A 00281 00282 rdychk 00283 IF wire3 00284 ;set up RA1 as a input before proceeding 00285 movlw b'00000010' ;set up porta 00286 tris serial ; 00287 ENDIF 00288 movlw tries ;Initialize time-out counter. 00289 movwf cnthi ; 00290 clrf cnt ; 00291 dsel ;De-select the 93CX6 93CX6. M bcf serial,cs ;Chip Select (CS) = `0' to de-select M ;the device. 00292 00293 ; nop ;NOTE: Check the 93CX6 93CX6 data sheet for 00294 ;minimum CS low time. Depending upon 00295 ;processor frequency, a nop(s) may be 00296 ;between the assertion and de-assertion of 00297 ;Chip Select. 00298 00299 sel ;Re-select the 93CX6 93CX6. M bsf serial,cs ;Chip Select (CS) = `1' to select 00300 notrdy btfsc serial,dout ;If DO is a `0', 93CX6 93CX6 has yet to completed 00301 ;the last operation (still busy). 00302 goto rdynoerr ;skip to no error 00303 decfsz cnt, F ;No, not yet ready. Decrement the LSB of 00304 ;our 16 bit timer and check for expiration. 00305 goto notrdy ;Still some time left. Try again. 00306 decfsz cnthi, F ;Least significant byte expired - decrement 00307 ;and check for expiration of the MSB. 00308 goto notrdy ;Still some time left. Try again. 00309 IF wire3 00310 ;setup RA1 back to output 00311 movlw 0 ;set RA1 as output 00312 tris serial ; / 00313 ENDIF 00314 retlw err1 ;RDY status was not present in the alloted 00315 ;time, return with error status. 00316 rdynoerr 00317 IF wire3 00318 ;setup RA1 back to output 00319 movlw 0 ;set porta as output 00320 tris serial ; / 00321 ENDIF 00322 retlw no_err 00323 00324 ;* 00325 ;* SEE * 00326 ;* 00327 00328 ;See will control the entire operation of a 00329 ;93CX6 93CX6 device. Prior to calling the routine, 00330 ;load a valid command/memory address into 00331 ;location cmd, and for WRITE or WRAL 00332 ;commands, load registers highb and lowb with 00333 ;16 bits of write data. Upon exit, the W 00334 ;register will contain the completion status. 00335 ;Only 93CX6 93CX6 instructions which require a 00336 ;status check can return with an error as the 00337 ;completion status. The values that denote 00338 ;the completion status are defined as 00339 ;variables `error' and `no_err' in the 00340 ;general assignments section. 00341 00342 see 00343 movf cmd,W ;save cmd © 1999 Microchip Technology Inc. DS00530F-page 9 AN530 AN530 0042 0043 0044 0045 003E 021B 003F 0C1A 0046 0024 0047 0545 0048 0525 0049 0565 004A 0000 004B 0465 004C 06FA 004D 0A73 004E 07DA 004F 0A75 0050 0A73 DS00530F-page 10 00344 00345 00346 00347 00348 00349 00350 00351 00352 M 00353 M M M M M M M M M M M M 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 movwf movf movwf movlw temp_cmd addr,W temp_addr cmd movwf fsr sel bsf strtbt bsf clkit bsf serial,cs serial,din serial,clock nop bcf ;save addr ; ;Load W with the location of the cmd ;register. ;Transfer that information into the ;File Select Register. The fsr now ;points to location cmd. ;Select the 93CX6 93CX6. ;Chip Select (CS) = `1' to select ;Send a start bit. ;Start Bit = `1'. ;Clock it out. ;of the 93CX6 93CX6 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93CX6 93CX6 data for the ;minimum CLK period. serial,clock ;Clock (CLK) = `0'. ; btfsc cmd,7 XC46 goto sca8 ENDIF IF LC468 LC468 goto sca9 ENDIF IF H16 goto sca10 ENDIF IF H8 goto sca11 ENDIF ;bit 7 = 0? IF ; goto set_cmd_addr btfss cmd,6 IF XC46 goto sc8 ENDIF IF LC468 LC468 goto sc9 ENDIF IF H16 goto sc10 ENDIF IF H8 goto sc11 ENDIF ; goto set_cmd IF XC46 goto sca8 ENDIF IF LC468 LC468 goto sca9 ENDIF IF H16 goto sca10 ENDIF IF H8 goto sca11 ENDIF ;xfer 8 bit cmd/adr ;xfer 9 bit cmd/adr ;xfer 10 bit cmd/adr ;xfer 11 bit cmd/adr ;no then set cmd/addr ;bit 6 = 0 ? ;xfer 8 bit cmd/adr ;xfer 9 bit cmd/adr ;xfer 10 bit cmd/adr ;xfer 11 bit cmd/adr ;yes then set cmd ;xfer 8 bit cmd/adr ;xfer 9 bit cmd/adr ;xfer 10 bit cmd/adr ;xfer 11 bit cmd/adr © 1999 Microchip Technology Inc. AN530 AN530 0051 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 021E 003A 021F 003B 06DA 0A5F 06FA 0A69 06BA 0A66 069A 0A6E 005D 0445 005E 0800 005F 07FA 0060 0A6E 0061 092E 0062 0445 0063 01E2 0064 0800 0065 0801 0066 069A 0067 0A5D 0068 0A61 0069 02A4 006A 091E 006B 02A4 006C 091E 006D 0A5D 006E 02A4 006F 0910 0070 02A4 0071 0910 0072 0A61 00397 ; goto set_cmd_addr 00398 see1 00399 movf temp_cmd,W 00400 movwf cmd 00401 movf temp_addr,W 00402 movwf addr 00403 btfsc cmd,6 00404 goto see2 00405 btfsc cmd,7 00406 goto read_ 00407 btfsc cmd,5 00408 goto see3 00409 btfsc cmd,4 00410 goto write_ 00411 00412 exit_ dsel M bcf serial,cs M 00413 00414 ; 00415 retlw no_err 00416 00417 see2 btfss cmd,7 00418 goto write_ 00419 exit2_ call rdychk 00420 dsel M bcf serial,cs M 00421 addwf pc, F 00422 00423 retlw no_err 00424 retlw err1 00425 00426 see3 btfsc cmd,4 00427 goto exit_ 00428 00429 goto exit2_ 00430 00431 00432 read_ incf fsr, F 00433 00434 00435 call din8 00436 IF org8 00437 ELSE 00438 incf fsr, F 00439 00440 call din8 00441 ENDIF 00442 goto exit_ 00443 00444 write_ incf fsr, F 00445 00446 00447 call dout8 00448 IF org8 00449 ELSE 00450 incf fsr, F 00451 00452 call dout8 00453 00454 ENDIF 00455 goto exit2_ 00456 00457 ; 00458 ; © 1999 Microchip Technology Inc. ;else set cmd/addr ;retore cmd ; / ;restore addr ; / ;Check for a WRITE or ERASE command. ;Yes, parse the command further. ;Check for a READ command. ;Yes, process READ command. ;Check for a EWEN or ERAL command. ;Yes, parse the command further. ;Check for a WRAL command. ;Yes, process WRITE/WRAL command. ;No further processing required; 93CX6 93CX6 ;Chip Select (CS) = `0' to de-select ;the device. ;command completed. ;Return with good completion status. ;Check for a ERASE command. ;No, process WRITE command. ;ERASE command requires a status check. ;De-select the 93CX6 93CX6. ;Chip Select (CS) = `0' to de-select ;the device. ;Compute completion status from ;results of status check. ;Return with good completion status. ;Return with bad completion status. ;Check for a EWEN command. ;Yes, no further processing required, ;exit now. ;No, ERAL command which requires a ;status check. ;Increment the File Select Register to ;point to the register receiving the upper ;byte of the incomming 93CX6 93CX6 data word. ;Input the upper byte. ;Increment the File Select Register to point ;to the register receiving the lower byte. ;Input 8 more bits. ;No further processing required, exit now. ;Increment the File Select Register to point ;to the upper byte of the 16 bit 93CX6 93CX6 data ;word to be transmitted. ;Output that byte. ;Increment the File Select Register to point ;to the lower byte. ;Output the lower byte of the 16 bit 93CX6 93CX6 ;data word. ;Exit with a status check. DS00530F-page 11 AN530 AN530 0073 0073 0901 0074 0A51 0075 0075 0076 0077 0078 0079 007A 037A 035A 003B 007A 0901 0A51 DS00530F-page 12 00459 IF XC46 00460 sca8 00461 movlw b'11000000' 00462 andwf cmd,W 00463 iorwf addr 00464 incf fsr 00465 call dout8 00466 goto see1 00467 ENDIF 00468 IF LC468 LC468 00469 ; 00470 sca9 00471 bcf addr,7 00472 btfsc cmd,6 00473 bsf addr,7 00474 call dout9 00475 goto see1 00476 ENDIF 00477 IF H16 00478 ; 00479 sca10 00480 call dout10 00481 goto see1 00482 ENDIF 00483 ; 00484 IF H8 00485 sca11 00486 bcf cmd,5 00487 btfsc cmd,3 00488 bsf cmd,5 00489 call dout11 00490 goto see1 00491 ; 00492 ENDIF 00493 ; 00494 ; 00495 ; 00496 IF XC46 00497 sc8 00498 movf cmd,W 00499 movwf addr 00500 incf fsr 00501 call dout8 00502 goto see1 00503 ; 00504 ENDIF 00505 IF LC468 LC468 00506 sc9 00507 rlf cmd,W 00508 movwf addr 00509 call dout9 00510 goto see1 00511 ENDIF 00512 IF H16 00513 ; 00514 sc10 00515 rlf cmd, F 00516 rlf cmd,W 00517 movwf addr 00518 clrf cmd 00519 call dout10 00520 goto see1 00521 ENDIF 00522 ; 00523 IF H8 00524 sc11 ;clr all but hi 2 ;save in w ;mask in addr. ;inc FSR ;output ;return ;clr hi of addr ;xfer cmd's bit 6 ;to addr's bit 7 ;output ;return ;output cmd reg ;return ;xfer cmd's bit 3 to ;cmd's bit 5 ; / ;output ;return ;get command ;save in addr ;inc pointer ;output ;return ;rotate cmd left ;save in addr ;xfer 9 bits ;return ;rotate cmd ;left twice ;save in addr ;clear command ;xfer 10 bits ;return © 1999 Microchip Technology Inc. AN530 AN530 007B 007B 0065 007C 0CF0 007D 0005 007E 0C30 007F 003A 0080 0941 0081 0082 0083 0084 0085 0086 0C20 003A 0941 0F01 0643 0AA6 000000AA 000000AA 0087 0C40 0088 003A 0089 0CAA 008A 003C 008B 008C 008D 008E 008F 0090 007B 0941 0F01 0643 0AA6 03FB 0091 0092 0093 0094 0095 0095 0096 0A8C 077A 0A95 0A97 0097 0097 0098 0099 009A 009B 057A 0A8C 0C80 003A 0941 0CAA 009C 009C 0743 009D 0AA6 009E 03FB 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 bcf addr,7 ;xfer cmd's bit 4 btfsc cmd,4 ;to addr's bit 7 bsf addr,7 ; / call dout11 ;xfer 11 bits goto see1 ;return ENDIF ;* ;* Test Program * ;* ; main ;We've include a sample program to ;exercise the PIC to 93C66 93C66 interface ;using a simple erase, write and verify ;routine.8 bit organization has been ;used with a 3 wire interface. clrf movlw tris serial b'11110000' serial ;Clear the port tied to the 93C66 93C66 device. ;Intialize the data direction register ;for that port. movlw movwf call ewen cmd see ;Load W with the Erase/Write Enable command. ;Transfer W into cmd register. ;Enable the 93C66 93C66 device. movlw movwf call xorlw btfsc goto eral cmd see err1 status, zflag errloop ;Load W with the Erase All command. ;Transfer W into cmd register. ;Erase the 93C66 93C66. ;Check completion status. ;Test for error condition. ;Yes, bad completion status, error-out. 0xAA ;Write loop: ;Define the test pattern to be written. tstptrn equ movlw movwf movlw movwf highb clrf call xorlw btfsc goto incfsz addr see err1 status,zflag errloop addr, F test1 write cmd tstptrn goto btfss goto goto wrt_nxt_pg bsf goto test1 cmd,3 wrt_nxt_pg read_tst ;Load W with the Write command. ;Transfer W into cmd register. ;Intialize the 93C66 93C66 data registers with ;write data. ;load in high byte only ;since 8 bit low byte is ignored ;start at addr 0 ;Write data word into 93C66 93C66 device. ;Check completion status. ;Test for error condition. ;Yes, bad completion status, error-out. ;No, increment the 8 bit memory address ;field. ;write another location ;see if all done ;no then write next page ;read written data cmd,3 test1 ;set page bit ;No, write another location. ;Read loop: read_tst test2 © 1999 Microchip Technology Inc. movlw movwf call movlw subwf read cmd see tstptrn highb,W btfss goto incfsz status,zflag errloop addr, F ;Load W with the Read command. ;Transfer W into cmd register. ;Read addressed data word from 93C66 93C66 device. ;Load W with the pattern written. ;Verify the data read against what was ;written. ;Same? ;No, error-out. ;Yes, both byte correct, increment the 8 bit DS00530F-page 13 AN530 AN530 00591 00592 00593 00594 00595 00596 057A 00597 0A99 00598 00599 00A5 0AA5 00600 00601 00602 00A6 00603 00A6 0AA6 00604 00605 00606 00607 00608 00609 01FF 00610 01FF 00611 01FF 0A00 00612 00613 00614 MEMORY USAGE MAP (`X' 009F 00A0 00A1 00A2 00A3 00A3 00A4 0000 0040 0080 01C0 0A99 077A 0AA3 0AA5 : : : : goto btfss goto goto rd_nxt_pg bsf goto test2 cmd,3 rd_nxt_pg allok ;memory address field. ;do next byte ;check page bit ;no then chk next page ;all done!!! cmd,3 test2 ;set page bit ;No, read another location. allok goto allok ; ; errloop goto errloop ; ; ; ;KEY DEFINITIONS ; ORG PIC54 PIC54 SYS_RESET GOTO START ; END = Used, `-' = Unused) XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX - XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX - ;Home safe! XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXX- XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX -X All other memory blocks unused. Program Memory Words Used: Program Memory Words Free: Errors : Warnings : Messages : 0 0 reported, 0 reported, DS00530F-page 14 168 344 0 suppressed 0 suppressed © 1999 Microchip Technology Inc. AN530 AN530 Please check the Microchip Worldwide Website at www.microchip.com for the latest version of the source code. APPENDIX B: 93C46 93C46.ASM MPASM 01.40 Released LOC OBJECT CODE VALUE 93C46 93C46.ASM 00000000 00000002 00000003 00000004 00000005 00000001 00000010 00000011 00000012 00000013 00000014 00000000 00000002 00000000 00000001 1-16-1997 13:13:14 PAGE 1 LINE SOURCE TEXT 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 ;* ;* PICALC Directives Section * ;* SUBTITL "93C46 93C46 3 WIRE INTERFACE ROUTINE" LIST P=16C54 16C54,N=40,C=132 ;* ; ; ; Program: 93C46 93C46.ASM ; Revision Date: ; 1-13-97 Compatibility with MPASMWIN 1.40 ; ;* ; ;* ;* Register Assignments * ;* indir equ 0x00 pc status fsr serial equ equ equ equ 0x02 0x03 0x04 0x05 F EQU 1 cmd equ 0x10 highb equ 0x11 lowb equ 0x12 cnthi equ 0x13 cnt equ 0x14 ;Use this register as source/destination for ;indirect addressing. ;PIC Program Counter. ;PIC Status Register. ;File Select Register. ;Port used for 93C46 93C46 control. Port A is ;4 bits wide, we'll use 3 or 4 of Port A. ;The following three registers must be ;located consecutively in memory. ;This register contains the 2 bit 93C46 93C46 ;command is the upper 2 bit positions and ;memory address in the lower 6. ;Used in read/write routines to store the ;upper byte of a 16 bit 93C46 93C46 data word. ;Used in read/write routines to store the ;lower byte of a 16 bit 93C46 93C46 data word. ;Used as the upper byte of a sixteen bit loop ;counter in RDYCHK routine. ;Used as the lower byte of a sixteen bit loop ;counter in RDYCHK routine, and elsewhere as ;an eight bit counter. ;* ;* Bit Assignments: The following assignment is for 3-wire setup. ;* For 4-wire setup assign din and dout to seperate pins. carry zflag equ equ 0 2 ;Carry Flag of Status Register. ;Zero Flag of Status Register. ;For the 3 wire interface, connect the din and dout to the same ;i/o line of the PIC16C5X PIC16C5X. cs equ 0 ;Port pin tied to CS on 93C46 93C46. din equ 1 ;Port pin tied to DI on 93C46 93C46. 3-wire © 1999 Microchip Technology Inc. DS00530F-page 15 AN530 AN530 00000001 00000002 00000000 00000001 00000004 00000080 00000040 000000C0 000000C0 00000030 00000000 00000020 00000010 01FF 01FF 0A56 0000 DS00530F-page 16 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 dout clock equ equ 1 2 ;Port pin tied to DO on 93C46 93C46. 3-wire ;Port pin tied to CLK on 93C46 93C46. ;* ;* General Assignments * ;* no_err err1 tries equ equ equ 0 1 0x04 ; ; ;After issuing a WRITE, ERASE, ERAL, or WRAL ;command, the approximate number of machine ;cycles X 256 to wait for the RDY status. ;This value must be adjusted for operating ;frequencies other than 4 MHz. read write erase ewen ewds eral wral equ equ equ equ equ equ equ 0x80 0x40 0xC0 0x30 0x00 0x20 0x10 ;93C46 93C46 ;93C46 93C46 ;93C46 93C46 ;93C46 93C46 ;93C46 93C46 ;92CXX 92CXX ;92CXX 92CXX Read command. Write command. Erase command. Erase/Write Enable command. Erase/Write Disable command. Erase All command. Write All command. ;* ;* Macro Definitions * ;* sel dsel MACRO bsf ENDM MACRO bcf serial,cs ;Selects the 93C46 93C46 device. ;Chip Select (CS) = `1' to select the device. serial,cs ;De-select the 93C46 93C46 device. ;Chip Select (CS) = `0' to de-select the ;device. serial,din ;Issue the Start Bit to the 93C46 93C46. ;Start Bit = `1'. ;Clock it out. ENDM strtbt clkit MACRO bsf clkit ENDM MACRO bsf serial,clock nop bcf ENDM ;Clocks a serial data bit into or out of the ;93C46 93C46 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93C46 93C46 data for the ;minimum CLK period. serial,clock ;Clock (CLK) = `0'. ;* ;* Power-On/Reset Entry Point * ;* reset_ org goto 0x1FF main ;* ;* 93C46 93C46 Routines * ;* org 0x000 ;Locate all subroutines in the lower half of ;a Program Memory Page. © 1999 Microchip Technology Inc. AN530 AN530 0000 0C08 0001 0034 0002 0425 0003 0360 0004 0603 0005 0525 0006 0545 0007 0000 0008 0009 000A 000B 000C 0445 02F4 0A02 0360 0800 000D 0C08 000E 0034 000F 0C02 0010 0005 0011 0545 0012 0000 0013 0445 0014 0360 0015 0400 0016 0625 0017 0500 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 M M M M M M M M M M 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 M M M M M M M M M M 00162 00163 00164 00165 00166 00167 00168 ;* ;* DOUT8 * ;* ;Dout8 will output 8 bits of data to the ;93C46 93C46. Before calling this routine, the FSR ;must point to the byte being transmitted. dout8 movlw movwf 0x08 cnt ;Initialize loop counter. ; d_o_8 bcf serial,din rlf indir, F btfsc status,carry bsf clkit serial,din bsf serial,clock ;Assume that the bit to be transfered is a ;'0'. Hence, de-assert DI. ;Rotate the actual bit to be transferred into ;the carry bit. ;Test the carry, if our assumption was ;correct, skip the next instruction. ;No, actual bit was a `1'. Assert DI. ;Clock the 93C46 93C46. ;93C46 93C46 device. ;Clock (CLK) = `1'. nop bcf decfsz goto rlf retlw ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93C46 93C46 data for the ;minimum CLK period. serial,clock cnt, F d_o_8 indir, F no_err ;Clock (CLK) = `0'. ;Repeat until cnt = 0. ;Cnt still > 0. ;Restore register to its original condition. ;Exit with good status. ;* ;* DIN8 * ;* ;Din8 will input 8 bits of data from the ;93C46 93C46. Before calling this routine, the FSR ;must point to the register being used to ;hold the incomming data. din8 movlw 0x08 ;Initialize loop counter. movwf cnt ; ;for the 3 wire interface the direction of the i/o line connected to ;din and dout has to converted from an output to an input. movlw b'00000010' ;convert RA1 to an input tris serial ; / d_i_8 © 1999 Microchip Technology Inc. clkit bsf serial,clock nop ;Clock a bit out of the 93C46 93C46. ;93C46 93C46 device. ;Clock (CLK) = `1'. ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93C46 93C46 data for the ;minimum CLK period. bcf rlf serial,clock indir, F bcf indir,0 btfsc serial,dout bsf indir,0 ;Clock (CLK) = `0'. ;Make room for the incomming bit in the ;destination register. ;Assume that the incomming bit is a `0' and ;clear the LSB of the destination register. ;Test the incomming bit, if our assumption ;was correct, skip the next instruction. ;No, actual bit is a `1'. Set the LSB of the DS00530F-page 17 AN530 AN530 0018 02F4 0019 0A11 001A 0C00 001B 0005 001C 0800 001D 0C04 001E 0033 001F 0074 0020 0C02 0021 0005 0022 0405 0023 0505 0024 0625 0025 0A2D 0026 02F4 0027 0A24 0028 02F3 0029 0A24 002A 0C00 002B 0005 002C 0801 002D 002D 0C00 002E 0005 002F 0800 DS00530F-page 18 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 M M 00193 00194 00195 00196 00197 00198 00199 00200 M 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 ;destination register. decfsz cnt, F ;Repeat until cnt = 0. goto d_i_8 ;Cnt still > 0 ;for a 3 wire interface, convert the RA1 line back to an output movlw 0 ;make RA1 to an output tris serial ; / retlw no_err ;Exit with good status. ;* ;* RDYCHK * ;* ;Rdychk will read the 93C46 93C46 READY/BUSY status ;and wait for RDY status within the alloted ;number of processor cycles. If RDY status ;is not present after this set period, the ;routine will return with an error status. rdychk movlw tries movwf cnthi clrf cnt ;for a 3 wire interface, make movlw b'00000010' tris serial dsel bcf serial,cs ;Initialize time-out counter. ; ; the RA1 line an input ; ; ;NOTE: Check the 93C46 93C46 data sheet for ;minimum CS low time. Depending upon ;processor frequency, a nop(s) may be ;between the assertion and de-assertion of ;Chip Select. nop sel bsf btfsc ;De-select the 93C46 93C46. ;Chip Select (CS) = `0' to de-select the ;device. ;Re-select the 93C46 93C46. ;Chip Select (CS) = `1' to select the device. notrdy ;If DO is a `0', 93C46 93C46 has yet to completed ;the last operation (still busy). goto no_error ;Otherwise RDY status is present within the ;alloted time, and return with good status. decfsz cnt, F ;No, not yet ready. Decrement the LSB of our ;16 bit timer and check for expiration. goto notrdy ;Still some time left. Try again. decfsz cnthi, F ;Least significant byte expired - decrement ;and check for expiration of the MSB. goto notrdy ;Still some time left. Try again. ;for a 3 wire interface, convert RA1 line back to an ouput movlw 0 ;convert RA1 to an output tris serial ; / retlw err1 ;RDY status was not present in the alloted ;time, return with error status. no_error ;for a 3 wire interface, convert RA1 line back to an ouput movlw 0 ;convert RA1 to an output tris serial ; / retlw no_err serial,cs serial,dout ;* ;* SEE * ;* ;See will control the entire operation of a ;93C46 93C46 device. Prior to calling the routine, ;load a valid command/memory address into ;location cmd, and for WRITE or WRAL ;commands, load registers highb and lowb with © 1999 Microchip Technology Inc. AN530 AN530 0030 0C10 0031 0024 0032 0505 0033 0525 0034 0545 0035 0000 0036 0445 0037 0900 0038 0039 003A 003B 003C 003D 003E 003F 06D0 0A42 06F0 0A4C 06B0 0A49 0690 0A51 0040 0405 0041 0800 0042 07F0 0043 0A51 0044 091D 0045 0405 0046 01E2 0047 0800 0048 0801 0049 0690 004A 0A40 004B 0A44 004C 02A4 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 M 00247 M M M M M M M M M M M M 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 M M 00260 00261 00262 00263 00264 00265 00266 M M 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 ;16 bits of write data. Upon exit, the W ;register will contain the completion status. ;Only 93C46 93C46 instructions which require a ;status check can return with an error as the ;completion status. The values that denote ;the completion status are defined as ;variables `error' and `no_err' in the ;general assignments section. see movlw cmd movwf fsr sel bsf strtbt bsf clkit bsf serial,cs serial,din serial,clock ;Load W with the location of the cmd ;register. ;Transfer that information into the File ;Select Register. The fsr now points to ;location cmd. ;Select the 93C46 93C46. ;Chip Select (CS) = `1' to select the device. ;Send a start bit. ;Start Bit = `1'. ;Clock it out. ;93C46 93C46 device. ;Clock (CLK) = `1'. nop ;Adjust the number of nop instructions ;between the assertion and de-assertion of ;CLK in proportion to the PIC operating ;frequency. Refer to the 93C46 93C46 data for the ;minimum CLK period. bcf serial,clock call dout8 ;Clock (CLK) = `0'. ;Transmit the 2 bit command and six bit ;address. ;Check for a WRITE or ERASE command. ;Yes, parse the command further. ;Check for a READ command. ;Yes, process READ command. ;Check for a EWEN or ERAL command. ;Yes, parse the command further. ;Check for a WRAL command. ;Yes, process WRITE/WRAL command. btfsc goto btfsc goto btfsc goto btfsc goto read_ © 1999 Microchip Technology Inc. btfss goto call dsel bcf cmd,7 write_ rdychk pc, F no_err err1 btfsc goto cmd,4 exit_ goto see3 no_err retlw retlw exit2_ serial,cs addwf see2 dsel bcf retlw exit_ cmd,6 see2 cmd,7 read_ cmd,5 see3 cmd,4 write_ exit2_ incf fsr, F serial,cs ;No further processing required; 93C46 93C46 ;Chip Select (CS) = `0' to de-select the ;device. ;command completed. ;Return with good completion status. ;Check for a ERASE command. ;No, process WRITE command. ;ERASE command requires a status check. ;De-select the 93C46 93C46. ;Chip Select (CS) = `0' to de-select the ;device. ;Compute completion status from results of ;status check. ;Return with good completion status. ;Return with bad completion status. ;Check for a EWEN command. ;Yes, no further processing required, exit ;now. ;No, ERAL command which requires a status ;check. ;Increment the File Select Register to point ;to the register receiving the upper byte of ;the incomming 93C46 93C46 data word. DS00530F-page 19 AN530 AN530 004D 090D 004E 02A4 004F 090D 0050 0A40 0051 02A4 0052 0900 0053 02A4 0054 0900 0055 0A44 0056 0056 0065 0057 0CF4 0058 0005 0059 0C30 005A 0030 005B 0930 005C 005D 005E 005F 0060 0061 0C20 0030 0930 0F01 0643 0A81 0000001F 0000001F 000000AA 000000AA 0062 0063 0064 0065 0066 0C40 003F 0C40 0030 0CAA 0067 0068 0069 006A 006B 006C 006D 0031 0032 0930 0F01 0643 0A81 02B0 006E 02FF 006F 0A69 0070 0C40 0071 003F 0072 0C80 DS00530F-page 20 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 call incf call goto din8 exit_ incf fsr, F call incf dout8 fsr, F call dout8 goto write_ din8 fsr, F exit2_ ;Input the upper byte. ;Increment the File Select Register to point ;to the register receiving the lower byte. ;Input 8 more bits. ;No further processing required, exit now. ;Increment the File Select Register to point ;to the upper byte of the 16 bit 93C46 93C46 data ;word to be transmitted. ;Output that byte. ;Increment the File Select Register to point ;to the lower byte. ;Output the lower byte of the 16 bit 93C46 93C46 ;data word. ;Exit with a status check. ;* ;* Test Program * ;* ; main ;We've include a sample program to exercise ;the PIC to 93C46 93C46 interface using a simple ;erase, write and varify routine. clrf movlw tris serial b'11110100' serial ;Clear the port tied to the 93C46 93C46 device. ;Intialize the data direction register for ;that port. movlw movwf call ewen cmd see ;Load W with the Erase/Write Enable command. ;Transfer W into cmd register. ;Enable the 93C46 93C46 device. movlw movwf call xorlw btfsc goto eral ;Load W with the Erase All command. cmd ;Transfer W into cmd register. see ;Erase the 93C46 93C46. err1 ;Check completion status. status, zflag ;Test for error condition. errloop ;Yes, bad completion status, error-out. loopcnt equ 0x1F tstptrn equ 0xAA movlw movwf movlw movwf movlw test1 .64 loopcnt write cmd tstptrn movwf movwf call xorlw btfsc goto incf highb lowb see err1 status,zflag errloop cmd, F decfsz goto loopcnt, F test1 ;Write loop: ;Define an unused location for our test ;program loop counter. ;Define the test pattern to be written. ;Initialize that counter. ; ;Load W with the Write command. ;Transfer W into cmd register. ;Intialize the 93C46 93C46 data registers with ;write data. ; ; ;Write data word into 93C46 93C46 device. ;Check completion status. ;Test for error condition. ;Yes, bad completion status, error-out. ;No, increment the 6 bit memory address ;field. ;Have we written all 64 locations? ;No, write another location. ;Read loop: movlw movwf movlw .64 loopcnt read ;Initialize loop counter. ; ;Load W with the Read command. © 1999 Microchip Technology Inc. AN530 AN530 0073 0074 0075 0076 0030 0930 0CAA 0091 00347 00348 00349 00350 00351 0077 0743 00352 0078 0A81 00353 0079 0CAA 00354 007A 0092 00355 007B 0743 00356 007C 0A81 00357 007D 02B0 00358 00359 007E 02FF 00360 007F 0A74 00361 00362 0080 0A80 00363 00364 0081 0A81 00365 00366 00367 MEMORY USAGE MAP (`X' movwf call movlw subwf status,zflag errloop tstptrn lowb,0 status,zflag errloop cmd, F decfsz goto loopcnt, F test2 ;Transfer W into cmd register. ;Read addressed data word from 93C46 93C46 device. ;Load W with the pattern written. ;Verify the data read against what was ;written. ;Same? ;No, error-out. ;Repeat with the lower byte read. ; ;Same? ;No, error-out. ;Yes, both byte correct, increment the 6 bit ;memory address field. ;Have we read all 64 locations? ;No, read another location. goto allok cmd see tstptrn highb,0 btfss goto movlw subwf btfss goto incf test2 allok ;Home safe! errloop ;Bad news! errloop goto END `-' = Unused) = Used, ;Thats all folks! 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XX- - - -93C46 -93C46 3 WIRE INTERFACE ROUTINE MEMORY USAGE MAP (`X' = Used, `-' = Unused) 01C0 : - - - -X All other memory blocks unused. Program Memory Words Used: Program Memory Words Free: Errors : Warnings : Messages : 0 0 reported, 0 reported, © 1999 Microchip Technology Inc. 131 381 0 suppressed 0 suppressed DS00530F-page 21 AN530 AN530 NOTES: DS00530F-page 22 © 1999 Microchip Technology Inc. AN530 AN530 NOTES: © 1999 Microchip Technology Inc. DS00530F-page 23 Note the following details of the code protection feature on PICmicro® MCUs. · · · · · · The PICmicro family meets the specifications contained in the Microchip Data Sheet. Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today, when used in the intended manner and under normal conditions. There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet. The person doing so may be engaged in theft of intellectual property. Microchip is willing to work with the customer who is concerned about the integrity of their code. Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable". Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our product. If you have any further questions about this matter, please contact the local sales office nearest to you. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip's products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. Trademarks The Microchip name and logo, the Microchip logo, FilterLab, KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER, PICSTART, PRO MATE, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, microPort, Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM, MXDEV, PICC, PICDEM, PICDEM.net, rfPIC, Select Mode and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A. Serialized Quick Turn Programming (SQTP) is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. © 2002, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received QS-9000 QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999. The Company's quality system processes and procedures are QS-9000 QS-9000 compliant for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs and microperipheral products. In addition, Microchip's quality system for the design and manufacture of development systems is ISO 9001 certified. 2002 Microchip Technology Inc. M WORLDWIDE SALES AND SERVICE AMERICAS ASIA/PACIFIC Japan Corporate Office Australia 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: http://www.microchip.com Microchip Technology Australia Pty Ltd Suite 22, 41 Rawson Street Epping 2121, NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 Microchip Technology Japan K.K. Benex S-1 6F 3-18-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa, 222-0033, Japan Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Rocky Mountain China - Beijing 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7966 Fax: 480-792-7456 Microchip Technology Consulting (Shanghai) Co., Ltd., Beijing Liaison Office Unit 915 Bei Hai Wan Tai Bldg. No. 6 Chaoyangmen Beidajie Beijing, 100027, No. China Tel: 86-10-85282100 Fax: 86-10-85282104 Atlanta 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307 Boston 2 Lan Drive, Suite 120 Westford, MA 01886 Tel: 978-692-3848 Fax: 978-692-3821 Chicago 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075 Dallas 4570 Westgrove Drive, Suite 160 Addison, TX 75001 Tel: 972-818-7423 Fax: 972-818-2924 Detroit Tri-Atria Office Building 32255 Northwestern Highway, Suite 190 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260 Kokomo 2767 S. Albright Road Kokomo, Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 949-263-1888 Fax: 949-263-1338 China - Chengdu Microchip Technology Consulting (Shanghai) Co., Ltd., Chengdu Liaison Office Rm. 2401, 24th Floor, Ming Xing Financial Tower No. 88 TIDU Street Chengdu 610016, China Tel: 86-28-6766200 Fax: 86-28-6766599 China - Fuzhou Microchip Technology Consulting (Shanghai) Co., Ltd., Fuzhou Liaison Office Unit 28F, World Trade Plaza No. 71 Wusi Road Fuzhou 350001, China Tel: 86-591-7503506 Fax: 86-591-7503521 China - Shanghai Microchip Technology Consulting (Shanghai) Co., Ltd. Room 701, Bldg. B Far East International Plaza No. 317 Xian Xia Road Shanghai, 200051 Tel: 86-21-6275-5700 Fax: 86-21-6275-5060 China - Shenzhen 150 Motor Parkway, Suite 202 Hauppauge, NY 11788 Tel: 631-273-5305 Fax: 631-273-5335 Microchip Technology Consulting (Shanghai) Co., Ltd., Shenzhen Liaison Office Rm. 1315, 13/F, Shenzhen Kerry Centre, Renminnan Lu Shenzhen 518001, China Tel: 86-755-2350361 Fax: 86-755-2366086 San Jose Hong Kong Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955 Microchip Technology Hongkong Ltd. Unit 901-6, Tower 2, Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 New York Toronto 6285 Northam Drive, Suite 108 Mississauga, Ontario L4V 1X5, Canada Tel: 905-673-0699 Fax: 905-673-6509 India Microchip Technology Inc. India Liaison Office Divyasree Chambers 1 Floor, Wing A (A3/A4) No. 11, O'Shaugnessey Road Bangalore, 560 025, India Tel: 91-80-2290061 Fax: 91-80-2290062 Korea Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934 Singapore Microchip Technology Singapore Pte Ltd. 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan Microchip Technology Taiwan 11F-3 11F-3, No. 207 Tung Hua North Road Taipei, 105, Taiwan Tel: 886-2-2717-7175 Fax: 886-2-2545-0139 EUROPE Denmark Microchip Technology Nordic ApS Regus Business Centre Lautrup hoj 1-3 Ballerup DK-2750 DK-2750 Denmark Tel: 45 4420 9895 Fax: 45 4420 9910 France Microchip Technology SARL Parc d'Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A - ler Etage 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Microchip Technology GmbH Gustav-Heinemann Ring 125 D-81739 D-81739 Munich, Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44 Italy Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus 1 V. Le Colleoni 1 20041 Agrate Brianza Milan, Italy Tel: 39-039-65791-1 Fax: 39-039-6899883 United Kingdom Arizona Microchip Technology Ltd. 505 Eskdale Road Winnersh Triangle Wokingham Berkshire, England RG41 5TU Tel: 44 118 921 5869 Fax: 44-118 921-5820 03/01/02 2002 Microchip Technology Inc.