Other optin is to have a variable always set according to the setting of the port every time.
for example you want to set value 0x3045 to port 1 you can sya
temp1 = 0x3045;
IO1PIN = temp1;
next time you want to change port 1 all you do is take existing value not by reading port but from temp1 varaible
so you canm say :
temp1 &= 0xfffffff0 ; for last eight bit
temp1 |= 0x04;
IO1PIN = temp1;
keep in mind you have to keep track of IO1PIN by updating temp1 every time you change IO1PIN. This is an old technique used in firmware for microcontroller for which it is not possible to know the status of the output port.
kb shah
----- Original Message -----
From: Aalt Lokhorst
To: lpc2000@yahoogroups.com
Sent: Tuesday, April 19, 2005 4:38 AM
Subject: Re: [lpc2000] Re: Writing 8 bits on the IO port
Hello Kimi and Rob,
Rob his solution reads the current port status. In most situations this
is no problem. But it is a read/modify write situation and I don't know
if you always want that. You can also use something like this (not
tested but I think it is clear what I mean):
IO0SET = ( Data<<14) & 0x3FC0;
IO0CLR = (~Data<<14) & 0x3FC0;
It changes the data bus in two steps so there will be intermediate
values on the bus. This is not a problem if you use separate control
lines to control when the data is valid. Don't forget to set the
direction of the pins according to the read or write situation and avoid
collisions as a result of two devices driving the bus at the same time.
Best regards,
--
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================
dibosco wrote:
>
> I've done an almost identical thing and just got my char value to
> write, chifted into its correct position in a temporary value in a
> long. Then read what's currently on the output port into another
> temporary long, ANDed out the relevant eight bits, then ORed into this
> the new bits which are in the correct positiion in the temporary long.
> This value is then written to the output port.
>
> Not sure that reads very well. Some code:
>
> // put char to write in temp and shift it to correct position
> Temp1 = NewVal << 14;
> // Get current output value of PORT0
> Temp2 = IO0PIN;
> // AND out P0.14-21
> Temp2 &= ~0x3FC000;
> //OR in what you *do* want to write.
> Temp2 |= Temp1;
> // Then write to the port
> IO0PIN = Temp1;
>
> Check the syntax of that last line's right!
>
> And you've written the value to the port. :-)
>
> Cheers,
>
> Rob
>
> --- In lpc2000@yahoogroups.com, "acetoel" <acetoel@y...> wrote:
> >
> > Hello,
> >
> > I making a little protocol to interfase between a LPC2106 and an Atmel
> > 8bits MCU. My idea is to use an 8bit data bus (P0.14 to P0.21) for
> > sending and receiving bytes, and then a few control lines (Busy/Ready,
> > Clock, Enable, Command/Data).
> > How can I write a byte variable (char) to that 8bit port? and how can
> > I read that data port, and save it on a variable? being P0.14 is the
> > Least Significative bit.
> >
> > Thanks
> > Kimi
>
>
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/lpc2000/
>
> * To unsubscribe from this group, send an email to:
> lpc2000-unsubscribe@yahoogroups.com
> <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
------------------------------------------------------------------------------
Yahoo! Groups Links
a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/lpc2000/
b.. To unsubscribe from this group, send an email to:
lpc2000-unsubscribe@yahoogroups.com
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]Message
Re: [lpc2000] Re: Writing 8 bits on the IO port
2005-04-19 by k b shah (lascaux)
Attachments
- No local attachments were found for this message.