Go Down

Topic: Ports on the Arduino Mega Pins 22-53 (Read 905 times) previous topic - next topic

psppb

I need to turn digital pins 22-53 on the mega 2560 on and off really (really) fast. No inputs being processed just switching on Mux's how do I manipulate the ports to do this? I cannot find a good example.

Thank you

tobyb121

Have a look on here: http://arduino.cc/en/Hacking/PinMapping2560
This gives you the port letter that corresponds to the pin on the Arduino board (be careful the pin number on the chip is different from the board)
You can then write to that port to set the pins
For example PortB 0,1,2,3 are digital pins 53,52,51,50 respectively
Code: [Select]

PORTB=B00001111; //To turn them all ON (NOTE: this also sets PORT: B4-B7 LOW)
PORTB=B00000000; //To turn them all OFF (again sets B4-7 LOW)
PORTB|=B00001111; //To Turn them all ON, but not changing B4-7 (slightly slower but generally better practice)
PORTB&=B11110000; //To Turn them all OFF, not changing B4-7

retrolefty

This one is helpful also:

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

PeterH

There is also a Fast Digital Write library which claims to be much, much faster than the standard Arduino digitalWrite while providing a similar level of abstraction from the underlying hardware ports.
I only provide help via the forum - please do not contact me for private consultancy.

psppb

Lefty,

I don't understand the spreadsheet I cannot find digital pins 22-53 on it.

Thanks

Bill

s-light

just look in the first column.
there are the arduino digital-pin numbers.
if you have find the number - for example Digital-Pin 7 you can follow the line and find that this arduino pin is on Port C 7
sunny greetings stefan

retrolefty


Lefty,

I don't understand the spreadsheet I cannot find digital pins 22-53 on it.

Thanks

Bill


Column one labeled Digital Pin has the 'Arduino' pin numbers going down the column. Find the row of the Arduino pin number you are interested in and the Port column of the same row will show the AVR port/pin number.

Lefty

Go Up