📄 usb.lst
字号:
C51 COMPILER V7.50 USB 03/07/2005 09:36:38 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE USB
OBJECT MODULE PLACED IN USB.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE USB.C LARGE ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND
line 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
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)
C51 COMPILER V7.50 USB 03/07/2005 09:36:38 PAGE 2
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 //设置配置
72 #define get_interface 0x0a //取得接口
73 #define set_interface 0x0b //设置接口
74
75
76
77 void AtmelUSBInit() //用于USB的PLL时钟20M晶振时如下设置
78 {
79 int data i;
80 PLLNDIV = 0x04; //设置PLL时钟
81 PLLCON |= (0x3&Rdiv)<<6;
82 PLLRDIV = (0x3ff&Rdiv)>>2;
83 USBCLK=0;
84 PLLCON&=(~PLLRES); //使能PLL
85 PLLCON|=PLLEN;
86 USBCON&=(~USBE); //关闭USB并复位USB
87 for(i=0;i<3000;i++); //等待PLL工作稳定
88 USBCON|=USBE; //开启USB控制器
89
90 }
91
92 void EpEnable(void) //初始化USB端点
93 {
94 UEPNUM=0x00; UEPCONX=0x80;
95 UEPNUM=0x01; UEPCONX=0x86;
96 UEPNUM=0x02; UEPCONX=0x82;
97 UEPRST=0x07; UEPRST= 0x00;
98 UEPIEN=0x07; USBIEN|=EEOFINT;
99 USBADDR=FEN;
100 }
101
102 unsigned char ReadEp(unsigned char EpNum,unsigned char *Data) //读取端口数据
103 {
104 unsigned char data i=0;
105 UEPNUM=EpNum; //指端口号
106 while(i<UBYCTLX) //读数据到缓冲//UBYCTX得到数据长度
107 {
108 Data[i++]=UEPDATX;
109 }
110 UEPSTAX&=~(RXOUTB0|RXOUTB1|RXSETUP); //清除相关位
111 return(i);
112 }
113
114 void WriteEp(unsigned char EpNum,unsigned char nLength,unsigned char *Data) //写端口数据
115 {
116 unsigned char data i=0;
117 UEPNUM=EpNum; //选择端口
C51 COMPILER V7.50 USB 03/07/2005 09:36:38 PAGE 3
118 UEPSTAX|=DIR; //控制方向
119 while(nLength--) UEPDATX=Data[i++]; //写入FIFO
120 UEPSTAX|=TXRDY; //开始发送
121 while(!(UEPSTAX&TXCMP)) ;
122 UEPSTAX&=(~(TXCMP)); //清除TXCMP
123 }
124
125 //-------------以下用于对端点进行处理
126
127 void Set_Address(unsigned char EpNum) //设置USB地址1-127
128 {
129 WriteEp(0,0,0); //在Status阶段过后才能改变设备地址
130 USBADDR|=EpNum;
131 USBADDR|=FEN; //设置地址
132 USBCON|=FADDEN; //地址使能
133 }
134
135 //设备描述符
136 code unsigned char Device_Descriptor[18] = {
137 0x12, //0x12
138 0x01, //DEVICE descriptor
139 0x10, 0x01, //spec rev level (BCD) 1.0
140 0x0, //device class
141 0x0, //device subclass
142 0x0, //device protocol
143 0x20, //max packet size
144 0x05, 0x82, //National's vendor ID
145 0x00, 0x11, //National's product ID
146 0x00, 0x00, //National's revision ID
147 0, //index of manuf. string
148 0, //index of prod. string
149 0, //index of ser. # string
150 0x01 //number of configs.
151 };
152 //配置描述符
153 code unsigned char Configuration_Descriptor_All[32] = {
154
155 9, //Size of Descriptor in Bytes
156 2, //Configuration Descriptor (0x02)
157 0x20, //Total length in bytes of data returned LSB
158 0x00, //MSB
159 1, //Number of Interfaces
160 1, //Value to use as an argument to select this configuration
161 0, //Index of String Descriptor describing this configuration
162 0x80,
163 0xfa, //Maximum Power Consumption in 2mA units
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -