📄 f34x_msd_cf_basic_functions.lst
字号:
=1 }
=1 #define CF_SET_REGISTER_VALUE(addr,value) {\
=1 CF_SET_ADDR_LINE(addr);\
=1 CF_WR_DATA(value);\
=1 CF_WRITE;\
=1 CF_WAIT_STATE;\
=1 CF_READWRITE_IDLE;\
=1 }
=1 #endif
130 =1
131 =1 #endif
37 #include <stdio.h>
1 =1 /*----------------------------------------------------------------
-----------
2 =1 STDIO.H
3 =1
4 =1 Prototypes for standard I/O functions.
5 =1 Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, In
-c.
6 =1 All rights reserved.
7 =1 ------------------------------------------------------------------
---------*/
8 =1
9 =1 #ifndef __STDIO_H__
C51 COMPILER V7.50 F34X_MSD_CF_BASIC_FUNCTIONS 11/28/2006 10:53:58 PAGE 18
10 =1 #define __STDIO_H__
11 =1
12 =1 #ifndef EOF
13 =1 #define EOF -1
14 =1 #endif
15 =1
16 =1 #ifndef NULL
17 =1 #define NULL ((void *) 0)
18 =1 #endif
19 =1
20 =1 #ifndef _SIZE_T
21 =1 #define _SIZE_T
22 =1 typedef unsigned int size_t;
23 =1 #endif
24 =1
25 =1 #pragma SAVE
26 =1 #pragma REGPARMS
27 =1 extern char _getkey (void);
28 =1 extern char getchar (void);
29 =1 extern char ungetchar (char);
30 =1 extern char putchar (char);
31 =1 extern int printf (const char *, ...);
32 =1 extern int sprintf (char *, const char *, ...);
33 =1 extern int vprintf (const char *, char *);
34 =1 extern int vsprintf (char *, const char *, char *);
35 =1 extern char *gets (char *, int n);
36 =1 extern int scanf (const char *, ...);
37 =1 extern int sscanf (char *, const char *, ...);
38 =1 extern int puts (const char *);
39 =1
40 =1 #pragma RESTORE
41 =1
42 =1 #endif
43 =1
38
39 sbit Led1 = P2^2;
40 sbit Led2 = P2^3;
41 void CF_Port_Init();
42
43 //----------------------------------------------------------------
-------------
44 // Init_CF
45 //----------------------------------------------------------------
-------------
46 //
47 // This routine initializes the Compact Flash memory card
48 //
49 // Parameters :
50 // Return Value :
51 //----------------------------------------------------------------
-------------
52
53 char Init_CF()
54 {
55 1 xdata char result = Dtct_Card();
56 1 xdata unsigned int loop = 0;
57 1 xdata unsigned reinit = 0;
58 1 if (result == 1) return (CF_NO_CARD);
59 1 REINIT:
60 1 CF_RST = 1;
61 1 while(++loop);
62 1 CF_WAIT_STATE;
C51 COMPILER V7.50 F34X_MSD_CF_BASIC_FUNCTIONS 11/28/2006 10:53:58 PAGE 19
63 1 CF_WAIT_STATE;
64 1 CF_WAIT_STATE;
65 1 CF_WAIT_STATE;
66 1 CF_RST = 0;
67 1 while(!CF_RDY) {
68 2 if(++loop == 0) {
69 3 CF_GET_REGISTER_VALUE(0x01);
70 3 goto REINIT;
71 3 }
72 2 }
73 1 while(++loop);
74 1 if((CF_GET_REGISTER_VALUE(0x01) & 0xf0) != 0)
75 1 goto REINIT;
76 1 return 0;
77 1 }
78
79
80 //----------------------------------------------------------------
-------------
81 // Wait_Drq
82 //----------------------------------------------------------------
-------------
83 //
84 // This function waits until data reqeust bit in staus register is
- clear
85 //
86 // Parameters :
87 // Return Value :
88 //----------------------------------------------------------------
-------------
89
90 void Wait_Drq()
91 {
92 1 xdata char wait, wait_drq;
93 1 xdata int loopguard = 0;
94 1 do {
95 2 #ifndef MACRO_CF_VERSIONS
96 2 wait = CF_GET_REGISTER_VALUE(0x07); // Read status register
97 2 #else
CF_GET_REGISTER_VALUE(0x07,wait); // Read status register
#endif
100 2 if(wait & 0x01) {
101 3 wait_drq = CF_GET_REGISTER_VALUE(0x01);
102 3 return;
103 3 }
104 2 wait_drq = wait & 0x08; // Wait for DRQ to SET
105 2 } while (wait_drq == (char)0x00);
106 1 }
107
108
109 //----------------------------------------------------------------
-------------
110 // Wait_Busy
111 //----------------------------------------------------------------
-------------
112 //
113 // This function waits until busy bit is set
114 //
115 // Parameters :
116 // Return Value :
117 //----------------------------------------------------------------
-------------
C51 COMPILER V7.50 F34X_MSD_CF_BASIC_FUNCTIONS 11/28/2006 10:53:58 PAGE 20
118
119 void Wait_Busy()
120 {
121 1 xdata char wait, wait_bsy;
122 1 do {
123 2 #ifndef MACRO_CF_VERSIONS
124 2 wait = CF_GET_REGISTER_VALUE(0x07); // Read status register
125 2 #else
CF_GET_REGISTER_VALUE(0x07,wait); // Read status register
#endif
128 2 wait_bsy = wait & 0x80; // Wait for DRQ to SET
129 2 } while (wait_bsy == (char)0x80);
130 1 }
131
132
133 //----------------------------------------------------------------
-------------
134 // Dtct_Card
135 //----------------------------------------------------------------
-------------
136 //
137 // Function detcts if compact flash card is in slot
138 //
139 // Parameters :
140 // Return Value : 0 card is on , 1 off
141 //----------------------------------------------------------------
-------------
142
143 char Dtct_Card(void)
144 {
145 1 xdata char card_detect;
146 1 card_detect = CF_CD1;
147 1 return (card_detect); // 0 card is on , 1 off
148 1 }
149
150 #ifndef MACRO_CF_VERSIONS
151
152 //----------------------------------------------------------------
-------------
153 // CF_GET_REGISTER_VALUE
154 //----------------------------------------------------------------
-------------
155 //
156 // Function returns value from register pointed by addr
157 //
158 // Parameters : addr - address value of CF register
159 // Return Value : value stroed in register
160 //----------------------------------------------------------------
-------------
161
162 char CF_GET_REGISTER_VALUE(char addr)
163 {
164 1 xdata char ret = 0;
165 1 CF_SET_ADDR_LINE(addr);
166 1 CF_READ;
167 1 CF_WAIT_STATE;
168 1 ret = CF_READ_DATA;
169 1 CF_READWRITE_IDLE;
170 1 return ret;
171 1 }
172
173
C51 COMPILER V7.50 F34X_MSD_CF_BASIC_FUNCTIONS 11/28/2006 10:53:58 PAGE 21
174 //----------------------------------------------------------------
-------------
175 // CF_SET_REGISTER_VALUE
176 //----------------------------------------------------------------
-------------
177 //
178 // Function sets value of register
179 //
180 // Parameters : addr - register address
181 // value - value to set
182 // Return Value :
183 //----------------------------------------------------------------
-------------
184
185 void CF_SET_REGISTER_VALUE(char addr, char value)
186 {
187 1 CF_SET_ADDR_LINE(addr);
188 1 CF_WR_DATA(value);
189 1 CF_WRITE;
190 1 CF_WAIT_STATE;
191 1 CF_READWRITE_IDLE;
192 1 }
193 #endif
194
195 //----------------------------------------------------------------
-------------
196 // Write_Sector
197 //----------------------------------------------------------------
-------------
198 //
199 // Function writes buffer into address
200 //
201 // Parameters : address - LBA address
202 // buffer - buffer with data to write
203 // Return Value : return error status or 0 if everything was OK
204 //----------------------------------------------------------------
-------------
205
206 char Write_Sector(unsigned long address, char* buffer)
207 {
208 1 xdata char cylinder_low, cylinder_high,sector,head;
209 1 xdata char result, error;
210 1 xdata int i;
211 1 result = Dtct_Card();
212 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -