Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › Bidirectional I/O

Page Index Toggle Pages: 1
Bidirectional I/O (Read 5227 times)
11/03/10 at 01:55:42

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
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
 

IP Logged
 
Reply #1 - 11/03/10 at 16:06:15

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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
 
IP Logged
 
Reply #2 - 11/04/10 at 05:19:59

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
Thanks, So all I have to do is just change the portMode direction imediatly before accessing the bus.

Zap.
 

IP Logged
 
Reply #3 - 11/04/10 at 05:25:10

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
yes, that's it.
 
IP Logged
 
Reply #4 - 11/04/10 at 05:38:28

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
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;
  delay(100);
   digitalWrite(27, HIGH);  // set the LED on
  delay(100);             // wait for a time
  digitalWrite(27, LOW);   // set the LED off

}
 

IP Logged
 
Reply #5 - 11/04/10 at 15:30:13

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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
« Last Edit: 11/04/10 at 23:02:12 by barragan »  
IP Logged
 
Reply #6 - 11/05/10 at 06:01:53

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
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.

 

IP Logged
 
Page Index Toggle Pages: 1