我用了ch375和ch451做了键盘。同时还有摇杆和推拉杆。。
现在在增加推拉杆的时候。我把推拉杆的键值定义为0xff和0xf0,但是数据上传后,变成了0x3f和0x30。并且,我定义了lastchannel的值,使之能传输初始化启动时的channel值。但是结果是并不传输。只能传输对推拉杆进行推拉动作后的channel值。
我是用参考程序修改的。 大概的传输程序如下 unsigned char getchannel(void) { if(channel==0) {return(0xff);} else {return(0xf0);} }
main( ) { // unsigned char key;// ,temp Delay50ms( ); /* 延时等待CH375初始化完成,如果单片机由CH375提供复位信号则不必延时 */ CH375_Init( ); /* 初始化CH375 */ Delay50ms(); EA = 1; /* 允许中断 */ lastchannel=0x00; while ( 1 ) //以下指令开始工作循环,等待PC机命令进行操作 { nowchannel=getchannel(); if(nowchannel!=lastchannel) {lastchannel=nowchannel; Delay50ms(); Delay50ms(); Delay50ms(); Delay50ms(); Delay50ms(); Delay50ms(); Delay50ms(); Delay50ms(); CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); // 向USB端点2的发送缓冲区写入数据块 CH375_WR_DAT_PORT( 1);//length 首先写入后续数据长度,回传刚接收到的数据长度 CH375_WR_DAT_PORT(nowchannel); } } }