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