📄 ide.lst
字号:
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE IDE
OBJECT MODULE PLACED IN IDE.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE IDE.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /******************************************************************
2 本程序只供学习使用,未经作者许可,不得用于其它任何用途
3 我的邮箱:computer-lov@tom.com
4 欢迎访问我的blog: http://computer00.21ic.org
5
6 IDE.C file
7
8 Created by Computer-lov
9 Date: 2005.3.12
10
11 Edit date:2006.3.2
12
13 Version V1.1
14 Copyright(C) Computer-lov 2005-2015
15 All rigths reserved
16
17 *******************************************************************/
18
19 #include <at89X52.h>
20 #include "IDE.H"
21 //#include <serial.h>
22
23
24
25 unsigned char IDE_Buffer_H,IDE_Buffer_L;
26
27 unsigned char bdata IDE_status;
28 sbit IDE_BSY = IDE_status^7;
29 sbit IDE_DRDY = IDE_status^6;
30 sbit IDE_DWF = IDE_status^5;
31 sbit IDE_DSC = IDE_status^4;
32 sbit IDE_DRQ = IDE_status^3;
33 sbit IDE_CORR = IDE_status^2;
34 sbit IDE_IDX = IDE_status^1;
35 sbit IDE_ERR = IDE_status^0;
36
37
38
39 unsigned char bdata IDE_error_register;
40 sbit IDE_BBK = IDE_error_register^7;
41 sbit IDE_UNC = IDE_error_register^6;
42 sbit IDE_MC = IDE_error_register^5;
43 sbit IDE_IDNF = IDE_error_register^4;
44 sbit IDE_MCR = IDE_error_register^3;
45 sbit IDE_ABRT = IDE_error_register^2;
46 sbit IDE_TKONF= IDE_error_register^1;
47 sbit IDE_AMNF = IDE_error_register^0;
48
49
50 void delayXms(unsigned int x)
51 {
52 1 unsigned int i,j;
53 1 for(i=0;i<x;i++)
54 1 for(j=0;j<225;j++);
55 1 }
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 2
56
57
58 void reset_IDE(void)
59 {
60 1 IDE_Address=IDE_Reset;
61 1 IDE_ALE=1;
62 1 IDE_ALE=0;
63 1 delayXms(200);
64 1 IDE_Address=IDE_Bus_Not_Use;
65 1 IDE_ALE=1;
66 1 IDE_ALE=0;
67 1 delayXms(200);
68 1 while(!IDE_IORDY);
69 1 }
70
71
72 void read_IDE_16(unsigned char address)
73 {
74 1 while(!IDE_IORDY);
75 1 IDE_Address=address;
76 1 set_IDE_address();
77 1 IDE_DATA_H=0xFF;
78 1 IDE_DATA_L=0xFF;
79 1 IDE_DIOR=0;
80 1 IDE_Buffer_H=IDE_DATA_H;
81 1 IDE_Buffer_L=IDE_DATA_L;
82 1 IDE_DIOR=1;
83 1 IDE_Address=IDE_Bus_Not_Use;
84 1 set_IDE_address();
85 1 }
86
87 /*
88 void write_IDE_16(unsigned char address)
89 {
90 while(!IDE_IORDY);
91 IDE_Address=address;
92 set_IDE_address();
93 IDE_DIOW=0;
94 IDE_DATA_H=IDE_Buffer_H;
95 IDE_DATA_L=IDE_Buffer_L;
96 IDE_DIOW=1;
97 IDE_Address=IDE_Bus_Not_Use;
98 set_IDE_address();
99 }*/
100
101 unsigned char read_IDE_8(unsigned char address)
102 {
103 1 unsigned char temp;
104 1 while(!IDE_IORDY);
105 1 IDE_Address=address;
106 1 set_IDE_address();
107 1 IDE_DATA_H=0xFF;
108 1 IDE_DATA_L=0xFF;
109 1 IDE_DIOR=0;
110 1 temp=IDE_DATA_L;
111 1 IDE_DIOR=1;
112 1 IDE_Address=IDE_Bus_Not_Use;
113 1 set_IDE_address();
114 1 return temp;
115 1 }
116
117 void write_IDE_8(unsigned char address,unsigned char w_data)
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 3
118 {
119 1 while(!IDE_IORDY);
120 1 IDE_Address=address;
121 1 set_IDE_address();
122 1 IDE_DIOW=0;
123 1 IDE_DATA_L=w_data;
124 1 IDE_DIOW=1;
125 1 IDE_Address=IDE_Bus_Not_Use;
126 1 set_IDE_address();
127 1 }
128
129 void read_IDE_data(void)
130 {
131 1 read_IDE_16(IDE_Data);
132 1 }
133
134 /*
135 void write_IDE_data(void)
136 {
137 write_IDE_16(IDE_Data);
138 }
139 */
140
141 void read_IDE_status(void)
142 {
143 1 IDE_status=read_IDE_8(IDE_Status);
144 1 }
145
146 void read_IDE_error(void)
147 {
148 1 IDE_error_register=read_IDE_8(IDE_Error_Register);
149 1 }
150
151 unsigned char wait_IDE_busy(void)
152 {
153 1 while(!IDE_IORDY);
154 1 do
155 1 {
156 2 read_IDE_status();
157 2 if(IDE_ERR)
158 2 {
159 3 read_IDE_error();
160 3 }
161 2 }while(IDE_BSY);
162 1 IDE_Address=IDE_Bus_Not_Use;
163 1 set_IDE_address();
164 1 return 0;
165 1 }
166
167 void write_IDE_command(unsigned char command)
168 {
169 1 write_IDE_8(IDE_Command,command);
170 1 wait_IDE_busy();
171 1 }
172
173 /*
174 void soft_reset_IDE(void)
175 {
176 write_IDE_8(IDE_Device_Control,0xFD);
177 wait_IDE_busy();
178 }*/
179
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 4
180 void get_IDE_information(void)
181 {
182 1 unsigned int i;
183 1 unsigned int n_cylinders;
184 1 unsigned int n_heads;
185 1 unsigned int n_sectors_per_track;
186 1 unsigned long int disk_capacity;
187 1 unsigned long int temp;
188 1 // prints("获取磁盘信息...",1);
189 1 write_IDE_command(IDE_Identify_Drive);
190 1 // prints("磁盘信息:",1);
191 1 read_IDE_data();//1st word
192 1 // if(IDE_Buffer_H&0x01)prints("磁盘传输速率: 小于5MBs",1);
193 1 // if(IDE_Buffer_H&0x02)prints("磁盘传输速率: 大于5MBs小于等于10MBs",1);
194 1 // if(IDE_Buffer_H&0x04)prints("磁盘传输速率: 大于10MBs",1);
195 1 // read_IDE_data();//2nd word
196 1 ((unsigned char *)&n_cylinders)[0]=IDE_Buffer_H;
197 1 ((unsigned char *)&n_cylinders)[1]=IDE_Buffer_L;
198 1 // prints("柱面数: ",0);
199 1 // printf(n_cylinders);
200 1 // prints("",1);
201 1 read_IDE_data();//3th word
202 1 read_IDE_data();//4th word
203 1 ((unsigned char *)&n_heads)[0]=IDE_Buffer_H;
204 1 ((unsigned char *)&n_heads)[1]=IDE_Buffer_L;
205 1 // prints("磁头数: ",0);
206 1 // printf(n_heads);
207 1 // prints("",1);
208 1 read_IDE_data();//5th word
209 1 read_IDE_data();//6th word
210 1 read_IDE_data();//7th word
211 1 ((unsigned char *)&n_sectors_per_track)[0]=IDE_Buffer_H;
212 1 ((unsigned char *)&n_sectors_per_track)[1]=IDE_Buffer_L;
213 1 // prints("每道扇区数: ",0);
214 1 // printf(n_sectors_per_track);
215 1 // prints("",1);
216 1 disk_capacity=n_cylinders;
217 1 disk_capacity*=n_heads;
218 1 disk_capacity*=n_sectors_per_track;
219 1 disk_capacity/=2048; //磁盘容量单位为MB
220 1 // prints("磁盘容量: ",0);
221 1 // printf(disk_capacity);
222 1 // prints(" MBytes",1);
223 1 read_IDE_data();//8th word
224 1 read_IDE_data();//9th word
225 1 read_IDE_data();//10th word
226 1 // prints("磁盘序列号: ",0);
227 1 for(i=0;i<10;i++) //11--20th words
228 1 {
229 2 read_IDE_data();
230 2 // send_to_comport(IDE_Buffer_L);
231 2 // send_to_comport(IDE_Buffer_H);
232 2 }
233 1 // prints("",1);
234 1 read_IDE_data();//21th
235 1 read_IDE_data();//22th
236 1 read_IDE_data();//23th
237 1 // prints("固件版本: ",0);//24th--27th
238 1 for(i=0;i<4;i++)
239 1 {
240 2 read_IDE_data();
241 2 // send_to_comport(IDE_Buffer_L);
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 5
242 2 // send_to_comport(IDE_Buffer_H);
243 2 }
244 1 // prints("",1);
245 1 // prints("Model number: ",0);//28th--47th
246 1 for(i=0;i<20;i++)
247 1 {
248 2 read_IDE_data();
249 2 // send_to_comport(IDE_Buffer_L);
250 2 // send_to_comport(IDE_Buffer_H);
251 2 }
252 1 // prints("",1);
253 1 read_IDE_data();//48th
254 1 read_IDE_data();//49th
255 1 read_IDE_data();//50th
256 1 // if(IDE_Buffer_H&0x01)prints("支持DMA模式",1);
257 1 // if(IDE_Buffer_H&0x02)prints("支持LBA模式",1);
258 1 for(i=0;i<4;i++)read_IDE_data();//51th--54th
259 1 // prints("当前柱面数: ",0);
260 1 read_IDE_data();//55th
261 1 temp=0;
262 1 ((unsigned char *)&temp)[2]=IDE_Buffer_H;
263 1 ((unsigned char *)&temp)[3]=IDE_Buffer_L;
264 1 // printf(temp);
265 1 // prints("",1);
266 1 // prints("当前磁头数: ",0);
267 1 read_IDE_data();//56th
268 1 temp=0;
269 1 ((unsigned char *)&temp)[2]=IDE_Buffer_H;
270 1 ((unsigned char *)&temp)[3]=IDE_Buffer_L;
271 1 // printf(temp);
272 1 // prints("",1);
273 1 // prints("当前每道扇区数: ",0);
274 1 read_IDE_data();//57th
275 1 temp=0;
276 1 ((unsigned char *)&temp)[2]=IDE_Buffer_H;
277 1 ((unsigned char *)&temp)[3]=IDE_Buffer_L;
278 1 // printf(temp);
279 1 // prints("",1);
280 1 // prints("当前磁盘容量: ",0);
281 1 read_IDE_data();//58th
282 1 DISK_CAPACITY[2]=IDE_Buffer_H;
283 1 DISK_CAPACITY[3]=IDE_Buffer_L;
284 1 ((unsigned char *)&temp)[2]=IDE_Buffer_H;
285 1 ((unsigned char *)&temp)[3]=IDE_Buffer_L;
286 1 read_IDE_data();//59th
287 1 DISK_CAPACITY[0]=IDE_Buffer_H;
288 1 DISK_CAPACITY[1]=IDE_Buffer_L;
289 1 ((unsigned char *)&temp)[0]=IDE_Buffer_H;
290 1 ((unsigned char *)&temp)[1]=IDE_Buffer_L;
291 1 temp/=2048; //磁盘容量单位为MB
292 1 // printf(temp);
293 1 // prints(" MBytes",1);
294 1
295 1 for(i=59;i<=255;i++)
296 1 {
297 2 read_IDE_data();
298 2 // printc(i);
299 2 //printc(IDE_Buffer_L);
300 2 // send_to_comport(' ');
301 2 //printc(IDE_Buffer_H);
302 2 //send_to_comport(' ');
303 2 }
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 6
304 1 }
305
306 void write_IDE_LBA3(unsigned char LBA3)
307 {
308 1 write_IDE_8(IDE_LBA_Bits_0_7,LBA3);
309 1 }
310
311 void write_IDE_LBA2(unsigned char LBA2)
312 {
313 1 write_IDE_8(IDE_LBA_Bits_8_15,LBA2);
314 1 }
315
316 void write_IDE_LBA1(unsigned char LBA1)
317 {
318 1 write_IDE_8(IDE_LBA_Bits_16_23,LBA1);
319 1 }
320
321 void write_IDE_LBA0(unsigned char LBA0)
322 {
323 1 LBA0&=0x0F;
324 1 LBA0|=0xE0;//磁盘0工作在LBA模式下
325 1 write_IDE_8(IDE_LBA_Bits_24_27,LBA0);
326 1 }
327
328 void write_IDE_sector_count(unsigned char count)
329 {
330 1 write_IDE_8(IDE_Sector_Count,count);
331 1 }
332 /*
333 void read_IDE_buffer(void)
334 {
335 write_IDE_command(IDE_Read_Buffer);
336 }
337
338 void write_IDE_buffer(void)
339 {
340 write_IDE_command(IDE_Write_Buffer);
341 }
342 */
343
344 void read_IDE_sector(void)
345 {
346 1 write_IDE_command(IDE_Read_Sectors);
347 1 }
348
349 void write_IDE_sector(void)
350 {
351 1 write_IDE_command(IDE_Write_Sectors);
352 1 }
353
354
355 void IDE_initial(void)
356 {
357 1 reset_IDE();
358 1 // prints("IDE复位...",1);
359 1 // prints("磁盘忙,请等待...",1);
360 1 do
361 1 {
362 2 write_IDE_8(IDE_Drive_Head,0xE0);
363 2 read_IDE_status();
364 2 }while(IDE_BSY);
365 1 wait_IDE_busy();
C51 COMPILER V7.06 IDE 03/02/2006 23:51:20 PAGE 7
366 1 write_IDE_8(IDE_Device_Control,0xFA);//没有中断模式f
367 1 get_IDE_information();
368 1 }
369
370 void system_initial(void)
371 {
372 1 EA=0;
373 1 IDE_Address=IDE_Bus_Not_Use;
374 1 IDE_ALE=1;
375 1 IDE_ALE=0;
376 1 delayXms(100);
377 1 // init_comport(57600);
378 1 // prints("",1);
379 1 // prints("开机...",1);
380 1 IDE_initial();
381 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 608 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 4 14
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 + -