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