📄 ide.lst
字号:
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE IDE
OBJECT MODULE PLACED IN ide.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ide.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /* IDE.C File
2 Created by Computer-lov. Date: 2005.3.19
3 Last edited date: 2005.5.31
4 Copyright (c) 2005 Computer-lov
5 version 1.1
6 */
7
8 #include "AT89C51SND1C.h"
9 #include "file_system.h"
10 #include "IDE.H"
11 #include "hardware.h"
12
13 #include "lcd.h"
14
15 unsigned char DISK_CAPACITY[8];
16 unsigned char driver_number=0; //磁盘驱动器
17
18 ////////////////////////////////////// IDE 状态寄存器 ////////////////////////////////////
19 unsigned char bdata IDE_status;
20 sbit IDE_BSY = IDE_status^7;
21 sbit IDE_DRDY = IDE_status^6;
22 sbit IDE_DWF = IDE_status^5;
23 sbit IDE_DSC = IDE_status^4;
24 sbit IDE_DRQ = IDE_status^3;
25 sbit IDE_CORR = IDE_status^2;
26 sbit IDE_IDX = IDE_status^1;
27 sbit IDE_ERR = IDE_status^0;
28 //////////////////////////////////////////////////////////////////////////////////////////////
29
30 ////////////////////////////////////// IDE 错误寄存器 ////////////////////////////////////
31 unsigned char bdata IDE_error_register;
32 sbit IDE_BBK = IDE_error_register^7;
33 sbit IDE_UNC = IDE_error_register^6;
34 sbit IDE_MC = IDE_error_register^5;
35 sbit IDE_IDNF = IDE_error_register^4;
36 sbit IDE_MCR = IDE_error_register^3;
37 sbit IDE_ABRT = IDE_error_register^2;
38 sbit IDE_TKONF= IDE_error_register^1;
39 sbit IDE_AMNF = IDE_error_register^0;
40 //////////////////////////////////////////////////////////////////////////////////////////////
41
42 //////////////////////////////////////////////////////////////////////////////////////////////
43 void delayXms(unsigned int x) //延时x毫秒,时间不准的
44 {
45 1 unsigned int i;
46 1 for(;x>0;x--)
47 1 for(i=0;i<500;i++);
48 1 }
49 //////////////////////////////////////////////////////////////////////////////////////////////
50
51 ///////////////////////////////// IDE 复位 ///////////////////////////////////////////////
52 void reset_IDE(void)
53 {
54 1 IDE_Address=IDE_Reset;
55 1 IDE_ALE=1;
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 2
56 1 IDE_ALE=0;
57 1 delayXms(200);
58 1 IDE_Address=IDE_Bus_Not_Use;
59 1 IDE_ALE=1;
60 1 IDE_ALE=0;
61 1 delayXms(200);
62 1 while(!IDE_IORDY);
63 1 }
64 ///////////////////////////////////////////////////////////////////////////////////////////////
65
66 ///////////////////////////////////// 读IDE 16位,未用 ////////////////////////////////////////
67 /*void read_IDE_16(unsigned char address)
68 {
69 while(!IDE_IORDY);
70 IDE_Address=address;
71 set_IDE_address();
72 IDE_DATA_H=0xFF;
73 IDE_DATA_L=0xFF;
74 IDE_DIOR=0;
75 IDE_Buffer_H=IDE_DATA_H;
76 IDE_Buffer_L=IDE_DATA_L;
77 IDE_DIOR=1;
78 IDE_Address=IDE_Bus_Not_Use;
79 set_IDE_address();
80 }*/
81 ///////////////////////////////////////////////////////////////////////////////////////////////
82
83 ///////////////////////////////////// 写IDE 16位,未用 ////////////////////////////////////////
84 /*void write_IDE_16(unsigned char address)
85 {
86 while(!IDE_IORDY);
87 IDE_Address=address;
88 set_IDE_address();
89 IDE_DIOW=0;
90 IDE_DATA_H=IDE_Buffer_H;
91 IDE_DATA_L=IDE_Buffer_L;
92 IDE_DIOW=1;
93 IDE_Address=IDE_Bus_Not_Use;
94 set_IDE_address();
95 }*/
96 ///////////////////////////////////////////////////////////////////////////////////////////////
97
98 //////////////////////////////////////////// 读IDE 低8位 /////////////////////////////////
99 unsigned char read_IDE_8(unsigned char address)
100 {
101 1 unsigned char temp;
102 1 while(!IDE_IORDY);
103 1 IDE_Address=address;
104 1 set_IDE_address();
105 1 IDE_DATA_H=0xFF;
106 1 IDE_DATA_L=0xFF;
107 1 IDE_DIOR=0;
108 1 temp=IDE_DATA_L;
109 1 IDE_DIOR=1;
110 1 IDE_Address=IDE_Bus_Not_Use;
111 1 set_IDE_address();
112 1 return temp;
113 1 }
114 ///////////////////////////////////////////////////////////////////////////////////////////////
115
116 ///////////////////////////////////////////// 写IDE 低8位 /////////////////////////////////
117 void write_IDE_8(unsigned char address,unsigned char w_data)
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 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
130 ////////////////////////////////////////// 从IDE读一个字 //////////////////////////////////
131 /*void read_IDE_word(void)
132 {
133 read_IDE_16(IDE_Data);
134 }*/
135 ///////////////////////////////////////////////////////////////////////////////////////////////
136
137 ///////////////////////////////////////// 往IDE写一个字 ///////////////////////////////////
138 /*void write_IDE_word(void)
139 {
140 write_IDE_16(IDE_Data);
141 }*/
142 ///////////////////////////////////////////////////////////////////////////////////////////////
143
144 //////////////////////////////////////// 读 IDE 状态寄存器 /////////////////////////////////
145 void read_IDE_status(void)
146 {
147 1 IDE_status=read_IDE_8(IDE_Status); //结果保存在状态寄存器中
148 1 }
149 ///////////////////////////////////////////////////////////////////////////////////////////////
150
151 ////////////////////////////////////// 读 IDE 错误寄存器 ///////////////////////////////////
152 void read_IDE_error(void)
153 {
154 1 IDE_error_register=read_IDE_8(IDE_Error_Register); //结果保存在错误寄存器中
155 1 }
156 ///////////////////////////////////////////////////////////////////////////////////////////////
157
158 ///////////////////////////////////// 等待IDE ///////////////////////////////////////////
159 unsigned char wait_IDE_busy(void)
160 {
161 1 while(!IDE_IORDY);
162 1 do
163 1 {
164 2 read_IDE_status();
165 2 if(IDE_ERR)
166 2 {
167 3 read_IDE_error();
168 3 LCD_go_home();
169 3 prints("硬盘错误! ");
170 3 printf(IDE_error_register);
171 3 }
172 2 }while(IDE_BSY);
173 1 IDE_Address=IDE_Bus_Not_Use;
174 1 set_IDE_address();
175 1 return 0;
176 1 }
177 //////////////////////////////////////////////////////////////////////////////////////////////
178
179 //////////////////////////////////////// 写 IDE 命令 /////////////////////////////////////
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 4
180 void write_IDE_command(unsigned char command)
181 {
182 1 write_IDE_8(IDE_Command,command);
183 1 wait_IDE_busy();
184 1 }
185 ///////////////////////////////////////////////////////////////////////////////////////////////
186
187 //////////////////////////////////////// IDE 软复位 /////////////////////////////////////
188 /*(void soft_reset_IDE(void)
189 {
190 write_IDE_8(IDE_Device_Control,0xFD);
191 wait_IDE_busy();
192 }
193 */
194 ///////////////////////////////////////////////////////////////////////////////////////////////
195
196 ///////////////////////////////////////// 写IDE 逻辑块地址LBA //////////////////////////////
197 void write_IDE_LBA(unsigned long int _LBA)
198 {
199 1 unsigned char LBA0;
200 1 LBA0=((unsigned char *)&_LBA)[0];
201 1 LBA0&=0x0F;
202 1 LBA0|=0xE0;//磁盘0工作在LBA模式下
203 1 write_IDE_8(IDE_LBA_Bits_24_27,LBA0);
204 1 write_IDE_8(IDE_LBA_Bits_16_23,((unsigned char *)&_LBA)[1]);
205 1 write_IDE_8(IDE_LBA_Bits_8_15,((unsigned char *)&_LBA)[2]);
206 1 write_IDE_8(IDE_LBA_Bits_0_7,((unsigned char *)&_LBA)[3]);
207 1 }
208 ///////////////////////////////////////////////////////////////////////////////////////////////
209
210 unsigned char xdata buffer[512]; //扇区缓冲
211
212 unsigned int byte_offset; //字节偏移
213 unsigned char disk_error=0; //磁盘错误
214
215
216 DPT xdata dpt[4]; //磁盘分区表
217 DBR xdata dbr[4]; //DOS引导记录
218
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -