找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 55824|回复: 13

[Software Driver]SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory

[复制链接]
发表于 2007-11-13 11:07:18 | 显示全部楼层 |阅读模式
EC挂接8Mbit SST25VF080B的话,可参考和学习,其它的SPI FLASH雷同。
  1. Software Driver/ j3 Q( }/ t5 {- @' D
  2. ! G& O1 t: F* h! W3 i5 }
  3. SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory
    1 m3 x* E9 M' B5 @  C" S2 m9 X
  4. & C! u5 u( h7 P1 [9 V1 F: A
  5. November 4th, 2005, Rev. 1.0+ f) o$ |  j& P6 m- D/ x

  6. ) O5 H) ~* |0 [3 [" }1 Q. l
  7. ABOUT THE SOFTWARE2 P7 c7 H- D$ r6 v
  8. This application note provides software driver examples for SST25VF080B,8 M( L& U+ o( c1 N$ B4 r  O
  9. Serial Flash. Extensive comments are included in each routine to describe
    ( E' ^% }9 Y& E: V/ B
  10. the function of each routine.  The interface coding uses polling method
    $ c3 i# ]: x, b# Q( Q0 |% w4 R; ?
  11. rather than the SPI protocol to interface with these serial devices.  The* i" n& P1 R& a
  12. functions are differentiated below in terms of the communication protocols
    ' D5 j, V; w: `; M
  13. (uses Mode 0) and specific device operation instructions. This code has been 9 }: B6 b$ ]1 A8 u$ s
  14. designed to compile using the Keil compiler.1 j$ j6 ?2 r  O8 M2 J

  15. / x# m4 |/ Q& o/ \( Z; _* @
  16. + Q8 V/ ]' m; d, ?; k2 o; K* ]
  17. ABOUT THE SST25VF080B  p5 r3 W3 C6 F7 R' ?4 d% _2 D" M
  18. ) ?- l% n; v# ^7 M) A& ^
  19. Companion product datasheets for the SST25VF080B should be reviewed in : A) @( A3 I2 T) v3 }8 s
  20. conjunction with this application note for a complete understanding
    & J4 I% T6 |- s" V
  21. of the device.% W2 P  D& j! r9 v8 q9 z# P4 N8 w
  22. 9 ]2 G$ s; K8 Y

  23. / D# s1 z7 Z0 ?: Y8 _. c& A
  24. Device Communication Protocol(pinout related) functions:
    : Y! ?) l! p( M+ f3 w

  25. 5 r# |. q& }: @1 C& S) J" o5 B9 K
  26. Functions                                    Function" b* |' m, d- j' K8 ?
  27. ------------------------------------------------------------------# Q( |; e  |: j
  28. init                                        Initializes clock to set up mode 0.
    " ?! \% `" K9 F1 Z- g5 r7 f
  29. Send_Byte                                Sends one byte using SI pin to send and
    : ^9 A/ @6 U3 e/ A$ `, B0 \
  30.                                                 shift out 1-bit per clock rising edge
    2 R% B" S5 J% G# S, \7 h: F
  31. Get_Byte                                Receives one byte using SO pin to receive and shift
    ( j& s9 M/ J' i( M$ H( }) K0 j4 l
  32.                                                 in 1-bit per clock falling edge2 C( W  ~3 ], L8 |. s1 R
  33. Poll_SO                                        Used in the polling for RY/BY# of SO during AAI programming
    3 Q$ Y7 l9 s' y- z6 N) b0 m. ]3 h
  34. CE_High                                        Sets Chip Enable pin of the serial flash to high
    6 C9 E5 Y% M0 Z9 ?$ f  X
  35. CE_Low                                        Clears Chip Enable of the serial flash to low
    : C5 X6 e! _; x# b. @) F4 |5 `
  36. Hold_Low                                Clears Hold pin to make serial flash hold
    8 k* }, u( @4 K' A: c" x
  37. Unhold                                        Unholds the serial flash: v" v+ l7 F: _( }4 P: {( o5 _6 [
  38. WP_Low                                        Clears WP pin to make serial flash write protected
    % V3 v7 ~# k2 K% _: k$ B& Y
  39. UnWP                                        Disables write protection pin7 n$ E+ B3 P. R- J7 M- Z( v" A
  40. : M: B- Q1 \$ I
  41. Note:  The pin names of the SST25VF080B are used in this application note. The associated test code
    : m3 J! F/ O: O# k2 x
  42. will not compile unless these pinouts (SCK, SI, SO, SO, CE, WP, Hold) are pre-defined on your
    & L% g1 @& n( M' [- f: W
  43. software which should reflect your hardware interfaced.          7 p2 t: D2 L6 D: y3 B9 D) n/ R

  44. ) e5 _- T2 h4 T1 ?4 q% r

  45. 0 o! H4 P# y0 n/ k/ ?
  46. Device Operation Instruction functions:/ u$ y4 a8 L; ^: R( }" M" L

  47. # D4 r6 L+ O3 ]1 ?8 q
  48. Functions                                    Function0 i3 d% A% L4 D
  49. ------------------------------------------------------------------
    % m$ }' {/ x8 p& |5 C& w8 c4 }& I
  50. Read_Status_Register        Reads the status register of the serial flash; A2 A, F5 R; K0 ~9 }6 _& k6 B) e! |
  51. EWSR                                        Enables the Write Status Register4 n/ r" `; X* {2 Z, _" N
  52. WRSR                                        Performs a write to the status register
    + u/ c5 u# u( K2 @6 s- O+ s
  53. WREN                                        Write enables the serial flash
    3 h+ y: `4 a: ?+ U; j# I
  54. WRDI                                        Write disables the serial flash5 o, F! S/ s5 \9 _5 k
  55. EBSY                                        Enable SO to output RY/BY# status during AAI programming
    ( P8 [  g: J5 X/ ?( W5 U
  56. DBSY                                        Disable SO to output RY/BY# status during AAI programming
    . b: B0 m% M+ ?6 V. b
  57. Read_ID                                        Reads the manufacturer ID and device ID
    7 I# L9 [0 M, y$ I) o& @6 W
  58. Jedec_ID_Read                        Reads the Jedec ID
    ! x' C4 c* P8 n& {% h) J. ?
  59. Read                                        Reads one byte from the serial flash and returns byte(max of 25 MHz CLK frequency)
    & D  D6 Z! V( ^$ e. w$ @
  60. Read_Cont                                Reads multiple bytes(max of 25 MHz CLK frequency)
    7 p- a, ]1 x* U
  61. HighSpeed_Read                        Reads one byte from the serial flash and returns byte(max of 50 MHz CLK frequency)
    - a% L9 w% l; w3 S5 v: t  ?
  62. HighSpeed_Read_Cont                Reads multiple bytes(max of 50 MHz CLK frequency)
    % t) h; c% M1 K' c8 k
  63. Byte_Program                        Program one byte to the serial flash
    . c6 U! ~( Y; h' X: Y
  64. Auto_Add_IncA                        Initial Auto Address Increment process# Z, V) A+ d8 i* B$ Y
  65. Auto_Add_IncB                        Successive Auto_Address_Increment process after AAI initiation
    & D$ T5 p, {6 S0 A( K! S
  66. Auto_Add_IncA_EBSY                Initial Auto Address Increment process with EBSY  _# b% Q3 l; x  M! C: i
  67. Auto_Add_IncB_EBSY                Successive Auto_Address_Increment process after AAI initiation with EBSY and WRDI/DBSY
    6 H: S% e) X5 h* _8 X
  68. Chip_Erase                                Erases entire serial flash
    & e& k( G- E! U
  69. Sector_Erase                        Erases one sector (4 KB) of the serial flash5 O& j2 l: P* g9 w* N3 |. k  K8 W
  70. Block_Erase_32K                        Erases 32 KByte block memory of the serial flash) @5 q7 \( O0 @2 |# F& t6 Y% \
  71. Block_Erase_64K                        Erases 64 KByte block memory of the serial flash
    6 T) S, F# z% m
  72. Wait_Busy                                Polls status register until busy bit is low
    1 r) D" ]' P6 o# f. D# U
  73. Wait_Busy_AAI                        Polls status register until busy bit is low for AAI programming( V2 |7 V* |/ p3 G- x
  74. WREN_Check                                Checks to see if WEL is set7 l' S1 R' w4 M8 O
  75. WREN_AAI_Check                        Checks to see if WEL and AAI mode is set" E( _1 R. _- J9 R* s

  76. 7 p- _/ A' w3 W+ y* j% g
  77. 9 n3 Y) n. s2 T
  78. $ _6 g9 w2 g/ |! `: i* c3 h6 m# Z, G$ r
  79.                                                                      2 l& q: `* e5 O7 l' ~" Q1 x
  80. "C" LANGUAGE DRIVERS
    8 |( \* D8 T' k8 O6 ~' J6 R

  81. 5 M; N* ^- Z' x
  82. /********************************************************************/3 u* J9 K1 c) I2 J: {5 k
  83. /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005            */
    ) ~# a2 q9 y3 S) U0 g# o' t' p
  84. /* Example "C" language Driver of SST25VF080B Serial Flash                        */3 U8 c5 c4 e: z; R" m1 x# j
  85. /* Conrado Canio, Silicon Storage Technology, Inc.                  */9 T8 ?/ g. p' b5 J* V8 l% \- {8 |
  86. /*                                                                  */4 n: ^0 V& j0 @8 D* I& |1 A
  87. /* Revision 1.0, November 4th, 2005                                                                          */   
    0 @6 H3 }. R6 B
  88. /*                                                                  */
    + l& U; H9 {% J) T( N" _5 g% }
  89. /*                                                                                                                                        */" W% g  `2 k) A2 A$ x
  90. /********************************************************************/
    2 k, _" l) u" c: a- G& ^, Z

  91. 7 H) D+ m- I- Q
  92. #include <stdio.h>
    " I" _7 }  }% k) O# g
  93. #include <stdlib.h>
    : T5 @2 z. p$ t8 X
  94. $ _7 ^& O, W! o( P6 K
  95. /* Function Prototypes */% j9 H* x4 T1 i9 M( Y& b8 u
  96. % z: }( A$ }- ~: \, ^& [) ~# [) B
  97. void init();
    . J! _, R; ?: Q8 e( B9 i' K0 `5 ^3 d
  98. void Send_Byte(unsigned char out);" E9 |" j! \( a" h0 b' _; I
  99. unsigned char Get_Byte();) S' N0 c2 o* I4 u
  100. void Poll_SO();
    1 H1 h8 j$ Z) ?9 K. S1 M
  101. void CE_High();
    ' p5 _; c+ E2 p# P; L/ O3 g
  102. void CE_Low();4 P! \/ \8 h3 J# d8 L6 r
  103. void Hold_Low();
    % d0 y; Z7 }; b! G, p: {
  104. void Unhold();
    6 L4 H* k  Q4 V  D& h
  105. void WP_Low();4 O: x# A2 x  M( _7 L, X+ R  J5 A( J
  106. void UnWP();
    5 q- @6 E/ W$ ?  j
  107. unsigned char Read_Status_Register();7 q2 Q* x  b) l# f5 d' `
  108. void EWSR();) }: y; J4 b4 U3 `
  109. void WRSR(byte);3 p6 C: g: @0 w* R" V  U8 O
  110. void WREN();
    / ?0 T: _8 ]/ m3 T6 W% v
  111. void WRDI();5 ]) `5 H, E+ w' e8 U/ \
  112. void EBSY();+ h( q: ~% Q: h9 \5 o( b2 r/ \
  113. void DBSY();2 K- T& K+ x( _! X  j8 U4 X" ]5 p3 q
  114. unsigned char Read_ID(ID_addr);
    ; W3 o8 x" A$ U% Q3 t" r
  115. unsigned long Jedec_ID_Read(); - U; |( M  O. B4 x' l
  116. unsigned char Read(unsigned long Dst);
    + ^. x6 d6 o3 g: Y6 e
  117. void Read_Cont(unsigned long Dst, unsigned long no_bytes);
    # M/ ?: A) Q  X% j1 W3 z3 X2 _
  118. unsigned char HighSpeed_Read(unsigned long Dst);
    9 R) [! x2 h( B3 V/ n0 x  I) u
  119. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes);$ Q3 \& V: a+ S  M/ d$ I. Y- r8 g5 f
  120. void Byte_Program(unsigned long Dst, unsigned char byte);
    3 O/ s: X& @( X4 S4 C
  121. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2);
    % Z7 y4 F6 W' l+ [; O
  122. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2);+ E( r( E$ D6 H3 G# H% P. d0 G
  123. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2);! O2 j* U% h/ @8 y7 O+ k+ F- Q
  124. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2);; @" i* |9 \- \* b' i* k+ z
  125. void Chip_Erase();
    % @: ?+ O2 X' Q
  126. void Sector_Erase(unsigned long Dst);' N$ b+ r2 I6 k: J% U2 `% C
  127. void Block_Erase_32K(unsigned long Dst);
    $ P& z2 K7 D) e5 L( }8 b5 u
  128. void Block_Erase_64K(unsigned long Dst);
    - g/ c1 B' b# M% Y" F2 e
  129. void Wait_Busy();1 i0 X$ ^+ {8 o6 t+ I  n
  130. void Wait_Busy_AAI();) T1 F6 a* K' S& \; j: j% H) q
  131. void WREN_Check();# H! R7 k( v  ^
  132. void WREN_AAI_Check();; j* ?$ k$ y5 k$ ?, g

  133. ( ?1 L* O) p1 A- F) ^
  134. void Verify(unsigned char byte, unsigned char cor_byte);
    $ F0 c( V, u, P; X1 E  K' [  H' ]

  135. 7 a" D' [0 T# ^( e: }) z/ t# l
  136. unsigned char idata upper_128[128];                /* global array to store read data */
    ! K2 H, h7 k9 _. H
  137.                                                                                 /* to upper RAM area from 80H - FFH */- l. Q& T0 u$ j
  138. - k+ `$ o# h" R% _2 O
  139. /************************************************************************/
    2 \9 }$ n% ]/ f4 C* H- k' s" ^
  140. /* PROCEDURE: init                                                                                                                */
    - |! `1 [9 k1 G& H  |$ c$ C
  141. /*                                                                                                                                                */; `& P- q1 w& V& T
  142. /* This procedure initializes the SCK to low. Must be called prior to         */
    # J: k, R7 y6 e9 g5 L( V$ P
  143. /* setting up mode 0.                                                                                                        */
    - M  |. q) K8 \* t- w- F8 R
  144. /*                                                                                                                                                */
    ) ]/ b+ j( A& k8 C
  145. /* Input:                                                                                                                                */- A( j  r$ V& z
  146. /*                None                                                                                                                        */
      Y( i- R7 x$ X! u" e, l& T, b9 Z
  147. /*                                                                                                                                                */+ b* ~  Y% i+ J- e1 K2 v
  148. /* Output:                                                                                                                                */- y7 F' i' g4 i& L4 G4 O5 q! E$ F
  149. /*                SCK                                                                                                                                */
    " V) L. I  V7 a7 R7 q
  150. /************************************************************************/
    + }0 A; U. v: s# x3 H
  151. void init()' z; M* b3 A1 h6 l  @3 P/ x5 p
  152. {$ b2 \8 O# _4 o
  153.         SCK = 0;        /* set clock to low initial state */
    ' ?4 e) J6 d: A6 \* o; p) |+ w
  154. }
      B1 ~4 M1 Q6 G4 O9 X6 m
  155. 5 o7 Z0 G. L! [( G5 L4 V6 t
  156. /************************************************************************/) S( w+ R- ^! x% |
  157. /* PROCEDURE: Send_Byte                                                                                                        */
    , o( i5 [" y1 l' i1 o% [
  158. /*                                                                                                                                                */' C. J& @$ D, y  N9 t' G
  159. /* This procedure outputs a byte shifting out 1-bit per clock rising        */5 E; a1 T* e) S; E; F- r
  160. /* edge on the the SI pin(LSB 1st).                                                                                */3 j9 y2 H# M, v& U& s: h' [+ F
  161. /*                                                                                                                                                */
    5 v, @3 B" W( z8 e- S
  162. /* Input:                                                                                                                                */
    * x4 g5 m5 o0 X) K, T+ M/ O7 T
  163. /*                out                                                                                                                                */
    6 B' ?/ K' e! l/ n3 p; q
  164. /*                                                                                                                                                */# S  h! H/ R' y- d* {* j2 U* f& M
  165. /* Output:                                                                                                                                */+ y# m, l2 Q+ b
  166. /*                SI                                                                                                                                */4 w5 L7 i' U" ]+ Z) s
  167. /************************************************************************/5 [8 q- ]( ^& o- ^) D# A
  168. void Send_Byte(unsigned char out)2 t9 m1 r6 }* {% C0 b
  169. {
    % g* E( p  q  W: U3 v# |
  170.         5 v; k5 J; f, Y7 R  o$ b  q( }  p
  171.         unsigned char i = 0;2 l7 n6 M) e7 j' n% b4 F  S
  172.         for (i = 0; i < 8; i++)9 I5 X2 S& G& m' v  d
  173.         {3 d, \% i3 ^3 v, h2 T0 {+ K2 @! j
  174.                
    + B! @& Z! d# i5 M* H
  175.                 if ((out & 0x80) == 0x80)        /* check if MSB is high */9 W+ r7 U( V9 n  j' U
  176.                         SI = 1;
    2 m, ~" a# s) P6 ^
  177.                 else
    - B! ]5 `. `' c- K0 P/ [3 b9 k' z
  178.                         SI = 0;                                /* if not, set to low */) @* T8 @  a# f8 P2 @
  179.                 SCK = 1;                                /* toggle clock high */
    7 J- t$ D% q6 A
  180.                 out = (out << 1);                /* shift 1 place for next bit */
    " E" L. g9 ]5 ~( M7 |
  181.                 SCK = 0;                                /* toggle clock low */! M" H: [0 @1 D5 T
  182.         }
    * x" Z+ j0 N# J! M; X5 G) t* w
  183. }6 _! o6 z- N  X* b7 F/ A
  184. 2 j. ^0 s" y+ ?7 R/ g# ^& C* h
  185. /************************************************************************/: u. T% g7 Y3 l+ }2 R
  186. /* PROCEDURE: Get_Byte                                                                                                        */5 Q: ^' I' J. _* L) |! W
  187. /*                                                                                                                                                */
    4 R: S6 X8 D0 q6 |* ~' |. i2 ?! Z
  188. /* This procedure inputs a byte shifting in 1-bit per clock falling                */6 k$ ^9 t; C6 Q' v- I
  189. /* edge on the SO pin(LSB 1st).                                                                                        */. S" U. b* v: F
  190. /*                                                                                                                                                */8 V* g5 s# \1 [4 A; b5 G- q7 a
  191. /* Input:                                                                                                                                */3 E! z) c: w* _- a
  192. /*                SO                                                                                                                                */
      b# A" J1 _" D3 }$ @+ a' l: p. F! A
  193. /*                                                                                                                                                */7 @" N4 }8 }6 W
  194. /* Output:                                                                                                                                */
    8 O$ x0 O4 E* z$ }
  195. /*                None                                                                                                                        */) w4 t3 ~1 J' u/ d2 X( Y
  196. /************************************************************************/
    ' z6 v; Y/ ?  a2 s8 m( a/ |- E( S- g
  197. unsigned char Get_Byte()
    8 Y8 O# p  R  M
  198. {6 u$ P3 e& y" \) S/ s
  199.         unsigned char i = 0, in = 0, temp = 0;5 s+ C  ?4 S0 J! I  J6 R
  200.         for (i = 0; i < 8; i++)- h" J' M3 {# h" {8 f9 f
  201.         {
    0 m* i0 ~7 F4 U' n" I1 p
  202.                 in = (in << 1);                /* shift 1 place to the left or shift in 0 */
    7 P1 x; O$ Q- G, i6 q( t
  203.                 temp = SO;                        /* save input */
    4 A, d# i& _. v# t7 w' v
  204.                 SCK = 1;                        /* toggle clock high */; f1 [/ }8 i# u7 [4 C$ @& f1 o
  205.                 if (temp == 1)                        /* check to see if bit is high */+ W6 I, a$ l) c$ a
  206.                         in = in | 0x01;                /* if high, make bit high */
    " X4 [' u7 X. _* V% v
  207. ! g9 }# E2 s; f; K) S$ K; ~
  208.                 SCK = 0;                        /* toggle clock low */
    0 l3 }7 ^5 \; R6 t9 V; }
  209. 7 {/ P, d9 l/ U' h5 e/ X7 n
  210.         }* }5 E9 R3 ^3 ~3 @2 w  T( Z
  211.         return in;
    ; [# H6 `* m3 p' ^/ k- {
  212. }
    & T/ d0 r8 h/ e6 [6 y! F
  213. % H! l  p/ V. n3 \
  214. /************************************************************************/2 y$ r# U# `: x) i7 }- z# o( p4 u
  215. /* PROCEDURE: Poll_SO                                                                                                        */) l% h% [6 j' I  C4 `+ r
  216. /*                                                                                                                                                */
    9 H( @3 c( ~, U5 i
  217. /* This procedure polls for the SO line during AAI programming                  */# G* W+ ^8 l7 L, C
  218. /* waiting for SO to transition to 1 which will indicate AAI programming*/. w0 t' o9 u0 F: o$ b: F$ ]2 s
  219. /* is completed                                                                                                                        */
    % `& }) B: o4 a: w5 i1 f  T7 x1 p2 H3 F) k
  220. /*                                                                                                                                                */
    ( k& L1 P/ z' X6 T- N. i
  221. /* Input:                                                                                                                                */
    1 x' M4 B% ^1 g) w- `. a$ }* ]
  222. /*                SO                                                                                                                                */) L' k3 R2 n( O; ~
  223. /*                                                                                                                                                */- h4 m, r3 c- M$ D9 ]/ `. {
  224. /* Output:                                                                                                                                */: ^! |$ k! t+ o
  225. /*                None                                                                                                                        */$ S/ h1 {1 U9 q0 s" f  T- q7 E( w
  226. /************************************************************************// ^0 }% P! V$ t% S. L; h% m
  227. void Poll_SO()5 f. j8 D+ Q+ B1 B
  228. {
    ' c1 ^$ Q6 w/ `4 g& a
  229.         unsigned char temp = 0;! X, @3 M5 F+ C
  230.         CE_Low();
    0 v* c5 H% N2 p& D) N" |6 u
  231.     while (temp == 0x00)        /* waste time until not busy */
    + H: [* E2 s; m2 c
  232.                 temp = SO;
      Z' d* v  F& n# w
  233.         CE_High();* a# D0 M1 Q0 L
  234. }
    & |  c* z1 g. y# O/ J) i, @9 l5 U% {
  235. ( h& C  d2 i7 G
  236. /************************************************************************/8 O7 S% G0 i  r) K0 j
  237. /* PROCEDURE: CE_High                                                                                                        */
    : O  |; w& i2 ~$ G5 J# k* u) o0 q$ i
  238. /*                                                                                                                                                */9 o" S: ?# Q1 |
  239. /* This procedure set CE = High.                                                                                */" P- O) X. d9 r9 M4 Z/ _9 P
  240. /*                                                                                                                                                */0 K* ^* r/ \; R" y
  241. /* Input:                                                                                                                                */
    & y9 W* s% K& T/ q# T* M5 j
  242. /*                None                                                                                                                        */" g% ~5 E) e+ B) Y% X- d* L
  243. /*                                                                                                                                                */9 ?& v0 `0 e% a# I2 w! r
  244. /* Output:                                                                                                                                */, g* j! {% I8 A1 ]- X1 J
  245. /*                CE                                                                                                                                *// ^/ {0 v+ T' P1 R
  246. /*                                                                                                                                                */  D( d+ }8 ~/ ?% R+ P/ H) _
  247. /************************************************************************/
    2 [6 c5 K( e9 x1 x, m
  248. void CE_High()
    - \! d0 w+ _: G, v2 P
  249. {
    5 [' T0 n: v# D- p0 F/ c4 ?
  250.         CE = 1;                                /* set CE high */
    5 i% }. r* D- B& R
  251. }
    4 {/ D6 J: m( }# q, H9 _' B

  252. 7 v. r! b) l7 M/ l' Q3 @- Q
  253. /************************************************************************/* S# D5 P7 Q# C  }. Z) D9 L
  254. /* PROCEDURE: CE_Low                                                                                                        */0 L% E& c/ q9 a
  255. /*                                                                                                                                                */
    ; X9 c* _- ^7 _7 [0 J* z; n" ~1 I
  256. /* This procedure drives the CE of the device to low.                                          */
    0 G9 i2 x1 u# i4 e4 m
  257. /*                                                                                                                                                */  R7 {  S- e! {8 @
  258. /* Input:                                                                                                                                */
    * {5 n( T% Z* w
  259. /*                None                                                                                                                        */
    $ `4 S1 K2 [" n0 R
  260. /*                                                                                                                                                */( J& b) a5 ^9 d# I4 s
  261. /* Output:                                                                                                                                */
    + R  q# D8 ~7 v  e+ P
  262. /*                CE                                                                                                                                */
    8 J) _$ P9 I9 C; J
  263. /*                                                                                                                                                */7 T0 c/ z1 b$ ]2 Z
  264. /************************************************************************/
    + x% |9 q# s8 K/ M- u6 u
  265. void CE_Low() + `" F- {6 z) q" ?, ^. s
  266. {        $ ?/ I; |1 D4 b5 I' \
  267.         CE = 0;                                /* clear CE low */: a8 ~, C0 @; z; s, ~% R* R
  268. }. Q0 I4 o6 Y3 J& |+ R$ ?: j' f( f2 }

  269. ) g/ G0 n) }+ w
  270. /************************************************************************/3 |4 c2 a  ]+ C  u/ J
  271. /* PROCEDURE: Hold()                                                                                                        */0 y1 D! Z3 v! l# I
  272. /*                                                                                                                                                */  b/ R" d. T: Z! c6 {/ H1 `  j
  273. /* This procedure clears the Hold pin to low.                                                        */0 V3 n8 _' b4 |% n  n) G5 l9 T
  274. /*                                                                                                                                                */. @  C5 u2 @) k$ |
  275. /* Input:                                                                                                                                */
    2 p( }# P& U0 S
  276. /*                None                                                                                                                        */
    3 |. K0 U" D2 @
  277. /*                                                                                                                                                */
    8 b1 g" ~, b' O- Q: S* u6 h, {
  278. /* Output:                                                                                                                                */
    0 H, f: n; ]; j) p9 D
  279. /*                Hold                                                                                                                        */1 v) `# J3 c+ _3 d  {: [+ l
  280. /************************************************************************/
    , Y3 p* Q# U- m; Q9 ]7 N3 m5 o
  281. void Hold_Low(). n. |8 t: K  X( J6 l- a
  282. {3 N. z/ D3 J7 U) N( {. P. d
  283.         Hold = 0;                        /* clear Hold pin */
    % ^$ F' T: J# f2 L
  284. }+ I6 b6 [: M7 A# s  U

  285. - s7 I5 A3 g. a# R* X# I
  286. /************************************************************************/4 y+ O1 n! Q; K4 t
  287. /* PROCEDURE: Unhold()                                                                                                        */
    9 f& d: w$ v) J  J9 U0 F& B
  288. /*                                                                                                                                                */
    6 L0 E! }! C' C5 s5 r
  289. /* This procedure sets the Hold pin to high.                                                        *// S8 {! g: O, r  n( L4 ^5 ?" M8 |2 Q
  290. /*                                                                                                                                                */
    / R. [; Y. i6 s9 q
  291. /* Input:                                                                                                                                */
    3 I8 f" T% W$ v7 d2 n
  292. /*                None                                                                                                                        */1 ~0 P5 \9 j- l: V7 k( N; \
  293. /*                                                                                                                                                */
    " j3 E4 {0 T5 u+ |0 d
  294. /* Output:                                                                                                                                */% l5 p' ?+ H0 |- ]8 M+ i, q, V7 j
  295. /*                Hold                                                                                                                        */
    8 d  ~" w) ?) E+ e6 y
  296. /************************************************************************/0 E; S- {! `( X" ]& X. n# U
  297. void Unhold()% x( r& e( p0 E
  298. {
    ) E, k7 z. x( G2 [5 B
  299.         Hold = 1;                        /* set Hold pin */7 g9 ^$ I6 M$ y( m* Y1 O
  300. }3 S, u. @/ ^; l' m. R! @

  301. 1 H2 o) Z' [' }
  302. /************************************************************************/
    ; I* I$ A5 S3 }' X! W2 [
  303. /* PROCEDURE: WP()                                                                                                                */
    $ l9 H/ y# F2 [
  304. /*                                                                                                                                                */) @6 V: X" c" g. f& `  |  o, o
  305. /* This procedure clears the WP pin to low.                                                                */
    1 a  j. j/ N2 B7 x/ i) _' c! k" ]
  306. /*                                                                                                                                                */# Z6 j9 O& Q: ^, b4 p+ D
  307. /* Input:                                                                                                                                */# ~1 e  G  ^6 W# r
  308. /*                None                                                                                                                        */
    . {1 J( T8 V( \2 h
  309. /*                                                                                                                                                */
    # s) \; z  G7 k3 N! W* g
  310. /* Output:                                                                                                                                */) ]' ?/ J0 C0 P% k! x: j5 Q
  311. /*                WP                                                                                                                                */
    1 s8 z) ^& o) M  x1 w# `
  312. /************************************************************************/
    " c  V9 ]! _4 H  g  E# g
  313. void WP_Low()% O3 ^6 S$ |# m" o' H, {, r
  314. {# q; w. t- {5 z4 m" k0 \
  315.         WP = 0;                                /* clear WP pin */
    7 J$ [  h+ ]! S" H
  316. }% j7 `5 Y4 i) X/ ^- x$ |% H, Q# D; B
  317. " s$ j% a7 K- ]- n( z* W
  318. /************************************************************************/' {' n5 G* X+ K1 O3 G
  319. /* PROCEDURE: UnWP()                                                                                                        */
    % B: g. f$ N1 k/ V9 e; f" X) i
  320. /*                                                                                                                                                */6 Z( @" c0 o' f; o
  321. /* This procedure sets the WP pin to high.                                                                */
    7 e% X: V! b( t- [
  322. /*                                                                                                                                                */
    - s+ t* R  [+ j; R; ?8 q
  323. /* Input:                                                                                                                                */
    : J! \4 C2 V3 ~: ^6 U0 U) H' \! |
  324. /*                None                                                                                                                        */! ~" R: I$ k0 I/ _' B/ Z9 x+ I  Z
  325. /*                                                                                                                                                */
    & J. Z8 n9 V9 U+ M: v& T* g: M
  326. /* Output:                                                                                                                                */' m7 U; V4 B+ p2 L' x
  327. /*                WP                                                                                                                                */5 V7 i1 i( d' M( s8 I# B
  328. /************************************************************************/
    * I* ^5 N- N0 _! t) @: D, z9 j- M* d
  329. void UnWP()& O: h) G; ^* ~  t# D
  330. {; {/ f- C9 Z9 k9 t2 H# v
  331.         WP = 1;                                /* set WP pin */1 _0 ^" g7 W+ @0 a
  332. }
    3 q% r+ ^, m9 g  j6 o# @4 E

  333. ! `9 i4 ^4 D* Q6 S
  334. /************************************************************************/
    1 g: }! u% `* \2 x+ A
  335. /* PROCEDURE: Read_Status_Register                                                                                */6 _& {6 K& {! m/ o: @) @
  336. /*                                                                                                                                                */+ l6 n9 E% a" N
  337. /* This procedure read the status register and returns the byte.                */
    : J5 P9 B2 o8 G9 n( _) r
  338. /*                                                                                                                                                */
    , H1 v, s9 w6 U, W
  339. /* Input:                                                                                                                                */  K- E1 D9 }) y# L3 E. m5 L! m% F  j
  340. /*                None                                                                                                                        */
    7 c: [2 s6 T8 J; i1 s" C
  341. /*                                                                                                                                                */
    * T% b; T4 o$ }5 ~5 F7 _
  342. /* Returns:                                                                                                                                */4 b0 U2 a1 u! V+ w' r
  343. /*                byte                                                                                                                        */' C" }# v7 s% d8 k+ l* P! D
  344. /************************************************************************/
    & t6 @4 T  S# Y
  345. unsigned char Read_Status_Register()/ J) ]$ y) C4 f6 y6 N/ \6 V5 U5 h
  346. {2 ~- a0 O: _8 I. L, M
  347.         unsigned char byte = 0;
    $ U" _. r6 \  k2 b; Q8 v8 p
  348.         CE_Low();                                /* enable device */" \: o( A+ t: b# ]- x* T0 s4 d0 b
  349.         Send_Byte(0x05);                /* send RDSR command */
    + ^$ t: W, Q1 h
  350.         byte = Get_Byte();                /* receive byte */7 U  y: N& C( h2 s
  351.         CE_High();                                /* disable device */
    1 P- j: r9 E( \$ a1 \( E
  352.         return byte;. b# Z" T1 p5 t1 ~) d
  353. }
    . J" _( e$ v1 H3 `3 m" ]5 x
  354. 8 ~0 u: v( g) `- R, ~6 }" O+ d$ m! a
  355. /************************************************************************/+ W0 w" I! j* I! O) T
  356. /* PROCEDURE: EWSR                                                                                                                */9 e5 J# }( t0 E3 Q
  357. /*                                                                                                                                                */
    4 c1 g# e( ^, j0 ?4 U
  358. /* This procedure Enables Write Status Register.                                                  */4 \# ~, }3 m+ [9 p3 W
  359. /*                                                                                                                                                */
    : D$ K5 ]7 k3 I1 }; \- k
  360. /* Input:                                                                                                                                */
    - d# r  C& T* Z, ~( A; z
  361. /*                None                                                                                                                        */
    . c' @% k+ |9 }1 o# Z2 L( N! |" t
  362. /*                                                                                                                                                */
    ! v" T8 z' D" D
  363. /* Returns:                                                                                                                                */
    + [( q0 Z5 C, \
  364. /*                Nothing                                                                                                                        */" C! m% ~' g5 b7 J9 d8 C4 y
  365. /************************************************************************/
    6 n. h' K9 g2 v4 F
  366. void EWSR()) W: \% V9 i7 b0 h- B
  367. {
    7 \* }8 A* _/ r) U" R) S
  368.         CE_Low();                                /* enable device */
    ! p& W) _* B) O- m* H, [) E
  369.         Send_Byte(0x50);                /* enable writing to the status register */
    9 N2 A8 R& i2 E, d/ [7 @5 s
  370.         CE_High();                                /* disable device */4 a$ K8 [! h. r7 H2 i0 P3 q% `
  371. }
      I* P* s1 v7 U7 B$ K% r
  372. " B4 x8 c! {" l3 }( \8 z6 v/ G
  373. /************************************************************************/; [. x, R  t. M+ u) {2 }3 ^4 H
  374. /* PROCEDURE: WRSR                                                                                                                */
    * H; _2 k% r/ I
  375. /*                                                                                                                                                */
    / c5 E9 n) s1 Y5 I" X% M, U4 Y
  376. /* This procedure writes a byte to the Status Register.                                        */' d! ^, D( ]$ S7 ^( g4 j; Z6 D
  377. /*                                                                                                                                                */% r( R# }' [  y0 ?, [3 V2 P- @
  378. /* Input:                                                                                                                                */
    2 q0 Q7 [- Z8 [: h. Y
  379. /*                byte                                                                                                                        */! G% i5 F7 p1 B) D6 X- d7 ~) T6 D
  380. /*                                                                                                                                                */
    + W4 A! h9 p6 p9 C
  381. /* Returns:                                                                                                                                */
    ! F( M/ l1 W1 a4 H
  382. /*                Nothing                                                                                                                        */) J) r$ ^" n' {4 E7 Q! I: t+ Z
  383. /************************************************************************/( A/ N3 _7 [  o3 R0 G, D& g! j; B  w1 c) r
  384. void WRSR(byte)
    * }3 j# U% n, N
  385. {& }! s/ [  ]. ^$ t
  386.         CE_Low();                                /* enable device */. g$ t) c9 ]& b! F
  387.         Send_Byte(0x01);                /* select write to status register */
    ( V8 u% ~0 S1 ^7 T
  388.         Send_Byte(byte);                /* data that will change the status of BPx 6 [9 S* D- @" {1 X, h( E
  389.                                                                 or BPL (only bits 2,3,4,5,7 can be written) */$ T  z9 Y$ `$ i
  390.         CE_High();                                /* disable the device */) Z0 f1 |% V, O" D% T; n4 \
  391. }4 \7 I: V* n7 l

  392. # w6 Z+ g* f  K
  393. /************************************************************************/
    / c9 Q' R  H8 d) |! X; n, e! }! s
  394. /* PROCEDURE: WREN                                                                                                                */
    * o4 x( d/ l# O' c0 H& N! t5 n& h; o
  395. /*                                                                                                                                                */
    4 R6 e7 I! z* S
  396. /* This procedure enables the Write Enable Latch.  It can also be used         */9 \  f7 F0 O9 k
  397. /* to Enables Write Status Register.                                                                        */7 j7 G0 c0 q8 c1 u' U4 r
  398. /*                                                                                                                                                */6 q  B' r5 ?% o/ n$ W, Y
  399. /* Input:                                                                                                                                */
    # m6 l( t( p$ A* o
  400. /*                None                                                                                                                        */
    - h' u* r: x6 s; k
  401. /*                                                                                                                                                */
    8 @+ H. n" U9 N+ x3 p$ j7 j
  402. /* Returns:                                                                                                                                */
    . e3 X. X/ q4 r+ h7 y4 h# H
  403. /*                Nothing                                                                                                                        */
    & w& G; a& M' m7 I+ ]
  404. /************************************************************************/
    " H& w! S: w  d  k* ~; X/ r
  405. void WREN()* N( u5 N+ \; B+ b5 h
  406. {5 l0 U1 X3 \5 O# }+ K  @
  407.         CE_Low();                                /* enable device */
    $ E  m# w- s+ v( L/ _4 D
  408.         Send_Byte(0x06);                /* send WREN command */  p; X  n. {+ G# p
  409.         CE_High();                                /* disable device */8 T% o9 ]) @$ j3 q: X
  410. }$ G7 Y: `) z3 r9 I

  411. # j* H/ B0 K4 J( N. D$ W
  412. /************************************************************************/" C0 O3 C5 l- ^3 P3 w8 C& a
  413. /* PROCEDURE: WRDI                                                                                                                */2 v4 m1 A( X1 y0 w. E) R6 o
  414. /*                                                                                                                                                */4 E7 Z7 |* \" ?3 q
  415. /* This procedure disables the Write Enable Latch.                                                */
      h7 r# N9 ]! }* _3 d, F8 g
  416. /*                                                                                                                                                */
    ) r& Q0 _+ i5 M- w5 p+ ~/ L
  417. /* Input:                                                                                                                                */
    & V* o' i* H6 f/ r) u( H/ ^2 O3 e
  418. /*                None                                                                                                                        */
    3 P5 C' P. ]# P: {. H, K) W& r! B
  419. /*                                                                                                                                                */7 Q9 A; a, {( {7 V
  420. /* Returns:                                                                                                                                */) f( k7 \4 l) ^9 ^: q8 `* _
  421. /*                Nothing                                                                                                                        */  m7 t. w$ m) c. d
  422. /************************************************************************/
    9 t2 |: [: {$ S  ~# i; d7 L
  423. void WRDI()) D% _* o9 l/ M% m' f
  424. {
    1 b0 ]* v2 p+ Q  A  B
  425.         CE_Low();                                /* enable device */
    0 n5 c4 K: s$ W5 \  D' O" `
  426.         Send_Byte(0x04);                /* send WRDI command */0 a1 B; |) n3 {  g( L
  427.         CE_High();                                /* disable device */# Y" j( d8 C5 ]( D1 i- \
  428. }) W# |7 l+ M' Z" F. z0 j

  429. 3 m0 b& y" n- e5 d
  430. /************************************************************************/! I( C& y, I4 C
  431. /* PROCEDURE: EBSY                                                                                                                */% v  k2 f* c8 r6 I% B0 [( C
  432. /*                                                                                                                                                */
    6 Q9 N: y0 M, I5 f8 P) Z
  433. /* This procedure enable SO to output RY/BY# status during AAI                         */
    ! |( D1 I, s4 j$ O* N
  434. /* programming.                                                                                                                        */
    : l+ G* L: m5 ]0 |' y! D3 s
  435. /*                                                                                                                                                */$ t& o6 j, d% q" |$ |/ h: a# q
  436. /* Input:                                                                                                                                */
    $ [, x- C6 R1 m, Z: l
  437. /*                None                                                                                                                        */3 W$ `* q! B% u9 ~% n
  438. /*                                                                                                                                                */
    / ?  e$ F% S) J. p
  439. /* Returns:                                                                                                                                */0 B) y- e3 ^, n( Y7 a
  440. /*                Nothing                                                                                                                        */
    ( s8 `7 t0 @) Z
  441. /************************************************************************/
    3 u; ?' o# R6 _( N
  442. void EBSY(). K8 i) Z: Z/ ^% y* O  d& p
  443. {% e2 Q  ]/ c* y) R
  444.         CE_Low();                                /* enable device */
    * Y5 v/ j8 ^' k2 `7 d: e8 j+ @
  445.         Send_Byte(0x70);                /* send EBSY command */! i' B! t0 Z' }
  446.         CE_High();                                /* disable device */4 b+ y# @! R7 a
  447. }
    " f( P* H. B8 P& l3 f3 ]* I, J
  448. / y5 U6 Y0 `1 ^
  449. /************************************************************************/. `$ @3 u% ^6 Q3 g  b& z
  450. /* PROCEDURE: DBSY                                                                                                                */3 r5 H! |3 T$ {
  451. /*                                                                                                                                                */9 V1 V/ _2 p. V! J
  452. /* This procedure disable SO as output RY/BY# status signal during AAI        */$ Y8 ^# `8 k8 E: e: _
  453. /* programming.                                                                                                                        */, a5 y3 i4 u/ B! L$ [1 h
  454. /*                                                                                                                                                */
      k: t% H' z) n* l  t* Q
  455. /* Input:                                                                                                                                */% ?/ r& {' a0 _9 W* J/ o) G8 R& Q
  456. /*                None                                                                                                                        */$ J/ G4 Y. t4 K% l+ o8 N, n
  457. /*                                                                                                                                                */
    4 @- i* f9 F/ g. g
  458. /* Returns:                                                                                                                                */. G. A( s1 q3 s. X
  459. /*                Nothing                                                                                                                        */9 j1 p" @& L- _$ x
  460. /************************************************************************/
    * y3 r, S2 {* ^3 s, M* D
  461. void DBSY()
    " @* ^4 y+ r5 b% c: n( {
  462. {
    : o2 G/ t! `9 W1 |0 S: R
  463.         CE_Low();                                /* enable device */% Y  J7 Z" M/ `) |  e2 L
  464.         Send_Byte(0x80);                /* send DBSY command */
    : |9 B, F2 [5 f4 e
  465.         CE_High();                                /* disable device */1 w0 Z# j" U' m# B7 m/ `
  466. }
    $ b# M, Z9 V5 ^- \

  467. * O1 J7 u1 i: u
  468. /************************************************************************/# O% a* a& X. Z8 i* J
  469. /* PROCEDURE: Read_ID                                                                                                        */
    / n- }. H( p4 G0 E
  470. /*                                                                                                                                                */
    " v2 ~. a5 Y8 Y  l
  471. /* This procedure Reads the manufacturer's ID and device ID.  It will         */
    ; Z1 u0 s. a! z. s% V
  472. /* use 90h or ABh as the command to read the ID (90h in this sample).   *// u1 |8 V4 Z" S; N; q4 a
  473. /* It is up to the user to give the last byte ID_addr to determine      */
    4 C& L) a/ k: ^* f/ n
  474. /* whether the device outputs manufacturer's ID first, or device ID         */7 z! F/ a/ G. W+ |8 v3 \
  475. /* first.  Please see the product datasheet for details.  Returns ID in */7 D8 ~1 A7 ^  {2 ~- E0 U
  476. /* variable byte.                                                                                                                */
    9 {" u& y4 j) q3 E& C) _( B
  477. /*                                                                                                                                                */
    ) f- e% Q4 C/ G) N3 g: q: |
  478. /* Input:                                                                                                                                */; ~' g2 a5 J, r- V7 P, i5 X4 e( h' r
  479. /*                ID_addr                                                                                                                        */* o0 F) d# a- [5 b% F- K! j
  480. /*                                                                                                                                                */* J1 f, X- F' B+ ]$ q
  481. /* Returns:                                                                                                                                */3 a8 G9 Q9 i, B/ ~; e
  482. /*                byte:        ID1(Manufacture's ID = BFh or Device ID = 8Eh)                        */
    " r$ J  X- Z& Z: C! n
  483. /*                                                                                                                                                */2 x' j: K) C" P' K1 z6 K2 l# d
  484. /************************************************************************/5 B0 N9 G5 D# k0 O& ?0 q
  485. unsigned char Read_ID(ID_addr)7 w4 C( n2 l0 T* d
  486. {
      P! E/ T6 f7 j5 N' q
  487.         unsigned char byte;
    ( y. q, e4 V; A! v
  488.         CE_Low();                                /* enable device */
    ' N: N$ v; ~8 x) l' S% g
  489.         Send_Byte(0x90);                /* send read ID command (90h or ABh) */
    % T7 }1 n# c8 L! E- U% L
  490.     Send_Byte(0x00);                /* send address */
    + T$ o( S7 B+ h) t
  491.         Send_Byte(0x00);                /* send address */
    6 U' X. l( c0 l2 T9 \
  492.         Send_Byte(ID_addr);                /* send address - either 00H or 01H */
    9 K9 W2 [* S& @
  493.         byte = Get_Byte();                /* receive byte */7 }- L6 {: F0 w$ a
  494.         CE_High();                                /* disable device */
    9 W/ l: K$ \/ f; k) B+ H
  495.         return byte;
    6 z6 Z+ [+ |; Y: r$ k$ s
  496. }
    " `' A0 m8 o! B" C4 A, v. h/ l

  497. 2 \; c5 i9 t/ [: I, w) m0 K) n
  498. /************************************************************************/' A) U( {& P+ V. I' T
  499. /* PROCEDURE: Jedec_ID_Read                                                                                                */8 p' C6 b2 x8 f. u+ r
  500. /*                                                                                                                                                */
    8 e4 i, S/ Y" b
  501. /* This procedure Reads the manufacturer's ID (BFh), memory type (25h)  */
    7 Q) X# }5 O& T
  502. /* and device ID (8Eh).  It will use 9Fh as the JEDEC ID command.            */4 H) r' `0 _5 d
  503. /* Please see the product datasheet for details.                                                  */! c: O' o* K1 e, O: J$ h
  504. /*                                                                                                                                                */
    " {/ a% Y5 A1 K: u1 i; O( E
  505. /* Input:                                                                                                                                */
    ! p& B3 y8 G3 b% B
  506. /*                None                                                                                                                        */# k, Z& R% w. m3 s; O! O) \
  507. /*                                                                                                                                                */
    # |8 C# t# y) i0 }" J6 ^+ u
  508. /* Returns:                                                                                                                                */. w; [. z8 X4 x, B1 g
  509. /*                IDs_Read:ID1(Manufacture's ID = BFh, Memory Type (25h),                        */
    ; w9 |  g3 R' ?2 O3 {. r
  510. /*                 and Device ID (8Eh)                                                                                        */
    ; ~" g& {: _) g1 X6 i- h$ n
  511. /*                                                                                                                                                */7 {; o, `* D& A4 X3 b# Z
  512. /************************************************************************/
    ' M  N, f& s1 V$ g' E" j- `
  513. unsigned long Jedec_ID_Read() ' R0 B  F9 v4 `3 r: O- ]
  514. {- A# s" K' Y' |4 u, R/ \8 o
  515.         unsigned long temp;
    9 f: w" p; n2 V; w
  516.         3 r8 h0 C* N7 X6 ~+ v& @- p% K, Z
  517.         temp = 0;' Q6 u* x. _/ M* C& {
  518. : s; U; G/ L! \
  519.         CE_Low();                                        /* enable device */
    ' \/ V9 E9 `1 O' I. o
  520.         Send_Byte(0x9F);                        /* send JEDEC ID command (9Fh) */2 ~3 x: n. [( Q. V5 b" N8 V
  521.     temp = (temp | Get_Byte()) << 8;        /* receive byte */
    ' t" W6 K( d9 I% q5 t+ P
  522.         temp = (temp | Get_Byte()) << 8;       
    ! e* b+ {% I# M7 W0 w
  523.         temp = (temp | Get_Byte());                 /* temp value = 0xBF258E */( c6 ^( j$ m# J8 A) w
  524.         CE_High();                                                        /* disable device */. \+ {- h  }: F
  525. - }$ c4 n2 m  ^# O$ d
  526.         return temp;* V6 |$ C% f& ~) O/ N' b
  527. }
    ( e6 q4 v6 Y, i9 l7 t! ~& b

  528. + h: R9 g: ^5 q1 k4 j5 \
  529. /************************************************************************/
    - n4 _' M/ O2 h( L9 r
  530. /* PROCEDURE:        Read                                                                                                        */
    , u6 B' v+ M8 @1 B) {
  531. /*                                                                                                                                                */               
    : J- g+ a; ^# R9 j1 z
  532. /* This procedure reads one address of the device.  It will return the         */- N+ P2 G# V) ^/ W- U% l6 c) u1 y
  533. /* byte read in variable byte.                                                                                        */+ Q) i) \! ]+ f$ @: G8 Q1 V
  534. /*                                                                                                                                                */
    " y3 m  K" U; [1 Y7 K' {$ l2 G% b9 X1 J
  535. /*                                                                                                                                                */% s, r& v3 y7 G3 h5 Y
  536. /*                                                                                                                                                */2 `5 Q: D0 O4 d# e; E2 B+ {2 g* r; L1 ]
  537. /* Input:                                                                                                                                */
    : _$ B9 B' `$ U  q
  538. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */9 ?% `, S6 J. G: k) {" M# t, Q
  539. /*                                                                                                                                      */) |8 x/ @) ]8 N4 l8 L3 ^
  540. /*                                                                                                                                                */! z8 l8 m( H$ u5 {+ J8 x( O" @
  541. /* Returns:                                                                                                                                */
    , h5 ?' _& J, n+ Q. P
  542. /*                byte                                                                                                                        */
    % w8 C2 F/ [' E/ c' _
  543. /*                                                                                                                                                */
    $ L% z1 T3 X- [2 y4 ?, F
  544. /************************************************************************/
    0 _8 I% g+ n2 K% |3 F( H
  545. unsigned char Read(unsigned long Dst) . u6 C5 c; i* ?1 m: Q
  546. {) Q8 J& {( B6 `: l! S( e7 G9 E  G2 ]
  547.         unsigned char byte = 0;        * y9 q; v9 K0 g) G

  548. 7 t, b; a% C8 f# j9 C& I
  549.         CE_Low();                                /* enable device */
    : F0 Y1 A+ K) L* J& m
  550.         Send_Byte(0x03);                 /* read command */* b" K& L/ W+ R4 g  k9 c
  551.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */
    6 |7 C7 o! n; k4 c1 J
  552.         Send_Byte(((Dst & 0xFFFF) >> 8));
    4 ?5 C3 j, W# ~/ H0 i
  553.         Send_Byte(Dst & 0xFF);
    8 W7 E! H. ]' F
  554.         byte = Get_Byte();
    . J& O$ d9 D; I8 E0 L" ?) M1 a
  555.         CE_High();                                /* disable device */
    7 g0 H+ _2 S$ s  w. x" d8 q
  556.         return byte;                        /* return one byte read */
    6 s" H1 Q! p7 D9 G& h9 x( U
  557. }) D/ q! o8 Z' ^! M$ ?
  558. 8 R: ^0 r2 M1 {; a) h8 a
  559. /************************************************************************/! A3 g3 b+ t8 B0 r0 `) C; W
  560. /* PROCEDURE:        Read_Cont                                                                                                */# i0 h- A- E9 K5 ~8 j/ V3 X1 r2 j
  561. /*                                                                                                                                                */                6 S; r6 Z7 |: T0 S. u, m" P% G
  562. /* This procedure reads multiple addresses of the device and stores                */
    3 G: |7 Q* b# s' D; U
  563. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
    0 w# d1 y, U. d! `: _
  564. /*                                                                                                                                                */. Y5 k: [1 N0 Y- F% |- {* R' I# Z' c
  565. /* Input:                                                                                                                                */
    - g- }& r5 g: U5 e8 d* R; V3 u
  566. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */7 t  S! a7 y3 x( c' O/ s5 Y$ T
  567. /*      no_bytes        Number of bytes to read        (max = 128)                                        */
    ! ]3 f, d/ S& _: i9 D
  568. /*                                                                                                                                                */6 |& ~7 Q: m. [8 ^
  569. /* Returns:                                                                                                                                */
    * ^+ s- [% d# l
  570. /*                Nothing                                                                                                                        */. n/ N8 V( r) |# l* r# n" h- H9 w
  571. /*                                                                                                                                                */+ N1 E1 l1 f" w, X- ]& `7 C$ P
  572. /************************************************************************/9 T# r) R  ^5 X1 R- U7 ^2 w, {, B0 T
  573. void Read_Cont(unsigned long Dst, unsigned long no_bytes)
    ; w/ B8 U; G) N  u
  574. {
    ! L5 \- t) i4 S5 z5 w7 L/ v# K
  575.         unsigned long i = 0;
    + Q8 k1 N9 D/ z& k
  576.         CE_Low();                                        /* enable device */# v, ]# ?( W3 @, B
  577.         Send_Byte(0x03);                         /* read command */) ?9 j9 B% N, x' X# o" T8 @
  578.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    % N/ g$ @8 V1 x1 Z$ A* j
  579.         Send_Byte(((Dst & 0xFFFF) >> 8));% g( v4 ^+ H: m8 Q  o0 T8 M# R# [
  580.         Send_Byte(Dst & 0xFF);2 k9 B4 P1 q3 F
  581.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */
    5 g9 y3 ^9 Q* r9 g. D
  582.         {# F. H' @) Z2 _5 d" c5 A
  583.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */. h) N; u) j2 Q7 z: G9 I  |- C0 h
  584.         }
    5 f  r; j8 D. y0 w8 T
  585.         CE_High();                                        /* disable device */
    % {8 Z& m/ v( n2 c2 _( }* d% }7 b
  586. 8 Z. ~: o3 O4 E
  587. }8 [2 x3 L  ^0 @0 p1 V  i8 p% r9 q
  588. / S3 ~% H% e' `6 W) A
  589. /************************************************************************/
    ! D" Z, @) j3 Z& T4 p7 c  o0 I
  590. /* PROCEDURE:        HighSpeed_Read                                                                                        */5 m. C0 ?  v& E
  591. /*                                                                                                                                                */                3 N# K3 ]& {) V% I4 I+ y3 b8 K
  592. /* This procedure reads one address of the device.  It will return the         */
    3 `4 ?" O. W$ ?
  593. /* byte read in variable byte.                                                                                        */4 V5 m- @6 z& o! |1 m  \- T
  594. /*                                                                                                                                                */
    , H1 C! t  l& W% W9 @
  595. /*                                                                                                                                                */
    $ ?% V7 d+ _- U
  596. /*                                                                                                                                                */! \# m" \* G& |; C
  597. /* Input:                                                                                                                                */
    . ?5 [/ R* a' c# P( d0 W% p; z$ N) ]
  598. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */9 Z  z* P0 {2 n  Y# \! u; j
  599. /*                                                                                                                                      */8 O* G' ?! S  `: [( r- }: p" ]- e
  600. /*                                                                                                                                                */
    ; W6 V) Z" x5 c& i3 J
  601. /* Returns:                                                                                                                                */
    . ]6 h1 Y" i$ }& U( b. p0 ^
  602. /*                byte                                                                                                                        */7 e; D% P: u3 H& t
  603. /*                                                                                                                                                */
    ; F& c+ q, T8 Y) z
  604. /************************************************************************/* }& b+ k* t6 U' L/ P
  605. unsigned char HighSpeed_Read(unsigned long Dst) . j* ~- [8 W! P" E8 |, _4 \
  606. {
    & y) m% }/ @5 d
  607.         unsigned char byte = 0;       
      l2 r; D6 O2 r' g8 N1 @$ E
  608. 1 V# K: F  l4 i3 K
  609.         CE_Low();                                /* enable device */2 e+ B8 A8 t2 E* H- v: d) Z6 ]
  610.         Send_Byte(0x0B);                 /* read command */
    # R9 Q& `( |, o* m7 _( g
  611.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */
    & q  W4 l: F% D9 ~! Z+ ~3 ~8 O
  612.         Send_Byte(((Dst & 0xFFFF) >> 8));
    / l; [) {( Q; [8 V6 g" t
  613.         Send_Byte(Dst & 0xFF);
    1 z! p# x  P3 E) e9 H/ T
  614.         Send_Byte(0xFF);                /*dummy byte*/
    / U- k) `: @# B
  615.         byte = Get_Byte();
      Y, ?. s- S3 Z) p( n8 q
  616.         CE_High();                                /* disable device */
    : M7 G* a2 W' T8 P) b/ ]
  617.         return byte;                        /* return one byte read */! [6 }& O. t$ @# E
  618. }
    ; |7 b, K8 }: ?: _/ a
  619. " T( J1 Y1 o/ J6 U  ^
  620. /************************************************************************/% s8 O! a3 A/ u( k
  621. /* PROCEDURE:        HighSpeed_Read_Cont                                                                                */
    * z$ ~. Y2 A! Q# }1 S
  622. /*                                                                                                                                                */                / u; \$ o7 d. q- Q3 _9 G# H0 r# R
  623. /* This procedure reads multiple addresses of the device and stores                */
    % d- U+ F5 v7 g
  624. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
    4 ^  o3 M  @" x/ `2 e: O" k
  625. /*                                                                                                                                                */7 `% Y( [. C* |& W
  626. /* Input:                                                                                                                                */
    1 `5 H# j* M8 Y) O" Q( ]5 r- L
  627. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */2 L. n' r5 ?& @
  628. /*      no_bytes        Number of bytes to read        (max = 128)                                        */6 b% U) o" S" g' n$ J8 }
  629. /*                                                                                                                                                */( Y& D$ F" o- E& n: A- r$ O
  630. /* Returns:                                                                                                                                */0 ?% h" `3 y3 h4 K
  631. /*                Nothing                                                                                                                        */
    0 G0 w) _( ?1 |5 o- m
  632. /*                                                                                                                                                */  I0 u! D% z8 ]% O
  633. /************************************************************************/
    % N4 T1 ?/ q+ Z7 y9 d1 m1 ^8 x
  634. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes)' a* H- Z& K% ~" L9 w' T
  635. {5 k" d5 ~$ K6 }1 h6 ?
  636.         unsigned long i = 0;
    4 }) k8 |0 D& |% h
  637.         CE_Low();                                        /* enable device */
    / y( N. L: ?# J
  638.         Send_Byte(0x0B);                         /* read command */8 u7 `$ _- P7 k
  639.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    6 l* h. ^* f" X$ p) X3 ?1 p
  640.         Send_Byte(((Dst & 0xFFFF) >> 8));9 h/ u1 Z1 [, T, {" ?# ^( l
  641.         Send_Byte(Dst & 0xFF);
    , @8 I. @5 O% M5 ~( H/ u9 a! }
  642.         Send_Byte(0xFF);                        /*dummy byte*/
    - Q2 g6 p2 R4 T1 x3 P
  643.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */1 B$ b0 p% E' e! t# C( x, w% z
  644.         {
    & q# o- B0 N4 Z4 N. ?0 e/ l" k$ _; n
  645.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */
    3 N; r0 C. D2 u7 Y8 v1 ?
  646.         }) v# f' T0 ?* y) h
  647.         CE_High();                                /* disable device */
    8 g( N2 I) Q) a0 V' ?4 {
  648. }
    ) g4 t! t7 \# Z

  649. 4 O, \) Y& e3 r+ \- s- f  w8 f, q4 q
  650. /************************************************************************/
    : \+ @! \% v3 S+ g
  651. /* PROCEDURE:        Byte_Program                                                                                        */
    0 k$ h: j. S: a" |* }
  652. /*                                                                                                                                                */* c6 E6 M2 A+ h2 [; b0 y/ x1 N+ h
  653. /* This procedure programs one address of the device.                                        */
    + }+ }1 B3 x! @+ k6 M4 [
  654. /* Assumption:  Address being programmed is already erased and is NOT        */
    5 _7 S) O2 \2 t! x7 K/ x9 r
  655. /* block protected.                                                                                                                */
    ( ~6 C7 d9 w  t. @8 R) N  S: c' }/ m. Q
  656. /*                                                                                                                                                */
    0 `# Y" W# P, e! }4 d; f
  657. /*                                                                                                                                                */8 F. s7 u) \1 T5 Z, g$ @
  658. /*                                                                                                                                                */
    , t$ |) O9 @. H6 S6 G+ w) I
  659. /* Input:                                                                                                                                */
    - W( {* D7 G' }/ ^8 I5 a
  660. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */1 ^4 N  C, z3 i1 f6 d
  661. /*                byte:                byte to be programmed                                                                */
    # [, u5 i5 U+ s! j! ~, U
  662. /*                                                                                                                                      *// G4 c& k9 {$ B5 v' \5 a
  663. /*                                                                                                                                                */; E# @2 z6 D# z5 x9 |0 A
  664. /* Returns:                                                                                                                                */
    " N( a4 f) i. J' L2 H
  665. /*                Nothing                                                                                                                        */
    : O) K, c( n0 P7 S  j# m: t
  666. /*                                                                                                                                                */; d. F8 `3 I  x) b8 C
  667. /************************************************************************/
    % H4 V* l5 v- t- `
  668. void Byte_Program(unsigned long Dst, unsigned char byte)
    + D4 j( S, X) ?) X, G6 k
  669. {
    6 q: a1 n" u' u$ E
  670.         CE_Low();                                        /* enable device */
    ( D% c/ ^/ o$ k# W3 h$ z
  671.         Send_Byte(0x02);                         /* send Byte Program command */2 L& j5 `) N1 X9 \: {& m9 _
  672.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */" C  `4 o7 N* f# n3 |
  673.         Send_Byte(((Dst & 0xFFFF) >> 8));
    3 {' c- x% h( \" T/ K
  674.         Send_Byte(Dst & 0xFF);
    ' k" X8 V1 Z, Z1 N& v
  675.         Send_Byte(byte);                        /* send byte to be programmed */
    + C1 {+ F3 K0 V* w$ v  e. D  F
  676.         CE_High();                                        /* disable device */& ?' Q! }3 k$ C# q
  677. }
    / K4 E3 ]$ G9 x8 Y
  678. 3 F, n5 p" ^" ?2 m, |5 H! s
  679. /************************************************************************/
    6 R1 F$ D2 H1 @4 m$ c+ b
  680. /* PROCEDURE:        Auto_Add_IncA                                                                                        */, b2 W* F% q3 f) s
  681. /*                                                                                                                                                */
    : [/ v5 g, g- P# N; P5 ]
  682. /* This procedure programs consecutive addresses of 2 bytes of data into*/
    5 q, x0 O4 j, K% U8 M
  683. /* the device:  1st data byte will be programmed into the initial                 */! m1 L6 Y' {: o
  684. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */5 x, S+ O" V  L- ^' v
  685. /* programmed into initial address [A23-A1] and with A0  = 1.  This          */
    9 J/ v$ `0 f( ?- ]2 |# V. f
  686. /* is used to to start the AAI process.  It should be followed by                 */2 d! m! \5 _- W$ d1 ?, \
  687. /* Auto_Add_IncB.                                                                                                                *// \: ~+ v1 M  B; ~/ m1 m( Q# o
  688. /* Assumption:  Address being programmed is already erased and is NOT        */
    7 t) R7 c2 T9 ?& K  K9 _  P
  689. /*                                block protected.                                                                                */! P1 D( C7 F/ E6 J
  690. /*                                                                                                                                                */: K1 u! K5 U5 `$ `3 S- W- J# e9 r
  691. /*                                                                                                                                                */
    8 y) ?. X4 [4 D9 d3 }( i0 F' t
  692. /* Note: Only RDSR command can be executed once in AAI mode with SO          */
      k2 f% E) R4 A4 h) C7 M! b) e
  693. /*          disable to output RY/BY# status.  Use WRDI to exit AAI mode                 */* C' ^( S6 B2 Q
  694. /*         unless AAI is programming the last address or last address of                */1 q( R& l  [+ O+ m, e, ]$ k
  695. /*          unprotected block, which automatically exits AAI mode.                                */1 D1 `, \% {8 M$ b$ ?* s
  696. /*                                                                                                                                                */% K4 m' ?% f/ J. k1 a# t* n1 d
  697. /* Input:                                                                                                                                */7 |- _' v# i0 s6 a9 t$ L
  698. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    6 L: N! Q, C1 ^% `' E2 h' H7 q
  699. /*                byte1:                1st byte to be programmed                                                        */
    ! I0 g1 w% H* S% A3 e
  700. /*      byte1:                2nd byte to be programmed                                                        */, x4 G0 Z) ~' i7 t. h1 m- i
  701. /*                                                                                                                                                */2 N# ]- y2 `7 X4 R7 }" |! a) F
  702. /* Returns:                                                                                                                                */) g% Y8 j2 _' ^& g1 c
  703. /*                Nothing                                                                                                                        */6 a! A/ e0 @# x& n1 a
  704. /*                                                                                                                                                */: T& r" W; G3 S: @3 l7 t
  705. /************************************************************************// r& F, {. g$ I
  706. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2)0 {3 S: t0 c: c6 s
  707. {
    0 V' |( z! G0 t6 R" T
  708.         CE_Low();                                        /* enable device */
    . Y  O+ f2 U& q' g
  709.         Send_Byte(0xAD);                        /* send AAI command */. O$ P) H- S% e9 d1 v
  710.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */# A2 A) A3 p1 N3 d
  711.         Send_Byte(((Dst & 0xFFFF) >> 8));, z! W) }3 F4 G8 K' \* c
  712.         Send_Byte(Dst & 0xFF);' t, Q/ o! Q( o; Z+ _8 F. r
  713.         Send_Byte(byte1);                        /* send 1st byte to be programmed */       
      \2 m% ?- J! x6 Y' Y% R/ X
  714.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */: I" f- S+ a1 e' \' f2 Z4 J& J
  715.         CE_High();                                        /* disable device */
    * v. c1 H% H0 b; u6 Q5 a, V& c
  716. }6 C* v7 k/ w: v# Z
  717. ; X3 a5 f  j1 k: ?
  718. /************************************************************************/9 w' p' `- ^5 U
  719. /* PROCEDURE:        Auto_Add_IncB                                                                                        */
    " U4 a$ a7 T! f. D$ X
  720. /*                                                                                                                                                */$ v0 V- h5 e+ b0 u. P9 M; S  b
  721. /* This procedure programs consecutive addresses of 2 bytes of data into*/+ X/ h; V+ |1 _: X+ T7 r
  722. /* the device:  1st data byte will be programmed into the initial                 */
    ; g+ V( H5 ?2 y# E5 u% P  V
  723. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */+ z5 w# K( [8 z6 X' F
  724. /* programmed into initial address [A23-A1] and with A0  = 1.    This          */
    , Q7 S: w. h: ^1 [6 o1 j( d# U$ n
  725. /* is used after Auto_Address_IncA.                                                                                */
      @: D1 ?- L' S9 {& \
  726. /* Assumption:  Address being programmed is already erased and is NOT        */
    4 G9 d* F' ?' a/ c
  727. /*                                block protected.                                                                                */& i% k0 j* T+ F' D. E  B8 g
  728. /*                                                                                                                                                */& E5 x2 ~; G7 @# G
  729. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    ' _5 M. u5 Y9 ~5 ]
  730. /*         with SO enabled as RY/BY# status.  When the device is busy                 */0 g5 c9 Y: i; J+ f8 ^" ~
  731. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */3 h) ?8 V( }! x$ _
  732. /*          to exit AAI mode unless AAI is programming the last address or                */; x. _9 V* k+ m
  733. /*         last address of unprotected block, which automatically exits                 */
    5 c/ K& ]3 l9 u4 M2 l) X: c$ E0 @/ _
  734. /*         AAI mode.                                                                                                                        */
    0 m; |$ N0 ?$ B* k' q5 [
  735. /*                                                                                                                                                */9 t5 E- g- J* W2 S+ M' J) s
  736. /* Input:                                                                                                                                */" ^  ~# h% i, P
  737. /*                                                                                                                                                */8 w. \/ y' _: ]; Z
  738. /*                byte1:                1st byte to be programmed                                                        *// V, v* M( [# d8 T2 u2 X
  739. /*                byte2:                2nd byte to be programmed                                                        */* g5 m0 ]& ^- L3 t$ M
  740. /*                                                                                                                                      */
    ) v) j) J( Q6 |1 D0 R0 Q
  741. /*                                                                                                                                                */: V$ u+ E+ n$ Y/ X* a5 m2 c& e
  742. /* Returns:                                                                                                                                */2 p* {7 b1 {* ]) N
  743. /*                Nothing                                                                                                                        */
    : F, M1 q& @# z( l, Y3 z
  744. /*                                                                                                                                                */
    2 I& N- t% f/ x- a
  745. /************************************************************************/
    " i5 U3 s' n2 X3 T# N) y* _/ n
  746. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2)' D5 w# T, n0 F8 _& P& e
  747. {4 B4 ~6 ^7 `# D  C$ B0 m; ]- I; M5 u
  748.         CE_Low();                                        /* enable device */" P* E" t$ W+ C
  749.         Send_Byte(0xAD);                        /* send AAI command */
    3 N+ _4 \! k, d$ {5 \* j
  750.         Send_Byte(byte1);                        /* send 1st byte to be programmed */
    / w. O; n: r- G- X9 D+ G, b, B
  751.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */. i$ e0 O! X! ]- b* v
  752.         CE_High();                                        /* disable device */
    / I  P* i) Z( x$ H; U" ]
  753. }1 e7 C- ]1 Z4 w- w1 P3 i6 U1 c& G+ T

  754. 1 D% D6 K, L1 W' n' ^
  755. /************************************************************************/
    9 c) m  z5 _& F; L# r. A
  756. /* PROCEDURE:        Auto_Add_IncA_EBSY                                                                                */" K; u1 Z, r/ b  w8 y# c& A
  757. /*                                                                                                                                                */
    ! X* S$ O) K7 E9 t- Y
  758. /* This procedure is the same as procedure Auto_Add_IncA except that it */0 B" Y; d1 w" f5 d. z
  759. /* uses EBSY and Poll_SO functions to check for RY/BY. It programs                 */- N" O( f% c' Q- u
  760. /* consecutive addresses of the device.  The 1st data byte will be                 */
    9 l5 @! z6 O: O2 U2 L: n7 b$ L
  761. /* programmed into the initial address [A23-A1] and with A0 = 0.  The         */# ?+ C) X1 ]# z3 \/ A; S5 ~
  762. /* 2nd data byte will be programmed into initial address [A23-A1] and         */
      W2 E" f8 h! v% i. v
  763. /* with A0  = 1.  This is used to to start the AAI process.  It should  */& {! `2 Y* J/ u! s  d# g
  764. /* be followed by Auto_Add_IncB_EBSY.                                                                        */: C9 e* g0 I# d, e
  765. /* Assumption:  Address being programmed is already erased and is NOT        */
    1 a# h0 B% R7 K/ e* F) m% s
  766. /*                                block protected.                                                                                */
      f( f" a% j) c, Z: B
  767. /*                                                                                                                                                */
    6 z- w# q. u+ X+ G
  768. /*                                                                                                                                                */( q' p, W9 q3 R6 I4 V
  769. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    4 l) v+ @3 X: N) S7 H/ Z! ?6 j2 P
  770. /*         with SO enabled as RY/BY# status.  When the device is busy                 */* f, d3 F1 s) K
  771. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */
    " G: b9 y1 t+ E9 i, |! e: m
  772. /*          to exit AAI mode unless AAI is programming the last address or                */2 X7 h+ K) B$ I( v; C
  773. /*         last address of unprotected block, which automatically exits                 */
    6 P& D6 G$ i* m! A, @# S! E
  774. /*         AAI mode.                                                                                                                        */
    5 D5 u& t) N7 S5 k1 ^3 N) W! y- k
  775. /*                                                                                                                                                */* Q* S* R0 A! t! U  j7 d& D  v8 \
  776. /* Input:                                                                                                                                */
    9 ]  U  A, s' ^, [) q! {3 v0 x
  777. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */7 S0 s* S' p4 h
  778. /*                byte1:                1st byte to be programmed                                                        */
    6 V6 E; ?3 m' j; `8 ~
  779. /*      byte1:                2nd byte to be programmed                                                        */) B7 N1 D+ X9 _: O: o# {
  780. /*                                                                                                                                                */
    & G$ q. L1 T& L8 Z) I- M# k, q- _) T
  781. /* Returns:                                                                                                                                */
    & h' K* O& p# {8 @; ]+ L
  782. /*                Nothing                                                                                                                        */+ [* V2 M2 X9 U1 h" T
  783. /*                                                                                                                                                */* O7 i$ V: _- q, `( S. h, _
  784. /************************************************************************/
    ' i: O! J' h9 j' m
  785. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)
    % L9 v0 E: j6 m: \! g
  786. {* }0 u) |5 a" Z3 s
  787.         EBSY();                                                /* enable RY/BY# status for SO in AAI */        8 s! d; J/ c8 {( c5 W  J( @
  788. ) g" X  p/ f, e
  789.         CE_Low();                                        /* enable device */
    9 a8 u8 N/ d8 N6 t' S' m
  790.         Send_Byte(0xAD);                        /* send AAI command */
    9 B. D, Z4 W7 ]1 f- o
  791.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    . ]0 _% F/ T1 \' y
  792.         Send_Byte(((Dst & 0xFFFF) >> 8));
    ) {) x6 k% m0 H/ P1 p3 s  n
  793.         Send_Byte(Dst & 0xFF);& P7 R2 v  U3 I9 Y: `
  794.         Send_Byte(byte1);                        /* send 1st byte to be programmed */        ' L0 ]- p: p5 R) {/ p- @" D4 j
  795.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */
    0 V3 r, U  S8 `  _8 o2 `
  796.         CE_High();                                        /* disable device */
    - ~0 G  i& W/ c
  797.         ) g' c# X& k1 ~1 h- X
  798.         Poll_SO();                                        /* polls RY/BY# using SO line */7 ~  B6 B( v/ \
  799. 2 b7 }# N4 Y2 C" w, ^4 N( N) N
  800. }& J" T* k, a# Z( k. [

  801. 5 U4 K, k7 j& p) w2 U* N9 M9 R# o
  802. /************************************************************************/
    9 E; H2 A1 A# m3 q% ?
  803. /* PROCEDURE:        Auto_Add_IncB_EBSY                                                                                */% y# H& {* w3 @8 ?$ m
  804. /*                                                                                                                                                */
    ; O% R' X0 z3 @) H  F
  805. /* This procedure is the same as Auto_Add_IncB except that it uses                 */
    / ?- o- d2 Q( `# N
  806. /* Poll_SO to poll for RY/BY#.  It demonstrate on how to use DBSY after        *// ^, z$ K4 I3 K  B# K
  807. /* AAI programmming is completed.  It programs consecutive addresses of */
    8 J  \, }% J. Q
  808. /* the device.  The 1st data byte will be programmed into the initial   */
    # B& z) E, i" t8 A
  809. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be                        */& e9 g; V2 g) T. k: r7 k7 g
  810. /* programmed into initial address [A23-A1] and with A0  = 1.  This is         */
    : T: Y# f. q. O% C
  811. /* used after Auto_Address_IncA.                                                                                */
    4 c8 R4 W/ j7 `
  812. /* Assumption:  Address being programmed is already erased and is NOT        */: H7 ]6 c3 E' o- L
  813. /*                                block protected.                                                                                */
    ( O: {0 C- k5 r! u3 t
  814. /*                                                                                                                                                */
    3 l( {- |& p$ g9 Y4 B& f7 T1 B. `
  815. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    0 `: R  ]2 G. g8 x' v5 S
  816. /*         with SO enabled as RY/BY# status.  When the device is busy,                 */0 w3 k' `' j, q  X3 N" m6 a
  817. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */
    9 w3 {, d7 u7 K: a. `
  818. /*          to exit AAI mode unless AAI is programming the last address or                */6 [/ _" u7 I' N6 U2 H- ?( Y5 @; A8 f
  819. /*         last address of unprotected block, which automatically exits                 */
    + R1 K6 Z9 ~# x
  820. /*         AAI mode.                                                                                                                        */  x6 Y7 p4 }, F$ p2 [
  821. /*                                                                                                                                                */
    $ l0 s/ Q% Y8 U' d+ `
  822. /* Input:                                                                                                                                */
    + X5 Y: l5 n5 }7 J+ [2 \
  823. /*                                                                                                                                                */: h6 o5 ?1 E* i0 k9 ?( j
  824. /*                byte1:                1st byte to be programmed                                                        */
    ' E, i6 z+ A8 P9 a
  825. /*                byte2:                2nd byte to be programmed                                                        */
    ) h% X4 S/ }5 O; g8 I& Q2 ]$ l9 o
  826. /*                                                                                                                                      */
    - s- L6 x# N  f8 k
  827. /*                                                                                                                                                */
    ! Z8 H4 s3 J9 i* |* o. q- j
  828. /* Returns:                                                                                                                                */
    6 a4 L7 j2 {% v+ `
  829. /*                Nothing                                                                                                                        */
    9 M5 c8 v/ }1 v5 O- f
  830. /*                                                                                                                                                */# G9 V: O, Y3 g; S! m
  831. /************************************************************************/5 v. e" |! ?: h
  832. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)
    # U# o3 `) W9 `
  833. {- @2 X: w/ X  R
  834.         CE_Low();                                /* enable device */
    7 ^- ?: W2 {4 C' m) @$ F
  835.         Send_Byte(0xAD);                /* send AAI command */1 F6 G8 G  D; f( C8 j# p
  836.         Send_Byte(byte1);                /* send 1st byte to be programmed */( x* l; U0 v0 D) [. q% p
  837.         Send_Byte(byte2);                /* send 2nd byte to be programmed */
    7 `  h& ]3 x) O: C& r3 v
  838.         CE_High();                                /* disable device */% }6 S+ V7 I3 o2 }
  839. ' h: u" }  Q# I3 B- F, \3 o* Z
  840.         Poll_SO();                                /* polls RY/BY# using SO line */$ A) Q- X% ^8 X1 [% v5 x; F% I$ C0 f
  841. 0 z" f7 e/ m' Z( [9 z- i! n2 X
  842.         WRDI();                                 /* Exit AAI before executing DBSY */6 e3 z8 N' D0 G/ O9 E
  843.         DBSY();                                        /* disable SO as RY/BY# output if in AAI */6 K# C9 M5 i- J8 d8 E) v  I
  844. }
    8 A! z/ U( ?+ A, L
  845. 4 X/ A' R" z  g
  846. /************************************************************************/
    + d8 i; U  _$ ?& U! b( n3 ^
  847. /* PROCEDURE: Chip_Erase                                                                                                *// @8 s& |1 c! }  h
  848. /*                                                                                                                                                */8 i5 O7 L0 I8 u7 r5 F
  849. /* This procedure erases the entire Chip.                                                                */
      H9 X% w$ g' Z0 [
  850. /*                                                                                                                                                */- [5 q& a7 B5 u$ f8 f: ?+ W
  851. /* Input:                                                                                                                                */) s( b" T2 W' H- ]
  852. /*                None                                                                                                                        */
    ) O7 M# G# F% u4 {7 M* I+ `
  853. /*                                                                                                                                                */4 M+ k- O, T. a/ d
  854. /* Returns:                                                                                                                                */
    * v  H$ u/ [, M; y
  855. /*                Nothing                                                                                                                        */
    4 X5 A/ F0 \8 X! f3 F- S
  856. /************************************************************************/
    6 Q* I. F) A1 a0 O: _; k$ V
  857. void Chip_Erase()
    4 J. ?- I! \. p. D2 s- T/ L( W
  858. {                                                0 g8 v1 P% U8 K" V  z
  859.         CE_Low();                                /* enable device */
    + m1 k/ t. e+ X! o" w
  860.         Send_Byte(0x60);                /* send Chip Erase command (60h or C7h) */) E+ E* s* x1 {
  861.         CE_High();                                /* disable device */
    - G3 J+ f; u1 F+ X2 P# T
  862. }3 J. R6 x' T" S9 n. G+ t3 S
  863. 1 L2 U1 s& T. X5 T
  864. /************************************************************************/
    9 L: H( ?8 K6 }1 ~* x
  865. /* PROCEDURE: Sector_Erase                                                                                                */
    ! T3 e9 [9 x' e( l) [. R
  866. /*                                                                                                                                                */
    " m' ^* q" J  A& A- h
  867. /* This procedure Sector Erases the Chip.                                                                */
    * O$ W/ w8 r) I" x0 O+ z' w" J/ b
  868. /*                                                                                                                                                */
    % P. a6 T  _4 T) p" }
  869. /* Input:                                                                                                                                */& }* M* I) q3 A
  870. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    # X' Q, y" ?/ @
  871. /*                                                                                                                                                */
    & y" {( E$ c  f6 n$ K
  872. /* Returns:                                                                                                                                */" p. q& ]# k0 x5 [  U- v  K
  873. /*                Nothing                                                                                                                        */$ h+ m3 j2 J# b2 B8 t# q
  874. /************************************************************************/* j: }( O2 A3 v; q
  875. void Sector_Erase(unsigned long Dst)
    3 f4 V0 ~& m1 ?6 J7 o5 f
  876. {$ m; |. O- c6 z) e

  877. 2 J5 @  b( A3 v5 A/ D2 C

  878. . O! k1 S! i9 `
  879.         CE_Low();                                        /* enable device */
    & j. g/ _1 m, d9 e+ U! L) T$ a* l
  880.         Send_Byte(0x20);                        /* send Sector Erase command */) d( z3 C! s' ^& f4 x- \
  881.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */7 U3 k# y- }4 ?6 |
  882.         Send_Byte(((Dst & 0xFFFF) >> 8));
      t  |+ g9 K# ^" }( P* c
  883.         Send_Byte(Dst & 0xFF);$ _( N' }) m: X( E, d; M+ h
  884.         CE_High();                                        /* disable device */
    . R9 h; O- O2 e5 P! M8 x. k; a
  885. }       
    2 E6 i0 p" q. X$ r( z
  886. 4 P2 b3 y# P" P
  887. /************************************************************************/" J3 a" a; B( B
  888. /* PROCEDURE: Block_Erase_32K                                                                                        */
    6 [' @. ~4 l( T
  889. /*                                                                                                                                                */  ~0 i% M! v/ T+ E. e  g
  890. /* This procedure Block Erases 32 KByte of the Chip.                                        */
    % m+ k4 Y' z9 f! g! x$ {  ?
  891. /*                                                                                                                                                */
      E& o, F: [5 Q3 W& N
  892. /* Input:                                                                                                                                */+ s0 p1 M8 d! P! I4 y# n
  893. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */1 C( F8 l/ M; t! |4 Z
  894. /*                                                                                                                                                */
    # \% Y( v1 |$ |: x
  895. /* Returns:                                                                                                                                */
    ( Q& _8 G& o9 T
  896. /*                Nothing                                                                                                                        */  `: ]) H+ J) s! V+ C
  897. /************************************************************************/, l9 P; Q& r+ P( [& b) B& R
  898. void Block_Erase_32K(unsigned long Dst)
    7 [  z5 n8 M; ]. w( R
  899. {' Z. A1 K2 m9 C, x* }
  900.         CE_Low();                                        /* enable device */, r; w( M4 H/ V6 K3 u6 H6 e3 p
  901.         Send_Byte(0x52);                        /* send 32 KByte Block Erase command */
    3 M; [  X4 b# I0 T/ M6 ^  n' b
  902.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    6 B. q6 I9 _7 K+ L  z( n4 E
  903.         Send_Byte(((Dst & 0xFFFF) >> 8));
    - c. b+ C) S$ Y& o( ^
  904.         Send_Byte(Dst & 0xFF);, W2 b/ ~; A7 f4 G7 \* j( V2 k
  905.         CE_High();                                        /* disable device */! H5 I' ]' ?5 P% j* v1 g) I* G& e' w
  906. }3 c1 F) @/ k# H; }( I4 E0 w

  907. $ s, @, y& k! ^. _5 }5 s7 \9 `! g
  908. /************************************************************************/
    ; S+ d- @3 s$ O$ @4 S% j
  909. /* PROCEDURE: Block_Erase_64K                                                                                        */
    ( J+ j/ u6 H. g/ E' Y: H
  910. /*                                                                                                                                                */* a) p" ], Y8 u  [% ^- N6 K& C
  911. /* This procedure Block Erases 64 KByte of the Chip.                                        */- a% E4 n( {+ W5 g  g' G! N& i
  912. /*                                                                                                                                                */
    6 Y& r/ {! G! ?/ Q8 ]. h
  913. /* Input:                                                                                                                                */3 g& _; k& w. p) |1 F
  914. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    : l. j8 h, G. {$ ?  o
  915. /*                                                                                                                                                */5 [* c* ~& o: Q; v4 B
  916. /* Returns:                                                                                                                                */
    # }) U5 B, ]! D" F$ r% P
  917. /*                Nothing                                                                                                                        *// h$ V- T% W/ c. n1 A9 x
  918. /************************************************************************/
    : o; w$ r% v" V3 O% I0 l
  919. void Block_Erase_64K(unsigned long Dst)& y# J. e. k2 q9 }; i) `: G
  920. {* G4 R5 n7 @7 f$ e4 L" ]! p
  921.         CE_Low();                                        /* enable device */+ [7 h8 U$ q7 Q3 E: E
  922.         Send_Byte(0xD8);                        /* send 64KByte Block Erase command */
    7 N+ N0 A/ W5 P: T  n/ N
  923.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */# w6 D4 {  k8 `6 x- j5 c$ g% p: }
  924.         Send_Byte(((Dst & 0xFFFF) >> 8));+ N- g7 T- q; v5 [% W0 I
  925.         Send_Byte(Dst & 0xFF);7 y$ P, c$ T9 q, r
  926.         CE_High();                                        /* disable device */
    , f3 U! s" x* w% D2 e% ^
  927. }& b1 ^! C! r; H2 b6 z

  928. ! @& }3 _2 |1 _/ A: G7 f% C3 T
  929. /************************************************************************/
    6 B" E! |9 U/ d3 r; z4 r
  930. /* PROCEDURE: Wait_Busy                                                                                                        */
    % Y7 J" N! A5 o  r. ~+ ~7 {' g
  931. /*                                                                                                                                                */3 z; Y; A9 V7 x8 M" g
  932. /* This procedure waits until device is no longer busy (can be used by        */
    8 K4 P1 |) t9 c7 n
  933. /* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase).                                */
    5 K8 m. c8 i$ y4 r" `
  934. /*                                                                                                                                                */
    ; R) P; I/ ]7 C
  935. /* Input:                                                                                                                                */
    % q" W- m4 D, Y% X: g# M9 k
  936. /*                None                                                                                                                        */# F; t1 N  ~7 l+ T
  937. /*                                                                                                                                                */4 B9 }- i; G# H& l
  938. /* Returns:                                                                                                                                */5 n1 x. P/ Q* b( }$ I* b) |
  939. /*                Nothing                                                                                                                        */
    6 Y* @/ X/ P* F( G6 \, }; n  `. P
  940. /************************************************************************/; A/ e# q" O; V! d
  941. void Wait_Busy()* \- e+ s. ]9 {- o. ~1 Q# ?
  942. {* N' }' r* O/ @7 O" ?' y0 |
  943.         while (Read_Status_Register() == 0x03)        /* waste time until not busy */8 J5 z" w4 r; A* C/ A. V/ B
  944.                 Read_Status_Register();/ w  C) X9 D3 Z1 U: w
  945. }
      |' p$ K# S7 Q; A7 m
  946. # a5 ]* h4 u: Q, W
  947. /************************************************************************/- T# ^" c. `- W0 C# j* `2 _! b3 E
  948. /* PROCEDURE: Wait_Busy_AAI                                                                                                */
    $ b! ~: |3 G+ \* ^6 ~; g. n
  949. /*                                                                                                                                                */- X# N3 j  C# N. }
  950. /* This procedure waits until device is no longer busy for AAI mode.        */, k) S( Q6 x1 L# @) I0 T
  951. /*                                                                                                                                                */
    - `3 `9 q5 i& Q$ M
  952. /* Input:                                                                                                                                */
    , i/ X9 ^4 Z- W% |5 k
  953. /*                None                                                                                                                        */
    ; W, ]  b& G7 m
  954. /*                                                                                                                                                */
    ) k$ V/ g2 j/ B& T; F% ^
  955. /* Returns:                                                                                                                                */
    $ m, Y# A/ A* O3 t
  956. /*                Nothing                                                                                                                        */
    : V) s9 f% {3 d, O$ d  [
  957. /************************************************************************/
    ( I0 N+ S: a2 s- ?" p' O
  958. void Wait_Busy_AAI()6 P9 r8 q, s9 o  }- O
  959. {3 V4 O0 B7 K5 V: y) S
  960.         while (Read_Status_Register() == 0x43)        /* waste time until not busy */
    8 W# m8 [9 ?8 V9 Z" ?
  961.                 Read_Status_Register();
    9 R# ^  c+ E9 M. K5 t7 F! S
  962. }; Z# E, U4 P7 U, ^: G; p

  963. : l" L. H6 F" ^
  964. /************************************************************************/
    . z# E5 i, }7 [) j  C# i' `4 u( X
  965. /* PROCEDURE: WREN_Check                                                                                                */
    9 U/ g) m% `% e* f# j
  966. /*                                                                                                                                                */
    $ a6 [' q8 H  N% f/ d& l5 o# ^
  967. /* This procedure checks to see if WEL bit set before program/erase.        */
    - C$ ?: w. B( b) \  ?
  968. /*                                                                                                                                                */  C: S3 d) |* Z3 \! K
  969. /* Input:                                                                                                                                */
    : ?, ~7 E$ E0 a: p4 N! ]
  970. /*                None                                                                                                                        */
    $ s( v' N. D  m" V& s+ A
  971. /*                                                                                                                                                */3 Z+ w  N- ?3 Z5 e0 ^: X# S) E
  972. /* Returns:                                                                                                                                */
    . d3 t; K/ c* \
  973. /*                Nothing                                                                                                                        */# W  ]" i  y/ C$ m; U' P6 u* w
  974. /************************************************************************/
    + T; m' C3 Q" u! J# ?2 m2 h8 e
  975. void WREN_Check()
    3 S. [; X) b- s  Q- m3 k
  976. {4 `9 z& U3 O! D& w/ G  q
  977.         unsigned char byte;5 S5 P5 v% M8 o( S: T" w! i
  978.         byte = Read_Status_Register();        /* read the status register */$ x6 l7 j5 I  J' H" L
  979.         if (byte != 0x02)                /* verify that WEL bit is set */, y! j6 }8 x4 m" l3 D
  980.         {1 v" S4 T" Z! C. |0 ~- \! Z* E
  981.                 while(1)
    , G2 p/ g$ }  `  s0 k! v% U4 K
  982.                         /* add source code or statements for this file */6 H: d2 f5 y2 v
  983.                         /* to compile                                  */
    9 B& y# r* H7 v- Z$ K3 j" ^8 E
  984.                         /* i.e. option: insert a display to view error on LED? */
    8 x! M$ j5 x: S/ y1 H
  985.                  % v+ A8 n. r8 u+ i: u/ V
  986.         }
    2 I( m0 F. }" W+ a
  987. }4 j7 t4 ~$ ~6 {; k1 u& ?

  988. ' |3 ^- k; u* G. c6 B; H& G
  989. /************************************************************************/
    6 `5 c) o4 V7 m  o  S/ b* i! ]
  990. /* PROCEDURE: WREN_AAI_Check                                                                                        */$ ?0 i& Q. d* P# k( v
  991. /*                                                                                                                                                */! f; o2 d6 R6 R* l* Z( ]; ]
  992. /* This procedure checks for AAI and WEL bit once in AAI mode.                        */
    * S: g& b4 ^3 e: {. g* n8 q1 w7 A1 p* o& P
  993. /*                                                                                                                                                *// H8 T3 B" h4 z: k6 m
  994. /* Input:                                                                                                                                */
    / I; Z( g. h$ B) k, x4 X) g
  995. /*                None                                                                                                                        */
    4 q0 h! `  O% T  s7 w
  996. /*                                                                                                                                                */1 }# @: K" `: Z. ~
  997. /* Returns:                                                                                                                                */: L( p. w% `/ a) m1 x* D
  998. /*                Nothing                                                                                                                        */
    * z$ n0 F6 d! S* o, _, ~* o9 @
  999. /************************************************************************/2 B2 c3 g, X+ R8 W& }
  1000. void WREN_AAI_Check()+ H$ L9 W# i; n9 @8 E0 T( u
  1001. {
    2 w$ ?2 V6 B; Y- ]2 l# O
  1002.         unsigned char byte;
    ; a- c. y0 ~6 T, |. R" C& n) f
  1003.         byte = Read_Status_Register();        /* read the status register */
      G, f$ w( U7 U
  1004.         if (byte != 0x42)                /* verify that AAI and WEL bit is set */
    * i( ~0 t' S( h1 y7 B! b  E2 k
  1005.         {; d! e- S# y0 R7 f
  1006.                 while(1)               
    , b& s: \; I; I! u1 `" \
  1007.                         /* add source code or statements for this file */
    # a5 K* i/ K: s! ?! q8 V2 q
  1008.                         /* to compile                                  */
    ; U" S2 z$ v+ S* a- S( a
  1009.                         /* i.e. option: insert a display to view error on LED? */
    : f: G  O/ Q9 L

  1010. 5 d" _6 h+ k, L4 N7 Y% h" e7 ~/ f
  1011.         }
    , o3 O% }$ L" h, p2 f
  1012. }- u: Q  U, ?9 {6 E* N

  1013. - t+ t* H0 K; m6 R
  1014. /************************************************************************/! p$ x7 S6 F5 n" O3 H
  1015. /* PROCEDURE: Verify                                                                                                        */* s1 ~+ f' r' r# Z
  1016. /*                                                                                                                                                */1 z, F, s9 p' X3 {9 g5 k; K1 s
  1017. /* This procedure checks to see if the correct byte has be read.                */
    / N4 Z* U& h2 |! `
  1018. /*                                                                                                                                                */
    . x# b0 p$ ^4 I* D4 u( I7 O0 _
  1019. /* Input:                                                                                                                                */" N, j$ i" g7 M1 ~7 G
  1020. /*                byte:                byte read                                                                                        */
    3 F( ^# S# e# q* b: ]$ j3 g
  1021. /*                cor_byte:        correct_byte that should be read                                        */
    5 ?; D" R- d6 U
  1022. /*                                                                                                                                                */
    ) K& a3 E& m( Q  t
  1023. /* Returns:                                                                                                                                */- _6 r1 C' [7 \$ q
  1024. /*                Nothing                                                                                                                        */
    6 g/ J( W) L5 t, G
  1025. /************************************************************************/
    ( j+ Q$ @- w$ X: e: g7 p+ x+ I
  1026. void Verify(unsigned char byte, unsigned char cor_byte)
    % i/ j9 j8 r+ @- B0 I0 O
  1027. {
    + o# P; j# b! H! m8 f; w/ {& C6 @
  1028.         if (byte != cor_byte)
    ; u, ~  |7 Z6 Q( _
  1029.         {+ o' ]; f% M' K7 H8 b5 E: |" w
  1030.                 while(1)7 D5 f7 j$ [$ i9 ?8 h
  1031.                         /* add source code or statement for this file */2 j- v% T% l- Z5 V8 D  g
  1032.                         /* to compile                                  */, ^+ A  T- K+ R. O
  1033.                         /* i.e. option: insert a display to view error on LED? */: \* k; I  K% |/ R
  1034.                
    1 H7 M- ?5 s8 D( L7 o
  1035.         }' L; W5 h/ R, _
  1036. }
    " R! t0 m/ t; j! `

  1037. 3 f: }& a+ \' Q, Z& ~, w  s

  1038. 4 B! c0 {1 y; |  V! _! e
  1039. int main()
    0 o# U" Y1 N3 k2 g3 m+ M5 A
  1040. {
    " ~: p( a' V$ u

  1041. 3 F; N4 w, e: u2 {- V+ {. n: S
  1042. return 0;* W; x7 h2 x. T7 B4 E" a* K
  1043. }
复制代码
发表于 2007-12-11 18:30:23 | 显示全部楼层
老大:$ j) t- j# k. {- z; Q9 v/ P) Q
   main()8 _8 e! L) c! L
   里面怎么是空的呢?# O. M, i8 X& I* v5 ]/ n: o
   发一份给我吧; w  ]( X4 J( [8 Y- m" X
mail:luyijun2005@hotmail.com
$ X1 S: _3 C; P1 [咯。。。。
回复

使用道具 举报

 楼主| 发表于 2007-12-11 19:37:35 | 显示全部楼层
本部分就是如此,它提供的是方法,并不是给你拿来编译的.你要main函数能用来干什么? 为什么不看看 Byte_Program...等函数?
回复

使用道具 举报

发表于 2008-1-8 17:42:00 | 显示全部楼层
如获至宝!请问哪里能找到SPI的官方spec(我不是指flash的datasheet)?网上只能找到些片断...管理员是否可以上传spi spec至本站?
回复

使用道具 举报

发表于 2008-1-8 17:42:29 | 显示全部楼层
另外请问:EC使用SPI flash的时候,EC firmware是直接在flash上运行吗?还是dump到EC内部的ram运行?直接在flash上运行会不会速度不够快?因为SPI是串行的,还要过转换才能得到指令阿,然后MCU才能执行。  T4 ~, e- l5 ?' T
6 ]8 r0 G1 X/ E" \% @) @! c; a
[ 本帖最后由 screw 于 2008-1-8 17:46 编辑 ]
回复

使用道具 举报

发表于 2008-1-10 09:20:46 | 显示全部楼层
感觉有些冷清啊。不知道现在OEM一般使用多大的flash?
回复

使用道具 举报

 楼主| 发表于 2008-1-10 17:30:38 | 显示全部楼层
每个FLASHROM的SPI协义部分几乎都在自己的DataSheet(DS)里有。
* H+ j; ?, {8 C# j" f& L/ b  dEC的代码在哪跑,你看DS的说明,每个EC都不同的。
7 ~# a) Z+ T! o  _# ]OEM用多大的FLASH,是由OEM决定的。或者你去各计算机厂商的网站上看看他们BIOS下载的文件有多大不就知道了?
3 t/ G/ E$ }1 B上面几个问题是你没看任何东西而白问。
$ H4 ~# W2 W$ m" F7 L" z* y7 R
6 ?. h( T# g0 J& e至于冷清,那是一定的。中国大陆本来就没多少静下心来做技术的。请问一下,你有静下心来看过spec了么?hoho...
回复

使用道具 举报

发表于 2008-1-11 18:49:08 | 显示全部楼层
该怎么说呢,我是抱着很诚恳的态度来问问题的。上面我问出来的问题都是经过认真思考才问的。您站上贴出来的跟EC有关的spec我都看多,而且是很多遍(ACPI不是全部章节都看,因为我是hw)。EC的spec我也看多很多家,因为我们要做EC chip。楼主“上面几个问题是你没看任何东西而白问。”“请问一下,你有静下心来看过spec了么?”这个结论未免武断。. M& O/ x: E5 a. A0 d" {0 m
% W0 ?5 e! x9 m1 Y& a' _
关于SPI flash对SPI接口的定义,我当然知道各家spec里面都有提到,但是我要知道如何才是通用的,我们不是只要支持一款就可以。所以我才会问SPI是否有官方spec。您也知道,做产品是一定要符合工业标准的!
; R; D. v# z- e0 z9 t4 D& Y7 Z) Q. Y( w% Q6 S! T  \0 V$ W# K
关于EC firmware在哪里运行,除了ns有用内部flash的以外,基本都说是在flash上直接跑,并行的flash不会有问题,但是串行的flash速度可能就是问题,因此我会问到“EC firmware是直接在flash上运行吗?还是dump到EC内部的ram运行?直接在flash上运行会不会速度不够快?因为SPI是串行的,还要过转换才能得到指令阿,然后MCU才能执行。”! n$ ^& \* l" }. I" a

: N; A5 T7 \, u7 ~7 I1 t# _关于flash的大小,我当然知道是OEM定义,所以我才问“OEM一般使用多大的flash?”。因为我猜想您应该在BIOS厂家做过,所以想问一下。何况Flash的大小跟BIOS code的大小不一定等价啊.... @- ?& k1 `+ U: |

4 [% ^! |% d# n+ f$ e1 Z- g不管怎么说,多谢。
回复

使用道具 举报

发表于 2008-1-11 18:55:40 | 显示全部楼层
我是很希望能在这里跟懂EC的人多交流的...国内弄EC的似乎不是太多
回复

使用道具 举报

发表于 2009-7-3 12:14:41 | 显示全部楼层
楼上这位前辈与我目前遇到的问题一样" R/ i: P5 J+ o( z# s- q! X
似乎要把SPI能support 到最大,这EC chip应该有好卖点- u, g& T* u& ?/ m1 Y1 m
BIOS功能要不要强大,也就决定了SPI Flach的大小
) n3 H2 Q4 Z& @% L4 t我是这么想的~让OEM去决定要挂多大!
- T8 o3 O1 T" O) ]- B7 \) B: y如果我司有BIOS工程师就好了~哈7 K3 B) f& {3 p
WPCE775应该算很新的东西,来看它支持到多大?) d9 n5 q$ O: |8 V7 p5 M$ Y

3 D6 ^# X3 _+ {/ e1 ]另外,我觉得好多人都说会抢BUS,那肯定EC也是经过SPI 去fetch code来执行,但应该不用解到内存,因为8051的内存只做128byte
0 D% Q0 b! @" ~% W* W6 C其它2K byte是放在SPI flash上(ENE),不会多花时间去存放,然后再decode一次执行代码.9 I9 Q* S. G8 ~7 l. U
* n; X" m, Z' u0 |& Z& C
这份driver收下~希望以后有用到6 B! L5 E7 [7 B) A
谢谢bini大大
/ D1 D. q! }) ~" P# Y5 Q# V9 i/ f- N9 i5 J$ E: `2 E$ @4 g8 ~+ J
很新很新的新手,如有错误请指正 (准备看第二家的EC SPEC)
回复

使用道具 举报

发表于 2009-7-18 15:16:34 | 显示全部楼层
我也有份汇编的DOS下的烧写代码,SST 1MB的 flash可以用。我不知道为什么AFUDOS为什么不能工作,AMI好象没有发送94 CMD下来,AFUDOS直接就说不支持。搞的下BIOS非要自己写个程序,烦的很啊。
回复

使用道具 举报

发表于 2009-8-13 10:59:30 | 显示全部楼层
前端时间小弟也在windows系统下写了一个并口到SST25VF080B的烧写程序......
回复

使用道具 举报

发表于 2009-8-17 16:47:36 | 显示全部楼层

这个函数看不懂Poll_SO()

void Poll_SO(). s. y, H4 K2 z/ ^
{0 |: ~7 t3 y, d! O: X1 `% z$ Q+ B
        unsigned char temp = 0;  ]+ K3 B$ Y, v$ g& \' K" ]" T+ F( W
        CE_Low();
) R) T- R$ J; |    while (temp == 0x00)        /* waste time until not busy */9 O* y" z. U1 F2 @$ i. Q- F
                temp = SO;; r& R) C+ h: Z7 s0 z
        CE_High();) t4 \" ~* I+ F  g# R! {
}
回复

使用道具 举报

发表于 2009-8-17 17:00:56 | 显示全部楼层
void Send_Byte(unsigned char out)
+ u! ^4 C" N7 ^3 z7 q: {9 b' ?{' L: P3 u# t' Y( U& h6 k
          E, }& l+ o5 ]0 t4 {8 I
        unsigned char i = 0;' O7 @* Y0 S6 P$ d5 E& a
        for (i = 0; i < 8; i++)8 H% ^: W2 ?/ L  G% [
        {
4 n+ z5 z1 y8 I3 M+ z/ U3 T3 W8 n                $ w7 e% E( ]: }" e' w
                if ((out & 0x80) == 0x80)        /* check if MSB is high */  \  Y7 |1 Q" t' f8 J" ?9 N
                        SI = 1;
, A5 H5 W* \- ]4 S                else
  ^5 N2 n+ F7 L( {4 n1 s, c                        SI = 0;                                /* if not, set to low */) K) k1 b$ i" C; m# ]+ \& h
问              SCK = 1;                                /* toggle clock high */4 S% w/ O) V; |2 m6 o# r# e
   题            out = (out << 1);                /* shift 1 place for next bit */- Y5 e2 S7 g4 U6 J
                SCK = 0;                                /* toggle clock low */- d$ e/ T  X- y) s1 ~1 Q
        }5 ~% q1 `$ x( a3 T
}+ `9 R; v9 h3 j6 Q" _
如果将SCK = 1; out = (out << 1); 调换。会因sck置位时间过短,而出现问题吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2026-12-4 07:50 , Processed in 0.047778 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表