KEMBAR78
Lecture 3 Architecture | PDF | Integrated Circuit | Computer Engineering
0% found this document useful (0 votes)
32 views20 pages

Lecture 3 Architecture

The document discusses the architecture of the ATmega328 microcontroller used on the Arduino Uno board. It describes the microcontroller's memory organization, CPU, I/O ports, and how programs are structured in Arduino using setup() and loop() functions.

Uploaded by

mythemyaseen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views20 pages

Lecture 3 Architecture

The document discusses the architecture of the ATmega328 microcontroller used on the Arduino Uno board. It describes the microcontroller's memory organization, CPU, I/O ports, and how programs are structured in Arduino using setup() and loop() functions.

Uploaded by

mythemyaseen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

CMP3010

EMBEDDED SYSTEMS
PROGRAMMING
LECTURE 3 ATMEGA328 ARCHITECTURE
Arduino Uno
•It is a microcontroller based on the ATmega328
•14 digital input/output (6 for PWM)
•6 Analog inputs
•CPU (8 bits) clock: 16 MHz
•Programs size can be max 30Kbytes
•SRAM 2KB, EEPROM 1KB
•UART, SPI and I2C protocol are enabled
Atmega 328 Pinout
AVR Architecture
•Clocks and Power
• Beyond scope of this course
•CPU
• Harvard architecture
•Flash – program memory
• 32K
•SRAM – data memory
• 2K
•EEPROM
• For long-term data
• On I/O data bus
Memory
•Flash (32K) (15-bit addresses)
• Program memory – read only
• Non-volatile
• Allocate data to Flash using PROGMEM keyword
• see documentation
•SRAM (2K)
• Temporary values, stack, etc.
• Volatile
• Limited space!
•EEPROM (1K)
• Long-term data
• see documentation on EEPROM library
AVR CPU
•Instruction Fetch and Decode
•ALU Instructions
•I/O and special functions
AVR Memory Organization
•Program Memory (ROM) •Data Memory
Data Memory
•Rx space
• 32 8-bit GP registers

•I/O Memory
• Special Function Registers (SFRs)

•Part of SRAM memory space


I/O Memory (SFR) Overview

See. Datasheet of Atmega328


Port Special Functions
•Lots of special uses for pins
• Clock connections
• Timer connections
• e.g. comparator output for PWM
• Interrupts
• Analog references
• Serial bus I/Os
• USART
• PCI
I/O Ports
•3 8-bit Ports (B, C, D)
•Each port controlled by 3 8-bit registers
• Each bit controls one I/O pin
• DDRx – Direction register
• Defines whether a pin is an input (0) or and output (1)
• PINx – Pin input value
• Reading this “register” returns value of pin
• PORTx – Pin output value
• Writing this register sets value of pin
Arduino Digital and Analog I/O Pins
•Digital pins:
• Pins 0 – 7: PORT D [0:7]
• Pins 8 – 13: PORT B [0:5]
• Pins 14 – 19: PORT C [0:5] (Arduino analog pins 0 – 5)
• digital pins 0 and 1 are RX and TX for serial communication
• digital pin 13 connected to the base board LED
•Digital Pin I/O Functions
• pinMode(pin, mode)
• Sets pin to INPUT or OUTPUT mode
• Writes 1 bit in the DDRx register
• digitalWrite(pin, value)
• Sets pin value to LOW or HIGH (0 or 1)
• Writes 1 bit in the PORTx register
• int value = digitalRead(pin)
• Reads back pin value (0 or 1)
• Read 1 bit in the PINx register
Reading and Writing Pins Directly
•Only one pin can be changed using the Arduino I/O functions
• Setting multiple pins takes time and instructions

•To change multiple pins simultaneously, directly read/write the pin registers
• DDR{B/C/D}
• PORT{B/C/D}
• PIN{B/C/D}

•e.g. to set all digital pins 0 – 7 to a value:


• PORTD = B01100101;
DDRx = 0

Pin Circuitry

PORTx

PINx
DDRx = 0

Pin Input
off

PORTx

PINx
Synchronization Timing
•Note: Takes a clock cycle for data output to be reflected on the input
DDRx = 1

Pin Output
on

PORTx

PINx
Arduino C/C++ Programs
•Arduino calls these “sketches”
• Basically C/C++ with libraries

•Program structure
• Header: declarations, includes, etc.
• setup()
• loop()

•setup()
• executes once when program starts

•loop() as superloop
• continuously re-executed when the end is reached
The Arduino C/C++ Main Program
int main(void)
{
setup();
for (;;)
loop();
return 0;

}
Blink Program
int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {

// initialize the digital pin as an output:


pinMode(ledPin, OUTPUT);

// the loop() method runs over and over again,

// as long as the Arduino has power

void loop()

{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second

You might also like