Arduino-Uno-LED

Arduino UNO boards are very helpful for the beginners to do projects in embedded system. Using the integrated Arduino libraries we can program the ATMEGA328 evenif without reading the datasheet. Yes its correct, its really helpful. But is it the right way if we think from an embedded student perspective? As he is using the Arduino libraries he won’t understand the basic register configurations required for the Microcontroller. That is not good for his future career. Please try to understand or try to write the code in very level always just like as my second program below.

I am posting two programs to Blink builtin LED(Connected to PORTB.5) for UNO R3 board. This will explains how to use the  integrated Arduino libraries for I/O ports and also without Arduino Libraries.

LEDBlink code using Arduino Library

/*
LEDBlink

This code demonstrates how to access I/O ports by using Arduino Library.
Blinks the LED connected to PORTB.5 pin in UNO R3 board with a delay for 1Sec.
*/

// the setup routine runs once when you press reset:
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // PortB.5 configured as output. PortB.5  is defined as LED_BUILTIN in Arduino library
}

// the loop routine runs over and over again forever:
void loop() {

digitalWrite(LED_BUILTIN, HIGH); //Set PortB.5
delay(1000);
digitalWrite(LED_BUILTIN, LOW);  //Clear PortB.5
delay(1000);

}

LEDBlink code without using Arduino Library

/*
LEDBlink

This code demonstrates how to access I/O ports direclty instead of using Arduino Library.
Blinks the LED connected to PORTB.5 pin in UNO R3 board with a delay for 1Sec.
*/

#define PORTB_D (*((volatile uint8_t *)0x25))  //PortB Data register
#define PORTB_DD (*((volatile uint8_t *)0x24)) //PortB Direction register

// the setup routine runs once when you press reset:
void setup() {

PORTB_DD |= 0X20; // PortB.5 configured as output

}

// the loop routine runs over and over again forever:
void loop() {

PORTB_D |= 0x20; //Set PortB.5
delay(1000);
PORTB_D &= 0xDF; //Clear PortB.5
delay(1000);

}