DIRS
Hi group,
On the i2c communication experment, they said
Devtype con %1010 << 4 'device type
What does mean %1010 << 4?
and also...
Devaddr con %000 << 1 'address = %000 ->1
What does mean %000 << 1 and address = %000->1
As much as I read about DIR , I still have no clue!
Thank you all!
Rene
On the i2c communication experment, they said
Devtype con %1010 << 4 'device type
What does mean %1010 << 4?
and also...
Devaddr con %000 << 1 'address = %000 ->1
What does mean %000 << 1 and address = %000->1
As much as I read about DIR , I still have no clue!
Thank you all!
Rene
Comments
operators section of the manual, you'll find that << is the left shift
operator. By the same token, %000 < 1 is equivalent to %0000.
Why do it this way? I do it to torture newbies! Just kidding (I'm away
from home and working on a Saturday so I can be silly...). The reason I
do this in my programs (I wrote the example you're sighting) is that the
device type of an I2C part is only 4 bits, but is positioned in the high
nibble of a byte. The address of most (not all) I2C parts is three
bits, and is also positioned.
For that part, the write address turns out to be:
%10100000
Here's how the bits are organized (i = ID, a = Address):
%10100000
iiiiaaa
Had I simply used the whole byte in the program I'm sure a bunch of
folks would have asked how I got there. Now you know.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Rene Genest [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9UfYNL3BcaXmz4MCdPZOf8PFxAunfTD9WWw2sKbm9zz6JrRyubktY9tPLLRoghg7Xh6d58oAKhUFQJt4CI44]rene.genest@q...[/url
Sent: Friday, April 02, 2004 8:00 PM
To: stamp
Subject: [noparse][[/noparse]basicstamps] DIRS
Hi group,
On the i2c communication experment, they said
Devtype con %1010 << 4 'device type
What does mean %1010 << 4?
and also...
Devaddr con %000 << 1 'address = %000 ->1
What does mean %000 << 1 and address = %000->1
As much as I read about DIR , I still have no clue!
Thank you all!
Rene
When I've read your answer, I laugh and realise suddenly that there
are 2 fantastic things on that planet, 1st , we all have our own newbies who all
count onto our knowledge to teach them as mentor on different branch as
electronic, mechanic, skydive etc.., 2nd we also are the newbie of somebodyelse
to get knowledge from them, and on Parallax, you and this group are my mentors!
Regardeless the negative comments of thoses who try to reinvent the wheel, you
still the best and cheapest "plug and go" solution on microcontroller market and
I
do not know how we could be better supported than that! As I tell to other, I've
never ever asked a question whitout getting an explicit answer, and I really do
appreciate everything I get from this group, it is diversified, relax and
friendly.
Thank you very much !
Rene
Jon Williams a
In many program's initialisation we see " DIRS = %00000001110000000 "
which said that pins 7, 8 and 9 are outputs and all others are inputs.
But, while
writing program code we also write for example " serout 7, n, [noparse][[/noparse]i, 195
etc..."
or " high 7" or "if in5 = 0 then......" such commands suppose to
already
define in or out to pins.
So, how and why is it important to apply DIRS command and what would
happen if we do not apply that command on certains conditions?
Thank you!
Rene
it for you. There are times when it is required, though.
LED PIN 0
Setup:
DIR0 = 1
Main:
LED = 1
PAUSE 100
LED = 0
PAUSE 100
GOTO Main
Since this program directly manipulates the OUTS register (OUT0 in this
case) the DIRS bit must be set ahead of the main code. This version,
however:
LED PIN 0
Main:
HIGH LED
PAUSE 100
LOW LED
PAUSE 100
GOTO Main
... requires not manipulation of the DIRS bit because HIGH and LOW do
that for us.
To your question, there is no harm in setting DIRS bits ahead of
instrucitons that will do that for us, the instruction will simply set
DIRS as required for its use. Keep this in mind, and in some cases the
DIRS bit will be left in a state other than where it started.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Rene Genest [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Pnk1GETF38ZvT31ngePKcQB1J9wuhBdYFjeAUfuDnpLkzNpyA1hK_nOxpQX6ylBtmtqT32Wj81QFOaZBvw]rene.genest@q...[/url
Sent: Sunday, April 11, 2004 10:40 PM
To: stamp
Subject: [noparse][[/noparse]basicstamps] DIRS
Hi group,
In many program's initialisation we see " DIRS = %00000001110000000 "
which said that pins 7, 8 and 9 are outputs and all others are inputs.
But, while writing program code we also write for example " serout 7, n,
[noparse][[/noparse]i, 195 etc..." or " high 7" or "if in5 = 0 then......" such commands
suppose to already define in or out to pins. So, how and why is it
important to apply DIRS command and what would happen if we do not apply
that command on certains conditions?
Thank you!
Rene
is needed so you can say:
MyVar = IN1 ' This does NOT make the pin an input!
for instance. If the P1 pin is still set
as an output, you'll get the last value
written to the pin, not the current value
of the data on the pin.
It is true that HIGH 1, and LOW 1, WILL
change the pin to an output. But that is
not true of all commands.
--- In basicstamps@yahoogroups.com, Rene Genest <rene.genest@q...>
wrote:
> Hi group,
>
> In many program's initialisation we see " DIRS = %
00000001110000000 "
> which said that pins 7, 8 and 9 are outputs and all others are
inputs.
> But, while
> writing program code we also write for example " serout 7, n, [noparse][[/noparse]i,
195
> etc..."
> or " high 7" or "if in5 = 0 then......" such commands suppose to
> already
> define in or out to pins.
> So, how and why is it important to apply DIRS command and what would
> happen if we do not apply that command on certains conditions?
>
> Thank you!
>
> Rene
logic level at P1, which--even if the pin is set to output--may in
fact be opposite to what is in OUT1 if driven to the opposite state
by external logic.
Regarding the original question, I use DIRS most often as a quick
and code-efficient way to set more than one pin to input/output mode
rather than using individual INPUT or OUTPUT statements. Sometimes
it's important to change multiple I/O states simultaneously.
Because your Stamp's pins initialize to inputs you needn't always use
the DIRS statement at the start of each program. It's a good way to
force yourself to think through the role of each pin, however.
Regards,
Steve
On 12 Apr 04 at 23:05, Allan Lane wrote:
> Setting the 'DIRS' pin direction variable
> is needed so you can say:
>
> MyVar = IN1 ' This does NOT make the pin an input!
>
> for instance. If the P1 pin is still set
> as an output, you'll get the last value
> written to the pin, not the current value
> of the data on the pin.
>
> It is true that HIGH 1, and LOW 1, WILL
> change the pin to an output. But that is
> not true of all commands.
>
> --- In basicstamps@yahoogroups.com, Rene Genest <rene.genest@q...>
> wrote:
> > Hi group,
> >
> > In many program's initialisation we see " DIRS = %
> 00000001110000000 "
> > which said that pins 7, 8 and 9 are outputs and all others are
> inputs.
> > But, while
> > writing program code we also write for example " serout 7, n, [noparse][[/noparse]i,
> 195
> > etc..."
> > or " high 7" or "if in5 = 0 then......" such commands suppose to
> > already
> > define in or out to pins.
> > So, how and why is it important to apply DIRS command and what would
> > happen if we do not apply that command on certains conditions?
> >
> > Thank you!
> >
> > Rene