【新版CH554评测】三、形成程序
<div class='showpostmsg'> 本帖最后由 ddllxxrr 于 2018-4-6 17:16 编辑按照评测计划,这次评测应形成程序了。
我的想法是把USB HID复合设备那个程序,与TOUCHKEY的那个程序合并
当然以复合设备为模板好,只是把TOUCHKEY.c和.h考贝过来。
然后加入到工程:
在主函数中加入触摸按键的声明
TK_Init( BIT4+BIT5+BIT6+BIT7,1, 1 ); /* Choose TIN2, TIN3, TIN4, TIN5 for touchkey input. enable interrupt. */
TK_SelectChannel(0); /* NOTICE: ch is not compatible with the IO actually. */
然后在HID处理函数加上触摸按键的判断:
void HIDValueHandle()
{
UINT8 i;
// if(MISO == 0)
// {
// //printf( "%c", 1 );
// //HIDMouse = 1;
// //Enp2IntIn();
// i = 1;
// }
// else if(SCK == 0)
// {
// //HIDMouse = -1;
// //Enp2IntIn();
// i = 2;
//
// }
// else
// i = 'A';
if( Touch_IN != 0 )
{
printf("come here 1...\n");
if( Touch_IN & CH2 )
{
i = 'a';
}
if( Touch_IN & CH3 )
{
i = 'w';
}
if( Touch_IN & CH4 )
{
i = 'd';
}
if( Touch_IN & CH5 )
{
i = 's';
}
Touch_IN = 0;
}
else
i=0;
switch(i)
{
//êó±êêy¾YéÏ′«ê¾ày
case 1: //×ó¼ü
HIDMouse = -1;
Enp2IntIn();
i=0;
//HIDMouse = 0;
break;
case 2: //óò¼ü
HIDMouse = 1;
Enp2IntIn();
i=0;
//HIDMouse = 0;
break;
//¼üÅìêy¾YéÏ′«ê¾ày
case 'a': //A¼ü
FLAG = 0;
HIDKey = 0x04; //°′¼ü¿aê¼
Enp1IntIn();
HIDKey = 0; //°′¼ü½áêø
while(FLAG == 0)
{
; /*μè′yéÏò»°ü′«êäíê3é*/
}
Enp1IntIn();
i=0;
break;
case 'w': //P¼ü
FLAG = 0;
HIDKey = 0x1a;
Enp1IntIn();
HIDKey = 0; //°′¼ü½áêø
while(FLAG == 0)
{
; /*μè′yéÏò»°ü′«êäíê3é*/
}
Enp1IntIn();
i=0;
break;
case 's': //P¼ü
FLAG = 0;
HIDKey = 0x16;
Enp1IntIn();
HIDKey = 0; //°′¼ü½áêø
while(FLAG == 0)
{
; /*μè′yéÏò»°ü′«êäíê3é*/
}
Enp1IntIn();
i=0;
break;
case 'd': //Num Lock¼ü
FLAG = 0;
HIDKey = 0x07;
Enp1IntIn();
HIDKey = 0; //°′¼ü½áêø
while(FLAG == 0)
{
; /*μè′yéÏò»°ü′«êäíê3é*/
}
Enp1IntIn();
i=0;
break;
default:
i=0; //ÆäËû
UEP1_CTRL = UEP1_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_NAK; //ĬèÏó|′eNAK
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_NAK; //ĬèÏó|′eNAK
break;
}
}
所以在上边加判断,因为主函数时正常情况下就是在上边的函数里循环:main()
{
CfgFsys( ); //CH559ê±ÖóÑ¡ÔñÅäÖÃ
mDelaymS(25); //DT¸ÄÖ÷Æμμè′yÄú2¿¾§ÕñÎ趨,±Ø¼ó
mInitSTDIO( ); //′®¿ú03õê¼»ˉ
#ifdef DE_PRINTF
printf("start ...\n");
#endif
printf("start ddllxxrr ...\n");
USBDeviceInit(); //USBé豸Ä£ê½3õê¼»ˉ
TK_Init( BIT4+BIT5+BIT6+BIT7,1, 1 ); /* Choose TIN2, TIN3, TIN4, TIN5 for touchkey input. enable interrupt. */
TK_SelectChannel(0); /* NOTICE: ch is not compatible with the IO actually. */
printf("come here ...\n");
EA = 1; //ÔêDíμ¥Ƭ»úÖD¶Ï
UEP1_T_LEN = 0; //Ô¤ê1ó÷¢Ëí3¤¶èò»¶¨òaÇå¿Õ
UEP2_T_LEN = 0; //Ô¤ê1ó÷¢Ëí3¤¶èò»¶¨òaÇå¿Õ
FLAG = 0;
Ready = 0;
//Port1Cfg(1,6);
//Port1Cfg(1,7);
while(1)
{
if(Ready)
{
while(1)
{
HIDValueHandle();
}
}
if(Ready&&(Ep2InKey == 0)){
#ifdef DE_PRINTF //¶áè¡D¾Æ¬IDoÅ
printf("ID0 = %02x %02x \n",(UINT16)*(PUINT8C)(0x3FFA),(UINT16)*(PUINT8C)(0x3FFB));
printf("ID1 = %02x %02x \n",(UINT16)*(PUINT8C)(0x3FFC),(UINT16)*(PUINT8C)(0x3FFD));
printf("ID2 = %02x %02x \n",(UINT16)*(PUINT8C)(0x3FFE),(UINT16)*(PUINT8C)(0x3FFF));
#endif
CH554USBDevWakeup(); //
mDelaymS( 10 );
Enp1IntIn();
}
mDelaymS( 100 ); //Ä£Äaμ¥Ƭ»ú×öÆäËüêÂ
}
}
上边的键值是在度娘上查到的:
然后,把开发板接USB插到电脑上,出现了两个键盘,打开记事本看了一下:
唯一不满意的是停不下来,要想停得先按别的按键一下
此内容由EEWORLD论坛网友ddllxxrr原创,如需转载或用于商业用途需征得作者同意并注明出处
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]