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