📄 flash.lst
字号:
C51 COMPILER V7.10 FLASH 07/01/2005 09:26:54 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE FLASH
OBJECT MODULE PLACED IN flash.OBJ
COMPILER INVOKED BY: D:\PROGRAM FILES\KEIL\C51\BIN\C51.EXE flash.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 //**********************************************************************************
2 //本函数模块来自"51单片机世界",作者版主丁丁(聂小猛)。
3 //主页地址http://www.mcu51.com
4 //本程序为本站推出的"MCU51-63K仿真器"及"DX-51多功能试验板"而设计的,详情请到本站查看.
5 //"51单片机世界"版权所有,未经允许,不得抄袭作为商业用途
6 //**********************************************************************************
7 //SST39F020的读写函数
8 #define uchar unsigned char
9 #define uint unsigned int
10 #define ulong unsigned long
11 #include <reg52.h>
12 #include "study.h"
13 //***********************************************************
14 //读N个flash中的字节,每次最多65535字节
15 //入口:在flash中的物理地址,读出来放在内存中的指针首位置,读出多少个字节
16 readeprom(ulong ad,uchar *pst,uint n)
17 {
18 1 union {ulong addr_l;struct {uint a32;uint a10;}addr_i;struct {uchar a3;uint a21;uchar a0;}addr;} address;
19 1 uint i;
20 1 uchar xdata *flash;
21 1 //uchar savep1;
22 1
23 1 //savep1=P1;
24 1 P1=0xff; //P1口如被占用暂停读取
25 1 while(P1!=0xff);
26 1 address.addr_l=ad;
27 1 P1=(P1&0xc0) | (address.addr.a21/0x20); //设置bank线,每块8K字节
28 1 flash=0x8000+address.addr_i.a10%0x2000; //flash窗口地址范围0x8000-0x9ffff
29 1 for(i=0;i<n;i++) //读N个字节
30 1 {
31 2 *(pst++)=*(flash++);
32 2 if(flash==0xa000) //如果地址跨页则翻到下一个bank
33 2 {
34 3 P1++;
35 3 flash=0x8000;
36 3 }
37 2 }
38 1 //P1=savep1;
39 1 }
40
41 //*********************************
42 //读全部flash数据,从串口输出
43 void readflash(void)
44 {
45 1 union {ulong addr_l;struct {uchar a3;uchar a2;uint a10;}addr_i;struct {uchar a3,a2,a1,a0;}addr;} address;
46 1 uchar xdata c[1];//用来读一个字节的缓存
47 1 uchar *pst=c;
48 1
49 1 cls(8);setcursor(0,0); //清屏,设置光标到左上方
50 1 lcdstring("波特率38400bps.按任意键开始发送。"); //输出提示到液晶
51 1 while(getkey(1000)==0); //等待按键
52 1 cls(8);setcursor(0,0); //提示正在发送
53 1 lcdstring("数据正在从串口发送... 按任意键结束");
54 1 putstring("以下是大虾51学习板中flash中的内容\r\n");
55 1 address.addr_l=0x00000; //读出全部的数据,起始地址为0
C51 COMPILER V7.10 FLASH 07/01/2005 09:26:54 PAGE 2
56 1 do
57 1 {
58 2 if (address.addr.a0%16==0)
59 2 { //输出格式,每16个字符一行,输出地址,形成HEX形式数据
60 3 CR;puthex(address.addr.a2);puthex(address.addr.a1);puthex(address.addr.a0);putbyte(':');
61 3 }
62 2 readeprom(address.addr_l,pst,1); //读出一个字节
63 2 puthex(*pst); //输出改字节的HEX码
64 2 putbyte(' '); //输出一个空格,格开每个字节
65 2 address.addr_l++; //地址加一
66 2 }while(getkey(1)==0); //没有按键继续发送
67 1 }
68
69 //**************************************
70 //擦除flash块,地址为0xffffffff时执行片擦,其他地址擦除当前位置的4K字节块
71 //入口:要擦除的地址
72 void erasesector(ulong addr)
73 {
74 1 //定义一个联合,以便地址计算更快速
75 1 union {ulong addr_l;struct {uchar a3;uchar a2;uint a10;}addr_i;struct {uchar a3;uint a21;uchar a0;}addr;}
- address;
76 1 uint delay;
77 1 uchar xdata *pst; //定义个指向外部xdata的指针
78 1
79 1 P1=0xff; //如果P1被占用则等待
80 1 while(P1!=0xff);
81 1
82 1 address.addr_l=addr;
83 1
84 1 pst=0x8000+0x5555%0x2000; //往flash写入钥匙串
85 1 P1=(P1&0xc0) | (0x55>>5);
86 1 *pst=0xaa;
87 1
88 1 pst=0x8000+0x2aaa%0x2000;
89 1 P1=(P1&0xc0) | (0x2a>>5);
90 1 *pst=0x55;
91 1
92 1 pst=0x8000+0x5555%0x2000;
93 1 P1=(P1&0xc0) | (0x55>>5);
94 1 *pst=0x80;
95 1
96 1
97 1 pst=0x8000+0x5555%0x2000;
98 1 P1=(P1&0xc0) | (0x55>>5);
99 1 *pst=0xaa;
100 1
101 1 pst=0x8000+0x2aaa%0x2000;
102 1 P1=(P1&0xc0) | (0x2a>>5);
103 1 *pst=0x55;
104 1
105 1 if(addr==0xffffffff) //如果地址是0xffffffff则改为片擦,这是为了方便,省得多做一个函数
106 1 {
107 2 pst=0x8000+0x5555%0x2000; //片擦
108 2 P1=(P1&0xc0) | (0x55>>5);
109 2 *pst=0x10;
110 2 }
111 1 else
112 1 {
113 2 pst=0x8000+address.addr_i.a10%0x2000; //按照输入的地址擦除当前所在的块
114 2 P1=(P1&0xc0) | (address.addr.a21/0x20);
115 2 *pst=0x30;
116 2 }
C51 COMPILER V7.10 FLASH 07/01/2005 09:26:54 PAGE 3
117 1 for(delay=0;delay<20000;delay++); //延时等待写入完成
118 1 }
119
120 //**************************
121 //在flash中写入一个字节
122 //入口:写入的地址,写入的字节
123 void writeflash(ulong addr_w,uchar ch)
124 {
125 1 union {ulong addr_l;struct {uchar a3;uchar a2;uint a10;}addr_i;struct {uchar a3;uint a21;uchar a0;}addr;}
- address;
126 1 uchar xdata *pst;
127 1
128 1 P1=0xff; //P1如被占用等待
129 1 while(P1!=0xff);
130 1
131 1 address.addr_l=addr_w;
132 1
133 1 pst=0x8000+0x5555%0x2000; //输入钥匙串
134 1 P1=(P1&0xc0) | (0x55>>5);
135 1 *pst=0xaa;
136 1
137 1 pst=0x8000+0x2aaa%0x2000;
138 1 P1=(P1&0xc0) | (0x2a>>5);
139 1 *pst=0x55;
140 1
141 1 pst=0x8000+0x5555%0x2000;
142 1 P1=(P1&0xc0) | (0x55>>5);
143 1 *pst=0xa0;
144 1
145 1 pst=0x8000+address.addr_i.a10%0x2000; //输入地址和数据
146 1 P1=(P1&0xc0) | (address.addr.a21/0x20);
147 1 *pst=ch;
148 1
149 1 }
150
151 //******************************
152 //写入一个文件,需要从计算机串口输出
153 void write_file(void)
154 {
155 1 ulong n;
156 1 uint x;
157 1 uchar ch;
158 1
159 1 cls(8); setcursor(0,0); //清屏,光标移到左上角
160 1 lcdstring("警告!写错文件会导致汉字无法显示!");
161 1 while((ch=getkey(1000))==0x00); //等待按键
162 1 if(ch!='Y') return; //如果收到Cancel键则退出
163 1 cls(8); setcursor(0,0);
164 1 lcdstring("波特率38400bps,等待计算机发送文件.");
165 1 while(inbufsign)getbyte(); //清除串口缓冲
166 1 putstring("\r\n请将光标放在计算机串口调试软件接收窗口.然后在计算机键盘输入擦除密码:2816\r\n");
167 1
168 1 if(getbyte()=='2')
169 1 {
170 2 if(getbyte()=='8')
171 2 {
172 3 if(getbyte()=='1')
173 3 {
174 4 if(getbyte()=='6')
175 4 {
176 5 putstring("\r\n密码正确,正在擦除学习板flash中的内容,请继续后面的发送字库文件的操作,否则液晶将无法显示
-!");
C51 COMPILER V7.10 FLASH 07/01/2005 09:26:54 PAGE 4
177 5 erasesector(0xffffffff); //擦除整块flash
178 5
179 5 putstring("\r\n擦除完成,请选择好要发送的文件,点'发送'输出到串口,发送之前不要按计算机键盘.");
180 5
181 5 while(!inbufsign);
182 5
183 5 for(n=0;n<0x80000;n++) //最大烧写512K字节
184 5 {
185 6 x=0;
186 6 while(!inbufsign)
187 6 {
188 7 x++;
189 7 if(x>60000) goto isOut; //接收超时退出
190 7 }
191 6 writeflash(n,getbyte());
192 6 }
193 5 isOut: putstring("\r\n烧写完毕!");
194 5 return;
195 5 }//end of if(getbyte()!='6')
196 4
197 4 }
198 3 }
199 2
200 2 }
201 1 putstring("\r\n密码错误!请复位单片机重新来过."); return;
202 1 }
203
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 974 ----
CONSTANT SIZE = 467 ----
XDATA SIZE = ---- 1
PDATA SIZE = ---- ----
DATA SIZE = ---- 47
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -