📄 mp3.lst
字号:
170 {
171 1 printu("Get_Configuration ");
172 1 }
173 void Set_Configuration(unsigned char wValue)
174 {
175 1
176 1 if(wValue == 0) {
177 2 /* put device in unconfigured state */
178 2 /* Disable all endpoints but EPP0. *///init_unconfig
C51 COMPILER V6.23a MP3 12/02/2003 11:07:53 PAGE 4
179 2
180 2 UEPNUM=0x00;//Ep0 as control Endpoint
181 2 UEPCONX=0x80;
182 2
183 2 UEPNUM=0x01;//Ep1 as Bulk-in Endpoint
184 2 UEPCONX=0x86;
185 2
186 2 UEPNUM=0x02;//Ep2 as Bulk-out Endpoint
187 2 UEPCONX=0x82;
188 2
189 2 // WriteEp(0,&Device_Descriptor[4],2);
190 2 USBCON&=(~CONFG);
191 2 WriteEp(0,0,0);//状态传送阶段之前完成指定操作
192 2
193 2 }
194 1 else if(wValue == 1) {
195 2 /* Configure device */
196 2 /* Enable generic/iso endpoints. init_config*/
197 2
198 2 UEPNUM=0x00;//Ep0 as control Endpoint
199 2 UEPCONX=0x80;
200 2
201 2 UEPNUM=0x01;//Ep1 as Bulk-in Endpoint
202 2 UEPCONX=0x86;
203 2
204 2 UEPNUM=0x02;//Ep2 as Bulk-out Endpoint
205 2 UEPCONX=0x82;
206 2
207 2
208 2 USBCON|=CONFG;
209 2 WriteEp(0,0,0);//状态传送阶段之前完成指定操作
210 2
211 2 }
212 1 // printu("Set_Configuration ");
213 1 }
214 void Get_Interface()
215 {
216 1 printu("Get_Interface ");
217 1 }
218 void Set_Interface()
219 {
220 1 WriteEp(0,0,0);
221 1 printu("Set_Interface ");
222 1 }
223
224 void Ep0Int()
225 {
226 1 unsigned char i,j;
227 1 unsigned char ControlData[32]={0,};
228 1 i=ReadEp(0,ControlData);//读端点0
229 1 P3_5 = 0;//USB通信指示灯点亮
230 1 j=ControlData[0]&0x60;//过滤端点0数据
231 1 if((j==0)&&i){//如果为标准USB请求
232 2 switch(ControlData[1]){//分别按请求类别进行处理
233 3 case get_status : Get_Status();break;
234 3 case clear_feature : Clear_Feature();break;
235 3
236 3 case set_feature : Set_Feature();break;
237 3
238 3 case set_address : Set_Address(ControlData[2]);break;
239 3 case get_descriptor : Get_Descriptor(ControlData[3],ControlData[6]);break;
240 3
C51 COMPILER V6.23a MP3 12/02/2003 11:07:53 PAGE 5
241 3 case get_configuration : Get_Configuration();break;
242 3 case set_configuration : Set_Configuration(ControlData[2]);break;
243 3 case get_interface : Get_Interface();break;
244 3 case set_interface : Set_Interface();break;
245 3 default : Reserved();break;
246 3 }
247 2 }
248 1 else if(ControlData[0]==0xa1){//特殊请求,特殊处理,直接返回Status
249 2 WriteEp(0,0,0);
250 2 }
251 1
252 1 P3_5 = 1;//USB通信指示灯关闭
253 1
254 1 }
255
256 //Bulk-In端点处理
257 void main_txdone()
258 {
259 1 // printuf("Bulk_State:%x\n",bulk_state);
260 1 P3_5 = 0;////USB通信指示灯点亮
261 1
262 1 UEPSTAX&=(~(TXCMP));//清中断标志位clear TXCMP
263 1 switch(bulk_state){//按不同的传输状态,进行不同的后续处理
264 2 case BULK_DATA_TRANS:
265 2 TransDataGoOn();
266 2 break;
267 2 case BULK_DATA_END:
268 2 TransmitCSW();
269 2 break;
270 2 case BULK_REQEST_TRANS:
271 2 TransRequestGoOn();
272 2 break;
273 2 case BULK_CSW_END:
274 2 break;
275 2 default: return;
276 2 }
277 1 P3_5 = 1;//USB通信指示灯关闭
278 1 }
279
280 //Bulk-Out端点处理
281 void main_rxdone()
282 {
283 1 // printu("\nmain_rxdone ");
284 1 P3_5 = 0;//USB通信指示灯点亮
285 1 ReadEp(2,Bulk_Out_Buf);//读取端点2
286 1 if((bulk_state != BULK_DATA_RECIEVE) &&(Bulk_Out_Buf[0] == 0x55)) InterpretCBW();//判断是否为命令数据
287 1 else Trans_Data2PC(); //为普通数据时转向数据接收处理程序
288 1 P3_5 = 1;//USB通信指示灯关闭
289 1
290 1 }
291 void Reserved()
292 {
293 1 printuf("Undefined Interrupt Occured:%x\n",UEPINT);
294 1 }
295 //END OF USB DISK
296
297
298 void MP3Init()
299 {
300 1
301 1 // printuf("Ready to set the pll clock\n");
302 1 AUXR1=0xf2; //这两个寄存器的值在用Start Application和直接上电时不一样,前一种情况下MP3蟹码器才工作,
C51 COMPILER V6.23a MP3 12/02/2003 11:07:53 PAGE 6
303 1 PLLCON=0; //这里强制将其置为与用Start Application按钮时一致
304 1
305 1 //锁相环时钟及MP3解码器时钟设置
306 1 PLLNDIV=0x03; //pll 84,000,000 1 13 7, 3 6 1, 1 6 3, 336000000 0,1b,1f
307 1 PLLRDIV=0x06; //pll 72M mp3clk 36M audclk 7.2M(3,6,a)
308 1 // 92M
309 1 PLLCON=PLLCON|PLLEN;
310 1 PLLCON=PLLCON|PLOCK;
311 1
312 1 MP3CLK=0x02;
313 1
314 1 //MP3音量及音效初始值
315 1 MP3VOR=0x0f;
316 1 MP3VOL=0x0f;
317 1 MP3BAS=0x0f;
318 1 MP3MED=0x0f;
319 1 MP3TRE=0x0f;
320 1
321 1 //音频解码器模式及时钟设置
322 1 AUDCON0=0x77;
323 1 AUDCON1=0x41;
324 1 AUDCLK=0x05; // 1a
325 1
326 1 // AUDCON0=0x76; //HLR=0,256X
327 1 // AUDCON1=0x41;
328 1 // AUDCLK=0x08; // 1a
329 1 // printuf("MP3STA:%x\n",MP3STA);
330 1
331 1 MP3CON&=(~MSKREQ); //允许产生MP3中断Clear to allow the MPREQ flag to generate a MP3 interrupt.
332 1
333 1 MP3CON|=MPEN; //使能MP3解码器Set to enable the MP3 decoder.
334 1
335 1
336 1 CKCON=0x01; //使能X2模式,增加处理速度
337 1
338 1 }
339 //播放MP3歌曲
340 void PlayMP3(unsigned char *SongName)
341 {
342 1 int i=0,j=0;
343 1
344 1 //First 1024 Byte MP3 Data
345 1 m=ReadSector(SongName,Page_Buf);//从当前歌曲中读取512字节
346 1 if(MP3STA1&MPFREQ) //解码器数据请求中断产生时
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -