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