📄 flash.lst
字号:
C51 COMPILER V6.02 FLASH 06/24/2002 22:07:27 PAGE 1
C51 COMPILER V6.02, COMPILATION OF MODULE FLASH
OBJECT MODULE PLACED IN D:\COMM_D\FLASH.OBJ
COMPILER INVOKED BY: C:\COMP51\C51.EXE D:\COMM_D\FLASH.C DB SB OE
stmt level source
1 #include "D:\comm_d\flash.h"
2 #include "D:\comm_d\flash_pub.h"
3
4
5
6
7 void init_spi(void)
8 {
9 1 CS=1;
10 1 SCK=1;
11 1 MOSI=1;
12 1 MISO=1;
13 1 }
14
15
16 void spi_send_uint(unsigned char dat)
17 {
18 1 idata unsigned int i;
19 1 for(i = 0; i < 8; i ++){
20 2
21 2 if(dat >= 0x80)
22 2 { MOSI = 1;
23 3 } //修改
24 2 else
25 2 MOSI = 0;
26 2 SCK = 0;
27 2 _nop_();
28 2 _nop_();
29 2 _nop_();
30 2 SCK = 1;
31 2 dat <<= 1;
32 2 }
33 1 }
34
35 unsigned int get_unsigned(void)
36 {
37 1 idata unsigned int i;
38 1 idata unsigned int result = 0;
39 1
40 1 for(i = 0; i < 8; i ++){
41 2 result <<= 1;
42 2 SCK = 0;
43 2 _nop_();
44 2 _nop_(); //修改
45 2 _nop_();
46 2 SCK = 1;
47 2 _nop_();
48 2 _nop_(); //修改
49 2 _nop_();
50 2 if(MISO == 0)
51 2 result |= 0;
52 2 else
53 2 result |= 1;
54 2 }
55 1 return result;
C51 COMPILER V6.02 FLASH 06/24/2002 22:07:27 PAGE 2
56 1 }
57 unsigned char read_status(void)
58 {
59 1 idata unsigned int result;
60 1 CS = 0;
61 1 spi_send_uint(CMD_READ_STATUS);
62 1 result = get_uint();
*** WARNING C206 IN LINE 62 OF D:\COMM_D\FLASH.C: 'get_uint': missing function-prototype
63 1 CS = 1;
64 1 return result;
65 1 }
66
67 unsigned char wait_ready(void)
68 {
69 1 unsigned int status;
70 1 do{
71 2 status = read_status();
72 2 }
73 1 while((status & 0x80) == 0); /* If flash is busy */
74 1 return status;
75 1 }
76
77 void send_cmd32(unsigned long cmd32)
78 {
79 1 unsigned int cmd8;
80 1
81 1 cmd8 = (unsigned int)(cmd32 >> 24);
82 1 spi_send_uint(cmd8);
83 1
84 1 cmd8 = (unsigned int)(cmd32 >> 16);
85 1 spi_send_uint(cmd8);
86 1
87 1 cmd8 = (unsigned int)(cmd32 >> 8);
88 1 spi_send_uint(cmd8);
89 1
90 1 cmd8 = (unsigned int)cmd32;
91 1 spi_send_uint(cmd8);
92 1 }
93
94
95
96 bit we_buf(unsigned int buf_no, unsigned int xdata *src, unsigned int BFA, unsigned int n)
97 {
*** WARNING C235 IN LINE 97 OF D:\COMM_D\FLASH.C: parameter 1: different types
*** WARNING C259 IN LINE 97 OF D:\COMM_D\FLASH.C: pointer: different mspace
*** WARNING C235 IN LINE 97 OF D:\COMM_D\FLASH.C: parameter 2: different types
98 1 unsigned long cmd32;
99 1 unsigned int i;
100 1 unsigned int xdata *temp;
101 1
102 1 switch(buf_no){
103 2 case BUFFER1:
104 2 cmd32 = CMD_WE_BUF1;
105 2 break;
106 2
107 2 case BUFFER2:
108 2 cmd32 = CMD_WE_BUF2;
109 2 break;
110 2
111 2 default:
112 2 return 0;
113 2 }
C51 COMPILER V6.02 FLASH 06/24/2002 22:07:27 PAGE 3
114 1 cmd32 |= BFA;
115 1 temp = src;
116 1
117 1 CS = 0;
118 1 send_cmd32(cmd32);
119 1 for(i = 0; i < n; i ++){
120 2 spi_send_uint(*temp++);
121 2 //temp ++;
122 2 }
123 1 CS = 1;
124 1 return 1;
125 1 }
126
127
128
129
130 bit we_buf_main_del(unsigned int buf_no, unsigned int PA)
131 {
*** WARNING C235 IN LINE 131 OF D:\COMM_D\FLASH.C: parameter 1: different types
132 1 unsigned long cmd32;
133 1 cmd32 = ((unsigned long)PA) << 9;
134 1 switch(buf_no){
135 2 case BUFFER1:
136 2 cmd32 |= CMD_WE_BUF1_MAIN_DEL;
137 2 break;
138 2
139 2 case BUFFER2:
140 2 cmd32 |= CMD_WE_BUF2_MAIN_DEL;
141 2 break;
142 2
143 2 default:
144 2 return 0;
145 2 }
146 1 CS = 0;
147 1 send_cmd32(cmd32);
148 1 CS = 1; /* Begin transfer from now */
149 1 wait_ready();
150 1 return 1;
151 1 }
152 /*
153
154 名称:read_main
155
156 功能:读AT45D021函数,指定页、指定起始字节及字节数,送到RAM指定地址中;
157
158 入口参数:PA:AT45D021主存储器页地址。
159
160 BA:页内起始字节。
161
162 dest:RAM区存放数据地址。
163
164 n :读取字节数
165
166 */
167 unsigned int at45d021_rd(unsigned int *rdbuf,unsigned int size,unsigned int pa,unsigned int ba)
168 {
*** WARNING C235 IN LINE 168 OF D:\COMM_D\FLASH.C: parameter 1: different types
169 1 unsigned long cmd32;
170 1 unsigned int i;
171 1 unsigned int xdata *gg;
172 1 gg=rdbuf;
173 1 cmd32 = ((unsigned long)pa) << 9;
C51 COMPILER V6.02 FLASH 06/24/2002 22:07:27 PAGE 4
174 1 cmd32 |= (unsigned long)ba;
175 1 cmd32 |= CMD_READ_MAIN;
176 1
177 1 CS = 0;
178 1 send_cmd32(cmd32);
179 1 send_cmd32(0L);
180 1 for(i = 0; i < size; i ++){
181 2 *gg++ = get_uint();
182 2 //gg++;
183 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -