📄 main.c
字号:
/******************************************************************
本程序只供学习使用,未经作者许可,不得用于其它任何用途
欢迎访问我的USB专区:http://group.ednchina.com/93/
欢迎访问我的blog: http://www.ednchina.com/blog/computer00
http://computer00.21ic.org
感谢PCB赞助商——电子园: http://bbs.cepark.com/
main.c file
作者:电脑圈圈
建立日期: 2008.06.27
修改日期: 2008.08.08
版本:V1.1
版权所有,盗版必究。
Copyright(C) 电脑圈圈 2008-2018
All rights reserved
*******************************************************************/
#include <AT89X52.H> //头文件
#include "Led.h"
#include "UART.h"
#include "pdiusbd12.h"
#include "UsbCore.h"
#include "config.h"
#ifdef DEBUG0
code uint8 HeadTable[][74]={
"********************************************************************\r\n",
"****** 《圈圈教你玩USB》之 假U盘 ******\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
/********************************************************************
函数功能:主函数。
入口参数:无。
返 回:无。
备 注:无。
********************************************************************/
void main(void) //主函数
{
#ifdef DEBUG0
uint8 i;
#endif
uint16 id;
uint8 InterruptSource;
EA=1; //打开中断
InitUART(); //初始化串口
id=D12ReadID();
#ifdef DEBUG0
for(i=0;i<15;i++) //显示信息
{
Prints(HeadTable[i]);
}
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
UsbDisconnect(); //先断开USB连接
UsbConnect(); //将USB连接上
ConfigValue=0; //配置值初始化为0
while(1) //死循环
{
if(D12GetIntPin()==0) //如果有中断发生
{
D12WriteCommand(READ_INTERRUPT_REGISTER); //写读中断寄存器的命令
InterruptSource=D12ReadByte(); //读回第一字节的中断寄存器
if(InterruptSource&0x80)UsbBusSuspend(); //总线挂起中断处理
if(InterruptSource&0x40)UsbBusReset(); //总线复位中断处理
if(InterruptSource&0x01)UsbEp0Out(); //端点0输出中断处理
if(InterruptSource&0x02)UsbEp0In(); //端点0输入中断处理
if(InterruptSource&0x04)UsbEp1Out(); //端点1输出中断处理
if(InterruptSource&0x08)UsbEp1In(); //端点1输入中断处理
if(InterruptSource&0x10)UsbEp2Out(); //端点2输出中断处理
if(InterruptSource&0x20)UsbEp2In(); //端点2输入中断处理
}
if(ConfigValue!=0) //如果已经设置为非0的配置,则可以返回数据
{
}
}
}
////////////////////////End of function//////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -