Trying to upload code on atmega328 to display temp but throws me this error :

temp1:12:3: error: 'DDRA' was not declared in this scope DDRA = 0x00; /* Make ADC port as input */ ^~~~

Here's the code :

#include <LiquidCrystal.h>

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include <stdio.h>

#define degree_sysmbol 0xdf

void ADC_Init(){                    
  DDRA = 0x00;          /* Make ADC port as input */
  ADCSRA = 0x87;          /* Enable ADC, with freq/128  */
  ADMUX = 0x40;           /* Vref: Avcc, ADC channel: 0 */

int ADC_Read(char channel)              
  ADMUX = 0x40 | (channel & 0x07);   /* set input channel to read */
  ADCSRA |= (1<<ADSC);               /* Start ADC conversion */
  while (!(ADCSRA & (1<<ADIF)));     /* Wait until end of conversion by polling ADC interrupt flag */
  ADCSRA |= (1<<ADIF);               /* Clear interrupt flag */
  _delay_ms(1);                      /* Wait a little bit */
  return ADCW;                       /* Return ADC word */

int main()
  char Temperature[10];
  float celsius;

  LCD_Init();                 /* initialize 16x2 LCD*/
  ADC_Init();                 /* initialize ADC*/
     celsius = (ADC_Read(0)*4.88);
     celsius = (celsius/10.00);
     sprintf(Temperature,"%d%cC  ", (int)celsius, degree_sysmbol);/* convert integer value to ASCII string */
     LCD_String_xy(2,0,Temperature);/* send string data for printing */

Error :

In function 'void ADC_Init()':
temp1:12:3: error: 'DDRA' was not declared in this scope
   DDRA = 0x00;          /* Make ADC port as input */
C:\Users\Yagna\Documents\Arduino\temp1\temp1.ino:12:3: note: suggested alternative: 'DDRB'
   DDRA = 0x00;          /* Make ADC port as input */
C:\Users\Yagna\Documents\Arduino\temp1\temp1.ino: In function 'int main()':
temp1:33:3: error: 'LCD_Init' was not declared in this scope
   LCD_Init();                 /* initialize 16x2 LCD*/
C:\Users\Yagna\Documents\Arduino\temp1\temp1.ino:33:3: note: suggested alternative: 'ADC_Init'
   LCD_Init();                 /* initialize 16x2 LCD*/
temp1:38:6: error: 'LCD_String_xy' was not declared in this scope
exit status 1
'DDRA' was not declared in this scope
  • \$\begingroup\$ Most likely you are invoking the compiler wrong, it does not know for which MCU you are compiling so the libraries don't know which MCU specific libraries to include. And most likely that is not the complete error message either. Let us know more information how are you compiling it and what are all the error messages. \$\endgroup\$
    – Justme
    Mar 20, 2021 at 9:33
  • \$\begingroup\$ I have added the whole error, trying atmega328 for the first time, cant seem to figure out whats wrong... \$\endgroup\$ Mar 20, 2021 at 13:30

1 Answer 1


An ATMega328P does not have a GPIO port A.

The code must be for some other AVR, and to make it work on this MCU, you have to use the ports and pins that are availabe, which means the code needs changes to work on another AVR.

Do not assume that any other peripheral register has identical usage.

  • \$\begingroup\$ Thanks! I changed the DDRA to DDRB , the error got fixed. \$\endgroup\$ Mar 20, 2021 at 14:08
  • \$\begingroup\$ error: 'LCD_Init' was not declared in this scope i got this message now.. \$\endgroup\$ Mar 20, 2021 at 15:23
  • \$\begingroup\$ That would be another question then. Otherwise this continues forever. I don't know what libraries you use and what functions they provide, but it is clear that there is no such function declared before compiling main.c. \$\endgroup\$
    – Justme
    Mar 20, 2021 at 16:03

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .