Blinking LED port 13 any #include's needed?

Hi, I'm trying do the BLINKING LED example from the Arduino homepage. I'm using ATmega168, Arduino 5000 and AVR Studio. I can't get it working because get the following error: 'OUTPUT' undeclared (first use in this function)' --> what do I need to include, what am I doing wrong?

int ledPin = 13; // LED connected to digital pin 13

void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin as output }

void loop() { digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second }

Thank very much for your support!

I'm confused as to what you are doing. AVR Studio is designed to be used with a programmer to program a "bare" AVR chip. I suppose you could make use of the bootloader burned into the Arduino chips, tho. But since you list the ATmega168, does this mean you actually have an Arduino? Or the Arduino environment?

I going to go out on a limb here and guess that what you have is either a naked chip or one of the Arduino boards, and a programmer which you have hooked up to the 6-pin header on the Arduino. But then you are compiling your code within the AVR Studio environment.

The code example you give below is correct and particular to the Arduino environment. I find it likely that these functions do not have the same names in the AVR Studio environment, and thus your code won't compile. I've been working with avr-gcc myself, and the basic library set doesn't use anything like "pinMode(pin, OUTPUT)" as a function.

(But perhaps that function is in a library in the Arduino folder? It would be specific to the ATmega168 only, tho, right?)

In any case. This entirely depends on what your desired process it. But it looks like you should make a choice, for the present between;

A) Use the complete Arduino (hardware and software environment) as designed; use Arduino 11 to compile and load a program through the USB connection to a chip with a pre-existing bootloader, or

B) Read up on the equivalent functions and code examples in AVR Studio, and load to any AVR chip (including the one sitting on an Arduino board), via the 6-pin programming header.

Am I making any sense?

Thank you very much for your answer!
I actually do have an Arduino and I’m using AVR Studio environment to compile my C-code. I then connect to the board using USB so the board can work independently from the notebook.
I already have some code which I am using to read the temperature from a PT100 sensor (and I am not so sure what is going on here…). Nevertheless, I just wanted to extend the program to be able to light up my LED (port 13). Where can I find the corresponding functions, syntax, snipplet…?

Here is some fragments of my code:

//***************** INCLUDES ***********************
#include <avr/io.h>
#include <stdio.h>
#include <compat/ina90.h>
#include <stdbool.h>
#include <float.h>
#include <stdlib.h>

#define FOSC 16000000 // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1

//***************** PROTOTYPES *********************
int main(void);
void init(unsigned int);
char get_char(void);
int put_char(char c, FILE *stream);
char in;

//***************** FUNCTIONS **********************

int main(void)
init(MYUBRR); //initialize system
fdevopen(put_char,get_char); //important if using stdio.h functions

DDRC |=(1<<DDD0)|(1<<DDD1); //Set RS(PD3) CLK(PD4) CS(PD5) R/W(PD6) as output
PORTC = 0; //No pull-ups

ADMUX = (1<<REFS1)|(1<<REFS0)|(0x03&0x0F); //Select ADC3 0x0f : 0V 0x0e : 1.1V
DIDR0 = (1<<ADC3D); //Disable DIO ADC3
ADCSRA = (1<<ADEN)|(0x07); //Enable ADC, Division Factor 128

To activate a port I’am doing this: PORTC &=~(1<<PC1)

Download the Arduino environment (arduino-0011). You will find the missing code in:


Note that the Arduino environment creates a hidden main() that first calls init() to set up some microcontroller peripherals and enable some interrupts. Then main() calls setup(), in which you have put your initialization code, followed by an infinite loop that calls loop().

There might also be some code you want to use in:


  • Ben

I dont like the arduino environment so much because I wouldn’t now what’s happening in the background. I finally found a nice website: that explains very nicely how to read and write digital I/O ports with AVR micro-controllers etc.

This is what the code looks like:

#include <avr/io.h> 
DDRB = ( 1 << PB5 );        // set PB5 at PORTB as output (connector 13 without additional resistor OK)
PORTB |= ( 1 << PB5 );  // switch on LED

Good day!


If you don’t like the arduino environment/language I recommend the website, it’s more about using raw c on avr boards…

Hi, I dont like the arduino environment so much because I wouldn't now what's happening in the background. I finally found a nice website: that explains very nicely how to read and write digital I/O ports with AVR micro-controllers etc.

Good day!


Ach! That seems like a great reference -- but I don't speak German and don't trust an automatic translation on such technical material.

I've written several posts on this forum that explain bit manipulation in general and how to manipulate the mega168's I/O registers directly. I'm not sure how easy they would be to find using the forum's search engine, but they're in English!

  • Ben