Ryanhsiung 发表于 2011-12-14 16:34

这么老的贴,不过写的不错,还是顶一下

明月小厨 发表于 2012-12-3 11:39

教材说的方法我只记得:
1.有键按下?   2.按键有20mS的抖动;
软件延时读键值,估计没有谁会真的这样做.

按键处理的程序.这个部分内容丰富,如果按键很多,这部分的处理才费劲,不同的方法,差异非常大的.

天命风流 发表于 2013-8-21 10:20

学习了!!!

q728117579 发表于 2013-8-21 10:52

弱弱的问一句,定时器资源是有限的,稍微大一点的话。定时器不会不够用吗?

zhengshizhe 发表于 2013-8-27 15:57

一般都用定时中断的

zdhlixiang2006 发表于 2013-8-31 19:00

程序匠人 发表于 2009-7-26 14:35 static/image/common/back.gif
会不会有点显得迟钝?

我觉得肯定会反应迟钝,一般40MS足够

dzjsl315 发表于 2013-8-31 23:12

是有见解,参考了

ytfdhb 发表于 2013-9-1 23:27

来学习学习^_^

sedatefire 发表于 2013-9-2 01:00

哦? delay这个事情,教科书上遍地都是了吗?

79xiaozaizai 发表于 2013-9-2 14:41

轮询,和用中断可行,同级不能相互中断

szuet 发表于 2013-9-2 15:11

毕竟书本和实际是不一样的!很多东西必须得我们自己在实际运用中来得到经验!

yylfcxpx168 发表于 2013-12-14 19:15

xuexile

lhchen922 发表于 2013-12-14 22:01

state machine

nizhenyuchina 发表于 2013-12-24 20:28

鄙视,看来你们落后了
//key bit state
#define keysw   0x04//fuction switch
#define keyplus 0x08//value add
#define prog    0x10//enter or exit prog mode
#define keyon   0x20//run or paulse
//macro defines
#define uchar unsigned char
#define uint unsigned int
//variable's type defines
typedef struct
{
uchar trun;
signed long tcount;
uchar tover;
} TIMER;
//gloable variable define
TIMER timer={0,0};//8channel timer initial
ucharvalue={0,0,0};//setting timer value;
uchar func=1;//function switch channel mode=1
uchar channel=1;//current channel value
uchar timode=1;//0.1s mode
uchar trg;//key trig
uchar cont;//continue buttons
bit pstate=0;//enter in or exit programing mode
bit flicker=0;//shan shuo
//declarationand define fuctions
//value pulse
void add(uchar i)
{
(value)++;
if(value>9) value=0;
}
//key scanning
void keyscan(void)
{
uchar ReadData = P3^0x3c;//save after invert
trg= ReadData & (ReadData ^ cont);//save trig bit effective
cont = ReadData;//continue button's bit
}
void keyproc(void)
{
keyscan();
//连续按下
if((!(trg&prog))&&(cont&prog))pstate = ~pstate;//change program mode

//单次按下: 点动
if((trg&keysw)&&(cont&keysw)&&(pstate)) {
                                           func++;
             if(func>5) func=1;
                                       }//change func value
if((trg&keyplus)&&(cont&keyplus)) //value pluse
    {
       if(!pstate)      channel++;//非编程模式
    else
      {      
            if(func==1) channel++;//编程模式1
                  if(channel>8) channel=1;//通道++
      if(func==2)   timode++;//时间++
      if(timode>3)timode=1;
      if(func==3)   add(0);//value*100
      if(func==4)   add(1);//value*10
      if(func==5)   add(2);//value*1
      }
    }
//run or stop flag bit 连续按下
if((!(trg&keyon))&&(cont&keyon))timer.trun = !(timer.trun) ;

}
void display(void)
{ //in programing
if(pstate)
//no-programing
else
{
    timer.tcount=


}


}
   
void main()
{      
keyproc();
while(1) ;
}
我也是学习别人的

lpzailushang 发表于 2013-12-25 09:51

挺好的 鼓励一下

3htech 发表于 2013-12-25 10:34

程序匠人 发表于 2009-7-26 22:35 static/image/common/back.gif
尽信书则不如无书

匠人,无书如何让新人入门???
您难道一开始学习的时候就能指点江上了?

delay方法简单,实现容易,是入门的好方法。
新人需要的东西很多,在以后的实践中,慢慢学习新的东西,有想法的新人会去对比,会进步。
这就足够了。

大家学C语言的时候也都是从a = a + 1过渡到a++的。

zhangyang86 发表于 2014-2-11 18:19

学习是可以的

icfree 发表于 2025-4-22 22:33

就是,要多探讨啊
页: 1 2 3 4 5 6 [7]
查看完整版本: 按键可有**了,能体现一个人的编程水平