View Full Version : SIMPLE question
ngeronikolos
- 5th February 2008, 09:22
I am happy to be a member of that forum!!!!
I have a SIMPLE question.
I need to look at the 10 pins (portb.0-portb.7,porta.0,porta.1) in a loop and find the first pin that set 1.I need the simplest code to check that ports.
Thanks
Nikos
duncan303
- 5th February 2008, 09:39
Hi Nikos
I too am happy to be a member of this forum!!!
You could alias each pin into a word variable.
Then simply check the value of the whole word
If w0 > 1 then
etc etc
endif
or
while w0 <> 0
wend
I guess there are lots of other ways but this came into my mind first.
Hope this Helps
Duncan
ngeronikolos
- 5th February 2008, 10:02
Good idea Duncan,
But I want to find exactly the pin that is 1.
When you say word(variable)that can have 10bits???
Nikos
duncan303
- 5th February 2008, 10:21
Hi Nikos
A word is indeed 16bits, there is a great post by Melanie in the FAQ section I think, which describes how to address bits bytes words and arrays,
but I think first it is worth taking the time to fully digest pages 21 to 24 of the PBP manual. Every minute taken will pay back in Spades. Settle back with a nice cool glass of retsina.... take your time.
Just in case you do search for other info: a nybble is 4 bits but PBP does not access these directly.
Cheers and good luck
Duncan
duncan303
- 5th February 2008, 10:41
Hi again,
I did not answer your question fully,
you can determine which bit in the word variable that has been set by its value.
if w0 = 8 this is the same as %0000000000001000
so if you aliased say portb.1 to bit <3> in the word then you would know that when w0 = 8 portb.1 = 1
etc etc
Duncan
Its many years since i had a glass of retsina.. but you know I can still smell it even now
Acetronics2
- 5th February 2008, 12:39
Hi, N'Geron
you can use:
For I = 0 to 7
IF PORTA.0[I] = 1 THEN Bail_out
NEXT I
For I = 0 to 1
IF PORTB.0[I] = 1 THEN Bail_out
NEXT I
In simple words, you add the value I to the "Base address" that is PORTA.0 ... same for PortB
You have it "officially written" in the 2.50 Manual, at th REPEAT --- UNTIL Command page !!!
Alain
Alain
ngeronikolos
- 5th February 2008, 16:32
Duncan,
What I was thinking...
portA PORTB
% 00000000 / 00001000
<0> PORTB.0 <1>PORTB.1 .... <8>PORTA.0
Let's say that this is my word that Contains PORTA+PORTB that I have to check.
The followings are correct???
----------------------------------------------
w0 var word
L var byte
H var byte
L = PORTB
H = PORTA
w0.LowByte = L
w0.HighByte = H
If w0 > 1 then
I WILL READ THE w0
endif
---------------------------------------------------
Thanks
Nikos
Retsina,Summer,Sea and Sun
paul borgmeier
- 5th February 2008, 18:27
Duncan,
What I was thinking...
portA PORTB
% 00000000 / 00001000
<0> PORTB.0 <1>PORTB.1 .... <8>PORTA.0
Let's say that this is my word that Contains PORTA+PORTB that I have to check.
The followings are correct???
----------------------------------------------
(w0 var word
L var byte
H var byte
L = PORTB
H = PORTA
w0.LowByte = L
w0.HighByte = H
If w0 > 1 then
I WILL READ THE w0
endif
---------------------------------------------------
Thanks
Nikos
Retsina,Summer,Sea and Sun
If that is what you want to do, you could use Darrel's trick with EXT
@PORTS = PORTA
PORTS VAR WORD EXT ; PORTS = PORTB:PORTA
; in middle of program
if PORTS > 1 then ....
(Don' t forget to mask the unused bits of PORTA if they might not be 0)
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.