📄 main.lst
字号:
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: E:\Program files\Keil\C51\BIN\C51.EXE main.c MODP2 DEBUG OBJECTEXTEND
stmt level source
1 #include "reg668.h"
2 #include <stdio.h>
3
4
5 #include <stdlib.h>
6 #include "cf.h"
7 #include <string.h>
8
9 //#define CLEAR_FAT
10 //#define DEBUG
11 //#define DEBUG_LINK
12 //#define WRITE_IN_OPEN
13
14 #ifdef TEST_RAM
unsigned char *ram_addr=&XBYTE[0x2000];
unsigned char *ram_1=&XBYTE[0x0000];
unsigned char *ram_2=&XBYTE[0x2000];
#endif
19
20 static xdata unsigned char data_buf[512]; //the buffer for read or write CF card's sector
21 static xdata struct sFileInfo s_fileinfo; //use to save opened file infomation
22 static xdata unsigned char write_buf[512]; //the buffer for write to CF
23 static xdata unsigned int buf_pos=0; //current position of write_buf
24 static xdata struct sBootInformation bootinfo;
25 unsigned char num;
26
27 #define USE_PRINTF
28
29 void CommInit()
30 {
31 1 unsigned char temp;
32 1 temp=TMOD;
33 1 temp&=0x0f;
34 1 temp|=0x20;
35 1 TMOD=temp;
36 1 TH1=0xFF;
37 1
38 1 S0CON=0X50;
39 1 PCON=0X80;
40 1 TR1=1;
41 1
42 1 #ifdef USE_PRINTF
43 1 TI=1;
44 1 ES0=0;
45 1 #else
ES0=0;
TI=0;
#endif
49 1 RI=0;
50 1 }
51
52 char zxPutChar (char c)
53 {
54 1 while (!TI)
55 1 ;
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 2
56 1 TI = 0;
57 1 return (S0BUF = c);
58 1 }
59
60
61
62 unsigned char CheckCFStatu()
63 {
64 1 return CF_STATUS;
65 1 }
66
67 //read 512 bytes from CF,
68 //sec_num:sector No.
69 //512 bytes data put in data_buf
70 //return: 1 success,0 error
71 bit ReadOneSec(unsigned long sec_num)
72 {
73 1 volatile unsigned long temp;
74 1 volatile unsigned int i,time_out;
75 1 CF_CYLINDER_HIGH=sec_num/65536;
76 1 temp=sec_num%65536;
77 1 CF_CYLINDER_LOW=temp/256;
78 1 CF_SECTOR_NUM=temp%256;
79 1 CF_SECTOR_COUNT=1;
80 1 CF_DRV_HEAD=0xe0;
81 1 // CF_DRV_HEAD=0x10;
82 1 CF_COMM=0x20;
83 1 for(i=0;i<512;i++)
84 1 {
85 2 time_out=0;
86 2 while((CF_STATUS & 0xf1)!=0x50)
87 2 {
88 3 if(time_out++>0xf000)
89 3 return 0;
90 3 }
91 2 data_buf[i]=CF_DATA;
92 2 }
93 1 for(i=0;i<0x01ff;i++)
94 1 {
95 2 time_out++;
96 2 }
97 1 return 1;
98 1 }
99
100 //return value: 1 success, 0 error
101 bit ReadCIS()
102 {
103 1 unsigned int i,time_out;
104 1 CF_COMM=0xec;
105 1 for(i=0;i<512;i++)
106 1 {
107 2 time_out=0;
108 2 while((CF_STATUS & 0xf1)!=0x50)
109 2 {
110 3 if(time_out++>0x8000)
111 3 return 0;
112 3 }
113 2 data_buf[i]=CF_DATA;
114 2 }
115 1 for(i=0;i<0x01ff;i++)
116 1 {
117 2 time_out++;
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 3
118 2 }
119 1 return 1;
120 1 }
121
122 // write 512 bytes to CF card
123 //return: 1 success,0 error
124 bit WriteOneSec(unsigned char* dat,unsigned long sec_num)
125 {
126 1 unsigned int i,time_out;
127 1 unsigned long temp;
128 1 CF_CYLINDER_HIGH=sec_num/65536;
129 1 temp=sec_num%65536;
130 1 CF_CYLINDER_LOW=temp/256;
131 1 CF_SECTOR_NUM=temp%256;
132 1 CF_SECTOR_COUNT=1;
133 1 CF_DRV_HEAD=0xe0;
134 1 // CF_DRV_HEAD=0x10;
135 1 CF_COMM=0x30;
136 1 for(i=0;i<512;i++)
137 1 {
138 2 time_out=0;
139 2 while((CF_STATUS & 0xf1)!=0x50)
140 2 {
141 3 if(time_out++>0xf000)
142 3 return 0;
143 3 }
144 2 CF_DATA=dat[i];
145 2 // CF_DATA=data_buf[i];
146 2 }
147 1 for(i=0;i<0x01ff;i++)
148 1 {
149 2 time_out++;
150 2 }
151 1 return 1;
152 1 }
153
154 //stacks 2
155 bit EraseSec(unsigned long sec_num,unsigned char num)
156 {
157 1 unsigned long temp;
158 1 unsigned int time_out,i;
159 1 CF_CYLINDER_HIGH=sec_num/65536;
160 1 temp=sec_num%65536;
161 1 CF_CYLINDER_LOW=temp/256;
162 1 CF_SECTOR_NUM=temp%256;
163 1 CF_SECTOR_COUNT=num;
164 1 CF_DRV_HEAD=0xe0;
165 1 // CF_DRV_HEAD=0x10;
166 1 CF_COMM=0xC0;
167 1 time_out=0;
168 1 while((CF_STATUS & 0xf0)!=0x50)
169 1 {
170 2 if(time_out++>0xf000)
171 2 return 0;
172 2 }
173 1 for(i=0;i<0x01ff;i++)
174 1 {
175 2 time_out++;
176 2 }
177 1 return 1;
178 1 }
179
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 4
180 //stacks 2
181 void CFInit()
182 {
183 1 reg_select=1;
184 1 reg=0;
185 1 CF_CONFIG=0x80;
186 1 reg_select=0;
187 1 reg=1;
188 1 // CF_STATUS=0xff;
189 1 }
190
191 void PrintBoot()
192 {
193 1 unsigned int temp;
194 1 printf("Oem:");
195 1 for(temp=0;temp<8;temp++)
196 1 {
197 2 printf("%c",((struct sBoot*)data_buf)->OemName[temp]);
198 2 }
199 1 printf("\nBytes/Sec:%u",((struct sBoot*)data_buf)->bsBytesPerSec[1]*256
200 1 +((struct sBoot*)data_buf)->bsBytesPerSec[0]);
201 1 printf("\nSec/Clustor:");
202 1 putchar(((struct sBoot*)data_buf)->bsSecPerClust+'0');
203 1
204 1 printf("\nTotal Sec:%u",((struct sBoot*)data_buf)->bsSectors[1]*256
205 1 +((struct sBoot*)data_buf)->bsSectors[0]);
206 1 printf("\nVolume:");
207 1 for(temp=0;temp<11;temp++)
208 1 {
209 2 printf("%c",((struct sBoot*)data_buf)->bsVolumeLabel[temp]);
210 2 }
211 1 printf("\nFileSystem:");
212 1 for(temp=0;temp<8;temp++)
213 1 {
214 2 printf("%c",((struct sBoot*)data_buf)->bsFileSysType[temp]);
215 2 }
216 1 }
217
218 //用于读取BOOT扇区的磁盘信息,在ReadOneSec后使用,得到的磁盘信息放在bootinfo结构中
219
220
221 char CFGetBoot()
222 {
223 1 unsigned char i;
224 1 if(ReadOneSec(0)==0)
225 1 {
226 2 return -1;
227 2 }
228 1 bootinfo.byte_per_sec=((struct sBoot*)data_buf)->bsBytesPerSec[1]*256+((struct sBoot*)data_buf)->bsBytesP
-erSec[0];
229 1 bootinfo.sec_per_clust=((struct sBoot*)data_buf)->bsSecPerClust;
230 1 bootinfo.reserved_sector=((struct sBoot*)data_buf)->bsResSectors[1]*256+((struct sBoot*)data_buf)->bsResS
-ectors[0];
231 1 bootinfo.fat_num=((struct sBoot*)data_buf)->bsFATs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -