How to use the whole 8 bits of a port?

I've been pouring over the Arduino documentation trying to figure out how to use a whole port on my Mega. The 2 examples I have in mind are -

  • writing to 2 8 bit D to A converters that drive my laser X/Y scanner or CRO for debugging, I'll need to use a couple of other pins for latching the data and controlling the "Z" axis.

  • using 2 ports to supply a 16 bit address to static CMOS RAM, then another 8 bits to read/write data, obviously the R/[u]W[/u] and [u]CS[/u] will have to come from a third port.

Can you actually do this in the Arduino environment or do I need to go to assembler?

I was looking at the Atmel site just then and was left wondering which version of AVRStudio I need to download.

No need for assemble instructions, it can be done using the Arduino IDE. Here are the Arduino commands to utilize port access:

However be aware that the port letter references are different for the mega's 1280 chip then the 168/328 chip. You should be able to determine the correct port letters by looking at the pin out of a 1280 chip.


Thanks Lefty! The Arduino documentation needs a little beefing up! I thought I'd seen some reference to what I was trying to do! I keep looking at the 1280 data sheet and thinking, "How do I do that in a high level language?"

I guess I've spent too much time coding in mnemonics! :)

In case you're wondering I have a few "rails" of 32K static CMOS RAM, like a few meg worth and a whole bunch of 6545 and 6845 CRTC display chips. I just got a TellyMate shield and thought I'd have a crack at designing a graphics shield, say 280x191x8 colours, Apple II hi-res or maybe even 320x200x256 colours CGA resolution.

Castle Arduinostien!

(insert evil laugh here!) ;)

Just for the record, is there any way to have inline machine code or assembler in a sketch?

check the schematics of your Mega, read which port you want to use, then initialize pins with something like

// PortF as left input and turn on pullup resistors DDRF = B00000000; PORTF = B11111111;

Then just read PORTF (or PORTX you want to use).

Pin/port numbers are written in reference design schematics, or, atmega chip datasheet.