How to define a 8bit port like other microcontroller

Hi…
How to read or write 8bit data by defining 8 bit port.I am beginner and learning this arduino language but…I am not understanding how to define a port. Am trying to interface GLCD to mega 2560 …and for that I need to define a port…so plz help me out…

You can read or write all the pins associated with a port in a single instruction, but you can't define a port.

Please…can you give me syntax for read/write all pins of port in single instruction?
I will be able to understand if the syntax is shown.

PORT<port-name>= x; where is A, B, C, D etc.

sourabhp:
Hi...
How to read or write 8bit data by defining 8 bit port.I am beginner and learning this arduino language but...I am not understanding how to define a port. Am trying to interface GLCD to mega 2560 ...and for that I need to define a port....so plz help me out...

This is an example (NOT TESTED) but should work I quickly modified this from the digitalWrite() function we use all the time.

you will be responsible for making sure that the bit you change truly affects the pin you want to control on that port. I removed all the pin to bit verification code to give you direct control.

void digitalBitmapWrite(uint8_t port, uint8_t bitmap)
{
  volatile uint8_t *out;
  out = portOutputRegister(port);

  uint8_t oldSREG = SREG;
  cli();
    *out = bitmap; // you are affecting all pins on that port if this is not desired you will need modify this to use a MASK to prevent changing all the pins.
  SREG = oldSREG;
}

Z

Hey there, sourabhp. The Mega 2560 has an external memory interface that acts a lot microprocessor's, with a data bus and an address bus. Perhaps this is what you're referring to? Memory-mapped IO ports? If so, download and read through the ATmega2560 MCU datasheet, in particular the sections on XMEM. It's not really an Arduino topic, per se. All of the related pins are brought out on the Mega 2560 board, though, and it's a relatively straightforward facility to use. The only annoyance is that the low 8 bits of the address bus are multiplexed with the data bus. In my projects so far, I've never had so many devices (or so much external memory) that I needed those, so I've just stuck with the high bits.

zhomeslice:
This is an example (NOT TESTED) but should work I quickly modified this from the digitalWrite() function we use all the time.

you will be responsible for making sure that the bit you change truly affects the pin you want to control on that port. I removed all the pin to bit verification code to give you direct control.

void digitalBitmapWrite(uint8_t port, uint8_t bitmap)

{
  volatile uint8_t *out;
  out = portOutputRegister(port);

uint8_t oldSREG = SREG;
  cli();
    *out = bitmap; // you are affecting all pins on that port if this is not desired you will need modify this to use a MASK to prevent changing all the pins.
  SREG = oldSREG;
}




Z

If you're writing the whole port, why bother disabling interrupts?

AWOL:
If you're writing the whole port, why bother disabling interrupts?

Agreed, I thought about removing that line but I added the comment about masking some of the pins and figured it to be safe since I removed all other checks :slight_smile:

Z

"If you're writing the whole port, why bother disabling interrupts?"
Yes, why? Internally it's a single clock instruction over the internal 8-bit bus.
Write a port,
PORTA = byteValue;
Read a port:
byteValue = PINA;

Can't really interrupt that. If the interrupt occurs During the read or write, the instruction finishes and then the interrupt is handled.
Complete ports on the Mega are A, B, C, F, K, L. If you have board like my Mini2560, then D, E, H, J and the 6-bit G port are also broken out in full:
http://www.crossroadsfencing.com/BobuinoRev17/


I have a full DIP version coming out also, waiting on boards now.

Ya...got it....
Thank you so much...guy's..!!!