📄 d12_driver.lst
字号:
C51 COMPILER V8.01 D12_DRIVER 04/19/2006 16:02:45 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE D12_DRIVER
OBJECT MODULE PLACED IN d12_driver.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE d12_driver.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "hardware.h"
2 #include "d12_driver.h"
3
4 //---------------------------------
5 #define D12Command() (D12_A0=1)
6 #define D12Data() (D12_A0=0)
7 #define D12En() (D12_CS=0)
8 #define D12Dis() (D12_CS=1)
9
10 #define D12OutPort(x) {CPU_WR=0;P2=x,CPU_WR=1;}
11 #define D12InPort(x) {CPU_RD=0;CPU_RD=1,x=P2;}
12
13
14 bit D12_GetID(void)
15 {
16 1 unsigned int D12ID;
17 1
18 1 D12Command();
19 1 D12En();
20 1 D12OutPort(D12_GETIDCMD);
21 1
22 1 D12Data();
23 1 P2=0xFF;
24 1 D12InPort(((UCHAR*)&D12ID)[0]);
25 1 D12InPort(((UCHAR*)&D12ID)[1]);
26 1 D12Dis();
27 1 if(D12ID==D12_ID)
28 1 return 1;
29 1 else
30 1 return 0;
31 1 }
32
33 //--------------------------
34 void D12_SetAddressEnable(unsigned char bAddress, unsigned char bEnable)
35 {
36 1 D12Command();
37 1 D12En();
38 1 D12OutPort(0xD0);
39 1
40 1 if(bEnable)
41 1 bAddress |= 0x80;
42 1 D12Data();
43 1 D12OutPort(bAddress);
44 1
45 1 D12Dis();
46 1 }
47
48 void D12_SetEndpointEnable(unsigned char bEnable)
49 {
50 1 D12Command();
51 1 D12En();
52 1 D12OutPort(0xD8);
53 1
54 1 D12Data();
55 1 if(bEnable)
C51 COMPILER V8.01 D12_DRIVER 04/19/2006 16:02:45 PAGE 2
56 1 {D12OutPort(1);}
57 1 else
58 1 {D12OutPort(0);}
59 1
60 1 D12Dis();
61 1 }
62
63 void D12_SetMode(unsigned char bConfig, unsigned char bClkDiv)
64 {
65 1 D12Command();
66 1 D12En();
67 1 D12OutPort(0xF3);
68 1 D12Data();
69 1 D12OutPort(bConfig);
70 1 D12OutPort(bClkDiv);
71 1 D12Dis();
72 1 }
73
74 /*
75 unsigned char D12_ReadEndpointStatus(unsigned char bEndp)
76 {
77 unsigned char c;
78
79 if(bEPPflags.bits.in_isr == 0)
80 DISABLE;
81
82 outportcmd(0x80 + bEndp);
83 c = inportb();
84
85 if(bEPPflags.bits.in_isr == 0)
86 ENABLE;
87
88 return c;
89 }
90 */
91 void D12_SetEndpointStatus(unsigned char bEndp, unsigned char bStalled)
92 {
93 1 D12Command();
94 1 D12En();
95 1 D12OutPort(0x40 + bEndp);
96 1 D12Data();
97 1 D12OutPort(bStalled);
98 1 D12Dis();
99 1 }
100
101
102 /*
103 void D12_SendResume(void)
104 {
105 outportcmd(0xF6);
106 }
107 */
108
109 unsigned char D12_WriteEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
110 {
111 1 unsigned char i;
112 1
113 1 //---------------------
114 1 D12Command();
115 1 D12En();
116 1
117 1 D12OutPort(endp); //选择端点
C51 COMPILER V8.01 D12_DRIVER 04/19/2006 16:02:45 PAGE 3
118 1 D12Data();
119 1 P2=0xFF;
120 1 D12InPort(i); //读入满/空状态
121 1
122 1 D12Command();
123 1 D12OutPort(0xF0); //写缓冲区命令
124 1
125 1 D12Data();
126 1 D12OutPort(0);
127 1 D12OutPort(len);
128 1
129 1 for(i=0; i<len; i++)
130 1 D12OutPort(*(buf+i));
131 1
132 1 D12Command();
133 1 D12OutPort(0xFA); //驶购冲区有效
134 1
135 1 D12Dis();
136 1 //--------------------------------
137 1
138 1 return len;
139 1 }
140 void D12_AcknowledgeEndpoint(unsigned char endp)
141 {
142 1 D12Command();
143 1 D12En();
144 1 D12OutPort(endp); //选择端点
145 1 D12OutPort(0xF1); //应答设置
146 1 if(endp == 0)
147 1 D12OutPort(0xF2); //缓冲区清零
148 1 D12Dis();
149 1 }
150 unsigned short D12_ReadInterruptRegister(void)
151 {
152 1 unsigned char b1;
153 1 unsigned int j;
154 1
155 1 D12Command();
156 1 D12En();
157 1 D12OutPort(0xF4);
158 1 D12Data();
159 1 P2=0xFF;
160 1 D12InPort(b1);
161 1 D12InPort(j);
162 1 D12Dis();
163 1 j <<= 8;
164 1 j += b1;
165 1 return j;
166 1 }
167
168 unsigned char D12_ReadLastTransactionStatus(unsigned char bEndp)
169 {
170 1 unsigned char i;
171 1
172 1 D12Command();
173 1 D12En();
174 1 D12OutPort(0x40 + bEndp);
175 1 D12Data();
176 1 P2=0xFF;
177 1 D12InPort(i);
178 1 D12Dis();
179 1
C51 COMPILER V8.01 D12_DRIVER 04/19/2006 16:02:45 PAGE 4
180 1 return i;
181 1 }
182 unsigned char D12_ReadEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
183 {
184 1 unsigned char i, j;
185 1
186 1 //--------------------------------
187 1 D12Command();
188 1 D12En();
189 1 D12OutPort(endp); //选择端点
190 1 D12Data();
191 1 P2=0xFF;
192 1 D12InPort(i);
193 1 if((i&D12_FULLEMPTY)==0)
194 1 return 0;
195 1
196 1 D12Command();
197 1 D12OutPort(0xF0); //读缓冲区
198 1 D12Data();
199 1 P2=0xFF;
200 1 D12InPort(j);
201 1 D12InPort(j);
202 1
203 1 if(j > len)
204 1 j = len;
205 1
206 1 for(i=0; i<j; i++)
207 1 D12InPort(*(buf+i));
208 1
209 1 D12Command();
210 1 D12OutPort(0xF2); //缓冲区清空
211 1 D12Dis();
212 1 //-------------------------------
213 1
214 1 return j;
215 1 }
216
217 unsigned char D12_SelectEndpoint(unsigned char bEndp)
218 {
219 1 unsigned char c;
220 1
221 1 D12Command();
222 1 D12En();
223 1 D12OutPort(bEndp);
224 1 D12Data();
225 1 P2=0xFF;
226 1 D12InPort(c);
227 1 D12Dis();
228 1
229 1 return c;
230 1 }
231
232 void D12_SetDMA(unsigned char bMode)
233 {
234 1 D12Command();
235 1 D12En();
236 1 D12OutPort(0xFB);
237 1 D12Data();
238 1 D12OutPort(bMode);
239 1 D12Dis();
240 1 }
241
C51 COMPILER V8.01 D12_DRIVER 04/19/2006 16:02:45 PAGE 5
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 510 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 8
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 + -