0% found this document useful (0 votes)
34 views

Programación C++

This document outlines the course structure for ICT 6641: Advanced Embedded System. It discusses the prerequisites, 14 planned lectures covering topics like AVR architecture, assembly language programming, interfacing concepts and projects. It also outlines the assessment structure including midterm and final exams worth 25% each and a project worth 25%. The document provides an introduction to computer systems, AVR microcontrollers, and embedded systems. It compares microprocessors and microcontrollers, and discusses the characteristics and design challenges of embedded systems.

Uploaded by

akarcz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Programación C++

This document outlines the course structure for ICT 6641: Advanced Embedded System. It discusses the prerequisites, 14 planned lectures covering topics like AVR architecture, assembly language programming, interfacing concepts and projects. It also outlines the assessment structure including midterm and final exams worth 25% each and a project worth 25%. The document provides an introduction to computer systems, AVR microcontrollers, and embedded systems. It compares microprocessors and microcontrollers, and discusses the characteristics and design challenges of embedded systems.

Uploaded by

akarcz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ICT 6641: Advanced Embedded System

Lecture 1
Introduction to the course
Computer system
AVR microcontroller: history and features
AVR architecture &
Assembly language programming

Prof. S. M. Lutful Kabir


IICT, BUET
Session: April, 2011

Prerequisite knowledge for the


course
• Digital Electronics
• Analogue Electronics
• Basic power circuits
• Experience of making electronics boards
• Programming in C language

IICT, BUET

1
Lecture Plan
• Lecture # 1: AVR microcontroller: History and Features, AVR Architecture and
assembly language programming
• Lecture # 2: Branch, Call and Delay Loops, AVR I/O port programming
• Lecture # 3: Arithmetic, Logic Instructions, AVR Advanced assembly language
programming,
• Lecture # 4: Assigning projects
• Lecture # 5: MID-TERM-I Examination, AVR programming in C, AVR Hardware
Connection, Hex file and flash loader
• Lecture # 6: AVR programming in C (continued)
• Lecture # 7: AVR Timer programming
• Lecture # 8: AVR Interrupt programming
• Lecture # 9: MID-TERM-II Examination, AVR serial port programming
• Lecture #10: ADC, DAC and sensor interfacing
• Lecture #11: SPI And I2C protocol
• Lecture #12: LCD and Keyboard Interfacing
• Lecture #13: More Interfacing concepts
• Lecture #14: Presentation on Projects
IICT, BUET

Assessment
• Mid term I Exam – 25%
• Mid term II Exam – 25%
• Final Exam – 25 %
• Project Paper & Viva – 25%

IICT, BUET

2
References
• The AVR microcontroller and embedded system:
using assembly and C by Muhammad Ali Mazidi,
Sarmad Naimi and Sepehr Naimi
• C Programming for microcontrollers, featuring
ATMEL’s AVR Butterfly and the free WinAVR
compiler by Joe Pardue
• The reference books, lecture notes and other
materials related to this course can be downloaded
using the following link
http://teacher.buet.ac.bd/lutfulkabir/ICT6641_April2011/
IICT, BUET

Internal Organization of a Computer


• Internal working of every computer can be broken
down in three parts:
– CPU (Central Processing Unit)
– Memory and
– I/O (Input/Output) Devices
Address Bus

RAM ROM PRINTER DISK MONITOR KEYBOARD


CPU

Data Bus

Control Bus (MEMR, MEMW, IORD, IOWR)

IICT, BUET

3
The function of CPU
• To execute (process) information stored in memory
• The CPU is connected to memory and I/O devices
through strips of wires called BUS
• Three types of BUSES: Data, Address and Control Bus
• Each device has an unique address
• Address is placed on the address bus, the data to be
written or to be read is placed on the data bus and
the proper signal of read or write is placed on the
control bus

IICT, BUET

Instruction execution
We can think of a microprocessor’s execution of instructions as
consisting of several basic stages:
• Fetch instruction: the task of reading the next instruction from
memory into the instruction register
• Decode instruction: the task of determining what operation
the instruction in the instruction register represents (e.g.,
add, move, etc.)
• Fetch operands: the task of moving the instruction’s operand
data into appropriate registers
• Execute operation: the task of feeding the appropriate
registers through the ALU and back into an appropriate
register
• Store results: the task of writing a register into memory. If
each stage takes one clock cycle, then we can see that a single
instruction may take several cycles to complete
IICT, BUET

4
Types of memory
• ROM
– Does not lose its contents when the power is turned off
– Called non-volatile memory
– Different types : PROM, EPROM, EEPROM, Flash EPROM,
mask ROM
• PROM
– Programmable, once burned can not be changed
– So, it is also called One Time Programmable (OTP)
• EPROM
– Erasable, can be erased by UV light, takes long time (20m)
– So, it is also called UV-EPROM
IICT, BUET

Types of memory (continued)


• EEPROM
– Electrically erasable
– Takes less time
– A portion (even a byte) can be erased
– Can be erased while it is on-board
• Flash EPROM
– Same as EEPROM but a byte can not be erased
– Can be erased block by block

IICT, BUET

5
Types of memory (continued)
• Mask ROM
– It refers to the ROM in which the contents are
programmed during IC fabrication stage
– Costly, so done when volume is high
• RAM
– Called volatile memory, data losses with power being cut-
off
– Three types of RAM
• SRAM
• NV-RAM
• DRAM

IICT, BUET

Types of memory (continued)


• SRAM (static RAM)
– Storage cells are made of flip-flops
– Requires number of transistor to keep one bit of data
– Use of CMOS technology allows producing high capacity
SRAM, but still far below than DRAM
• NV-RAM
– Like other RAM, CPU can read/write on NV-RAM but unlike
them, data does not loss on Power-cut
– Use an internal lithium battery to store the energy
– Uses an intelligence control circuit

IICT, BUET

6
Types of memory (continued)
• DRAM
– Uses capacitor to store bits of data
– Requires continuous refreshing due to leakage
– Smaller in size, so high density

IICT, BUET

Microcontroller versus
Microprocessor
Data Bus
CPU RAM ROM
Serial
ROM I/O Timer
CPU RAM COM Serial
Port
port I/O
Timer COM
ADC port
Address Bus
a) General Purpose Microprocessor System b) Microcontroller

• When one talk about microprocessor it is meant for general


purpose processor
• It does not have and built-in RAM, ROM, I/O ports etc.
• On the other hand, microcontroller contains all those built-in

IICT, BUET

7
General purpose microprocessor
system and microcontroller system
• A designer using a general purpose microprocessor such
as Pentium or PowerPc must add RAM, ROM, I/O ports
to make them functional
• Although it becomes bulkier and costlier still they have
the advantage of versatility
• But for the microcontroller all are integrated in a single
chip, so it is sometimes called “single chip computer”
• In many applications, the space used, the power
consumed and the price per unit is much more critical
consideration than the computing power
• In those applications, microcontrollers are used
IICT, BUET

Application of Microcontrollers
• Consumer electronics -- cell phones, pagers, digital
cameras, camcorders, video cassette recorders, portable
video games, calculators, and personal digital assistants;
• Home appliances -- microwave ovens, answering
machines, thermostat, home security, washing machines,
and lighting systems;
• Office automation -- fax machines, copiers, printers, and
scanners;
• Business equipment -- cash registers, curbside check-in,
alarm systems, card readers, product scanners, and
automated teller machines;
• Automobiles -- transmission control, cruise control, fuel
injection, anti-lock brakes, and active suspension.
IICT, BUET

8
Characteristics of Embedded Systems

• Single-functioned: An embedded system usually


executes only one program, repeatedly
• Tightly constrained: All computing systems have
constraints on design metrics, but those on
embedded systems can be especially tight
• Reactive and real-time: Many embedded systems
must continually react to changes in the system’s
environment, and must compute certain results in
real time without delay

IICT, BUET

Design challenges
Main challenges
• Non-Recurring Engineering Cost
• Unit cost
• Size
• Performance
• Power
• Flexibility
• Time-to-market
• Time-to-prototype
• Correctness
• Safety
IICT, BUET

9
Microcontroller for embedded
system
• Microprocessors and microcontrollers are widely used in
embedded system products
• An embedded system is controlled by its own internal
microprocessor (or microcontroller) as opposed to
external controller
• Printer is an example of embedded system, it does only
one task, taking data from the PC and print it
• In a mouse, there is a microcontroller which tracks the
mouse’s position and sends the information to the PC
• In an embedded system, typically only one application
software is burned into ROM
IICT, BUET

High end embedded system


• Sometimes microcontroller is inadequate for a
certain embedded system
• So, some manufacturers like Intel, AMD, Freescale
targeted their microprocessors for the high end
embedded market
• For example, PowerPC microprocessor
manufactured jointly by IBM and Freescale is
targeted for that market
• Another chip called ARM (Advanced Risk Machine) is
used for high end embedded system
IICT, BUET

10
Choosing a microcontroller
• Efficiency and cost effectiveness
– Speed
– Packaging
– Power consumption
– The amount of ROM and RAM
– The number of I/O pins and timers
– Ease of upgrade to higher performance and lower
power consumption
– Cost per unit
IICT, BUET

Choosing a microcontroller
(continued)
• Easy to develop product around it. Availability of
– Assembler
– Debugger
– Code efficient C language compiler
– An emulator
– Technical support
– Expertise
• Ready availability now and in near future. In recent
years, companies have begun to sell Field-Programmable
Gate Array (FPGA) and Application Specific Integrated
Circuit (ASIC) libraries for the different microcontrollers

IICT, BUET

11
A brief history of AVR
microcontroller
• Two students of Norwegian Institute of Technology – Alf
Bogan and Vegard Wollan designed the basic
architecture of AVR
• How did the name come? Atmel says it is nothing but a
product name. Guess works – Advanced Virtual Risk, Alf
Vegard RISC
• Almost all of AVR microcontrollers are 8-bit
• They are not 100% compatible when moved from one
family to other
• Recompilation and changing of some code requires
• Four types: Mega, Tiny, Special Purpose and Classic
IICT, BUET

AVR family overview


• Classic AVR (AT90Sxxxx)
– This is the original AVR Chip
• Mega AVR (ATmegaxxxx)
– Powerful, with more than 120 instructions and lots of peripheral
capabilities
• Tiny AVR (ATtinyxxxx)
– Have less number of instructions and smaller package
• Special Purpose AVR
– Considered as a subset of other groups
– Special capabilities are made for designing specific application
– USB controller, CAN controller, LCD controller, Zigbee, Ethernet
controller, FPGA, Advanced PWM etc

IICT, BUET

12
AVR features
• RISC Architecture
• Harvard Architecture
• On chip program ROM
• Data RAM
• Data EEPROM
• Timers
• I/O ports
• Most of the AVRs have ADC, PWM, USART
• Some of them have SPI, I2C (TWI), CAN and USB
interface
IICT, BUET

AVR Microcontroller program ROM

• The ROM is used for storing the program and hence


is called program ROM
• AVR has the capabilities of 8M ROM space but
program ROM size varies from 1K to 256K
• AVR is one of the first microcontrollers to use on-
chip Flash memory for program storage

IICT, BUET

13
AVR Microcontroller peripherals
• AVR can have 3 to 86 pins for I/O
• Most of the AVR comes with ADC, timer and USART
as standard peripherals
• ADC is 10-bit and number of channel can be upto 16

IICT, BUET

Other Microcontrollers
• Microchip produces PIC family
• Freescale (formerly Motorola) makes HCS08 and
many of its variations
• Zilog produces the Z8 and its variations
• Intel and number of other companies make 8051
microcontrollers

IICT, BUET

14
The general purpose registers in the
AVR
• CPU uses many registers to store information
temporarily
• This information could be a byte of data to be
processed or an address pointing to the data to be
fetched
• In AVR, there are 32 general purpose registers, they
are R0-R31 and are located in the lowest location of
memory address

IICT, BUET

LDI Instruction
• LDI Rd, K ; load Rd (destination) with immediate
value K) and 16<=d<=31
• “I” in LDI instruction stands for immediate
• Among the two operands of LDI instruction
destination comes first
• Moving a value larger that 255 will cause an error

IICT, BUET

15
ADD instruction

• The ADD instruction has the following


format:
ADD Rd, Rr ; ADD Rr ro Rd and store the
result in Rd
• To add two numbers such as 0x25 and
0x34, one can do the following:
LDI R16, 0x25 ; Load 0x25 into R16
LDI R16, 0x34 ; Load 0x34 into R17
ADD R16, R17 ; Add IICT,
valueBUET
R17 to R16

The AVR Data Memory

• Two kinds of memory space: General


– Code memory Purpose
– Data memory Registers
• Data memory has three parts: I/O
– GPRs Registers
– I/O memory
(SFRs)
– Internal data SRAM
General
purpose
RAM
(SRAM)
IICT, BUET

16
Different types of data memory
• GPRs
– Regardless of AVR chip, GPRs occupies 0x00-0xFF
addresses
• I/O memory
– Dedicated to specific functions such as status register,
timers, serial communication, I/O ports, ADC and so on.
– Space varies from chip to chip
– Standard 64 bytes of I/O memory
– Extended I/O memory > if more than 64 bytes

IICT, BUET

Different types of data memory


(continued)

• Internal data SRAM


– Scratch pad
– Used by program to store data temporarily
– Size varies from chip to chip
– May be standard (512 byte) and extended
• EEPROM
– A small amount of EEPROM is available
– Size varies from chip to chip

IICT, BUET

17
Using Instructions with Data
Memory
• Other than Immediate value or data at the GPRs,
AVR allows direct access to other locations in the
data memory
• LDS instruction
– LDS Rd, K ; load Rd with the contents of location K, K is
the address between 0x0000 to 0xFFFF
• The following program adds the contents of 0x300
to location 0x302
– LDS R0, 0x300 ; R0 = the contents of location 0x300
– LDS R1, 0x302 ; R1 = the contents of location 0x302
– ADD R1, R0 ; add R0 to R1 and store in R1

IICT, BUET

Using Instructions with Data


Memory (continued)
• STS Instruction (STore direct to data Space)
STS K, Rr ; Store the content of register Rr into the memory
location having address K
• The following program first loads the content of R16
register with value 0x55, then moves this value to a
memory location having address 0x38
LDI R16, 0x55 ; R16 = 55 (in hex)
STS 0x38, R16 ; Copy R16 to 0x38

IICT, BUET

18
Using Instructions with Data
Memory (continued)
• IN instruction (IN from I/O location)
– IN Rd, A ; load an I/O location to one GPR
• This instruction is only valid for I/O locations (see
page 64 of the book)
• Here we have to use relative address of I/O
locations
• Similar to LDS, but IN has several advantages
– IN > 1 m/c; LDS > 2 m/c
– For IN we can use name of the I/O registers
– IN is available in all AVR, but LDS is not available in all
IICT, BUET

Using Instructions with Data


Memory (continued)
• OUT instruction (OUT to I/O location)
– OUT A, Rr ; store to I/O location
• To store the content of R10 to the I/O register called
PORTD, one should write
– OUT PORTD, R10

IICT, BUET

19
Using Instructions with Data
Memory (continued)
• MOV instruction
– The MOV instruction is used to copy data among the GPR
registers, it has the following format
– MOV Rd, Rr
• INC Rd, DEC Rd, COM Rd
– Increment, decrement and complements the content of
the register

IICT, BUET

AVR Status Register


• It is an 8-bit register
• Also called flag register

I T H S V N Z C

C - Carry flag S - Sign flag


Z - Zero flag H - Half carry
N - Negative flag T - Bit copy storage
V - Overflow flag I - Global Interrupt Enable

IICT, BUET

20
AVR Status Register (continued)
• C, the carry flag – carry out from D7
• Z, the zero flag – if the result of an arithmetic or logic
operation zero
• N, the negative flag – used for signed number
• V, the overflow flag – used for signed number
• S, the sign flag – used for signed number
• H, the half carry flag – when there is a carry from D3
to D4
• T, Bit copy storage – will be discussed later
• I, Global Interrupt enable – will be discussed later
IICT, BUET

Assembler Directives
• Instructions – direction to the CPU
• Directives – direction to the assembler
• .EQU, .SET – same, but .SET directive may be
reassigned
• .ORG – beginning of the address
• .INCLUDE – to add the content of a file
• Label – to reference a point in the program; label
name must be unique; consists of a-z, A-Z, 0-9, ?, . ,
@, _ ; not a number, not reserved word

IICT, BUET

21
Introduction to AVR assembly language
programming
• CPU can work only in binary
• Programming in binary, called machine language, is
tedious
• Eventually assembly language was developed
• This use shorter form of binary codes called
mnemonics
• A program called assembler converts mnemonics
into machine language
• Assembly language is referred to as low level
language
• But now a days high level language such as C is used
to program microcontroller
IICT, BUET

Structure of Assembly Language

• Contains instructions called mnemonics optionally


followed by one or two operands
• In general, there are four fields –
[label] mnemonics [operands] [;comment]
• Bracket indicates that the fields are optional
• Comment field starts with ; like // in C
• Assembler ignores the comments

IICT, BUET

22
The program counter
• The most important register in the AVR
microcontroller is the program counter (PC)
• It is used by the CPU to point to the address of the
next instruction to be executed
• As CPU fetches opcode from the program ROM, the
program counter is incremented automatically to
point to the next instruction
• The wider the program counter the more memory
locations a CPU can access; a 14 bit program
counter can access 214 = 16K byte of program
memory
IICT, BUET

Program ROM space


• Some family members have only a few kilobytes of
on-chip ROM and some, such as the ATmega128,
have 128K of ROM
• No member can access more than 4M of ROM
because the program counter can not be more than
22 bits

IICT, BUET

23
AVR’s wakeup location
• In case of AVR, it wakes up at 0x0000 location when
it is powered up
• That means that it expects the first opcode to be
stored in 0x0000 location
• We achieve this by using .ORG statement

IICT, BUET

Harvard Architecture in AVR


• AVR uses Harvard Architecture, it means that it uses
separate buses for the code and the data memory
• Program bus provides access to the program flash
whereas data bus is used for bringing data to the CPU
A

DATA CODE CPU DATA


CPU CODE
MEMORY MEMORY A A MEMORY
MEMORY

D
D D

Von Neumann Harvard


IICT, BUET

24
RISC Architecture in the AVR
• More or less fixed instruction size
• Large number of registers
• Less number of instruction set
• More than 95% of instructions are executed in one
clock cycle
• Harvard Architecture
• No microinstruction circuitry
• Load/ Store architecture

IICT, BUET

End of Lecture 1

IICT, BUET

25

You might also like