nflash.lst
来自「D12和89s52+K9F5608组成的系统」· LST 代码 · 共 417 行 · 第 1/2 页
LST
417 行
C51 COMPILER V7.50 NFLASH 12/29/2005 19:53:03 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE NFLASH
OBJECT MODULE PLACED IN NFLASH.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE NFLASH.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /***********************************************************
2 Module Name:
3
4 NFlash32.c
5 ***********************************************************/
6 #include "reg52.h"
7 #include "d12config.h"
8 #include "D12CI.h"
9 #include "Chap_9.h"
10 #include "SCSI.h"
11 #include "NFLASH.h"
12
13
14 unsigned int idata WriteResidueVal = 0;
15 unsigned char idata Flash_Write_Sec = 0x00;
16 unsigned char idata Flash_Write_Col = 0x00;
17 unsigned char idata Flash_Write_addl = 0x00;
18 unsigned char idata Flash_Write_addh = 0x00;
19 unsigned long idata ReadResidueVal = 0;
20 unsigned char idata Flash_Read_Sec = 0x00;
21 unsigned char idata Flash_Read_Col = 0x00;
22 unsigned char idata Flash_Read_addl = 0x00;
23 unsigned char idata Flash_Read_addh = 0x00;
24 unsigned char idata Flash_Write_No = 0x00;
25
26
27 sbit fRB = P1^4;
28 sbit fRE = P1^5;
29 sbit CLE = P3^0;
30 sbit ALE = P3^1;
31 sbit fWE = P3^4;
32 sbit fWP = P3^5;
33
34 /********************************************************
35 Flash 底层读写操作
36 **********************************************************/
37
38 void fcommand(unsigned char cmd)
39 {
40 1 P2 = cmd;
41 1 CLE = 1;
42 1 fWE = 0;
43 1 fWE = 1;
44 1 CLE = 0;
45 1 }
46
47
48 void faddr(unsigned char addr)
49 {
50 1 P2 = addr;
51 1 ALE = 1;
52 1 fWE = 0;
53 1 fWE = 1;
54 1 ALE = 0;
55 1 }
C51 COMPILER V7.50 NFLASH 12/29/2005 19:53:03 PAGE 2
56
57
58 void fwedata(unsigned char Data)
59 {
60 1 P2 = Data;
61 1 fWE = 0;
62 1 fWE = 1;
63 1 }
64
65
66
67 unsigned char fredata(void)
68 {
69 1 fRE = 0;
70 1 return P2;
71 1 fRE = 1;
72 1 }
73
74
75 /************************************************************
76 **函数功能:块擦除函数
77 **函数输入参数及说明:
78 addh:高地址
79 addl:低地址
80
81 **函数返回值:无
82 **在本函数以外定义的变量:fCOMMAND,fADD,fWPs,fWPc,fRB
83 **调用的函数说明:无
84
85 **修改人:胡琦宗
86 **修改日期:2005.12.9
87 **修改说明:创建
88 *************************************************************/
89 void flashErase(unsigned char addh,unsigned char addl)
90 {
91 1 unsigned char i = 0;
92 1 fWP = 1;//打开写保护
93 1 fcommand(0x60);//块擦除命令
94 1 faddr(addl);//低地址
95 1 faddr(addh);//高地址
96 1 fcommand(0xd0);//处理命令
97 1 while(!fRB);
98 1 fcommand(0x70);//读状态命令
99 1 i = fredata();//读状态值
100 1 fWP = 0;//写保护
101 1 // printf("%x,%x erase is %x",addh,addl,i);//串口打印
102 1 }
103 /************************************************************
104 **函数功能:写FLASH预处理函数
105 **函数输入参数及说明:无
106
107 **函数返回值:无
108 **在本函数以外定义的变量:
109 **调用的函数说明:无
110
111 **修改人:胡琦宗
112 **修改日期:2005.12.9
113 **修改说明:创建
114 *************************************************************/
115 void flashWritecmd(void)
116 {
117 1 unsigned char idata Erase_addh,Erase_addl;
C51 COMPILER V7.50 NFLASH 12/29/2005 19:53:03 PAGE 3
118 1 unsigned char idata Sour_addh,Sour_addl,Dest_addh,Dest_addl;
119 1 unsigned char idata Sour_two_addh,Sour_two_addl,Dest_two_addh,Dest_two_addl;
120 1 unsigned int idata Erase_Count = 0,i = 0;
121 1 unsigned int idata CopyBack_Count = 0;
122 1 unsigned int idata CopyBack_two_count = 0;
123 1 unsigned int idata WritePageNum = 0;
124 1 union{
125 1 unsigned char c[2];
126 1 unsigned int add;
127 1 }Start_add;
128 1 union{
129 1 unsigned char c[2];
130 1 unsigned int add;
131 1 }End_add;
132 1 /************说明*****************
133 1 对于FLASH的写操作原理是,写之前
134 1 必须擦除,FLASH写是按页写,但是擦
135 1 除是按块擦除,1块 = 32页,所以在
136 1 一块内只有部分页被写入时就需要先
137 1 将块内其他页保存,代整块擦除后一起
138 1 写入,这里用0XFA,0X00作为头块缓冲,
139 1 0XFB,0X00作为最后块缓冲,中间块采
140 1 用直接擦除处理
141 1 **********************************/
142 1 flashErase(0xfa, 0x00);
143 1 Sour_addh = ControlData.dataBuffer[19];
144 1 Sour_addl = (ControlData.dataBuffer[20]/0x20) * 0x20;
145 1 Dest_addh = 0xfa;
146 1 Dest_addl = (ControlData.dataBuffer[20]/0x20) * 0x20;
147 1 CopyBack_Count = ControlData.dataBuffer[20]%0x20;
148 1 for(i=0;i<CopyBack_Count;i++){
149 2 flashCopyBLack(Sour_addh,Sour_addl,Dest_addh,Dest_addl);
150 2 Sour_addl ++;
151 2 Dest_addl ++;
152 2 }
153 1 Erase_addl = (ControlData.dataBuffer[20]/0x20) * 0x20;
154 1 Erase_addh = ControlData.dataBuffer[19];
155 1 WritePageNum = (ControlData.dataBuffer[22]<<8)+ControlData.dataBuffer[23];
156 1 Erase_Count = WritePageNum / 0x20;
157 1 if(WritePageNum % 0x20){
158 2 Erase_Count ++;
159 2 if((WritePageNum % 0x20) > (0x20 - (ControlData.dataBuffer[20] % 0x20)))
160 2 Erase_Count ++;
161 2 }else if(ControlData.dataBuffer[20] % 0x20){
162 2 Erase_Count ++;
163 2 }
164 1 Start_add.add = (ControlData.dataBuffer[19]<<8)+ControlData.dataBuffer[20];
165 1 End_add.add = Start_add.add + WritePageNum;
166 1 flashErase(0xfb, 0x00);
167 1 Sour_two_addh = End_add.c[1];
168 1 Sour_two_addl = End_add.c[0];
169 1 Dest_two_addh = 0xfb;
170 1 Dest_two_addl = End_add.c[0];
171 1 CopyBack_two_count = (Erase_Count * 0x20) - CopyBack_Count -WritePageNum;
172 1 for(i=0;i<CopyBack_two_count;i++){
173 2 flashCopyBLack(Sour_two_addh,Sour_two_addl,Dest_two_addh,Dest_two_addl);
174 2 Sour_two_addl ++;
175 2 Dest_two_addl ++;
176 2 }
177 1 for(i=0;i<Erase_Count;i++){
178 2 flashErase(Erase_addh, Erase_addl);
179 2 if(Erase_addl == 224){
C51 COMPILER V7.50 NFLASH 12/29/2005 19:53:03 PAGE 4
180 3 Erase_addl = 0x00;
181 3 Erase_addh ++;
182 3 }else
183 2 Erase_addl += 0x20;
184 2 }
185 1 for(i=0;i<CopyBack_Count;i++){
186 2 Sour_addl --;
187 2 Dest_addl --;
188 2 flashCopyBLack(Dest_addh,Dest_addl,Sour_addh,Sour_addl);
189 2 }
190 1 for(i=0;i<CopyBack_two_count;i++){
191 2 Sour_two_addl --;
192 2 Dest_two_addl --;
193 2 flashCopyBLack(Dest_two_addh,Dest_two_addl,Sour_two_addh,Sour_two_addl);
194 2 }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?