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