CH372 键盘模式(HID)连续上传数据(3)[求助]

/*;CH372/CH375 USB device mode & external firmware ; U2(AT89C51) Program ; ; Website: http://winchiphead.com ; Email: 个人信息保护,已隐藏 ; Author: W.ch 2003.12, 2005.03 ; ;**************************************************************************** CH375 外部固件方式范例 这里仅处理标准请求和端点2的简单读写 */

/* MCS-51单片机C语言的示例程序 */ #pragma NOAREGS #include #include "stdio.h" #include "CH375INC.H" unsigned char ch451_key; unsigned char a; #include "CH451.h" #include "hid.h" // sundy

sbit SEND_FLAG = P1^2;

unsigned char bord; unsigned char idata UPDATA_FLAG; //unsigned char idata buf[8]; typedef union _REQUEST_PACK{ unsigned char buffer[8]; struct{ unsigned char bmReuestType; //标准请求字 unsigned char bRequest; //请求代码 unsigned int wValue; //特性选择高 unsigned int wIndx; //索引 unsigned int wLength; //数据长度 }r; } mREQUEST_PACKET, *mpREQUEST_PACKET;

//unsigned char code LangDes[]={0x04,0x03,0x09,0x04}; //语言描述符 //unsigned char code SerDes[]={0x12,0x03,'C',0,'H',0,'3',0,'7',0,'5',0,'U',0,'S',0,'B',0}; //字符串描述符 unsigned char code Key_Hid_des[]={ /* from WCH 0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, 0x07, 0x19, 0xe0, 0x29, 0xe7, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0x95, 0x08, 0x75, 0x01, 0x81, 0x01, 0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x95, 0x05, 0x75, 0x01, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x01, 0x05, 0x07, 0x19, 0x00, 0x2a, 0xff, 0x00, 0x15, 0x00, 0x26, 0xff, 0x00, 0x95, 0x06, 0x75, 0x08, 0x81, 0x00, 0xc0 // */ // 从USB键盘芯片来 HID_UsagePage(HID_USAGE_PAGE_GENERIC), //0x05, 0x01, HID_Usage(HID_USAGE_GENERIC_KEYBOARD), //0x09, 0x06, HID_Collection(HID_Application), //0xa1, 0x01, HID_UsagePage(HID_USAGE_PAGE_LED), //0x05, 0x08, HID_UsageMin(HID_USAGE_LED_NUM_LOCK), //0x19, 0x01, HID_UsageMax(HID_USAGE_LED_SCROLL_LOCK), //0x29, 0x03, HID_LogicalMin(0), //0x15, 0x00, HID_LogicalMax(1), //0x25, 0x01, HID_ReportSize(1), //0x75, 0x01, HID_ReportCount(3), //0x95, 0x03, HID_Output(2), //0x91, 0x02, HID_Data+HID_Variable+HID_Absolute HID_ReportCount(5), //0x95, 0x05, HID_Output(1), //0x91, 0x01, HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), //0x05, 0x07, HID_Constant HID_UsageMin(HID_USAGE_KEYBOARD_LCTRL), //0x19, 0xe0, HID_UsageMax(HID_USAGE_KEYBOARD_RGUI), //0x29, 0xe7, HID_ReportCount(8), //0x95, 0x08, HID_Input(2), //0x81, 0x02, HID_ReportSize(8), //0x75, 0x08, HID_ReportCount(1), //0x95, 0x01, HID_Input(1), //0x81, 0x01, HID_UsageMin(0), //0x19, 0x00, HID_UsageMax(0x91), //0x29, 0x91, HID_LogicalMaxS(0x00ff), //0x26, 0xff, 0x00, HID_ReportCount(6), //0x95, 0x06, HID_Input(0), //0x81, 0x00, HID_EndCollection //0xc0 // */ };

unsigned char code Mouse_Hid_des[]={ /* from WCH 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x03, 0x81, 0x02, 0x95, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x95, 0x03, 0x75, 0x08, 0x81, 0x06, 0xc0, 0xc0, 0x09, 0x80, 0xa1, 0x01, 0x85, 0x02, 0x05, 0x01, 0x19, 0x81, 0x29, 0x88, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0xc0 // */ //* WCH HID_UsagePage(HID_USAGE_PAGE_GENERIC), //0x05, 0x01, HID_Usage(HID_USAGE_GENERIC_MOUSE), //0x09, 0x02, HID_Collection(HID_Application), //0xa1, 0x01, HID_ReportID(1), //0x85, 0x01, // HID_Usage(HID_USAGE_GENERIC_POINTER), //0x09, 0x01, // HID_Collection(HID_Physical), //0xa1, 0x00, // HID_UsagePage(HID_USAGE_PAGE_BUTTON), //0x05, 0x09, // HID_UsageMin(1), //0x19, 0x01, // HID_UsageMax(3), //0x29, 0x03, // HID_LogicalMin(0), //0x15, 0x00, // HID_LogicalMax(1), //0x25, 0x01, // HID_ReportSize(1), //0x75, 0x01, // HID_ReportCount(3), //0x95, 0x03, // HID_Input(2), //0x81, 0x02, // HID_ReportCount(5), //0x95, 0x05, // HID_Input(1), //0x81, 0x01, HID_Data+HID_Array 3 HID_UsagePage(HID_USAGE_PAGE_GENERIC), //0x05, 0x01, // HID_Usage(HID_USAGE_GENERIC_X), //0x09, 0x30, // HID_Usage(HID_USAGE_GENERIC_Y), //0x09, 0x31, // HID_Usage(HID_USAGE_GENERIC_WHEEL), //0x09, 0x38, // HID_LogicalMin(0x81), //0x15, 0x81, // -127 HID_LogicalMax(0x7F), //0x25, 0x7f, // HID_ReportCount(3), //0x95, 0x03, // HID_ReportSize(8), //0x75, 0x08, // HID_Input(6), //0x81, 0x06, //HID_Data+HID_Variable+HID_Relative HID_EndCollection, //0xc0, /* HID_EndCollection, //0xc0, // HID_Usage(HID_USAGE_GENERIC_SYSTEM_CTL), //0x09, 0x80, // HID_Collection(HID_Application), //0xa1, 0x01, // HID_ReportID(2), //0x85, 0x02, // HID_UsagePage(HID_USAGE_PAGE_GENERIC), //0x05, 0x01, //HID_USAGE_PAGE_DEV_CONTROLS HID_UsageMin(HID_USAGE_GENERIC_SYSCTL_POWER), //0x19, 0x81, // HID_UsageMax(HID_USAGE_GENERIC_SYSCTL_MENU_EXIT),//0x29, 0x88, // HID_LogicalMin(0), //0x15, 0x00, // HID_LogicalMax(1), //0x25, 0x01, // HID_ReportCount(8), //0x95, 0x08, // HID_ReportSize(1), //0x75, 0x01, // HID_Input(2), //0x81, 0x02, // HID_Data+HID_Variable+HID_Absolute // 这一段是WCH提供的配置里的,注释后不影响 sundy */ /* HID_EndCollection, //0xc0, // HID_Usage(HID_USAGE_GENERIC_SYSTEM_CTL), //0x09, 0x80, // HID_Collection(HID_Application), //0xa1, 0x01, // HID_ReportID(2), //0x85, 0x02, // HID_UsagePage(HID_USAGE_PAGE_DEV_CONTROLS), //0x05, 0x01, // //HID_UsageMin(HID_USAGE_GENERIC_SYSCTL_POWER), //0x19, 0x81, // //HID_UsageMax(HID_USAGE_GENERIC_SYSCTL_MENU_EXIT),//0x29, 0x88, // HID_LogicalMin(0), //0x15, 0x00, // HID_LogicalMax(0xFF), //0x25, 0x01, // HID_ReportCount(8), //0x95, 0x08, // HID_ReportSize(8), //0x75, 0x01, // HID_Output(2), // 这一段是我增加的,配置后PC无法枚举

我汗!!!! 给你解释了不下5遍,你居然还没明白。 最后和你解释一遍,每次发送一包8个字节的数据,等待CH372中断,解锁之后在发送8个字节的0X00等待CH372中断。再次解锁,之后才能发送下一个按键值。 而不是你上面所写的,你见过谁按键是微秒级的啊?????


大哥啊,原理我也重复过了,你们都说正确,可现在得看实际结果啊,不能刚说原理

我已近列出了两种结果,一种正常,一种异常,这个怎么解释?


呵呵,看样子你还是没理解,这样吧,你把程序发到fqb@wch.cn,我来帮你把程序改好。改好之后麻烦你在回头看下我们解释的是否正确。


我们已经给你解释了几次正确的流程应该怎么做。我们也不希望去给你解释一个错误的行为产生的现象。请按照我们提供的流程去做。 产生这个现象是由于USBHOST发送IN令牌的时候对单片机来说这个时间并不是一定在一个固定的位置。取数据有个时间差可能会导致这个问题。一句话,你的流程错误。

按照我们给你说的流程,绝对不会有任何问题。为什么不能去修改呢? 这样你下载一个软件叫BUSHOUDN软件,对你调试软件也有帮助。


哈,这里好多CODE是我写的噢。


只有登录才能回复,可以选择微信账号登录