WR Home      Topic Home      Chapter:  1 
<Previous Next>

Chapter 01

Page 9

A short note on Atmega328P registers

In computer architecture, a processor register is a small amount of storage available as part of a CPU/ALU/processor/IC. Registers are temporary memory locations built inside the micro-controllers. Registers can be accessed more quickly as compared to other memory.

In the microcontroller Atmega328P, there are three ports B, C & D.
Each of the port is "associated" with THREE registers
(so there are NINE registers)

  1. Data Direction Registers (Configures the pins as Output or Input pins): DDRB, DDRC, DDRD
  2. Output Registers: PORTB, PORTC, PORTD
  3. Input Registers: PINB, PINC, PIND

Lets start with an example:
Suppose, a developer needs to connect an LED to the microcontroller. If the LED is connected to the microcontroller "properly", then it can be switched ON/OFF via a program OR can be blinked ON-OFF-ON-OFF .........., even its blink-rate can be programmatically controlled. In order to do so, the developer needs to connect the LED to a General Purpose Input Output pin as shown below:

LED at PB05

Here the LED is connected on the 6th pin of PORTB. The name of the six’th pin is PB5, as the pin numbers start from zero, rembember PB0 to PB7 were the 8-pins.

LED is a output device. The data/signal will flow from micro-controllor to outside. So, the developer needs to specify that PB5 is an output pin. At a particular time instant a pin can either act as an input pin OR an output pin, but not both. The data direction can be specified with the help of a control register, which has nothing to do with the data itself, but the direction of data. Hence it is call a Data Direction Register or DDR in short. Since there are three ports B,C & D, there are three data direction registers: DDRB, DDRC & DDRD

Now consider the following program. It switches on the LED for 0.5 second and switches it off for 0.5 second.

C-code

NOTE: This example used the pin PB5 (Arduino: Digital Pin 13) because the Arduino board already has a LED connected to this pin.

To use a delay for 500ms (or 0.5 sec) : A 10ms delay was called 50 times.
WHY ?
Bacause:

_delay_ms(max)

NOTE: The software WinAVR has an excellent documentation on library files (header files) Once WinAVR is installed the typical path to find the help files is: C:\WinAVR-20100110\doc\avr-libc\avr-libc-user-manual\index.html (Click on Library Reference, then click on <util/delay.h> An online version of the is here.



WR Home      Topic Home      Chapter:  1 
<Previous Next>