/****************************************
** Copyright (C) WCH 1999-2009 **
** Web: **
****************************************
** USB 1.1 Host Examples for CH376 **
** KC7.0@MCS-51 **
** Version: v1.0 **
** Author: tech14 **
** Time : 2009/11/18 **
****************************************
*/
/* 用CH376操作HID设备,比如键盘,鼠标,兼容HID复合设备*/
#include <stdio.h>
#include <reg52.h>
#include <string.h>
#include "CH376INC.H"
#include "hid.h"
// 获取设备描述符
constunsigned char code SetupGetDevDescr[] = { 0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00 };
// 获取配置描述符
constunsigned char code SetupGetCfgDescr[] = { 0x80, 0x06, 0x00, 0x02, 0x00, 0x00, 0x09, 0x00 };
// 设置USB地址
constunsigned char code SetupSetUsbAddr[] = { 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
// 设置USB配置
//constunsigned char code SetupSetUsbConfig[] = { 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// SET IDLE
constunsigned char code SetupSetidle[]={0x21,0x0a,0x00,0x00,0x00,0x00,0x00,0x00};
// 获取HID 报告描述符
constunsigned char code SetupGetHidDes[]={0x81,0x06,0x00,0x22,0x00,0x00,0x81,0x00};
// SET REPORT
const unsigned char code SetupSetReport[]={0x21,0x09,0x00,0x02,0x00,0x00,0x01,0x00};
//单片机总线方式操作CH376
#define CH376_CMD_PORT *(unsigned char volatile xdata *)0xBDF1
#define CH376_DAT_PORT *(unsigned char volatile xdata *)0xBCF0
#define CH376_INT_WIRE INT0 //定义CH376中断引脚,可省略;
struct _Device_Atti{
UINT8 Device_connect; //设备连接状态 1:连接,0:断开
UINT8 Device_compat; //0:非复合设备,1表示复合设备
UINT8 Cfg_value; //设备配置描述符中配置值
struct _Device{
UINT8 Device_type; //设备类型 1:键盘,2:鼠标
UINT8 Device_inf; //设备接口号 默认为0 最多支持两个接口设备
UINT8 Device_endp; //设备端点地址 最多支持一个端点
UINT8 Device_size; //设备端点大小
UINT16 Device_report_len; //设备报表长度
UINT8 tog; //端点的同步标志
}Device[2];
}Device_Atti = { 0 };
UINT8 receive_mode = 0x00,send_mode = 0x00;
UINT8 data_buf[160];
UINT8 status;
bit flag_config_2; //第二次获取配置描述符标志
UINT8 report_cou; //实际获取的报表长度
//**********************************************
//*NAME: mDelay2uS( )
//*FUCTION: 延时2us子函数
//*输入参数:无
//* 输出参数:无
//*说明: 根据单片机的主频进行调整
//*********************************************
*
void mDelay2uS( )
{
UINT8 i;
for(i=1;i!=0;i--);
}
//**********************************************
//*NAME: mDelay50mS( )
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新人文社科CH376主机控制键盘鼠标程序全文阅读和word下载服务。
相关推荐: