First, it has lots of directly addressable pins... grouped together. For example, to set to "high" the pins marked "analog pins 0 to 7" as GPIO (digital pins), it is sufficient a single instruction:
PORTF = 0xff;It is also convenient for setting more than one pin in a single instruction:
PORTF &= 0x3c;More info on Port Manipulation.
Summary on the Arduino Mega boards (1280 and 2560):
- PORTF: 8 in-line pins, west side ("analog pins 0 to 7")
- PORTK: 8 in-line pins, west side ("analog pins 8 to 15")
- PORTA: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 22 to 29")
- PORTC: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 30 to 37")
- PORTL: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 42 to 49")
- note also the blocks of 4 adjacent pins for PORTB, PORTH, PORTD.
If you don't need external RAM/SRAM, you can fully use PORTA and PORTC.
If you don't use weird things like external interrupts, you can fully use PORTL.
Yeah, five blocks of 8 pins each. Things like:
if(PINK) call_a_function();"if any input pin of PORTK is on level high, then call a function".
Just forget the digitalRead/digitalWrite stuff.
Just don't forget to assign the appropriate data direction register in the setup() phase.
DDRF = 0xff; // declare eight output pins
PORTF = 0x1f; // output 3 low and 5 high pins
No comments:
Post a Comment