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