while condition

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

while condition

2,808件の閲覧回数
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,424件の閲覧回数
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,424件の閲覧回数
electronicfan
Contributor II
hello Stanish,

thanks for your help!

0 件の賞賛
返信

1,424件の閲覧回数
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,424件の閲覧回数
electronicfan
Contributor II
Hello Mac,

thanks!
0 件の賞賛
返信

1,424件の閲覧回数
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 件の賞賛
返信