📄 usb.lst
字号:
C51 COMPILER V7.06 USB 03/21/2006 09:38:04 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE USB
OBJECT MODULE PLACED IN USB.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE USB.C LARGE BROWSE DEBUG OBJECTEXTEND PAGEWIDTH(130) PAGELENGTH(80)
stmt level source
1
2 /*********************************************************************************************************
3 **
4 ** MP3 and U Disk Source Code
5 ** Copyright (c) 2005,北京博创兴业科技有限公司
6 ** All Rights Reserved
7 ** V3.00.0
8 **
9 **--------------文件信息--------------------------------------------------------------------------------
10 **文 件 名: USB.C
11 **创 建 人: Frank Wang Xiao Jun
12 **创 建 日 期: 2003.12
13 **描 述: ATMEL AT89C51SND1单片机USB硬件寄存器的配置以及Bulk_Only协议和U盘的实现
14 **
15 **--------------历史版本信息----------------------------------------------------------------------------
16 ** 创建人: Frank Wang Xiao Jun
17 ** 版 本: V1.00.0
18 ** 日 期: 2003.12
19 ** 描 述: ATMEL AT89C51SND1单片机USB硬件寄存器的配置以及Bulk_Only协议和U盘的实现
20 **
21 **------------------------------------------------------------------------------------------------------
22 ** 修改人: Kent Zou Ying
23 ** 版 本: V2.00.0
24 ** 日 期: 2004. 5
25 ** 描 述: ATMEL AT89C51SND1单片机USB硬件寄存器的配置以及Bulk_Only协议和U盘的实现
26 **
27 **--------------当前版本修订------------------------------------------------------------------------------
28 ** 修改人: Phoenix Hua Yue Guang
29 ** 版 本: V3.00.0
30 ** 日 期: 2005.3
31 ** 描 述: ATMEL AT89C51SND1单片机USB硬件寄存器的配置以及Bulk_Only协议和U盘的实现
32 **
33 **------------------------------------------------------------------------------------------------------
34 ********************************************************************************************************/
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include "REGSND1.H"
39 #include "USBDEF.H"
40 #include "UART.h"
41
42 //时钟参数宏
43 #define Rdiv 11
44 //USB寄存器设置相关的宏定义
45 #define PLLRES (0x1<<3) //PLLCON
46 #define PLLEN (0x1<<1)
47 #define USBE (0x1<<7) //USBCON ,usb enable.
48 #define EEOFINT (0x1<<4)
49 #define FEN (0x1<<7)
50 #define FADDEN (0x1)
51 #define CONFG (0x1<<1)
52 #define DIR (0x1<<7) //UEPSTAX
53 #define RXOUTB1 (0x1<<6)
54 #define STALLRQ (0x1<<5)
55 #define TXRDY (0x1<<4)
56 #define STLCRC (0x1<<3)
57 #define RXSETUP (0x1<<2)
58 #define RXOUTB0 (0x1<<1)
59 #define TXCMP (0x1<<0)
60
61 //USB 请求的bRequert的含意宏
62 #define get_status 0x00 //取得状态
63 #define clear_feature 0x01 //清除特性
64 #define reserved 0x02 //保留
65 #define set_feature 0x03 //设置特性
66
67 #define set_address 0x05 //设置地址
68 #define get_descriptor 0x06 //取得描述符
69
70 #define get_configuration 0x08 //取得配置
71 #define set_configuration 0x09 //设置配置
C51 COMPILER V7.06 USB 03/21/2006 09:38:04 PAGE 2
72 #define get_interface 0x0a //取得接口
73 #define set_interface 0x0b //设置接口
74
75 /**---------------------------------------------------------------------------------
76
77 ----------------------------------------------------------------------------------**/
78
79 void AtmelUSBInit() //用于USB的PLL时钟20M晶振时如下设置
80 {
81 1 int data i;
82 1 PLLNDIV = 0x04; //设置PLL时钟
83 1 PLLCON |= (0x3&Rdiv)<<6;
84 1 PLLRDIV = (0x3ff&Rdiv)>>2;
85 1 USBCLK=0;
86 1 PLLCON&=(~PLLRES); //使能PLL
87 1 PLLCON|=PLLEN;
88 1 USBCON&=(~USBE); //关闭USB并复位USB
89 1 for(i=0;i<3000;i++); //等待PLL工作稳定
90 1 USBCON|=USBE; //开启USB控制器
91 1
92 1 }
93
94 void EpEnable(void) //初始化USB端点
95 {
96 1 UEPNUM=0x00; UEPCONX=0x80;
97 1 UEPNUM=0x01; UEPCONX=0x86;
98 1 UEPNUM=0x02; UEPCONX=0x82;
99 1 UEPRST=0x07; UEPRST= 0x00;
100 1 UEPIEN=0x07; USBIEN|=EEOFINT;
101 1 USBADDR=FEN;
102 1 }
103
104 unsigned char ReadEp(unsigned char EpNum,unsigned char *Data) //读取端口数据
105 {
106 1 unsigned char data i=0;
107 1 UEPNUM=EpNum; //指端口号
108 1 while(i<UBYCTLX) //读数据到缓冲//UBYCTX得到数据长度
109 1 {
110 2 Data[i++]=UEPDATX;
111 2 }
112 1 UEPSTAX&=~(RXOUTB0|RXOUTB1|RXSETUP); //清除相关位
113 1 return(i);
114 1 }
115
116 void WriteEp(unsigned char EpNum,unsigned char nLength,unsigned char *Data) //写端口数据
117 {
118 1 unsigned char data i=0;
119 1 UEPNUM=EpNum; //选择端口
120 1 UEPSTAX|=DIR; //控制方向
121 1 while(nLength--) UEPDATX=Data[i++]; //写入FIFO
122 1 UEPSTAX|=TXRDY; //开始发送
123 1 while(!(UEPSTAX&TXCMP)) ;
124 1 UEPSTAX&=(~(TXCMP)); //清除TXCMP
125 1 }
126
127 //-------------以下用于对端点进行处理
128
129 void Set_Address(unsigned char EpNum) //设置USB地址1-127
130 {
131 1 WriteEp(0,0,0); //在Status阶段过后才能改变设备地址
132 1 USBADDR|=EpNum;
133 1 USBADDR|=FEN; //设置地址
134 1 USBCON|=FADDEN; //地址使能
135 1 }
136
137 //设备描述符
138 code unsigned char Device_Descriptor[18] = {
139 0x12, //0x12
140 0x01, //DEVICE descriptor
141 0x10, 0x01, //spec rev level (BCD) 1.0
142 0x0, //device class
143 0x0, //device subclass
144 0x0, //device protocol
145 0x20, //max packet size
146 0x05, 0x82, //National's vendor ID
147 0x00, 0x11, //National's product ID
148 0x00, 0x00, //National's revision ID
149 0, //index of manuf. string
C51 COMPILER V7.06 USB 03/21/2006 09:38:04 PAGE 3
150 0, //index of prod. string
151 0, //index of ser. # string
152 0x01 //number of configs.
153 };
154 //配置描述符
155 code unsigned char Configuration_Descriptor_All[32] = {
156
157 9, //Size of Descriptor in Bytes
158 2, //Configuration Descriptor (0x02)
159 0x20, //Total length in bytes of data returned LSB
160 0x00, //MSB
161 1, //Number of Interfaces
162 1, //Value to use as an argument to select this configuration
163 0, //Index of String Descriptor describing this configuration
164 0x80,
165 0xfa, //Maximum Power Consumption in 2mA units
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -