Stuck with deciding the location and the type of variable declarations for this MCU code
In terms of speed and efficiency, I cannot be sure where to declare them.


For clean code the scope must be as small as possible.
Use the static keyword if you have to make it persistent.

For speed you may want to look into how and where you use it. Often automatic (local) scope variables are very fast since they fit in R0-R15, then follow relative operations on stack, and the slowest are absolute (global) or external variables which also require a full pointer to be loaded before read/write.


  Also how can we make judgement whether we need to use volatile or not?


"An object that has volatile-qualified type may be modified in ways unknown to the
implementation or have other unknown side effects."

Volatile is only required when the object changes outside program flow the compiler can predict.  Such as peripheral registers or variables shared with interrupts or threads.
Volatile is expensive! Each expression with volatile is evaluated separately.



I also see some blobs of code that do have an obvious function to the reader. You may want to move these into a function. eg:

void sendDataByBitBanging(unsigned long data){
    uint8_t val;
    for (int i = 0; i &lt; 25; i++){
        data &lt;&lt;= 1;
        PORTD &amp;= ~(1 &lt;&lt; 5);
        _delay_us(2);
        PORTD |= (1 &lt;&lt; 5);
        _delay_us(2);

        val = 1 &amp; (PIND &gt;&gt; PIND6);

        data |= val;
    }
}


Although a function might costs you a stackframe and a call/return instruction. Many modern compilers can inline functions when side-effects are limited.
As Micheal said below, you shouldn’t sacrifice readability or maintainability for performance.  

As embedded developer you always have to make a compromise between abstraction, readability and raw performance due to the limited environment the software has to work on.