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