Theoretical question: DigitalWrite(PORT_DDRA_bit 7) vs: OUTPORT(PORT_DDRA_BIT7)

HI;

I just wonder:

The examples below are not neccessarily syntactically correct: !!

IF I want to program the PORTA register to be OUTPUT on a Mega 2560 I normally use the command: DDRA = 255; or DDRA = 0x01; - if I only want PORTA bit 0 to be OUTput.

I can use OUTPORT(DDRA, 0x01) , i suppose - or can I ?.

Let's for a very short moment assume that the DDRA bit 0 number is pin 48 . Is it then possible to use digitalWrite(48,High) instead of OUTport(DDRA,0x01) - command. ?

digitalWrite(48,HIGH); sets pin 48 = HIGH (again assuming DDRA bit 0 == pin 48) and OUTPORT(DDRA, 0x01) set DDRA-bit 0 HIGH, too.

What's the difference between the 2 commands ?

KRIS aka snestrup2016

The valid commands are given in the following sketch:

void setup()
{
  DDRA = 255; //0xFF  directions set of IO line using data direction registerall port pins are output; valid instruction
  //--------------------------
  DDRA = 0x01;                     //only PA0 is output; direction set of IO line using data direction register
  pinMode(PA0, OUTPUT);       //direction set of single IO line using Arduino command (macro)
  pinMode(PORTA0, OUTPUT); //direction set of single IO line using PORTX Register
  pinMode(48, OUTPUT);        //direction set of single IO lines using MEGA's DPin(Digital Pin)
  //--------------------------
  // OUTPORT(DDRA, 0x01);   //OUTPORT() is not an Arduino command
  digitalWrite(48, HIGH);        //writing 1-bit data on an ouput line referred by dPin-48; valid instruction
  // Outport(DDRA, 0x01);     //not a valid Arduino command
  // OUTPORT(DDRA, 0x01);  //not a valid arduino command
  bitSet(PORTA, 0);               //writing LH at Bit-0 of PORTA Register; valid Arduino command
  bitWrite(PORTA, 0, HIGH);  //writing LH at Bit-0 position of PORTA Register; valid Arduino command
}

void loop()
{

}

I’ve never heard of OUTPORT...

HI,

Thanks for "updating" me. Things are much clearer now.

And you're right - OUTPORT is NOT a Ard- command. I wonder where I have heard it .... - but that's another theoretical question...

Anyway, again thanks for updaing me.

Kris