Memory
- How does it work?
- Map it’s units in personal computer
– Input
Output
Memor
y ALU
Software –
System
software &
Application
software
Introduction to
Microprocessor
ARITHMATIC LOGIC MICROPROCESSO
R
UNIT
MEMOR
Y
MICROCOMPUTE
R
Microprocessor Based
System
INPUT µP OUTPUT
MEMORY
MEMORY
INPUT
µC OUTPUT
External memory in
MEMORY addition to internal
memory may be desired
Address, Data and Control
• Bus -Bus
defined pathway for transfer of digital
information between different units.
• To write data to memory or output device.
- µp needs to send
. Address of memory location or
port address of device.
. Data
. Write control signal
• To read data from memory or Input device
- µp needs to send
. Address and
. Read Control Signal
- Memory/device sends – data.
Thus three pathways (buses) for 3 types of
digital information.
Address Bus - From µp to devices
- Unidirectional.
Data Bus - From µp to devices & devices to µp
- Bidirectional
Control - From µp to devices & from devices to
µp [Interrupt, DMA]
- Bidirectional
µp Control
Bus
Data
Bus
Microcontrolle
r
A microcontroller is a complete computer system, including
a CPU, memory, a clock oscillator, and I/O on a single
integrated circuit chip. [1]
ANALO
G
INPUTS
http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC05TB.pdf, p. 25
General Facilities
8 bit CPU
On chip clock oscillator
4 KB of ROM (Program memory)
128 bytes RAM (Data Memory)
21 Special Function Registers(SFR)
32 I/O lines (Ports P0 to P3)
64 KB address space for external data memory
64 KB address space for program memory
2- 16 bit timer/counter
5 source interrupt structure
Full duplex serial port
Bit addressability
Why Arduino?
Special
functio
n
Note the
limitations!
p. 316 Source:http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega328P
High Performance, Low Power AVR® 8-Bit
Microcontroller
– Advanced RISC Architecture
– 131 Powerful Instructions – Most Single Clock Cycle
Execution
– 32 x 8 General Purpose Working Registers
– Up to 20 MIPS Throughput at 20 MHz
Operating Voltage:
– 1.8 - 5.5V for ATmega48PA/88PA/168PA/328P
Temperature Range:
– -40°C to 85°C
Speed Grade:
– 0 - 20 MHz @ 1.8 - 5.5V
microcontroller
Ex. PORTB
Pins PB0 – PB7
May not be contiguous
Often bi-
See next slides!
directional
Port Pin Data
Directionality
• Input
– When you want to take information from the
external world (sensors) into the MCU
• Output
– When you want to change the state of something
outside
the MCU (turn a motor on or off, etc.)
• Pins default to input direction on power-up or
reset.
• Your program can set or change the directionality
of a pin at any time
ATmega328
Block
Diagram
Input
Output
Setting the Pin Data
Direction
• Arduino
– pinMode(pin_no., dir)
• Ex. Make Arduino pin 3 (PD3) an output
– pinMode(3, OUTPUT);
– pinMode(PIN_D3, OUTPUT); // with me106.h
– Note: one pin at a time
• Suppose you wanted Arduino pins 3, 5, and 7
(PD3, PD5, and PD7) to be outputs?
• Is there a way to make them all outputs at the
same
time?
Pin Used as an
Output
• Turn on an LED, which is
ATmega3
connected to pin Arduino pin 0 28
(PD0) Arduin
– What should the data o pin 0
(PD0)
direction be for pin 0 (PD0)?
• pinMode( ,
);
– Turn on the LED
• digitalWrite(0,HIGH);
– Turn off the LED
• digitalWrite(0,LOW);
Pin Used as an
Output
• Recall the question:
– Is there a way change the data direction for a set of pins
all at the same time?
• All the work of MCU happens through registers
(special memory locations)
– Registers on the Atmega328 are 8-bits wide
• The data direction register (DDRx) handles the
data directions for pins in PORTx
Source:http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega328P p. 93
Data Direction
• Register
If the bit is zero -> pin will be an input
– Making a bit to be zero == ‘clearing the bit’
• If the bit is one -> pin will be an output
– Making a bit to be one == ‘setting the bit’
• To change the data direction for a set of
pins belonging to PORTx at the same time:
1. Determine which bits need to be set and
cleared in DDRx
2. Store the binary number or its equivalent (in
an alternate
base, such as hex) into DDRx
Example
1
Make Arduino pins 3, 5, and 7 (PD3, PD5,
and PD7) to be outputs
• Arduino approach • Alternate
approach
pinMode(3, OUTPUT); DDRD =
pinMode(5, 0b10101000;
OUTPUT); or
pinMode(7,
Or if me106.h is
OUTPUT); DDRD =
used:
pinMode(PIN_D3, OUTPUT); 0xA8;
pinMode(PIN_D5,
OUTPUT);
pinMode(PIN_D7,
OUTPUT);
Example
2
Make pins Arduino pins 0 and 1 (PD0 and
PD1) inputs, and turn on the LEDs
connected to it.
• Arduino approach • Alternate
approach
pinMode(0, INPUT); DDRD = 0; / / all PORTD pins
pinMode(1, INPUT); inputs PORTD = 0b00000011;
digitalWrite(0, HIGH); or
digitalWrite(1, PORTD = 0x03;
HIGH);
Or if me106.h is
used:
pinMode(PIN_D0, INPUT);
pinMode(PIN_D1, INPUT);
digitalWrite(PIN_D0, HIGH);
digitalWrite(PIN_D1,
HIGH);
OFFICIAL
BOARDS
Arduino
Duemilanove
http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove
See the handout:
Arduino_ATmega328_pin_mapping_and_schematic
ATmega328
MCU
Power-ground
header
http://arduino.cc/en/uploads/Main/ArduinoDuemilanove.jpg
Arduino Uno
comms
R3
ATmega16u2 replaces FT232RL for USB-serial
http://www.adafruit.com/index.php?main_page=popup_image&pID=50
See: http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-uno-faq
Arduino Note: 3.3 V !!
http://www.adafruit.com/index.php?main_page=popup_image&pID=1076
See: http://arduino.cc/en/Main/ArduinoBoardDue
Arduino Duemilanove/Uno
Features
Microcontroller ATmega168/328
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB
Flash Memory
used by bootloader
SRAM 1 KB (ATmega168) or 2 KB (ATmega328)
EEPROM 512 bytes (ATmega168) or 1 KB (ATmega328)
Clock Speed 16 MHz
http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove
About Arduino
Programming
• The Arduino Duemilanove can be programmed with the
Arduino software.
; void loop()
{
digitalWrite(LED_PIN, / / set the LED
} HIGH);
delay(DELAY_ON); / / wait for DELA
on Y_ON msec
digitalWrite(LED_PIN, LOW); / / set the LED off
delay(DELAY_OFF); / / wait for DELAY_OFF
msec
}
Various
Components
Projects Using
1.
2.
Arduino
Line follower/Path
Obstacles Avoider
follower
5TB.pdf, p. 25
2. Arduino, “Avalable at http://www.arduino.cc,” 2010.
3. "Programming Arduino Getting Started with Sketches“ :
http://www.amazon.com/Programming-Arduino-Getting-Started-
Sketches/dp/0071784225/ref=sr_1_1?
s=books&ie=UTF8&qid=136449413 8&sr=1-
1&keywords=arduino+sketches). McGraw-Hill. Nov 8, 2011. Retrieved
2013-03-28.
4. C. L. Dym, A. M. Agogino, D. D. Frey, and L. J. Leifer,
“Engineering design thinking, teaching, and learning,” Journal of
Engineering Education, vol. 94, pp. 103–120, 2005. [Online].
Available:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.72.1593
5. http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega32
8
6. J. Provost, “Why the arduino won and why it’s here to stay,”
Tech.Rep.