📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 11/16/2008 16:00:07 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND TABS(1)
stmt level source
1 /******************************************************************
2 本程序只供学习使用,未经作者许可,不得用于其它任何用途
3
4 欢迎访问我的USB专区:http://group.ednchina.com/93/
5 欢迎访问我的blog: http://www.ednchina.com/blog/computer00
6 http://computer00.21ic.org
7
8 感谢PCB赞助商——电子园: http://bbs.cepark.com/
9
10 main.c file
11
12 作者:电脑圈圈
13 建立日期: 2008.06.27
14 修改日期: 2008.08.05
15 版本:V1.1
16 版权所有,盗版必究。
17 Copyright(C) 电脑圈圈 2008-2018
18 All rights reserved
19 *******************************************************************/
20
21 #include <AT89X52.H> //头文件
22 #include "UART.h"
23 #include "pdiusbd12.h"
24 #include "UsbCore.h"
25 #include "config.h"
26
27 #ifdef DEBUG0
code uint8 HeadTable[][74]={
"********************************************************************\r\n",
"****** 《圈圈教你玩USB》之 USB转串口 ******\r\n",
"****** AT89S52 CPU ******\r\n",
"****** 建立日期:",__DATE__," ******\r\n",
"****** 建立时间:",__TIME__," ******\r\n",
"****** 作者:电脑圈圈 ******\r\n",
"****** 欢迎访问作者的 ******\r\n",
"****** USB专区:http://group.ednchina.com/93/ ******\r\n",
"****** BLOG1:http://www.ednchina.com/blog/computer00 ******\r\n",
"****** BLOG2:http://computer00.21ic.org ******\r\n",
"********************************************************************\r\n",
};
#endif
42
43 /********************************************************************
44 函数功能:将串口缓冲区中的数据发送到端点2的函数。
45 入口参数:无。
46 返 回:无。
47 备 注:无。
48 ********************************************************************/
49 void SendUartDataToEp2(void)
50 {
51 1 uint8 Len;
52 1
53 1 //暂时禁止串行中断,防止UartByteCount在中断中修改而导致不同步
54 1 ES=0;
55 1 //将串口缓冲区接收到的字节数复制出来
C51 COMPILER V7.06 MAIN 11/16/2008 16:00:07 PAGE 2
56 1 Len=UartByteCount;
57 1 //检查长度是否为0,如果没有收到数据,则不需要处理,直接返回
58 1 if(Len==0)
59 1 {
60 2 ES=1; //记得打开串口中断
61 2 return;
62 2 }
63 1 //检查Len字节个数据是否跨越了缓冲区边界,如果跨越了,那么本次只发送
64 1 //跨越边界之前的数据,剩余的数据留待下次发送。否则,可以一次发送全部。
65 1 if((Len+UartBufferOutputPoint)>BUF_LEN)
66 1 {
67 2 Len=BUF_LEN-UartBufferOutputPoint;
68 2 }
69 1 //修改缓冲区数据字节数
70 1 UartByteCount-=Len;
71 1
72 1 //到这里可以打开串口中断了
73 1 ES=1;
74 1
75 1 //将数据写入到端点2输入缓冲区
76 1 D12WriteEndpointBuffer(5,Len,UartBuffer+UartBufferOutputPoint);
77 1 //修改输出数据的位置
78 1 UartBufferOutputPoint+=Len;
79 1 //如果已经到达缓冲区末尾,则设置回开头
80 1 if(UartBufferOutputPoint>=BUF_LEN)
81 1 {
82 2 UartBufferOutputPoint=0;
83 2 }
84 1 //只有两个缓冲区都满时,才设置端点2输入忙
85 1 if((D12ReadEndpointStatus(5)&0x60)==0x60)
86 1 {
87 2 Ep2InIsBusy=1;
88 2 }
89 1 }
90 ////////////////////////End of function//////////////////////////////
91
92 /********************************************************************
93 函数功能:主函数。
94 入口参数:无。
95 返 回:无。
96 备 注:无。
97 ********************************************************************/
98 void main(void) //主函数
99 {
100 1 #ifdef DEBUG0
uint8 i;
#endif
103 1
104 1 uint16 id;
105 1 uint8 InterruptSource;
106 1
107 1 EA=1; //打开中断
108 1 InitUART(); //初始化串口
109 1
110 1 #ifdef DEBUG0
for(i=0;i<15;i++) //显示信息
{
Prints(HeadTable[i]);
}
#endif
116 1
117 1 id=D12ReadID();
C51 COMPILER V7.06 MAIN 11/16/2008 16:00:07 PAGE 3
118 1
119 1 #ifdef DEBUG0
Prints("Your D12 chip\'s ID is: ");
PrintShortIntHex(id);
if(id==0x1012)
{
Prints(". ID is correct! Congratulations!\r\n\r\n");
}
else
{
Prints(". ID is incorrect! What a pity!\r\n\r\n");
}
#endif
132 1
133 1 UsbDisconnect(); //先断开USB连接
134 1 UsbConnect(); //将USB连接上
135 1 ConfigValue=0; //配置值初始化为0
136 1
137 1 while(1) //死循环
138 1 {
139 2 if(D12GetIntPin()==0) //如果有中断发生
140 2 {
141 3 D12WriteCommand(READ_INTERRUPT_REGISTER); //写读中断寄存器的命令
142 3 InterruptSource=D12ReadByte(); //读回第一字节的中断寄存器
143 3 if(InterruptSource&0x80)UsbBusSuspend(); //总线挂起中断处理
144 3 if(InterruptSource&0x40)UsbBusReset(); //总线复位中断处理
145 3 if(InterruptSource&0x01)UsbEp0Out(); //端点0输出中断处理
146 3 if(InterruptSource&0x02)UsbEp0In(); //端点0输入中断处理
147 3 if(InterruptSource&0x04)UsbEp1Out(); //端点1输出中断处理
148 3 if(InterruptSource&0x08)UsbEp1In(); //端点1输入中断处理
149 3 if(InterruptSource&0x10)UsbEp2Out(); //端点2输出中断处理
150 3 if(InterruptSource&0x20)UsbEp2In(); //端点2输入中断处理
151 3 }
152 2 if(ConfigValue!=0) //如果已经设置为非0的配置,则可以返回和发送串口数据
153 2 {
154 3 if(Ep2InIsBusy==0) //如果端点2空闲,则发送串口数据到端点2
155 3 {
156 4 SendUartDataToEp2(); //调用函数将缓冲区数据发送到端点2
157 4 }
158 3 if(UsbEp2ByteCount!=0) //端点2接收缓冲区中还有数据未发送,则发送到串口
159 3 {
160 4 //发送一字节到串口
161 4 UartPutChar(UsbEp2Buffer[UsbEp2BufferOutputPoint]);
162 4 UsbEp2BufferOutputPoint++; //发送位置后移1
163 4 UsbEp2ByteCount--; //计数值减1
164 4 }
165 3 }
166 2 }
167 1 }
168 ////////////////////////End of function//////////////////////////////
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 220 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V7.06 MAIN 11/16/2008 16:00:07 PAGE 4
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -