while condition

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

while condition

2,806 次查看
electronicfan
Contributor II
hello,

i have a little problem with codewarrior.

I would like to have this one:

while(PTAD_PTAD7 !=0 | PTAD_PTAD6 !=0) { }

Wait while key 7 or key 6 not pressed.

Thanks!
标签 (1)
标记 (1)
0 项奖励
回复
5 回复数

1,422 次查看
stanish
NXP Employee
NXP Employee
Hi electronicfan,

It depends on how the keys are connected.
Let's assume if PTAD_PTADx input value is 1 then a key is pressed.(pull-down)
In case you need to wait until at least 1 key is released (loop only if both keys are pressed)

PTAD7 PTAD6  Exit Loop
0     0      Y
0     1      Y
1     0      Y
1     1      N


then you can use:

while ((PTAD & 0xC0) == 0xC0);

If I miss the logic perhaps you could specify the truth table.

Stanish

1,422 次查看
electronicfan
Contributor II
hello Stanish,

thanks for your help!

0 项奖励
回复

1,422 次查看
bigmac
Specialist III
Hello,

An alternative expression to that presented by Stanish for active low switch connections, might be the following:

while (PTAD_PTAD7 && PTAD_PTAD6) {}

Looping will continue while both pins remain high.

Regards,
Mac


1,422 次查看
electronicfan
Contributor II
Hello Mac,

thanks!
0 项奖励
回复

1,422 次查看
stanish
NXP Employee
NXP Employee
Hi,

bigmac's bit access approach results in more code size optimized code so I'd recommend it:

  0000          L0:     
   while ((PTAD & 0xC0) == 0xC0);
  0000 b600     [3]             LDA   _PTAD
  0002 a4c0     [2]             AND   #-64
  0004 a1c0     [2]             CMP   #-64
  0006 27f8     [3]             BEQ   L0 ;abs = 0000

 --------------------------------------------------------
 0008          L8:   
  while (PTAD_PTAD7 && PTAD_PTAD6);
  0008 0f0003   [5]             BRCLR 7,_PTAD,LE ;abs = 000e
  000b 0c00fa   [5]             BRSET 6,_PTAD,L8 ;abs = 0008
  000e          LE:


Stanish


Message Edited by stanish on 2008-11-18 05:22 PM
0 项奖励
回复