|
|
EC挂接8Mbit SST25VF080B的话,可参考和学习,其它的SPI FLASH雷同。- Software Driver% X9 z, Q! V) s1 L" C
' z0 P E! x$ e1 U6 s- SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory
4 p) A( {( W, H5 K9 A- F1 f - . P3 `* T# s! @; Z. L7 G1 g
- November 4th, 2005, Rev. 1.0) v$ i0 z# ^- O8 I3 H8 T, @. P
- ; e& ]0 E- H _
- ABOUT THE SOFTWARE7 n2 N8 e5 p. _: ?) N# g ?
- This application note provides software driver examples for SST25VF080B,4 h' A! x" M% h/ L! G& G9 I
- Serial Flash. Extensive comments are included in each routine to describe 8 i: b" d1 E/ R/ ?8 D
- the function of each routine. The interface coding uses polling method ( X. B; k* l/ |" N
- rather than the SPI protocol to interface with these serial devices. The3 M$ s3 |+ g; l: D, s
- functions are differentiated below in terms of the communication protocols
6 w- f, M! ~9 R - (uses Mode 0) and specific device operation instructions. This code has been * `' P# c! W* M0 m9 h! ~
- designed to compile using the Keil compiler.; ?& i: n# I. A) K
- 9 l2 I2 ?" J" o+ A( r
- & B/ r( [' }5 |$ O6 H0 {2 `
- ABOUT THE SST25VF080B
7 b$ c: M7 e( {" Y2 }) K; j/ o1 m7 f, F - ) B' R4 @! y( n% `. d$ D N0 m
- Companion product datasheets for the SST25VF080B should be reviewed in
3 r( }: e% G! l, C0 s7 \' W - conjunction with this application note for a complete understanding 9 ?9 U% ]+ j! N* E
- of the device.( D/ g4 l3 |! Q6 S1 ^5 \! v
- / l2 y9 `0 w$ Y* l- @) A
- 2 |. p5 G r& B
- Device Communication Protocol(pinout related) functions:( J9 b# F$ Y0 A5 g m5 D
- ' i& B9 b" u3 N$ J* f
- Functions Function, F! L2 O' d# G+ j$ v$ u( t
- ------------------------------------------------------------------5 G2 [! u0 c! A8 U" |
- init Initializes clock to set up mode 0.
! r1 ?. Q L* P \& ^# x& ? - Send_Byte Sends one byte using SI pin to send and
- q2 w9 R: x3 J/ f" b8 C* S; r2 s - shift out 1-bit per clock rising edge
5 b( V" f& L8 V3 P% k6 w* d! d - Get_Byte Receives one byte using SO pin to receive and shift % U' i1 e1 g3 C% w) P
- in 1-bit per clock falling edge
# E. P/ ^# p/ R: g - Poll_SO Used in the polling for RY/BY# of SO during AAI programming
^7 ^: J0 m4 J - CE_High Sets Chip Enable pin of the serial flash to high1 n; F9 e1 D2 N2 B7 A
- CE_Low Clears Chip Enable of the serial flash to low
9 M9 ?) a# X8 |" Y" P9 ~! Z - Hold_Low Clears Hold pin to make serial flash hold
7 Q) g; Y" s( P3 b - Unhold Unholds the serial flash. z0 c; R# h# b! j5 b3 p
- WP_Low Clears WP pin to make serial flash write protected/ ~% M& D; b9 R- _5 N3 N
- UnWP Disables write protection pin6 h% ^; @7 N9 ]2 q
) l4 I7 `3 M S- Note: The pin names of the SST25VF080B are used in this application note. The associated test code
( a8 k M9 G5 v/ p- {) N O- A - will not compile unless these pinouts (SCK, SI, SO, SO, CE, WP, Hold) are pre-defined on your
9 k; P7 {4 T1 S d. d. d - software which should reflect your hardware interfaced. - `+ k- n+ Q) S
- 6 T4 g; {5 b3 i+ S. c/ _0 n: `" I
8 \/ b/ f) a3 n6 ?, r7 O) {) I! t- Device Operation Instruction functions:
! X3 O. G9 f* m# o
3 W' ? K& s. `+ x3 D- Functions Function6 l% }9 r& b/ J, A+ p( g
- ------------------------------------------------------------------
( Y, X* U' ^0 [2 |' g - Read_Status_Register Reads the status register of the serial flash& M7 O7 @/ Q' ^ }7 ?- G9 w8 S
- EWSR Enables the Write Status Register. @: c- _5 @# `% S0 P/ z. w+ D
- WRSR Performs a write to the status register: {' p% }( B |
- WREN Write enables the serial flash1 r, l6 Q5 C- i% d
- WRDI Write disables the serial flash" \+ {: v1 Z' G
- EBSY Enable SO to output RY/BY# status during AAI programming
0 {. E+ h* C( L! y" G - DBSY Disable SO to output RY/BY# status during AAI programming
4 d& T3 U: H* w1 k1 h1 I - Read_ID Reads the manufacturer ID and device ID8 U( w* ]. T2 S& S: U
- Jedec_ID_Read Reads the Jedec ID# A; W( M# H) N* S/ [) l
- Read Reads one byte from the serial flash and returns byte(max of 25 MHz CLK frequency)
- i/ F# s7 D; F1 o/ l8 ^. i - Read_Cont Reads multiple bytes(max of 25 MHz CLK frequency)- _+ I! G0 @: Y8 ?! u
- HighSpeed_Read Reads one byte from the serial flash and returns byte(max of 50 MHz CLK frequency)
- R- M: K! k5 M8 {9 L - HighSpeed_Read_Cont Reads multiple bytes(max of 50 MHz CLK frequency)
. |# K; _. t" K5 @7 B - Byte_Program Program one byte to the serial flash7 A% Q8 ? V( C, I. ^7 ]5 g
- Auto_Add_IncA Initial Auto Address Increment process
/ S4 `" j3 v0 Z/ V' V" ^ - Auto_Add_IncB Successive Auto_Address_Increment process after AAI initiation3 x9 Z! t& p. I. q$ i
- Auto_Add_IncA_EBSY Initial Auto Address Increment process with EBSY. V8 `8 a+ t) W2 P
- Auto_Add_IncB_EBSY Successive Auto_Address_Increment process after AAI initiation with EBSY and WRDI/DBSY# S# n; m6 {9 q1 M2 q! Y) }
- Chip_Erase Erases entire serial flash9 Z" \7 n# L0 i [: s6 q
- Sector_Erase Erases one sector (4 KB) of the serial flash+ B2 n) @. p$ j# m
- Block_Erase_32K Erases 32 KByte block memory of the serial flash" P: y8 V+ O, p3 H! j& G
- Block_Erase_64K Erases 64 KByte block memory of the serial flash
3 T3 \$ E3 p5 Y! X' E - Wait_Busy Polls status register until busy bit is low
5 D/ M' O# J: h9 }, f+ Q5 t - Wait_Busy_AAI Polls status register until busy bit is low for AAI programming
, q/ j% K2 C# H2 d - WREN_Check Checks to see if WEL is set7 F# x+ R9 J: L+ _! g. X' I
- WREN_AAI_Check Checks to see if WEL and AAI mode is set: }: }! E: y2 F1 w. ?1 R: K6 J5 p
Z R7 C: }4 {+ S! @' _7 V
2 F0 i! a! l9 g' e' l$ z* P/ w: }0 k: t; s- 2 @: V( h. X* g7 o; e. \% Z
-
$ N: f# q' ]1 N/ t3 v2 n' ^ - "C" LANGUAGE DRIVERS : i# X) X3 ]; b. `% r
R, B# a# z; l5 y- /********************************************************************/
/ d# W s& ^* _ ~ l - /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005 */
1 K$ s. W) J) z7 b - /* Example "C" language Driver of SST25VF080B Serial Flash */
" I: ?) b2 c. K9 n6 Z - /* Conrado Canio, Silicon Storage Technology, Inc. */
% P7 d4 o, S$ g" _8 O6 t - /* */
# S# Q w8 T7 ]2 g - /* Revision 1.0, November 4th, 2005 */
* U8 O+ r2 _' v) s4 q: Y - /* */
3 y/ H7 v5 G/ v% F5 n0 a. P- {' T - /* */
5 S' C" \ s4 M/ d' ~0 J - /********************************************************************/
! ~4 N( l, K( v3 ? - ! E* F; \8 p0 m5 p
- #include <stdio.h>. L# }5 b6 _4 V5 j* _
- #include <stdlib.h>
( e4 j& A9 N' e2 c1 { ^/ ~' P
% Z, ?: O+ [) `9 d' b7 F- /* Function Prototypes */, a! W# b1 _/ T4 H( |% ~7 Q
- 8 M g( p5 G% o7 a' F
- void init();
2 `- O; s* p$ p$ K/ G - void Send_Byte(unsigned char out);
* x* J2 \: u% \' t; P r# K - unsigned char Get_Byte();: a3 d& s0 \1 C/ y, Z' H3 n7 q
- void Poll_SO();9 \. c/ q8 k' A6 s9 Z9 d
- void CE_High();
$ }/ Z. [. c* Q - void CE_Low();8 H. K) G7 h/ t% H0 D( S( S
- void Hold_Low();! A1 V5 l8 r( G5 \2 M
- void Unhold();& k# c0 P- z7 S2 ]% c' y
- void WP_Low();
( [4 B: W5 p" s$ O5 t0 \8 ^ - void UnWP();* `" i* R8 @7 o. P/ t- ~" N
- unsigned char Read_Status_Register();4 w2 s% a- p5 ]& x
- void EWSR();
" f9 P* Q& f2 o; x* q - void WRSR(byte);
. C0 k0 a1 [0 J( e; W+ p; Q9 v - void WREN();
|- C- @! [# O. _; f- D - void WRDI();
6 D1 k: \ }! ~' p4 I) n! e; e" C - void EBSY();
@+ g/ x7 E! }8 D l - void DBSY(); v8 Y+ P$ f7 _" @. Q9 L3 ~9 z
- unsigned char Read_ID(ID_addr);
0 c; B, O2 V5 `: p" ?: |, Y& Z - unsigned long Jedec_ID_Read();
# b- k% u$ d! G# h - unsigned char Read(unsigned long Dst);
7 X8 e! n7 S1 l6 Q+ l - void Read_Cont(unsigned long Dst, unsigned long no_bytes);
" U1 r- ~5 A% \% \& q$ N; @; A - unsigned char HighSpeed_Read(unsigned long Dst); n0 }. Q0 a2 ~' Y. v4 q
- void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes);7 M9 X8 c) r; t. K& `( b. x5 K
- void Byte_Program(unsigned long Dst, unsigned char byte);
5 y p' x4 B0 b4 c - void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2);% l7 k5 Q9 m7 {2 b
- void Auto_Add_IncB(unsigned char byte1, unsigned char byte2);+ n7 H( h% [ z2 V, k
- void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2);# I+ k/ E3 T4 O$ W* ?! l
- void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2);1 W, h$ J( g! Z. \
- void Chip_Erase();. J' v; [, n* e G6 n! Y& i1 }% G8 T
- void Sector_Erase(unsigned long Dst);+ b0 X9 ^6 r0 ^" d
- void Block_Erase_32K(unsigned long Dst);
! F, m( Z' p3 n& ] - void Block_Erase_64K(unsigned long Dst);* W% u9 z* i7 v; h0 p
- void Wait_Busy();( Y7 Y6 J5 Z E* _( f5 N
- void Wait_Busy_AAI();
+ {4 l$ e- p' ~9 j ] - void WREN_Check();
+ B0 f3 R; `7 u& X3 H$ f" U3 `7 l0 W - void WREN_AAI_Check();" I& T) A* n' }, J
' m) l* s& V& z. g8 Z1 [- void Verify(unsigned char byte, unsigned char cor_byte);8 B7 E J' i# K+ B
- 9 u5 A, V& g- z7 a1 {
- unsigned char idata upper_128[128]; /* global array to store read data */
6 b( p6 k3 k% s9 n6 Q# p& K! G - /* to upper RAM area from 80H - FFH */- r7 V- I/ h7 q- K, p/ r1 C2 V
- 0 B: o9 W# y! ]+ r( d; `
- /************************************************************************/
4 f% W7 g, `6 b. d - /* PROCEDURE: init */
5 N# j D" b5 ]( n - /* */
- C: `$ E! K: Z2 z - /* This procedure initializes the SCK to low. Must be called prior to */
4 b" L. u* Z# L - /* setting up mode 0. */8 X7 s& W J j" r9 S7 B3 U
- /* */: V/ Q0 |1 ^' w* ~; ]+ a
- /* Input: */
' B, j3 C/ g- c: |6 I - /* None */2 z5 j, G3 ` X
- /* */7 s+ J+ |# z& [% J \ H: Z
- /* Output: */
2 d- q" p$ l3 {4 i. u9 A% B - /* SCK *// n# z6 m6 [/ S: {3 ]* }
- /************************************************************************/' \: V3 |/ e& w
- void init()3 [" `$ B9 \: q9 p# u: l P
- {0 H3 |& b1 w5 W8 S' J
- SCK = 0; /* set clock to low initial state */
. b, }7 I$ P( n( L- o& y - }
4 a8 ?: z7 w) r2 }
7 C: U- e. l. U% b( ^ y- /************************************************************************/4 e) T1 S# a" n, X- K* M4 |) q
- /* PROCEDURE: Send_Byte */' c K# O9 |+ i; [
- /* */4 T# J: ]0 M e- q7 q0 K9 X" o
- /* This procedure outputs a byte shifting out 1-bit per clock rising */1 S' y+ l/ F* G' N- W" W
- /* edge on the the SI pin(LSB 1st). */- T6 I' Q" @% g6 w
- /* */
" [# L. m8 J2 u3 k3 b6 F - /* Input: */
5 h& H' d* V% R: D) g - /* out */% V1 d+ w: d1 s" Y
- /* */
. S+ `" d! r* a9 h, B! _' C9 ~ - /* Output: */; r/ L6 ]8 B! S3 Z8 |* _2 ?5 e1 I
- /* SI */
& P7 n, s+ N) p - /************************************************************************/& I8 W |, [1 p0 B# h, M: f
- void Send_Byte(unsigned char out)
( @) x% z9 e# h - {
2 V; N+ e) R0 S& ^* E% B - - z" \3 f) a A
- unsigned char i = 0;3 l$ \& y: [9 n( w6 s
- for (i = 0; i < 8; i++)
8 x& ~8 f. W9 n( ^7 d9 ]5 d - {
6 q3 _. h4 y( ~# y1 v' c4 A -
( h- W3 W2 I& V1 G8 s - if ((out & 0x80) == 0x80) /* check if MSB is high */
+ R* L2 s; O# K4 m - SI = 1;) |% H. g$ _' e/ y5 \& O. f
- else6 M, `1 d+ z/ h. V
- SI = 0; /* if not, set to low */% C9 v- c5 h" `2 o8 h* z* x' S# K
- SCK = 1; /* toggle clock high */& {9 q. P/ N6 A( \! U1 n$ ?
- out = (out << 1); /* shift 1 place for next bit */
: d5 p* ~; }5 J3 j - SCK = 0; /* toggle clock low */# N% ^" f. z; i0 d$ l
- }9 _- w3 P1 @: k: Z/ L! n1 b1 a2 f
- }% `; K, P2 w7 f) a- Q
- " d. i; Z' k: k: V! o; D; D
- /************************************************************************/
/ ] B( d9 f+ H3 K9 D2 [, V - /* PROCEDURE: Get_Byte */
5 H8 C }7 B/ l7 N0 i6 i: B - /* */: u3 `( Z2 `0 E2 Z( c
- /* This procedure inputs a byte shifting in 1-bit per clock falling */& C* k: d; G9 y6 X6 y6 C5 H5 E
- /* edge on the SO pin(LSB 1st). */9 S$ P; o5 m8 c" P1 X4 b2 f2 h
- /* *// R O Q# m1 V4 W- q
- /* Input: */
( }; S2 j- `3 w2 ], Z( ? - /* SO */
. R. @# g; C& i4 U: A - /* */9 z9 B4 o6 s. J/ Z, D
- /* Output: */
$ e) {/ _6 E7 @ P" c5 k - /* None */! p% w# R4 T* C4 {* r9 _2 Y
- /************************************************************************/4 U4 {! [ r3 s3 z4 H' f0 K
- unsigned char Get_Byte()
3 ~; e! \9 a( e8 y! h+ q - {7 b1 A- L" Z) d" c
- unsigned char i = 0, in = 0, temp = 0;2 {& Y6 C% D7 c$ u' ~) m8 h2 @
- for (i = 0; i < 8; i++)& T0 r/ l$ v }" H6 K6 F
- {
1 r. m( d4 F# Z: M4 Y - in = (in << 1); /* shift 1 place to the left or shift in 0 */& s1 X, y7 s# g! k
- temp = SO; /* save input */1 K7 v% J9 Y5 M4 h& i% l. |0 A
- SCK = 1; /* toggle clock high */
2 N4 \6 |) S! @- t' F - if (temp == 1) /* check to see if bit is high */7 l! C* X) b6 g7 z% X
- in = in | 0x01; /* if high, make bit high */
# ?& u+ C6 w+ ^( Q w - " k! o' Y* {, V1 a1 N
- SCK = 0; /* toggle clock low */
% Q B' Z9 d, y7 } - 8 d1 U" J( `$ |1 G: m# W% W
- }
7 M% y* @% ^( b0 ^, [9 r$ w% D - return in;
; k9 ^! ~( m0 Z. A( b: Z - }, N" ?+ J2 ]: I5 }" W( w- i6 m. C
0 Z7 b7 o$ _1 J7 g. G" }. k- /************************************************************************/& Q' k/ h. e& I& J1 p8 }8 {' ~
- /* PROCEDURE: Poll_SO */" r ^& I Y" j+ n
- /* */
& m; I ]7 k5 j( O+ G - /* This procedure polls for the SO line during AAI programming */* X6 K5 r9 r, }1 h3 P6 ?
- /* waiting for SO to transition to 1 which will indicate AAI programming*/
2 v% ]$ N6 ^9 i" V. v - /* is completed */$ W4 P. g6 h, v
- /* */
( j/ U6 q5 d( {+ G - /* Input: */* ]: \5 U4 c2 q- x
- /* SO */
+ `1 n. l6 ~0 I% ]5 @: N - /* */
1 Q$ u% V2 Y( o7 z+ x% j - /* Output: */& |7 W% e' C% i/ T+ S
- /* None */
* t, g1 S! y: O - /************************************************************************/5 j0 r/ A9 n H w ?
- void Poll_SO()
, J, D1 v# T3 [ - {5 E$ P6 T8 F4 q6 V7 k: U$ m/ k2 f* ^
- unsigned char temp = 0;, j1 ^; ~7 A6 l5 E4 U
- CE_Low();
& c; O$ X* p# \$ K - while (temp == 0x00) /* waste time until not busy */
5 e. d( L0 N! Z; j" z3 t3 B& m - temp = SO;
3 ?5 c: }& N- {8 ]* ?0 G- x - CE_High();
, |' C& Q9 C( s- a" w9 B - }: ~2 S7 b3 p: D( M5 e
- s8 W. x2 _. M. ?% T! p
- /************************************************************************/7 G ^9 [. A2 @# \& W
- /* PROCEDURE: CE_High */
" i' s, c2 ]4 l1 {# V) L- e - /* */# G! _7 H$ t! F; k7 ~$ ]
- /* This procedure set CE = High. */
2 X; g# X' k+ E& n: \6 D! T - /* */
$ M9 y, P7 L$ g7 n2 A( e6 M8 `! s. v - /* Input: *// I( Q2 f) e6 p/ r1 W3 D1 y* @
- /* None */
6 i& ? R3 b: l6 g - /* */
3 n0 R; I8 s! y0 [3 K' y2 [ - /* Output: */
+ b2 T, W' Q& _1 D$ j/ y4 c - /* CE *// @1 x" d! ]- d& F7 G
- /* */
! R/ x7 Y4 ~6 ~- v: M! ]# D7 V - /************************************************************************/
! W+ C3 ~! W, P4 y! ^2 o - void CE_High() * x" C1 u* _: b" |1 X0 n
- {' X- K: l- |& Z5 E* i' n7 j
- CE = 1; /* set CE high */
6 Q' t) K8 v' _. h/ v# Q - }
- N' U0 |2 _ L/ o( V5 P
; X, a/ P/ |( N( r. L- /************************************************************************/
8 }3 {/ P9 W; l- D: s4 [) U4 H - /* PROCEDURE: CE_Low */
s \+ ]) P6 E! T$ v$ d% F# \7 b - /* */
% H9 g- S7 j* G+ \6 J. L - /* This procedure drives the CE of the device to low. */
& E8 t2 n$ X0 Q- i0 i4 l - /* */( e* K! Q- q% c: `
- /* Input: */7 q* F' m; H+ ~. G
- /* None */
2 }& ~' m/ T6 r* V: z1 `+ t - /* */
! D% @/ W" f7 [' Q7 S: i: A - /* Output: */
* Z/ N! K0 v6 Z( H- a - /* CE */. y8 _: _4 }- `
- /* */% L- t5 ^% b3 ~, F
- /************************************************************************/. ^# @% P# Z1 _7 ?) Z$ ]! L
- void CE_Low() % ~" Y! S. g8 F7 D3 |2 G: `( C
- {
8 X- h3 c% i8 U4 a - CE = 0; /* clear CE low */; ^ z' f% L" {3 q( Y. B2 Y
- }, n4 u7 @5 e5 {: d8 b- k
! {: o; H, x( Y. ~5 O3 |) d- /************************************************************************/
# K8 j+ V# `+ w# d0 z G$ [ - /* PROCEDURE: Hold() */3 D, O- ?9 m( b
- /* */
4 |/ L1 o* N$ h* S; d7 q, v - /* This procedure clears the Hold pin to low. */
" N3 z, T5 e" s% o0 e4 Y2 E - /* */
3 P* M- ^0 d: F5 A - /* Input: */
" W. c7 y* U7 I - /* None */
6 ^ Z, ?' T" X - /* */4 \0 x0 W9 ~+ H; @+ @$ k M
- /* Output: */5 l0 C* U' i; J8 d
- /* Hold */* v7 G" ]9 [* z+ ?4 C: o
- /************************************************************************/
+ c4 a, @$ i- S - void Hold_Low()
9 V9 o- O" q {3 C% b1 A6 s& G; f% e - {
6 l1 r2 `7 T1 A2 Z+ B- G2 D - Hold = 0; /* clear Hold pin */. L* [0 L' B3 x O7 T
- }( a6 @$ Y5 s3 F# s/ _; I1 y+ O4 t
' L! |0 d$ d; O' s% D9 D- /************************************************************************/( G6 N& q2 Z+ c' v3 w$ t
- /* PROCEDURE: Unhold() */% N4 B3 t( f1 t
- /* */
% G2 H4 f% ?, q8 P( e+ v, c - /* This procedure sets the Hold pin to high. */5 a N4 u# q7 u: N
- /* */
0 e6 a9 \% ^1 M1 L& q9 E- I, K - /* Input: */! F8 N0 ? w% b) c3 }
- /* None */- G( A- P' N0 U7 z+ F3 |6 X
- /* */' h( }5 Q% O+ S: U) h7 |
- /* Output: */; S# |" v1 o5 O$ O {% z
- /* Hold */
2 T- \& G* q* l; \, V$ s - /************************************************************************/
2 {, ?% p$ k/ L h5 S K - void Unhold()8 G% w+ s0 B1 j* q6 l1 y
- {9 b; L& E2 Q. ] Z3 O i: R; x
- Hold = 1; /* set Hold pin */6 ^8 _- S2 ~3 [* T
- }/ l& U0 i! s9 y
. J% a* }" V7 V3 ~$ \- /************************************************************************/* V0 P0 W. g# \8 Y0 B
- /* PROCEDURE: WP() */) I/ Y- V/ q, X+ _) U. Z0 r
- /* */
2 l- h% `0 m! N0 T* S - /* This procedure clears the WP pin to low. */
N+ H+ t N! e' f. i - /* */
9 E6 N2 q/ i. d% n } - /* Input: */
# R- b- q$ w* P: w: [& C. g# L) | - /* None */) y/ }; V4 F4 F1 ^ n2 p# P
- /* */
- t8 P1 {5 Y$ ~8 Z0 \: ] - /* Output: */
; o0 |- V, T2 z' z1 }1 w$ | - /* WP */* s7 r- M4 J# M; |7 V
- /************************************************************************/7 M0 S9 D4 `! s
- void WP_Low()! l; y1 ~& p7 V) L
- {
9 g [) g$ [; R! ]4 l' z) y/ V - WP = 0; /* clear WP pin */* R2 }; m! M2 F8 ]/ Q* |
- }
1 ]4 J/ Y# P3 Q1 f" k
/ [, `$ M) \+ x% H3 V% ~" N- r- /************************************************************************/
0 _( W( E# j' k& c - /* PROCEDURE: UnWP() */- c+ \- j7 w) o2 S( v
- /* */6 k7 L2 M9 [' [3 v3 z& h# X
- /* This procedure sets the WP pin to high. */
; @+ @) [8 W D- f& P" e - /* */" K p6 y0 U8 Y& l# A0 b
- /* Input: */+ K, Q( X3 B/ p' d# a5 {
- /* None */
2 w! A. t. [$ i4 _8 P5 G - /* */
9 ~$ X0 }+ h5 @, i! o6 A$ v - /* Output: */
0 T$ c' d% t! R8 i/ `3 r( a! a - /* WP */3 D& l2 m( \- j2 N. F
- /************************************************************************/
& ~/ X" {, m/ r, t5 {8 G2 K - void UnWP()) ` l/ }2 K1 D
- {
; q3 b5 v) j' s9 S: H, L- V - WP = 1; /* set WP pin */; R5 a) L+ Z4 z* v
- }1 ?* Y1 C, t% @* ]
- , k- }6 P; u- k# I& S. s, B
- /************************************************************************/
0 V2 A' \# Y8 M0 d7 h3 b5 C! t - /* PROCEDURE: Read_Status_Register */
+ e/ D6 L$ {1 i# W% t3 e3 G7 m - /* */; C) J6 p$ Z+ m; g: J0 j9 W
- /* This procedure read the status register and returns the byte. */- c2 N3 Y6 E% t1 w) p5 C7 S4 }
- /* */
7 D3 `" j7 l- e - /* Input: */+ J7 q2 G% f3 n! |
- /* None */
' h7 B, U5 c# i% a - /* */
) b. S$ b7 a- S; F% Y- E5 `% e* x5 Q - /* Returns: */# M3 g% F1 q6 I% n: O+ p( c
- /* byte */$ Q1 P) d+ c# d! \; P- R X- j
- /************************************************************************/% ?! o, C! x+ s8 W% ?1 v
- unsigned char Read_Status_Register()
$ H2 J9 U+ P- L9 X4 c o# M! `1 o - {
; o* H: E. \" w5 {. b7 p - unsigned char byte = 0;
. q4 @& P1 M* y% X( }" X - CE_Low(); /* enable device */ d+ `" b2 g0 F+ S2 G# }+ W8 `
- Send_Byte(0x05); /* send RDSR command */
2 `9 t/ D4 O$ ?" n& S8 ]( e# I - byte = Get_Byte(); /* receive byte */
8 b) g# m5 r% b- `* W ^7 l - CE_High(); /* disable device */
8 E) h7 ?- W9 k- ^9 ?; l - return byte;
9 C: ^) C) F5 E$ w: q9 X - }% u$ U. s5 M2 a3 |: v8 L8 `% R
3 x4 m/ f+ g' w- l5 f- /************************************************************************/
6 P u4 I6 `, j - /* PROCEDURE: EWSR */, C: P! |: p6 M `/ h+ @
- /* */, [+ P3 J3 L" h" i& Q# E
- /* This procedure Enables Write Status Register. */ X" a+ w' b4 V9 i7 E+ o9 G
- /* */2 ~: T0 N& L& ]& [, o' B) a
- /* Input: */& a8 T# L: X) X' R1 Y
- /* None */
- F$ a7 y" A3 W4 h1 J0 D; a8 y, S1 v. q - /* */
" P G+ A3 r, n- i4 e - /* Returns: */
3 C7 [# {3 Z2 b; w! A! _( { - /* Nothing */
: h: {& H! d5 v$ z% f - /************************************************************************/* d$ K2 P2 e; Q( @0 @- z# L: x8 x: T
- void EWSR()4 z3 j8 Q- {9 B
- {
S$ j0 N5 u& ~; _- R. P4 Q - CE_Low(); /* enable device */# ^: G$ _5 C4 r d0 F+ L Y
- Send_Byte(0x50); /* enable writing to the status register */
7 }/ ?# W* o7 P1 f0 y8 V% Q `. W - CE_High(); /* disable device */
% q( S6 i$ X; |2 x/ C: v - }: C8 ?; R* C& o0 {" {0 }
p M/ v. X! o1 x( D% d- /************************************************************************// l, S2 A X4 [8 K7 w/ |
- /* PROCEDURE: WRSR */
' w- s- x) H) w: B6 E - /* */9 |* q& W! K7 j4 x6 @
- /* This procedure writes a byte to the Status Register. */; x5 L7 G5 [' u) B5 K
- /* */
p' ~1 W8 M! \! k% ^) E: w( ` - /* Input: */8 l. C* v7 e' t Y0 g9 b* w3 _0 K
- /* byte */
3 j7 ?, h3 J5 I - /* */
$ @; { f$ \2 O/ D2 P - /* Returns: */
+ j, j( t2 d, F# V' ?6 M" J - /* Nothing */% ^0 p$ k5 w% r: k6 d
- /************************************************************************/
2 w, L/ o" `. @ - void WRSR(byte)
$ f" i8 S3 q0 E) `) F# H; b- N - {
) o. j n6 [* v. K3 s6 Y - CE_Low(); /* enable device */# m2 `* Q# N0 G7 `
- Send_Byte(0x01); /* select write to status register */
. W2 j6 K2 c6 Z; a/ J8 l4 x, m, e - Send_Byte(byte); /* data that will change the status of BPx ; X4 U' O; }% q7 `) W0 @
- or BPL (only bits 2,3,4,5,7 can be written) */
! a" ^. U4 ~2 G# C - CE_High(); /* disable the device */
1 C1 Q) f( z" R, @1 P o1 e- c - }) Q% H" K: R) G, _6 F# T! }
- 0 o2 R* z8 @3 q; d
- /************************************************************************/
# l% |( N6 e7 S' S J) }7 ~! x# a - /* PROCEDURE: WREN */
3 b. ?9 [/ _* O; Y. ?- ? - /* */9 ^& Q9 E9 E8 v# u- w0 W# B
- /* This procedure enables the Write Enable Latch. It can also be used */
+ h C9 K) u) X: P& @6 Q - /* to Enables Write Status Register. */; y S. ?# r8 l+ z" ^
- /* */" j. p7 |- b# o; b4 q
- /* Input: */
1 T1 u, x- a5 R$ s7 B$ P# S5 o* o - /* None */
: [/ |0 r9 D# s0 c - /* */
3 Z" Q* F1 G* X - /* Returns: */
# @: I7 z c! N" d* L; ~2 i - /* Nothing */
% Y6 }7 o1 e0 ?, E6 S- Y7 s - /************************************************************************/
. a `0 t+ F6 {/ [6 b3 g - void WREN()
8 s/ r2 s+ s$ T: q1 V& ?- D* E% w - {% \+ Q5 R0 @) Y6 q1 L" g# e9 j
- CE_Low(); /* enable device */ [& s: b: e+ k, C8 E
- Send_Byte(0x06); /* send WREN command */
& N8 i7 n; q$ d" s& w, R - CE_High(); /* disable device */
+ Z, Z- c- m/ L' H& e% w - }
1 f5 R5 A/ ?; `* D# U - ( I) A# m( ~" p& |) e& U
- /************************************************************************/# P0 d+ O0 \ o+ Z. y' a. |& U8 D
- /* PROCEDURE: WRDI */* k6 l5 a2 r* O7 H
- /* */5 j% K4 p) _9 s5 R: }
- /* This procedure disables the Write Enable Latch. */
. B- k$ F3 Q9 P. \; r - /* */
1 K$ v: G7 q4 v2 W - /* Input: */
& \% d- ?2 y, z! c - /* None */# n/ W8 ?0 {/ @* c2 a+ P/ y/ t
- /* */
2 C! T5 J! ]3 n9 [$ h/ S0 s - /* Returns: */# |" {+ @8 E8 a% S$ ^5 u3 e' M
- /* Nothing */1 s( {; l* I8 E( `4 \5 _
- /************************************************************************/% y7 m) ~1 E) P8 q- S6 J$ o0 v3 o' ^
- void WRDI()
- _- v& s3 ?; Q/ K. l! i0 l- I - { m3 Y* n, K) b7 q& q- C
- CE_Low(); /* enable device */
0 u* k2 y, k+ ~( t: i* \ - Send_Byte(0x04); /* send WRDI command */
9 T: E8 t; ?# B. l* F. `9 t) z0 D - CE_High(); /* disable device */3 K1 e9 ?: b+ h3 T- X. h
- }: _ k, b! ]* D2 [3 @! v) N
% F$ J$ V9 T6 p7 B! k- /************************************************************************/% G, k4 U2 a5 y+ J3 G/ t
- /* PROCEDURE: EBSY */8 }' n3 J0 G/ a3 n
- /* */( E' C" }+ W, T- M( b
- /* This procedure enable SO to output RY/BY# status during AAI */% |: k. n3 H* u w
- /* programming. */! _) @$ a9 |" L# ^) A8 z
- /* */, @8 v; u, Q8 x6 E# Z, J# ^4 g5 X
- /* Input: */
- @3 F0 p: `8 a0 d7 g - /* None */
' {9 ^6 P+ d0 i* I. l% ` - /* */$ @! W1 b) {. d* L
- /* Returns: */1 K1 C, ~4 D2 ?/ y) [- A0 t
- /* Nothing */
& l) T2 S+ K8 C - /************************************************************************/
% _/ `% l: b* W6 B( {4 m - void EBSY()
) c7 b$ m" X& m) N. C - {1 _" ?4 }2 ]+ M5 c6 B) Q0 e
- CE_Low(); /* enable device */" M! \0 C# p, x5 x, D
- Send_Byte(0x70); /* send EBSY command */
4 R5 I8 h( R1 t0 h - CE_High(); /* disable device */
# o* i' ?' w( D- D1 C `. H - }& n6 v7 _- X' U t6 g
! J( m/ M6 B2 O3 R2 d- /************************************************************************/+ ]) \2 G7 P8 U# e* u
- /* PROCEDURE: DBSY */+ a# s. ?. Z8 J$ B. _, T
- /* */ g- d: H$ d' ^( @4 z; n4 ?, w
- /* This procedure disable SO as output RY/BY# status signal during AAI */" U# q2 c1 u, |7 L
- /* programming. */
) c3 t) @& S4 j: c - /* */ w$ a! ]& }* T& Q! \5 s/ \
- /* Input: */
+ @8 z8 U7 p' U7 _ - /* None */' b4 n) a7 i! k- K2 l/ X1 K
- /* */
8 q$ y+ t& D6 {% ]; S- E! w - /* Returns: */$ D6 H8 k- _+ P _
- /* Nothing */4 f1 N R4 F$ n) c
- /************************************************************************/* u, U8 ~ Y8 k3 \# w" ~
- void DBSY()
" Z5 x& K# ~, m/ d8 ] - {
" Z- }, V7 Y+ t+ c$ n - CE_Low(); /* enable device */% Z j9 H# i7 e. b, |% u
- Send_Byte(0x80); /* send DBSY command */
) }% L! ^/ y5 q1 w7 X6 s% r - CE_High(); /* disable device */2 w# R% M( t( g7 }, v" d) q
- }
( `" \# J* _6 v5 e/ ` v- t
! T3 w6 u/ C- o$ O- /************************************************************************/
: q) r. i _$ p4 o8 I7 j( M* G - /* PROCEDURE: Read_ID */
) Y1 f+ x$ U- Y( e; J( r6 A5 e - /* */2 i9 D5 {3 C2 K/ |' W0 m3 H8 M
- /* This procedure Reads the manufacturer's ID and device ID. It will */0 S1 {1 M9 O, l& G
- /* use 90h or ABh as the command to read the ID (90h in this sample). */" y8 T. _' S, K$ V
- /* It is up to the user to give the last byte ID_addr to determine */
5 V1 T- l+ |8 }1 C. l - /* whether the device outputs manufacturer's ID first, or device ID */
! W1 V, e$ a/ v5 ] - /* first. Please see the product datasheet for details. Returns ID in */! L( B9 H3 y6 _+ b5 r
- /* variable byte. */& P/ U, E8 c9 R1 S8 s
- /* */# }$ E8 U) X8 H
- /* Input: */
5 B: c3 N/ ?1 _8 l6 q - /* ID_addr */
h6 ]- y M4 D: {( i3 l* \7 I1 r" Y - /* */: G; w% }: C/ U) q
- /* Returns: */# v0 G$ J& m( V# }" y
- /* byte: ID1(Manufacture's ID = BFh or Device ID = 8Eh) */+ f0 x9 L% ]4 e" @
- /* */
4 ~" J: |) S3 z1 u - /************************************************************************/
) Z. L) t* j+ o& j A$ h- b - unsigned char Read_ID(ID_addr)
" ]$ D$ X6 p% i3 I a7 t0 s - {
& O5 u2 Q6 G! d$ i5 Z - unsigned char byte;8 J% O# H; T& o% u5 K; Q
- CE_Low(); /* enable device */7 x% [& V2 f l" s, h
- Send_Byte(0x90); /* send read ID command (90h or ABh) */ A, H+ N2 A: K# D
- Send_Byte(0x00); /* send address */8 @& O s3 Q" a; S
- Send_Byte(0x00); /* send address */
. }1 |- V# e# |7 |# i - Send_Byte(ID_addr); /* send address - either 00H or 01H */! P6 }0 {3 r+ k5 |( B- T; l& d
- byte = Get_Byte(); /* receive byte */8 Y( }% n% V! a' H5 V, b# S9 @
- CE_High(); /* disable device */
/ v$ a) Q. U( z } - return byte;
5 F2 Z. M c& p; w3 }2 n2 ]! e - }
3 L4 [1 F7 D3 m0 k9 Q6 o - $ ~6 O. m: L+ t J; b2 ]
- /************************************************************************/, ?, q) _ R( H; G D7 n# U1 u
- /* PROCEDURE: Jedec_ID_Read */
. P4 J, h. Q/ B8 ]5 X! K - /* *// s3 x- U9 x/ c5 o
- /* This procedure Reads the manufacturer's ID (BFh), memory type (25h) */
6 E7 V: `& Z3 v! N# g/ z - /* and device ID (8Eh). It will use 9Fh as the JEDEC ID command. */
( X/ E) w$ p$ o' f; T: j- { - /* Please see the product datasheet for details. */
$ q* G* e2 ]. H' j- [& Z0 A) b - /* */
0 U S9 O1 U6 o: D# | x) \& Q# v - /* Input: */1 I7 ~( {! l3 i Y. z" [
- /* None */
5 e* l; g3 i" a! ~6 I/ J - /* */( x( |$ w p! K$ I
- /* Returns: */3 i/ U4 \# ^. v4 \) ^+ F
- /* IDs_Read:ID1(Manufacture's ID = BFh, Memory Type (25h), */
/ }2 @: x/ Z6 _+ w3 X - /* and Device ID (8Eh) */1 y9 f, G% I N9 O' P/ G+ T0 N
- /* */
0 i$ O: E; R% L* W5 C+ I- p4 J9 ~7 H - /************************************************************************/0 u# K8 w) z8 t$ E' E
- unsigned long Jedec_ID_Read()
7 Y7 f/ s$ }& B F" j/ k - {
n$ W/ b" @3 m0 G- L - unsigned long temp;
0 k3 x, S$ \6 F# G2 M - # m8 m) r) E) i! u; n$ Z0 K' G
- temp = 0;
" T/ u: W2 S$ v! R5 f0 O
2 F! J8 s. k6 } n/ S# ]. k- Y- CE_Low(); /* enable device */
1 |& r3 L y: N7 i. o - Send_Byte(0x9F); /* send JEDEC ID command (9Fh) */
* w8 f3 I# M l4 R3 u - temp = (temp | Get_Byte()) << 8; /* receive byte */
/ T! x$ M: O! ?* g - temp = (temp | Get_Byte()) << 8; ) @1 \, T7 W/ Z
- temp = (temp | Get_Byte()); /* temp value = 0xBF258E */. l- w7 k9 g: P: q1 } R2 A
- CE_High(); /* disable device */" m1 H: U% l8 p7 J; @
2 Q o3 b6 ]- h( F4 x- return temp;3 v# }/ J% v6 {% H* D8 V9 C
- } O/ k8 @; F( D' T3 Q \" a v: P+ t5 J
- c: H( t$ Y E. F! s6 w
- /************************************************************************/5 h; x0 Q& P5 \0 k/ g, Z4 d
- /* PROCEDURE: Read */
) }. k$ _- o6 P( l1 V3 ?8 w. ` - /* */ 4 ?1 |% A( R: R$ X% o) ~6 ?
- /* This procedure reads one address of the device. It will return the */$ y, w3 f* X' ~0 h, o% z
- /* byte read in variable byte. */
8 S- q5 X+ v# y+ a - /* */
% q9 i, |( {. i' ^+ X8 r - /* */
/ a6 `7 }/ x& R+ T$ k; a - /* */
' k1 P! a" C" l2 b: _ - /* Input: */
4 ^! J4 D( L; B$ n3 r4 D - /* Dst: Destination Address 000000H - 0FFFFFH */
* s' e3 l" O" K) ? w) Y9 O E% O - /* */1 o# B! e7 \! n5 r+ Q# a
- /* */
5 G0 z6 w: x k9 h5 W - /* Returns: */5 f, X/ k- `! }- T/ u) l& Z5 V
- /* byte */8 J2 K$ t& {" M: K5 o+ d: i2 q
- /* */
! a8 [/ U! @! O$ ]1 V - /************************************************************************/6 L8 `* I/ q6 V
- unsigned char Read(unsigned long Dst) 3 K% [" ~# k2 F+ B4 U; G
- {
; d, E& d- I' g4 B - unsigned char byte = 0;
3 B9 M& q7 d' A. H; V0 ~. U/ M- V - / }! J, A! H" i: {
- CE_Low(); /* enable device */
8 D2 U: ], O0 d! J6 X& f% T! @ - Send_Byte(0x03); /* read command */
+ |# q7 _; T: R; d; V+ E1 z% s - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
0 _' g$ U8 I- `- N# ]. X - Send_Byte(((Dst & 0xFFFF) >> 8));: Z o$ G# J) I ?$ [. D+ N
- Send_Byte(Dst & 0xFF);. b. i3 E3 F; N
- byte = Get_Byte();6 H; \ T* O9 N3 O5 \
- CE_High(); /* disable device */
! o9 `$ P- B3 @. ?; b7 H - return byte; /* return one byte read */
4 S. Y J( R1 [: |! u - }
' O! G) c- @+ _/ f - : t% c: w( G3 g. a( k
- /************************************************************************/
, L* w- I- x) ] - /* PROCEDURE: Read_Cont */
Z$ V$ G0 _* N/ i4 C - /* */
5 s" E/ F) D+ e1 I) ~6 ] - /* This procedure reads multiple addresses of the device and stores */8 C- N7 V5 X3 |/ t; C5 o
- /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
6 p9 b) p5 u/ z* y a - /* */' k8 t# y% N. I( g* Y# I+ W U
- /* Input: */
[4 F9 Y! n2 Q$ v2 ] - /* Dst: Destination Address 000000H - 0FFFFFH *// t( |: N z$ o
- /* no_bytes Number of bytes to read (max = 128) */
, B$ d6 E; ?" m - /* */
# W$ V0 q+ }( H& H2 J& p$ r: E2 G+ H% W - /* Returns: */6 w2 M( s* q9 Z) R
- /* Nothing */# N+ c }( d/ V$ K- n
- /* */
2 U5 m; b1 G( u& e+ o) F+ o3 _ - /************************************************************************/6 V K. ^$ t! f
- void Read_Cont(unsigned long Dst, unsigned long no_bytes)
" S; |3 }- K4 u7 t - {! F2 h- }0 x( v6 H# e; c
- unsigned long i = 0;4 P7 ~5 Y/ b- O/ V! f
- CE_Low(); /* enable device */7 G0 j' P5 \" R* Z) G3 ^
- Send_Byte(0x03); /* read command *// v# b1 H5 _" ~$ H0 K- {# V: e0 p
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */6 f" D# ?; A$ m; ^
- Send_Byte(((Dst & 0xFFFF) >> 8));
) G8 Y* b( f2 ^. @/ A+ J ~) J8 j - Send_Byte(Dst & 0xFF);2 E( k6 ?4 \' n3 r
- for (i = 0; i < no_bytes; i++) /* read until no_bytes is reached */
0 z9 X% T0 I& k( ]3 e9 r1 c. F5 j - {5 T+ q) ^+ @# e. v1 ?/ {
- upper_128[i] = Get_Byte(); /* receive byte and store at address 80H - FFH */
. }& g: i8 [* t" G7 K F6 U - }. P* B5 v" Q1 s t8 S4 L/ H
- CE_High(); /* disable device */
% [ z# S, W l5 D( [+ c - - u2 I1 v8 y1 r
- }
8 x1 A a; r8 k2 M4 `# \ - ) g( _; [3 z u* o% m0 o
- /************************************************************************/
% \- y$ @/ f# y: I7 f* u - /* PROCEDURE: HighSpeed_Read */3 w$ B7 d) s2 D5 J
- /* */ - S8 g( m0 {. ~" ~3 k
- /* This procedure reads one address of the device. It will return the */4 P" ^" {! x7 {/ G! B5 y
- /* byte read in variable byte. */
4 j+ b. a: k9 n/ c" v* d- s - /* */
& o+ i9 e: J3 t; j! \ - /* */% X# v$ o( e& p
- /* */
3 B, p3 |7 v# n: K7 P - /* Input: */$ v6 o, D- x* [" C k
- /* Dst: Destination Address 000000H - 0FFFFFH */
" ]- U6 B% {* i" B. M) n - /* */% R5 z! r, e$ S5 Q' y# {. I8 ]! b
- /* */$ |0 V* u) X' Y1 N& U( v- b, g
- /* Returns: */
8 Q1 L# V! B0 H v* [ n! c- y - /* byte */
* M$ O6 c: \" J7 w. V/ c, L. l - /* */
# w$ |8 X6 R9 Y0 y - /************************************************************************/
9 _+ F1 O0 }& V4 ^" r# G9 h - unsigned char HighSpeed_Read(unsigned long Dst)
. G% D; g& \6 P$ o% ~2 y# d5 k - {$ P! l& V! I8 Y/ p* B5 V
- unsigned char byte = 0; - I3 j, c/ B. {( s' z+ }, R2 n0 [
- 7 x* n) I# x& K2 C) v" H! ^
- CE_Low(); /* enable device */+ q, H/ [5 \- j( \9 _2 P
- Send_Byte(0x0B); /* read command */
4 e# c' C0 g4 g& T% _ - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
5 O1 J; T% A/ i+ E, K" S - Send_Byte(((Dst & 0xFFFF) >> 8));1 k Z! @6 u0 H J
- Send_Byte(Dst & 0xFF);
* K* |4 x) _. V9 W' k0 ~0 Z - Send_Byte(0xFF); /*dummy byte*/* m3 u2 @1 n) r n( K/ B
- byte = Get_Byte();3 w _9 X* j) x: U. i7 b" e9 w) v
- CE_High(); /* disable device */3 T" G9 r) @! o4 q
- return byte; /* return one byte read */
- r4 o3 \9 m, H - }9 n7 Y9 C) N2 x2 O/ _2 T, |
- : w; |3 y. z8 V/ M, d
- /************************************************************************// b' }4 Y. o! \0 O9 z& }
- /* PROCEDURE: HighSpeed_Read_Cont */
7 U6 _6 T/ Z1 y% n% O2 l1 C- F - /* */ " t4 n8 f0 s7 K; v' s! Q9 x0 p
- /* This procedure reads multiple addresses of the device and stores */, A/ j4 @1 ?7 U; O( M
- /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
% i6 Y6 L+ W" _ - /* */) q, L# r: p3 e$ G& K5 N# O3 G6 j8 v- B( V
- /* Input: */
, v' F- Y |) |! ^- ^0 V - /* Dst: Destination Address 000000H - 0FFFFFH */
4 n" }- `4 [6 n* J+ w - /* no_bytes Number of bytes to read (max = 128) */
4 f, ^0 L- ]3 H+ Q9 k/ x3 l - /* */7 }5 R- A- c0 l
- /* Returns: */
1 G& p0 l# _2 D3 u( L+ W - /* Nothing */
" H6 F5 M( E+ B" g, ?4 G9 C1 i - /* */! j5 w: {8 j% {+ M; f
- /************************************************************************/
8 W+ r' e% ^6 i& e- T - void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes)
4 a5 F3 V# X- V: i1 L3 v0 Q5 [ - {
5 |, N3 } ~: ]1 s% U+ x( ?* M1 ? - unsigned long i = 0;0 P% k* o% `) K. ?2 `
- CE_Low(); /* enable device */
f. V4 O( c6 @+ t0 r& O8 F( Y+ m - Send_Byte(0x0B); /* read command */4 U& j8 q1 _- l& \4 e4 Q6 O# s r
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */! O6 ^. S- `1 v9 Z- _9 s3 e
- Send_Byte(((Dst & 0xFFFF) >> 8));
8 B5 m3 v0 n( N& u' {' f/ k1 P - Send_Byte(Dst & 0xFF);
% t+ s* l4 D5 g9 V: R - Send_Byte(0xFF); /*dummy byte*/1 Z' I3 k8 r/ q7 S @6 _
- for (i = 0; i < no_bytes; i++) /* read until no_bytes is reached */% v! g4 }* ^' \7 ^0 A
- {) w1 T5 w' ]& q2 W% e$ @+ G1 b
- upper_128[i] = Get_Byte(); /* receive byte and store at address 80H - FFH */
. Z5 O+ t9 V) p1 ~3 N/ x7 | - }. n* [ n0 n6 Q% z8 l# z
- CE_High(); /* disable device */
# s" B( C/ M! P1 a/ E' y# L( K - }
8 E# ?. _% T) f' @1 W
+ C% w9 [. N7 o+ Q' Y) b& ^- /************************************************************************/' R* U6 `/ }! u: H) |0 c
- /* PROCEDURE: Byte_Program */3 d! w% i: z9 }1 m9 Q0 w: q6 b
- /* */
2 I/ w0 k/ h; h5 s; Q% c - /* This procedure programs one address of the device. */
4 ?' M) P) _5 s2 ^+ z - /* Assumption: Address being programmed is already erased and is NOT */6 ?* d! K0 h3 K6 f+ P1 I1 O
- /* block protected. */+ P# o( c" _- w' K+ H
- /* */# S! r1 b# ^( k+ Z
- /* */; g F* E# l. T
- /* */1 V: ?! q) o/ n8 ~$ E# s" Q; I7 u' f
- /* Input: */+ a/ s1 P+ [% r1 m8 e M5 A7 }
- /* Dst: Destination Address 000000H - 0FFFFFH */
: D( n* s7 F: k) D2 K- v - /* byte: byte to be programmed */
! V3 A* y! G" ?7 W2 U - /* */
: A6 B# a& M* F" i# J( a5 t - /* */
7 @7 k6 S* c; q( R4 g7 a3 i - /* Returns: */
. I' f) b. w5 z: @6 o - /* Nothing */. w" N( _+ J+ Y* ?
- /* */) T" C$ d0 M$ q" ?* _4 P( z
- /************************************************************************/
8 h+ c0 F; m1 b) |+ m - void Byte_Program(unsigned long Dst, unsigned char byte)
; e& Z, L9 H& d3 l$ S0 ?- N - {/ N* L( _* |4 Z
- CE_Low(); /* enable device */2 d( K; \( e# Y, u* @6 s
- Send_Byte(0x02); /* send Byte Program command */8 g* U* ~2 Y2 c+ S
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
* @* M5 S9 v% O# @- I - Send_Byte(((Dst & 0xFFFF) >> 8));* t0 _% f! l& R; U6 ]
- Send_Byte(Dst & 0xFF);
0 M# t/ l( H" y; ^4 |# V - Send_Byte(byte); /* send byte to be programmed */3 G# q; b7 U" r1 w7 U
- CE_High(); /* disable device */
* z$ n' r0 c g; t9 [' B. c) z! d) @ - }
* d5 Q1 x- s. I" [8 N6 q# g! n+ K, S$ g - ' M) m+ D0 Z" n- r1 Z
- /************************************************************************/" |! A( p8 y0 S* N
- /* PROCEDURE: Auto_Add_IncA */' S; C, J) d! D& @" c6 I
- /* */% [5 u! u0 R) h1 ]
- /* This procedure programs consecutive addresses of 2 bytes of data into*/
3 J/ m( i0 K5 {! b6 n - /* the device: 1st data byte will be programmed into the initial */
! X% c" X6 u) T9 D. J - /* address [A23-A1] and with A0 = 0. The 2nd data byte will be be */; ]' v* E# c- `$ `/ i% U( U
- /* programmed into initial address [A23-A1] and with A0 = 1. This */
$ @7 y4 V9 H; g - /* is used to to start the AAI process. It should be followed by */) z$ l K/ e9 v
- /* Auto_Add_IncB. */
, y5 m( |! Q7 n4 G d. e( y - /* Assumption: Address being programmed is already erased and is NOT */+ c0 [& k' X" t& b4 L0 V$ v" |
- /* block protected. */
% i2 K& \0 I/ a* g+ O" p - /* */
; o" {8 ]* G# @4 T5 B0 k - /* */
( X/ K( e/ t/ {- }2 W- y - /* Note: Only RDSR command can be executed once in AAI mode with SO */$ V$ a- ^0 }5 Z4 D5 K# _
- /* disable to output RY/BY# status. Use WRDI to exit AAI mode */
0 t* r* [) C( p$ a, @1 f# { - /* unless AAI is programming the last address or last address of */
* r9 s0 N; o% _ {, @2 x - /* unprotected block, which automatically exits AAI mode. */
L0 z6 @- n c s - /* */
$ k6 {( r0 g+ X9 Y9 ~) Q% y. E/ @+ A - /* Input: */3 S! l( m; R% `/ u
- /* Dst: Destination Address 000000H - 0FFFFFH */* ^% J$ w, R+ C% r$ e; Z. T7 F
- /* byte1: 1st byte to be programmed */0 F( ~ X) W* |* W* ~& k
- /* byte1: 2nd byte to be programmed */
) p# h7 s5 ]9 ?, ]8 v& k' v5 ^ - /* */ t4 W c9 V7 \
- /* Returns: */
0 l Z; r. S8 G- D A; k - /* Nothing */% l' u" \- `+ U0 ^# d9 V
- /* */9 R5 H! S, u( r+ H( _
- /************************************************************************/
6 u; d/ t6 b7 p. g - void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2)
+ W( Q: n' R$ G% _# l; r V - {
$ }$ V7 a# B6 d6 ?( W - CE_Low(); /* enable device */
" v' {" T* G0 b5 r0 X: J* L - Send_Byte(0xAD); /* send AAI command */7 V9 \8 I+ ~ \/ N
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */5 A4 e4 `3 }, A; M
- Send_Byte(((Dst & 0xFFFF) >> 8));
9 C! O* k+ R& ~& b* y( j B% H - Send_Byte(Dst & 0xFF);7 V& i8 b: P* K1 ?/ [4 g
- Send_Byte(byte1); /* send 1st byte to be programmed */
3 y% L$ |* Z6 b7 l4 e: w7 Y - Send_Byte(byte2); /* send 2nd byte to be programmed */
, f5 ^/ o5 y4 h6 p3 V$ w6 w - CE_High(); /* disable device */
, u& `# s; W4 u - }) D. [: Z& d2 m; j4 s, m
- T9 `& B/ C7 o, l3 J- /************************************************************************/
% p+ ^9 b) }( S7 H% F - /* PROCEDURE: Auto_Add_IncB */
& ?9 G+ k$ _7 K - /* */
! D, b- I" I% q- r8 a0 y# W; A - /* This procedure programs consecutive addresses of 2 bytes of data into*/
( x$ x& V; y m( u; x# y J# U' u0 F0 ] - /* the device: 1st data byte will be programmed into the initial */( q4 h, E" m9 S7 L; l
- /* address [A23-A1] and with A0 = 0. The 2nd data byte will be be */8 H. D* o' u1 O
- /* programmed into initial address [A23-A1] and with A0 = 1. This */
1 E8 i& F! W, h0 p* T W - /* is used after Auto_Address_IncA. */! R# v" \3 P1 `1 n2 A& W- w
- /* Assumption: Address being programmed is already erased and is NOT */
# N8 ]# V' ^6 a. [6 l! K - /* block protected. */% U. u1 \' t, k3 r
- /* */( J# q2 {% B k" ?, n
- /* Note: Only WRDI and AAI command can be executed once in AAI mode */) P: }9 @! ]% r1 D# Z4 R0 c
- /* with SO enabled as RY/BY# status. When the device is busy */1 T- Z9 v( N5 w: }
- /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */
! ~; P& o: B) p2 P. V - /* to exit AAI mode unless AAI is programming the last address or */! X2 Z. J+ g* A! ~# G; v
- /* last address of unprotected block, which automatically exits */: j) Y2 M; V, y3 H
- /* AAI mode. */5 P# ]* b* ^" s$ n9 H
- /* */, {. i" @4 j2 k! H3 A
- /* Input: */1 P9 S2 {. S' J/ O0 m. H
- /* */) u0 D/ l; `' Y7 e7 T% k, s
- /* byte1: 1st byte to be programmed */
6 @7 C' ?/ q$ j8 p9 m - /* byte2: 2nd byte to be programmed */) c$ f1 |' y+ s9 K& V8 q
- /* */
: F- G) N( e& Y/ o h) _% N - /* */+ P5 y- G# B3 w9 v8 y5 m
- /* Returns: */
$ X- s$ C9 t. @0 U7 k/ T L8 a - /* Nothing */. L6 R: q: U% J1 y0 z
- /* */0 j* P2 E7 I$ W: w# r, @- `
- /************************************************************************/1 J6 l9 p ?" f+ X+ \; ]2 h
- void Auto_Add_IncB(unsigned char byte1, unsigned char byte2)$ m5 Y* ^; h: f* Z. j& o8 k
- {
% C" D2 X( m2 D - CE_Low(); /* enable device */" p' V$ D' U6 C9 H" {; E1 I O1 Z3 I
- Send_Byte(0xAD); /* send AAI command */
: d; g9 B, ]# [" K% _ - Send_Byte(byte1); /* send 1st byte to be programmed */% j- S0 \; \. U! }6 s6 F6 |- z
- Send_Byte(byte2); /* send 2nd byte to be programmed */
. G2 N. [+ e* {1 b* G* H) q% | - CE_High(); /* disable device */$ F) Q$ X) h# Y0 h
- }, o$ N# i' ]- ^- X0 Z2 u. j) E6 y1 ~. o
* ~3 G6 i( l9 k3 u0 |# F( S- h5 z5 D- /************************************************************************/
; J7 Z* U' L7 I0 D; B0 X, [ - /* PROCEDURE: Auto_Add_IncA_EBSY */
8 P0 @) w+ B) N) ^. [5 N5 V - /* */+ g$ c) k( M, ~* p% B5 J
- /* This procedure is the same as procedure Auto_Add_IncA except that it */
$ g; W a# p% _2 h4 l0 J, ~ - /* uses EBSY and Poll_SO functions to check for RY/BY. It programs */) F- A' c7 K; |& v3 g* B) W: O
- /* consecutive addresses of the device. The 1st data byte will be */" b' E* ]2 s" [: B8 Q
- /* programmed into the initial address [A23-A1] and with A0 = 0. The */
' ]/ ~5 A$ \. h3 F& i, V - /* 2nd data byte will be programmed into initial address [A23-A1] and */
) ]) U* E* V7 _ - /* with A0 = 1. This is used to to start the AAI process. It should */! k5 [2 C2 @8 w4 Q/ m
- /* be followed by Auto_Add_IncB_EBSY. */2 J9 l) Z0 t3 W2 J' X
- /* Assumption: Address being programmed is already erased and is NOT */
0 m1 J) B/ I- B D* L$ G - /* block protected. */
" H7 z# f8 T4 a% U - /* */, \2 l6 E: w' _: W9 x: V
- /* */2 `! u/ e7 ]9 x$ W' d
- /* Note: Only WRDI and AAI command can be executed once in AAI mode */
' z: e% c1 U& `8 c - /* with SO enabled as RY/BY# status. When the device is busy */
* G% o$ S0 i2 r5 \3 I - /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */- L$ [( y8 e& {* G8 Z# _
- /* to exit AAI mode unless AAI is programming the last address or */
7 p# P- G. d* q/ o7 c: P% d3 L+ _ - /* last address of unprotected block, which automatically exits */
$ U4 Q2 g* m) k1 d2 _2 \+ x - /* AAI mode. */
" ]4 Q$ ]. |, a4 c - /* */
2 D" _/ P( V) f( X" [0 F - /* Input: */( p( B7 ?% x' i7 `- B! i* ?8 y) w2 R
- /* Dst: Destination Address 000000H - 0FFFFFH */: `5 E3 ^3 X( I8 W$ ~
- /* byte1: 1st byte to be programmed */
/ c' V% V5 b( Z$ i) b8 U - /* byte1: 2nd byte to be programmed */+ m' j1 X4 `8 z, S+ y5 {
- /* */. p) s" L7 ?7 @4 c$ m$ w% I
- /* Returns: */2 a- r% K5 d, i0 d( m, K x! }' k: J4 Z
- /* Nothing *// _) D! u! \5 Y( R7 D w6 e
- /* */
* g$ Y& n7 x1 S; i0 B( J; H - /************************************************************************/0 j/ ~& k/ A! [2 P4 C
- void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)2 k) J6 i8 |, a% M
- {
6 y) V( s) N; l - EBSY(); /* enable RY/BY# status for SO in AAI */ / S+ J n1 u/ k9 W* H" M4 {/ p2 q
/ W( s+ _+ K# V0 n# f# Q- CE_Low(); /* enable device */6 ]; ? g* [" k; C7 \7 M9 F
- Send_Byte(0xAD); /* send AAI command */' l! ^- L% D, H* H4 F
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */# s- x5 i9 L K. ?4 T
- Send_Byte(((Dst & 0xFFFF) >> 8));
& [; ^, W) \$ K - Send_Byte(Dst & 0xFF);* E! P' K; j! i) h1 x
- Send_Byte(byte1); /* send 1st byte to be programmed */ 8 \4 u! c7 L$ M7 Y6 e) u" H
- Send_Byte(byte2); /* send 2nd byte to be programmed */
! ~9 g. I5 b: n. U: d - CE_High(); /* disable device */3 h9 [3 m8 c4 [: s% A8 ~2 Y
-
3 b q" D$ \5 ?. F' Q4 u - Poll_SO(); /* polls RY/BY# using SO line */
& Q( j4 S3 V* V r$ Y9 d
1 m3 A# M; Y" n' V- }2 `& L: ^3 h/ i' Q. s) _
! s5 X" T# a# w- /************************************************************************/
9 W+ J8 D& [% ~- A% e. i o - /* PROCEDURE: Auto_Add_IncB_EBSY */( Y$ i7 _/ y ~9 X. L9 D
- /* */! p2 J* S9 e+ T) ^0 [
- /* This procedure is the same as Auto_Add_IncB except that it uses */
' ?, h) q! A/ _, C. a7 r - /* Poll_SO to poll for RY/BY#. It demonstrate on how to use DBSY after */! Y6 |9 F5 b* P2 H. H Z
- /* AAI programmming is completed. It programs consecutive addresses of */
; y/ J, \& ?8 Y) H - /* the device. The 1st data byte will be programmed into the initial */, f( X) X# c# z: c
- /* address [A23-A1] and with A0 = 0. The 2nd data byte will be */
. Q, [6 U+ _8 k0 P0 \) T$ W9 K - /* programmed into initial address [A23-A1] and with A0 = 1. This is */
* B" U9 ~+ S; _; j/ v - /* used after Auto_Address_IncA. */0 P X3 U' H; k5 f
- /* Assumption: Address being programmed is already erased and is NOT */
5 u* i- \' M/ j) V( X( m) ~ - /* block protected. */) [# J" b1 B8 d+ a) i2 f+ {/ R, Q
- /* */
$ _9 u# Q# q& t3 Y - /* Note: Only WRDI and AAI command can be executed once in AAI mode */
# C, P3 J5 D2 [0 o, w! u2 C9 c, `7 a - /* with SO enabled as RY/BY# status. When the device is busy, */ \, ?6 v; Z# \7 r( D, @) l1 t: {
- /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */
3 T5 ]: f# {% u" K - /* to exit AAI mode unless AAI is programming the last address or */
: _" |; V* J! w2 ?) p t - /* last address of unprotected block, which automatically exits */* B) j+ T! L( L6 {; \% [
- /* AAI mode. */) s# y3 n: V7 L# P: Z
- /* */
, L+ ]. d8 {/ T: m, T- x/ X$ @6 p - /* Input: */: m! N2 O* P/ }# v2 k
- /* */$ z+ `( O: r$ [0 _' G$ |5 @' C5 _
- /* byte1: 1st byte to be programmed */3 O% B/ O4 d/ m. M" E
- /* byte2: 2nd byte to be programmed */
0 r& K' V% M7 ]6 L; y, q- L - /* */& Z" U5 y0 G$ p6 A3 ] ?
- /* */6 M2 l9 L/ B; D9 O& N; G/ o& x5 G# q# c
- /* Returns: */1 b4 i% `" Y5 a- I
- /* Nothing */
: I4 f0 k% ^5 W% W$ I5 o H& X B - /* */
% J8 E% Z4 z k+ s. H2 L - /************************************************************************/
5 O; ^, y4 R8 P - void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)+ R8 l8 j5 d( o
- {
; R) x( A0 Q H5 n- K - CE_Low(); /* enable device */# V9 a/ E# y. w" P" p, j9 v, ]
- Send_Byte(0xAD); /* send AAI command */, l. s# i3 S/ `( A J
- Send_Byte(byte1); /* send 1st byte to be programmed */
/ U1 n* d0 m+ ~1 O8 i" m* a4 z - Send_Byte(byte2); /* send 2nd byte to be programmed */" y" v0 B/ o4 A& I/ s
- CE_High(); /* disable device */" C" a0 U$ H( ~( t9 j9 F p
' Y; N+ t+ b, c5 w- Poll_SO(); /* polls RY/BY# using SO line */3 x& N5 k& K- y" f) `6 i
- . L3 ]4 \; i3 [
- WRDI(); /* Exit AAI before executing DBSY */
7 v" m6 Z* n( }" V5 x9 C* C2 Y4 ^ - DBSY(); /* disable SO as RY/BY# output if in AAI */# n/ V7 `0 j+ i- ?
- }
& @! ?3 k& c" X6 \5 S) i- A; P, L - / z) p& K( Y4 }
- /************************************************************************/
' E! X: W+ Y* E9 ^4 A! r. `" t - /* PROCEDURE: Chip_Erase */
6 l& w' g1 S N* |2 C - /* */% H/ `( S' M# }8 z' ]6 y4 t
- /* This procedure erases the entire Chip. */ D$ u' Z g2 J6 _, b1 N
- /* */1 I T0 }& D# ?- L* d
- /* Input: */
- f6 _, c( n ?! |" | - /* None */
k" v- t4 m, s7 S% m$ p1 J - /* */
- C u- E& q3 c: R4 `% m* w - /* Returns: */
: `2 G4 o. n0 i - /* Nothing */" k6 p8 `* }- h; h, i! i( @+ g4 V% N
- /************************************************************************/6 x0 t' D2 @* U! a6 }! H8 ]
- void Chip_Erase()" M+ n7 P( m3 G2 B- M' a& U
- { # B9 y8 X }7 L- E$ X, s9 p( d" O
- CE_Low(); /* enable device */: n) h& P+ F- `$ w- S: _) l0 X4 a
- Send_Byte(0x60); /* send Chip Erase command (60h or C7h) */
6 }4 l! H$ Y% p+ p: N - CE_High(); /* disable device */
+ r+ [* v) }! [( p0 b% R2 A - }
' E0 {+ Z$ g7 J5 D& n! M6 b/ V
2 f* c3 S7 X1 V8 J- /************************************************************************/& |, b: p! ^5 j. n. W% N1 d
- /* PROCEDURE: Sector_Erase */3 y/ i: i2 w7 O+ E
- /* */" v3 \7 {3 ~' D5 l. O7 a
- /* This procedure Sector Erases the Chip. */9 B& `/ ~7 }/ A) J- g
- /* */0 J; t% p! F2 o; P2 I
- /* Input: */
& M8 ?4 {! _* Q - /* Dst: Destination Address 000000H - 0FFFFFH */* k7 A9 e+ F) Y, m
- /* */5 v ?! s! B# Y6 I" [' V S" A1 J
- /* Returns: */1 I2 C3 G; {+ x1 @4 D0 k
- /* Nothing */
' u& h. I; [" u/ o - /************************************************************************/* C6 {9 D5 R \) w. q
- void Sector_Erase(unsigned long Dst)7 k7 z- |; {- u* a$ l: j
- {4 a* C/ W( o/ B6 J/ D
* ^& N, Q. j) b+ o* s- . G$ ^ U( d2 K! E5 q% c
- CE_Low(); /* enable device */- `# g" A! R: V/ q' k5 q
- Send_Byte(0x20); /* send Sector Erase command */& [4 p4 `; R+ H: ~5 ]# P
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
6 k/ p& I2 J1 \0 J& k) E - Send_Byte(((Dst & 0xFFFF) >> 8));
% x2 _3 D$ r7 m2 B. L - Send_Byte(Dst & 0xFF);
; b# @! E# b6 j! l - CE_High(); /* disable device */
, g/ |6 R5 G! ~7 y4 ~ B5 d# M# t - }
' I: L3 T: S3 m! w/ Q - , m" q8 [& y' n. J4 l( v1 }
- /************************************************************************/
1 h, k, s" ^: S# h+ j, \ - /* PROCEDURE: Block_Erase_32K *// T: ]; U! e4 v1 M3 K& k( H9 f; n u$ t
- /* */
6 Z) k/ M4 b/ \0 U3 Q& X' `# _# p, L/ P - /* This procedure Block Erases 32 KByte of the Chip. */# D( q# {# {) {4 n1 I5 ]! e A
- /* */
$ W% n; z% y8 i) P1 V: r+ R - /* Input: */. ?# Y1 i$ ^+ f' S( d+ k
- /* Dst: Destination Address 000000H - 0FFFFFH */
4 {/ U% v4 `- Q3 K - /* */
( t1 y7 m6 c x) j) s: d" m0 ^+ d - /* Returns: */
' q5 K- N$ o* w0 u) e: s" } - /* Nothing */
7 u5 Y( l* L" o5 @1 N - /************************************************************************// c2 b# M6 s D7 e) X6 z4 a) D
- void Block_Erase_32K(unsigned long Dst)2 J& I, ]1 P9 j- t i" |. k
- {
, n+ b# r6 }; ?* Q - CE_Low(); /* enable device */
& }+ l" H0 R+ O7 q: A - Send_Byte(0x52); /* send 32 KByte Block Erase command */6 D0 x) ?: b) b7 P
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
`8 h' r; W0 W) D* M* I" { - Send_Byte(((Dst & 0xFFFF) >> 8));
& _/ d/ a9 B0 N. l% v2 I - Send_Byte(Dst & 0xFF);' n7 p" m3 K& B* t
- CE_High(); /* disable device */
2 }4 ]5 K4 Z& a2 U0 H; A - }
+ E+ X& ^# w! W* d) a - 8 @5 V) ~; V/ v4 I6 `
- /************************************************************************/
" h( I# [5 l G9 f3 N - /* PROCEDURE: Block_Erase_64K */0 t3 O* T& H t- W
- /* */) X2 B" Z; k, J0 a: A
- /* This procedure Block Erases 64 KByte of the Chip. */
' Y" d: R& I l6 F# y - /* */
7 y$ s1 D+ r- m6 t - /* Input: */7 E0 D8 J: E% G! k/ m' a
- /* Dst: Destination Address 000000H - 0FFFFFH */- t7 p4 g' S4 ]8 |6 h8 x
- /* */* B: ^' ^ i! }
- /* Returns: */6 n6 L8 |. S3 u3 T$ a
- /* Nothing */
/ g9 s, m- K: p - /************************************************************************/) q1 o: R" ~1 S" \6 c
- void Block_Erase_64K(unsigned long Dst)& m+ X& k( G3 \/ [( b0 J0 ]' F
- {
1 K- A! o5 Q9 H" ]% Z - CE_Low(); /* enable device */0 q: o7 r1 g; o
- Send_Byte(0xD8); /* send 64KByte Block Erase command */. r$ r" d2 d4 e
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */2 Z- h( e1 p! m3 r$ C
- Send_Byte(((Dst & 0xFFFF) >> 8));
5 O. o% N7 g- s+ Z9 h% O( R: `! q - Send_Byte(Dst & 0xFF);
8 u' o3 \3 m# B% p1 t, D; N6 b - CE_High(); /* disable device */2 ?5 Y5 b6 `) y
- }
# w! C) a5 t8 K- v - 3 I$ C# \6 H* h) Z* L( E
- /************************************************************************/
. M; `# x% I! C - /* PROCEDURE: Wait_Busy */: ~7 Z) Y7 _; W5 }5 E8 F
- /* */. S- U. m. J% @
- /* This procedure waits until device is no longer busy (can be used by */: a# I1 m/ `8 S t, L
- /* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase). */
! I# b, M, L* M, ^' X: x - /* */- k! Y1 h1 w% v& \% ?" h* |
- /* Input: */
. J7 n; c# ? v: i( ]4 ^ - /* None */
/ H+ \9 U1 U! Q# T3 E# z5 F - /* */3 C' R- T6 g! h& W. g) l; ?
- /* Returns: */0 _* P; a( d9 D# B. t) w
- /* Nothing */- v' G2 q. q5 m( N
- /************************************************************************/
! l3 n: G4 e/ W, P& m& a0 x - void Wait_Busy()
6 R$ e8 Z. D4 U' @6 f0 | - {. S z ^* }0 m- D o6 Q
- while (Read_Status_Register() == 0x03) /* waste time until not busy */
9 {$ N" s* W! h4 C - Read_Status_Register();0 i) I% P( f1 W( P
- }9 P' @1 ? a! T0 ^
- * V$ n0 D a4 a, v6 [# M
- /************************************************************************/6 W$ u, _1 \$ _. \
- /* PROCEDURE: Wait_Busy_AAI */! `, P; w) ?) D; _! j' P
- /* */, p6 Q+ h2 W) b1 s' q
- /* This procedure waits until device is no longer busy for AAI mode. */) A8 _1 S( a8 Y
- /* */+ i. U9 g2 z3 s3 D- ^( F) Q
- /* Input: */
* P, j, r7 a% P7 ^- O - /* None */
3 L6 {9 T# c T" Q' I - /* */, E4 v+ d/ D4 }8 s3 w
- /* Returns: */
6 ~) j& U1 t1 s: n# ?! [ - /* Nothing */8 Y" n! r/ _9 A9 ^3 c9 c
- /************************************************************************/- A7 f9 p7 q' N, X2 U; B2 Z8 y
- void Wait_Busy_AAI()
6 W% o. T# `) g/ k6 I V - {
1 w" M( g" a& P6 z) b; Q+ s - while (Read_Status_Register() == 0x43) /* waste time until not busy */
+ ~- I3 e9 X% ?( g+ Q/ S - Read_Status_Register();/ t W ~6 A8 G# r0 M: ]
- }
! y7 Z* O# B1 C/ A! m3 t: c
/ l! i( r7 ^3 Y" y& f- /************************************************************************/
/ s1 @/ a+ E8 n+ v6 |; [* i - /* PROCEDURE: WREN_Check */
; z) p3 \% U4 A9 ^! d6 z) M - /* */
1 k3 L) l! E) R1 H3 E8 X4 W - /* This procedure checks to see if WEL bit set before program/erase. */
8 q/ r6 S k# J* n - /* */
1 z J- l7 c5 Z7 U* f$ t- R - /* Input: */
, u* o5 Q D: g& k2 L$ { - /* None */! F: c3 s% P, f. i, D: p
- /* */" B0 k4 @9 }9 m+ M6 v: O/ C
- /* Returns: */; z/ K1 G# T4 o' F8 s1 m0 h
- /* Nothing */
+ ~. Z. Q k/ `( m - /************************************************************************/
4 O7 s- r7 l6 m% H* x9 G* r9 E5 f" Z - void WREN_Check()! E+ |8 ?) D" `: c
- {
8 d, c6 C; z" b! y' h - unsigned char byte;
$ d& m" r9 Y3 N. Q+ ^ - byte = Read_Status_Register(); /* read the status register */) r: ^) \0 `* U7 X5 P
- if (byte != 0x02) /* verify that WEL bit is set */$ g$ D) L. E) X
- {
# U' {3 D5 F J, Z- `$ `& U1 U - while(1)
" B2 G8 J. \) e& D - /* add source code or statements for this file */ z9 e3 ?; g( w: }; O
- /* to compile */
. D$ X5 a2 c& k- r# x L+ h$ n - /* i.e. option: insert a display to view error on LED? */
4 N% O/ r0 L P$ N5 p - , P# M0 `8 O$ Y6 `/ ^% s% @
- }% M8 q( H4 S$ e& | {6 L5 e6 {& Y
- }
5 g0 ?' V* D+ B- A6 \
! z) {2 {; v$ q, j: `- /************************************************************************/+ F1 {* t/ u1 s. d! O: [5 D) q
- /* PROCEDURE: WREN_AAI_Check */
) {% Y3 t7 `1 r6 Y/ J' t f - /* */+ m @. J G/ W# j7 ^- ]" |: `
- /* This procedure checks for AAI and WEL bit once in AAI mode. */
7 K r( |9 ~* e; \5 }9 { - /* */
% C% I) i/ m, W C - /* Input: */0 t# n$ [2 l; \' J4 S! C; ]0 [
- /* None */5 }9 E0 X6 ]5 ?! p
- /* */6 Y- U$ G& Q' J% T9 }& v* M
- /* Returns: */5 [6 Y3 i4 F4 ^5 k
- /* Nothing */
7 a, W0 {' E* o. q1 A - /************************************************************************/* N/ O) \' {' ~1 r% b
- void WREN_AAI_Check()% k1 O" N) H. H% I0 _) V" H8 M
- {) N4 _ g# ]* g2 i
- unsigned char byte;: U" z$ q. P& }6 U& r! x, @& C
- byte = Read_Status_Register(); /* read the status register */
$ i) H0 J6 ~& u - if (byte != 0x42) /* verify that AAI and WEL bit is set */% g& i- L! T p$ J
- { l8 p! B5 V7 x' a
- while(1) ! b; o5 D$ u/ Q$ e+ q3 B
- /* add source code or statements for this file */- d7 ?2 q' P& ?" S7 ^* S, c
- /* to compile */3 t0 I: L& a8 r( @" R/ p' H
- /* i.e. option: insert a display to view error on LED? */
+ J1 f$ g- Q4 U4 U# j! L) S - 2 `* ^: j( U; U) k4 D9 G8 }1 \5 j
- }
* a, _0 x: x" K/ C$ I, L! o - }
) J. }$ h- l; s' S3 @
9 n8 ? ~+ R- k- /************************************************************************/( p* j6 K* `/ {% f* b- Q
- /* PROCEDURE: Verify */. r+ e* t% N; T: n
- /* */
5 M. O' x3 `% o4 n9 s- \) |; x& u; g - /* This procedure checks to see if the correct byte has be read. */$ r% `; ^; T7 E+ i) F
- /* */) T9 w' t0 }+ k
- /* Input: */' z; p$ x5 T3 `; Y* ^+ Z8 H
- /* byte: byte read */
6 E( t, g( u! L" o) G - /* cor_byte: correct_byte that should be read */5 ]: a. e1 D n) G) E1 N2 T
- /* */
% o9 V$ ~8 _1 U! J( I$ H - /* Returns: */
+ s1 d: X: J. b - /* Nothing */! B. x) ?" c" D/ h! L+ @' n q
- /************************************************************************/0 L: n k6 B6 d, l2 n- Y
- void Verify(unsigned char byte, unsigned char cor_byte)
0 s$ z+ [3 E. m" I4 A7 b0 w \# R* |* I - {( w# |6 u8 ^8 B$ z8 N9 j
- if (byte != cor_byte) X8 A. c( i2 B& ~; i* T- e
- {
( R2 m# h# Q/ ?. M$ n - while(1)
2 @" q) G( x& c5 J7 w' l1 O - /* add source code or statement for this file */
2 v- S# K: A4 l0 h8 ? - /* to compile */! d, k! a1 k3 N) K. D
- /* i.e. option: insert a display to view error on LED? */
# h. C5 E9 ^' h( ^2 P" V0 ~- E -
' j) c. [2 J' x: v9 U2 m Y - }: Y( D- d3 t, T2 e1 \: Q1 d
- }
" B8 l S- f7 G2 m7 p# i' \ - ) m% o6 c( e: j& b+ U/ ?" N$ ~
4 U) N t2 U2 d: B1 s) r2 U0 \# w! w- int main()
2 i3 S ?/ r* l5 e+ i: @ - {
l( {& |/ {- p# N8 _9 E - % z- e3 L6 D' E) X$ e" g8 a
- return 0;
# j1 G! {9 ?" ~" {+ g. c - }
复制代码 |
|