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