32musb.lst
来自「这个是一个完整的MP3项目」· LST 代码 · 共 941 行 · 第 1/4 页
LST
941 行
C51 COMPILER V7.20 32MUSB 03/21/2007 13:34:25 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE 32MUSB
OBJECT MODULE PLACED IN 32MUSB.OBJ
COMPILER INVOKED BY: C:\Program Files\keil\C51\BIN\C51.EXE 32MUSB.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 * Copyright (c) 2004,北京博创兴业科技有限公司
3 * All rights reserved.
4 *
5 * 文件名称:32MUSB.c
6 * 文件标识:32MUSB
7 * 摘 要:主函数
8 *
9 * 当前版本:2.0
10 * 作 者:Kent
11 * 完成日期:2004年5月20日
12 *
13 * 取代版本:1.1
14 * 原作者 :Frank
15 * 完成日期:2003年8月10日
16 */
17
18 #include "REGSND1.H"
19 #include "atmelusbci.h"
20 #include "uart.h"
21 #include "usbdisk.h"
22 #include "bulk_only.h"
23 #include "fat16.h"
24 #include "flash.h"
25
26 //****************************by kent******************************************************************
27 int m = 0;
28 unsigned char MP3InitFlag;
29 //unsigned char PLLRegister;
30 //unsigned char MP3Register;
31 //unsigned char AudioRegister;
32 unsigned char FirstStart = 1;
33 //extern unsigned char bulk_state;//记录USB传输过程中传输状态
34 //extern unsigned char Bulk_Out_Buf[];//Bulk-Out端点缓存区
35 //extern unsigned char Page_Buf[];//页(扇区)缓存区
36 unsigned char MP3_Framehead[4];//解析MP3帧头数组
37 /*
38 bits name comments
39 --------------------------------------------------
40 12 sync 0xFFF
41 1 version 1=mpeg1.0, 0=mpeg2.0
42 2 lay 4-lay = layerI, II or III
43 1 error protection 0=yes, 1=no
44 4 bitrate_index see table below
45 2 sampling_freq see table below
46 1 padding
47 1 extension see table below
48 2 mode see table below
49 2 mode_ext used with "joint stereo" mode
50 1 copyright 0=no 1=yes
51 1 original 0=no 1=yes
52 2 emphasis see table below
53 --------------------------------------------------
54
55 */
C51 COMPILER V7.20 32MUSB 03/21/2007 13:34:25 PAGE 2
56 //unsigned char MP3_Trailer[128];//
57 /*
58 at end of file - 128 bytes
59
60
61
62 offset type len name
63 --------------------------------------------
64 0 char 3 "TAG"
65 3 char 30 title
66 33 char 30 artist
67 63 char 30 album
68 93 char 4 year
69 97 char 30 comments
70 127 byte 1 genre
71 --------------------------------------------
72 */
73 code unsigned char BaudRate[2][3][14] = {
74 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,
75 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,
76 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,
77
78 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,
79 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,
80 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160
81 };
82 //extern unsigned char FirstTransaction;
83 //int m=0;
84 extern unsigned char bulk_CSW[];
85 extern unsigned char bulk_state;//记录USB传输过程中传输状态
86 //extern unsigned char Bulk_Out_Buf[];//Bulk-Out端点缓存区
87 extern unsigned char Page_Buf[];//页(扇区)缓存区
88 extern unsigned char FirstTransaction;
89 extern unsigned char *BulkPoint;
90 extern unsigned char *BulkStartPoint;
91 //设备描述符
92 code unsigned char Device_Descriptor[18] = {
93 0x12, //0x12
94 0x01, //DEVICE descriptor
95 0x10, 0x01, //spec rev level (BCD) 1.0
96 0x0, //device class
97 0x0, //device subclass
98 0x0, //device protocol
99 0x20, //max packet size
100 0x05, 0x82, //National's vendor ID
101 0x00, 0x11, //National's product ID
102 0x00, 0x00, //National's revision ID
103 0, //index of manuf. string
104 0, //index of prod. string
105 0, //index of ser. # string
106 0x01 //number of configs.
107 };
108 //配置描述符
109 code unsigned char Configuration_Descriptor_All[32] = {
110
111 9,//Size of Descriptor in Bytes
112 2,//Configuration Descriptor (0x02)
113 0x20,//Total length in bytes of data returned LSB
114 0x00,//MSB
115 1,//Number of Interfaces
116 1,//Value to use as an argument to select this configuration
117 0,//Index of String Descriptor describing this configuration
C51 COMPILER V7.20 32MUSB 03/21/2007 13:34:25 PAGE 3
118 0x80,
119 0xfa,//Maximum Power Consumption in 2mA units
120
121 9,
122 4,
123 0,//the index of the interface descriptor Number of Interface
124 0,//Value used to select alternative setting
125 2,//EndPoint Number Used in this Descriptor
126 8,//Class Code (Assigned by USB Org)
127 6, //interface subclass1=RBC,2=SFF,3=QIC,4=UFI,5=SFF,6=SCSI
128 0x50,//bulk 0nly Transport
129 0,//Index of String Descriptor Describing this interface
130
131 //Bulk-in Endpoint
132 0x07, //length of this desc.
133 0x05, //ENDPOINT descriptor TYPE
134 0x81, //address (IN) Endpoint 4 84
135 0x02, //attributes (BULK)
136 0x40, 0x00, //max packet size (64)
137 0x0, //Does not apply to Bulk endpoints
138
139 //Bulk-out Endpoint
140 0x07, //length of this desc.
141 0x05, //ENDPOINT descriptor TYPE
142 0x02, //address (OUT) Endpoint 5 05
143 0x02, //attributes (BULK)
144 0x40, 0x00, //max packet size (64)
145 0x0 //Does not apply to Bulk endpoints
146 };
147
148 //用于存放歌曲列表的数组
149 unsigned char SONG[88] = {'M', 'O', 'O', 'N', ' ', ' ', ' ', ' ', 'T', 'X', 'T'};
150
151 //MP3有关的变量*********************
152 #define VOLUME 1
153 #define EFFECTION 2
154 #define SELECTSONG 3
155 #define PLAY 1
156 #define STOP 0
157 unsigned char CurrentFun = SELECTSONG;
158 unsigned char PlayState = STOP;
159 unsigned char ChangeSong = 0;
160
161 unsigned char NowPlaying = 0;
162 unsigned char NumofSong = 0;
163 extern long int DataRead;
164 //***************************
165
166 //USB DISK
167 //读端点数据
168 unsigned char ReadEp(unsigned char EpNum, unsigned char *Data)
169 {
170 1 unsigned char i = 0, nLength;
171 1 UEPNUM = EpNum;//指向相应端点
172 1 BulkStartPoint = Data;
173 1 nLength = UBYCTX;//读取端点数据长度
174 1
175 1 while (nLength--)
176 1 {
177 2 if (UEPNUM == 2)
178 2 {
179 3 *(BulkPoint++) = UEPDATX;
C51 COMPILER V7.20 32MUSB 03/21/2007 13:34:25 PAGE 4
180 3 i++;
181 3 }
182 2 else
183 2 {
184 3 Data[i++] = UEPDATX;//*printuf("%x ",Data[i]);*/}//依次读取端点收到的数据
185 3 }
186 2 }
187 1
188 1 UEPSTAX &= ~(RXOUTB0 | RXOUTB1 | RXSETUP);//清中断标志
189 1 return (i);//返回读取到的数据的长度
190 1 }
191
192 //向端点0写数据
193 void WriteEp(unsigned char EpNum, unsigned char nLength, unsigned char *Data)
194 {
195 1 unsigned char i=0;
196 1
197 1 UEPNUM = EpNum;//指向相应端点
198 1 UEPSTAX |= DIR;//设置方向为写
199 1
200 1 while (nLength--)
201 1 {
202 2 UEPDATX = Data[i++];//将数据写入端点
203 2 }
204 1
205 1 UEPSTAX |= TXRDY;//发送数据Sending the data,this action will switch between bank0 and bank1
206 1
207 1 while (!(UEPSTAX & TXCMP)) ;//等待发送完成
208 1
209 1 UEPSTAX &= (~(TXCMP));//清中断标志clear TXCMP
210 1 }
211
212 //写Bulk端点
213 void WriteEpBulk(unsigned char EpNum, unsigned char nLength, unsigned char *Data)
214 {
215 1 unsigned char i;
216 1
217 1 UEPNUM = EpNum;//指向相应端点
218 1 UEPSTAX |= DIR;//设置方向为写Set for status of a Control In transaction
219 1
220 1 for (i=0; i<nLength; i++)
221 1 {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?