?? at45db.lst
字號:
C51 COMPILER V7.50 AT45DB 05/14/2008 18:26:14 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE AT45DB
OBJECT MODULE PLACED IN AT45DB.OBJ
COMPILER INVOKED BY: E:\keil\C51\BIN\C51.EXE AT45DB.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /******************************************************************************/
2 /*正常操作電壓為2.7~3.6V,實驗中發現當電壓超過4.25V后讀出的狀態字節為9A(正常 */
3 /*的狀態字節值為9D),并且讀寫數據均不準確,所以應當保證卡片的供電電壓不超過 */
4 /*4.25V。 */
5 /*SPI規范:Data is always clocked into the device on the rising edge of SCK a-*/
6 /* nd clocked out of the device on the falling edge of SCK.All instruction-*/
7 /* s,addresses and data are transferred with the most significant bit(MSB) */
8 /* first. */
9 /* 2005-06-02*/
10 /******************************************************************************/
11
12 #pragma optimize(5)
13 #include <reg52.h>
14 #include <string.h>
15 #include"charcode.h"
16 #define UCHAR unsigned char
17 #define UINT unsigned int
18
19 sbit SPI_CS = P0^1;
20 sbit SPI_SCK = P0^3;
21 sbit SPI_SO = P2^3;
22 sbit SPI_SI = P0^4;
23 sbit SPI_RES = P0^2;
24 sbit SPI_WP = P0^0;
25 sbit SPI_AY1 = P2^4;
26 sbit SPI_AY2 = P2^5;
27 sbit SPI_AY3 = P2^6;
28
29
30
31
32
33 static void delay(unsigned int s)
34 {
35 1 unsigned int i;
36 1 for(i=0; i<s; i++);
37 1 for(i=0; i<s; i++);
38 1 }
39
40
41 void init_serial(void)
42
43 {
44 1 //定時器1的工作方式2
45 1 TMOD=0x20; //裝載計數初值
46 1 TL1=0xfb;
47 1 TH1=0xfb; //采用串口工作方式1,無奇偶校驗
48 1 SCON=0x50; //串口波特率不加倍
49 1 PCON=0x00; //開總中斷,開串口中斷
50 1 TCON=0x01; //中斷設置
51 1 IE=0x90;
52 1 //啟動定時器1
53 1 TR1=1;
54 1 }
55
C51 COMPILER V7.50 AT45DB 05/14/2008 18:26:14 PAGE 2
56
57 void SendCh(unsigned char c)
58 {EA=0;
59 1 TI=0;
60 1 SBUF=c;
61 1 while(!TI);
62 1 TI=0;
63 1 EA=1;
64 1 }
65
66
67 unsigned char SPI_HostReadByte(void){
68 1 unsigned char i,rByte=0;
69 1
70 1 for(i=0;i<8;i++){
71 2 SPI_SCK=0;
72 2 SPI_SCK=1;
73 2
74 2 rByte<<=1;
75 2 rByte|=SPI_SO;
76 2 }
77 1 return rByte;
78 1 }
79 void SPI_HostWriteByte(unsigned char wByte){
80 1 unsigned char i;
81 1
82 1 for(i=0;i<8;i++){
83 2 if((wByte<<i)&0x80){SPI_SI=1;}
84 2 else{SPI_SI=0;}
85 2
86 2 SPI_SCK=0;
87 2 SPI_SCK=1;
88 2 }
89 1 }
90 /******************************************************************************/
91 /*Status Register Format: */
92 /* ----------------------------------------------------------------------- */
93 /* | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 | */
94 /* |--------|--------|--------|--------|--------|--------|--------|--------| */
95 /* |RDY/BUSY| COMP | 0 | 1 | 1 | 1 | X | X | */
96 /* ----------------------------------------------------------------------- */
97 /* bit7 - 忙標記,0為忙1為不忙。 */
98 /* 當Status Register的位0移出之后,接下來的時鐘脈沖序列將使SPI器件繼續*/
99 /* 將最新的狀態字節送出。 */
100 /* bit6 - 標記最近一次Main Memory Page和Buffer的比較結果,0相同,1不同。 */
101 /* bit5 */
102 /* bit4 */
103 /* bit3 */
104 /* bit2 - 這4位用來標記器件密度,對于AT45DB041B,這4位應該是0111,一共能標記 */
105 /* 16種不同密度的器件。 */
106 /* bit1 */
107 /* bit0 - 這2位暫時無效 */
108 /******************************************************************************/
109 unsigned char AT45DB041B_StatusRegisterRead(void){
110 1 unsigned char i;
111 1
112 1 SPI_CS=0;
113 1 SPI_HostWriteByte(0xd7);
114 1 i=SPI_HostReadByte();
115 1 SPI_CS=1;
116 1
117 1 return i;
C51 COMPILER V7.50 AT45DB 05/14/2008 18:26:14 PAGE 3
118 1 }
119 /******************************************************************************/
120 /*描述: */
121 /* When the last bit in the main memory array has been read,the device will*/
122 /* continue reading back at the beginning of the first page of memory.As w-*/
123 /* ith crossing over page boundaries,no delays will be incurred when wrapp-*/
124 /* ing around from the end of the array to the beginning of the array. */
125 /*參數: */
126 /* PA - 頁地址,0~2047 */
127 /* BFA - 指定BUFFER中的起始寫入地址 */
128 /* pHeader - 指定數據的首地址 */
129 /* len - 指定數據的長度 */
130 /******************************************************************************/
131 void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,unsigned char *pHeader,UINT len){
132 1 unsigned int i;
133 1
134 1 while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
135 1 SPI_CS=0;
136 1 SPI_HostWriteByte(0xe8);
137 1 SPI_HostWriteByte((unsigned char)(PA>>7));
138 1 SPI_HostWriteByte((unsigned char)((PA<<1)|(BFA>>8)));
139 1 SPI_HostWriteByte((unsigned char)BFA);
140 1 for(i=0;i<4;i++){SPI_HostWriteByte(0x00);}
141 1
142 1 for(i=0;i<len;i++){pHeader[i]=SPI_HostReadByte();}
143 1 SPI_CS=1;
144 1 }
145 /******************************************************************************/
146 /*描述: */
147 /* 將指定數據讀出從某個地址(0~263)開始的BUFFER中。 */
148 /*參數: */
149 /* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */
150 /* 在該指令序列中,操作碼d4H選擇BUFFER 1,d6H選擇BUFFER 2 */
151 /* BFA - BUFFER中的起始地址,0~263 */
152 /* pHeader - 待存數據的頭指針 */
153 /* len - 待存數據的長度1~264 */
154 /******************************************************************************/
155 void AT45DB041B_BufferRead(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len){
156 1 unsigned int i;
157 1
158 1 while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
159 1 SPI_CS=0;
160 1 switch(buffer){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -