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