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