?? flash.lst
字號:
C51 COMPILER V6.12 FLASH 08/20/2006 19:41:24 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE FLASH
OBJECT MODULE PLACED IN Flash.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\c51.exe Flash.c DB OE
stmt level source
*** WARNING C500 IN LINE 1 OF FLASH.C: MISSING DEVICE (SECURITY KEY NOT FOUND)
1 //頭文件
2 /////////////////////////////
3 #include "c8051F320.h"
4 #include "stdio.h"
5 ////////////////////////////////////////////////////////////////////////////////////////////////////
6 //位定義
7 sbit FLASH_WP =P2^0; //命令鎖存
8 sbit FLASH_WE =P2^1; //地址鎖存
9 sbit FLASH_ALE =P2^2; //寫保護
10 sbit FLASH_CLE =P2^3; //片選
11 sbit FLASH_CE =P2^4; //寫使能
12 sbit FLASH_RE =P2^5; //讀使能
13 sbit FLASH_RB =P2^6; //忙指示
14 sbit FLASH_SE =P2^7;
15
16 //P1口為數據口
17 //注釋掉的函數在需要時可以取掉注釋即可
18 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 //FLASH函數聲明
20 void Flash_Init(void); //FLASH初始化
21 //unsigned int Get_Flash_ID(void); //讀FLASH的ID號
22 //unsigned char Get_Flash_Status(void); //讀FLASH的狀態
23 unsigned char Flash_Erase_Block(unsigned int BlockNum); //擦除FLASH中的第BlockNum個BLOCK,擦除成功則返回1
24 void Flash_Read_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned int Dat
-a_Length);
25 //讀出第BlockNum個BLOCK中第BlockPageNum個PAGE中的內容,長度為Data_Length
26 unsigned char Flash_Write_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned
- int Data_Length);
27 //意義同上
28 void Flash_Write_Command(unsigned char command); //寫命令
29 void Flash_Write_Address(unsigned char address); //寫地址
30 void Flash_Write_Data(unsigned char num); //寫一字節數據
31 unsigned char Flash_Read_Data(void); //讀一字節數據
32
33 //void Test_Flash(void); //FLASH測試函數,首先讀取FLASH的ID號,然后寫入512字節數據,再讀出來,判斷是否正
-確
34
35 extern void Time_Delay(unsigned int time);
36 ////////////////////////////////////////////////////////////////////////////////////////////////////
37
38
39 void Flash_Init()
40 {
41 1 unsigned int i=0;
42 1 P1=0xff;
43 1 P2MDOUT=0xff;
44 1 FLASH_SE=0;FLASH_WP=1;FLASH_CE=0;FLASH_ALE=0;
45 1 FLASH_CLE=0;FLASH_WE=1;FLASH_RE=1;FLASH_RB=1; //控制位的初始狀態
46 1 Flash_Write_Command(0xff); //復位命令
47 1 Time_Delay(50); //延時50ms
48 1 }
49 /*
50 unsigned int Get_Flash_ID(void)
51 {
C51 COMPILER V6.12 FLASH 08/20/2006 19:41:24 PAGE 2
52 unsigned int id=0;
53 Flash_Write_Command(0x90); //讀ID命令
54 Flash_Write_Address(0x00); //地址
55 id=Flash_Read_Data(); //讀ID的高8位
56 id *=256;
57 id+=Flash_Read_Data(); //讀ID的低8位
58 return(id);
59 }
60 */
61 /*
62 unsigned char Get_Flash_Status()
63 {
64 unsigned char status=0;
65 Flash_Write_Command(0x70);
66 status=Flash_Read_Data();
67 return(status);
68 }*/
69
70 unsigned char Flash_Erase_Block(unsigned int BlockNum)
71 {
72 1 unsigned char Address_M=0,Address_H=0,Address_HH=0;
73 1 unsigned long PageNum=0;
74 1 unsigned char status=0;
75 1 PageNum=BlockNum*32; //計算PAGE地址(這是該BLOCK中的第一個PAGE),每個BLOCK含32個PAGE
76 1 Address_M=PageNum & 0xff;
77 1 Address_H=(PageNum>>8) & 0xff; //擦除BLOCK時,只需要輸入地址的高兩字節,此處為計算地址的高兩字節
78 1 Address_HH=(PageNum>>8) & 0xff;
79 1
80 1 Flash_Write_Command(0x60); //發送擦除命令
81 1 Flash_Write_Address(Address_M);
82 1 Flash_Write_Address(Address_H); //發送地址
83 1 Flash_Write_Address(Address_HH);
84 1 Flash_Write_Command(0xd0); //啟動擦除
85 1 P2MDOUT =0xbf;
86 1 FLASH_RB=1; //FLASH_RB漏極開路輸出
87 1 while(!FLASH_RB) //判斷是否擦除完畢
88 1 {}
89 1
90 1 Flash_Write_Command(0x70); //發送讀狀態命令
91 1 status=Flash_Read_Data(); //讀狀態
92 1 if(status & 0x01) //如果有錯誤,則返回false
93 1 {
94 2 return(0);
95 2 }
96 1 else //否則返回true
97 1 {
98 2 return(1);
99 2 }
100 1 }
101
102 void Flash_Read_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned int Data_L
-ength)
103 {
104 1 unsigned int i=0;
105 1 unsigned long PageNum=0;
106 1 unsigned char Address_L=0,Address_M=0,Address_H=0,Address_HH=0;
107 1 PageNum=BLockNum*32+BlockPageNum; //計算該PAGE在整個FLASH中的PAGE地址
108 1 Address_L=0;
109 1 Address_M=PageNum & 0xff;
110 1 Address_H=(PageNum>>8) & 0xff;
111 1 Address_HH=(PageNum>>8) & 0xff;
112 1
C51 COMPILER V6.12 FLASH 08/20/2006 19:41:24 PAGE 3
113 1 Flash_Write_Command(0x00); //將內部指針指向A區
114 1 Flash_Write_Address(Address_L); //寫地址
115 1 Flash_Write_Address(Address_M);
116 1 Flash_Write_Address(Address_H);
117 1 Flash_Write_Address(Address_HH);
118 1 for(i=0;i<Data_Length;i++)
119 1 {
120 2 *(P+i)=Flash_Read_Data(); //讀數據
121 2 }
122 1
123 1 }
124
125 unsigned char Flash_Write_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned
-int Data_Length)
126 {
127 1 unsigned int i=0;
128 1 unsigned long PageNum=0;
129 1 unsigned char Address_L=0,Address_M=0,Address_H=0,Address_HH=0;
130 1 unsigned char status=0;
131 1 PageNum=BLockNum*32+BlockPageNum; //計算該PAGE在整個FLASH中的PAGE地址
132 1 Address_L=0;
133 1 Address_M=PageNum & 0xff;
134 1 Address_H=(PageNum>>8) & 0xff;
135 1 Address_HH=(PageNum>>8) & 0xff;
136 1
137 1 Flash_Write_Command(0x00); //將內部指針指向A區
138 1 Flash_Write_Command(0x80); //寫FLASH命令
139 1 Flash_Write_Address(Address_L); //寫地址
140 1 Flash_Write_Address(Address_M);
141 1 Flash_Write_Address(Address_H);
142 1 Flash_Write_Address(Address_HH);
143 1 for(i=0;i<Data_Length;i++)
144 1 {
145 2 Flash_Write_Data(*(P+i)); //將數據寫入緩沖區
146 2 }
147 1 Flash_Write_Command(0x10); //啟動寫入,將數據從緩沖區寫入到FLASH
148 1 P2MDOUT =0xbf; //FLASH_RB漏極開路輸出
149 1 FLASH_RB=1;
150 1 while(!FLASH_RB) //判斷是否操作完畢
151 1 {}
152 1
153 1 Flash_Write_Command(0x70); //發送讀狀態命令
154 1 status=Flash_Read_Data(); //讀狀態
155 1 if(status & 0x01) //如果有錯誤,則返回false
156 1 {
157 2 return(0);
158 2 }
159 1 else //否則返回true
160 1 {
161 2 return(1);
162 2 }
163 1
164 1 }
165
166 void Flash_Write_Command(unsigned char command)
167 {
168 1 FLASH_ALE=0; //地址鎖存禁止
169 1 FLASH_CLE=1; //命令鎖存使能
170 1 FLASH_WE =0; //寫使能信號,上升沿有效
171 1 P1MDOUT =0xff; //設置P1為推挽輸出
172 1 P1=command;
173 1 FLASH_WE =1; //命令在上升沿寫入
C51 COMPILER V6.12 FLASH 08/20/2006 19:41:24 PAGE 4
174 1 FLASH_CLE=0; //命令鎖存禁止
175 1 FLASH_ALE=1;
176 1 }
177
178 void Flash_Write_Address(unsigned char address)
179 {
180 1 FLASH_WE=1;
181 1 FLASH_CLE=0; //命令鎖存禁止
182 1 FLASH_ALE=1; //地址鎖存使能
183 1 FLASH_WE =0; //寫使能信號,上升沿有效
184 1 P1MDOUT =0xff; //設置P1為推挽輸出
185 1 P1=address;
186 1 FLASH_WE =1; //上升沿寫入
187 1 FLASH_ALE=0; //地址鎖存禁止
188 1 }
189
190 void Flash_Write_Data(unsigned char num)
191 {
192 1 FLASH_WE=1;
193 1 FLASH_CLE=0; //命令鎖存禁止
194 1 FLASH_ALE=0; //地址鎖存禁止
195 1 FLASH_WE =0; //寫使能信號, 上升沿有效
196 1 P1MDOUT =0xff; //設置P1為推挽輸出
197 1 P1=num;
198 1 FLASH_WE =1; //命令在上升沿寫入
199 1 }
200
201 unsigned char Flash_Read_Data(void)
202 {
203 1 unsigned char num=0;
204 1 FLASH_CLE =0; //命令鎖存禁止
205 1 FLASH_ALE =0; //地址鎖存禁止
206 1 P1MDOUT =0x00; //設置P1為漏極開路輸出
207 1 P1 =0xff;
208 1 FLASH_RE =0; //讀信號使能
209 1 P2MDOUT =0xbf; //FLASH_RB漏極開路輸出
210 1 FLASH_RB=1;
211 1 while(!FLASH_RB) //判斷是否操作完畢
212 1 {}
213 1 num=P1;
214 1 FLASH_RE=1;
215 1 return(num);
216 1 }
217 /*
218 void Test_Flash()
219 {
220 unsigned int Flash_ID;
221 xdata unsigned char Buffer[512];
222 unsigned int i=0,dat=0;
223 Flash_ID=Get_Flash_ID();
224 printf("Flash_ID is %u\n",Flash_ID);
225
226 for(i=0;i<512;i++)
227 {Buffer[i]=i;}
228 for(i=0;i<256;i++)
229 {Buffer[256+i]=i;}
230 Flash_Write_Page(1,1,Buffer,512);
231 for(i=0;i<512;i++)
232 {Buffer[i]=0;}
233 Flash_Read_Page(1,1,Buffer,512);
234 for(i=0;i<512;i++)
235 {
C51 COMPILER V6.12 FLASH 08/20/2006 19:41:24 PAGE 5
236 dat=Buffer[i];
237 printf("the No.%u data is %u\n",i,dat);
238 }
239
240 }*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 576 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 47
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -