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