|
爱科技、爱创意、爱折腾、爱极致,我们都是技术控
您需要 登录 才可以下载或查看,没有账号?立即注册
x
谢谢朋友帮我看看这段代码,我看了一下理解这是按键长按短按的代码?但不知道怎么调用合适,我想实现长按和短按的功能。
- static unsigned char p16key(void)
- {
- static bit p16isLockKey=1;
- unsigned char p16key_cnt=120;
- if(!P16 && p16isLockKey)
- {
- p16isLockKey = 0;
- do
- {
- p16key_cnt--;
- delay_ms(10);
- }while(!P16 && p16key_cnt>0);
- return p16key_cnt;
- }
- else if(P16)
- {
- p16isLockKey = 1;
- }
-
- return 0xFF;
- }
复制代码
下面这段是自己写的一段长按短按的代码,开始显示的时候要么停止了,只能按一下走一下。要么就是长按走动的数字位置不对,请也帮我看看。
- static unsigned char KeyScan(void)
- {
- static bit isLockKey=1;
- unsigned char key_cnt=120;
- /* unsigned int p=0;
-
- while(1)
- {
- if(Vtemp<=99000)
- {
- if(P16!=1)
- {
- p++;
- delay_ms(10);
- if(p>=50)
- {
- Vtemp +=1000;
- return 1;
- }
- }
- else
- {
- if(P16!=1 && p<45)
- {
- Vtemp +=10;
- return 0;
- }
- }
- }
- }
复制代码
|
|