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