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