Wiring Forum
Programming Questions & Help >> Syntax >> Bidirectional I/O

Message started by Zap on 11/03/10 at 01:55:42

Title: Bidirectional I/O
Post by Zap on 11/03/10 at 01:55:42
I've build up a mega128 board of my own design that has several 8 bit I/O latches on port 2 , each latched (enabled) by a pin on port 1.

How do I setup port 2 portMode for bidirectional for both writing and reading to & from the latch bus?

Thanks zap

Title: Re: Bidirectional I/O
Post by barragan on 11/03/10 at 16:06:15
you can't a port could be read or write at a time. What you could do is:

porMode(1, INPUT);
// do reading operations
portMode(1, OUTPUT);
// do write operations

Title: Re: Bidirectional I/O
Post by Zap on 11/04/10 at 05:19:59
Thanks, So all I have to do is just change the portMode direction imediatly before accessing the bus.


Title: Re: Bidirectional I/O
Post by barragan on 11/04/10 at 05:25:10
yes, that's it.

Title: Re: Bidirectional I/O
Post by Zap on 11/04/10 at 05:38:28
Hernando , I just tried to submit another post with an LCD problem but the forum said I was a spammer and dumped the post by the look of it.

Basically I hooked up an LCD and used the LiquidCrystal example but it wont run on the micro (hangs), I have a blink led to make sure it works. If I comment out the "LiquidCrystal myDisplay = LiquidCrystal(48,12,31,0); "  line the LED will blink but hangs if that line is complied and uploaded.

using 0027 and  atmega128stk500boot.hex bootloader.  What am I doing wrong?

Also can I protect the bootloader witha BLB1 mode 2 lock bit?

Thanks Zap

* LCD print

#include <LiquidCrystal.h>

// creates a LiquidDisplay object with R/S, R/W and E on pins 48,12,31 and
// data pins on port 0
LiquidCrystal myDisplay = LiquidCrystal(48,12,31,0);

  int a = 0;
void setup()
  pinMode(27, OUTPUT);   // set pin 27 as output

void loop()
//  myDisplay.clear();
//  myDisplay.home();
//  myDisplay.print("Variable a is: ");
// myDisplay.setCursor(16, 0);
// myDisplay.print(a);
  a = a + 1;
   digitalWrite(27, HIGH);  // set the LED on
  delay(100);             // wait for a time
  digitalWrite(27, LOW);   // set the LED off


Title: Re: Bidirectional I/O
Post by barragan on 11/04/10 at 15:30:13
hi Zap, you can protect it using Mode 3, Wiring boards use this as default for bootloader protection. Are you sire you have the pins connected as in the figure? http://wiring.org.co/learning/libraries/printdata.html

Title: Re: Bidirectional I/O
Post by Zap on 11/05/10 at 06:01:53
AH ha-- never asume anything--- problem located!!!

I've always built my microcontroller LCD projects with the display only being writen, and so tieing the R/W pin to gnd to save a pin on the micro.

It seems that LiquidCrystal Lib requires the R/W pin to be connected to the micro on the designated pin otherwise it won't go past the LCD init in the micro code.

It had to be as simple as "operator error".

On a similar subject is there a 4 bit LCD lib to save pins?

Thanks Zap.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.