microprocessors, lecture 3
TRANSCRIPT
![Page 1: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/1.jpg)
AVR Microcontrollers- Introduction
Microprocessors, Lecture 3:
![Page 2: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/2.jpg)
AVR Microcontrollers
2
Widely-used microcontroller
Different familiesBased on the application and Flash memory capacity
Classic AVRe.g. AT90S2313, AT90S4433
Megae.g. ATmega8, ATmega32, ATmega128
Tinye.g. ATtiny13, ATtiny25
Special Purpose AVRe.g. AT90PWM216,AT90USB1287
![Page 3: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/3.jpg)
3
AVR internal architecture
PROGRAM ROM
PortsOSC
CPU
Timers
OtherPeripherals
ProgramBus Bus
RAM
I/O PINS
EEPROM
Interrupt Unit
3
![Page 4: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/4.jpg)
AVR’s CPU
4
CPU:RISC architecture131 instructionsMost instructions are executed in a single cycle32 general-purpose registers64 IO registersMany useful peripherals
Very low-powerless than 10mW power consumption
![Page 5: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/5.jpg)
5
AVR’s CPU
AVR’s CPUALU
32 General Purpose registers (R0 to R31)
PC register
Instruction decoder
Almost the same for all families
CPUPC
ALU
registers
R1
R0
R15
R2
…
R16
R17
…
R30
R31
Instruction Register
Instruction decoder
SREG: I T H S V N CZ
5
![Page 6: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/6.jpg)
SREG flags
6
Not all instructions affect flagsExample: load instruction has nothing to do with flags
![Page 7: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/7.jpg)
Decision making by flags
7
![Page 8: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/8.jpg)
Memory address space
8
A unified address space
32 general-purpose registersDirectly connected to the ALU
64 IO registersTo keep the data sent to/ received from peripherals
StackStarting from the end of SRAM and grow up to lower addressesIndexed by SPL-SPH registers
![Page 9: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/9.jpg)
Internal busses
9
![Page 10: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/10.jpg)
10
Some simple instructions1. Loading values into the general purpose registers
LDI (Load Immediate)LDI Rd, k
Its equivalent in high level languages:
Rd = k
Example: LDI R16,53
R16 = 53
LDS (Load from SRAM)LDS R0,0x300Load R0 by data from address 300
10
![Page 11: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/11.jpg)
11
Some simple instructions2. Arithmetic calculation
There are some instructions for doing arithmetic and logic operations; such as:
ADD, SUB, MUL, AND, etc.
ADD Rd,RsRd = Rd + Rs
Example:
ADD R25, R9
R25 = R25 + R9
ADD R17,R30
R17 = R17 + R30
11
![Page 12: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/12.jpg)
12
Some simple instructions3. store
No immediate value store! Just stores can be done through registers
12
![Page 13: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/13.jpg)
13
Some simple instructions3. IN and OUT
Each IO register can be addressed in two ways:Memory addressIO address (relative to the beginning of the IO registers)
“IN” and “OUT” use the IO address
example: IN r1,0x16 ;// copy IO register no. 10 (memory address 0x36 to r1)
13
![Page 14: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/14.jpg)
Some other instructions
14
![Page 15: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/15.jpg)
ALU instructions
15
![Page 16: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/16.jpg)
Single operand instructions
16
![Page 17: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/17.jpg)
Directives
17
Like directives in high level languages
For core readability
Not instructions that generate machine code after compile
Example: EQUTo set a constant valueEquivalent to CONSTANT in C++
![Page 18: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/18.jpg)
Other directives
18
![Page 19: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/19.jpg)
AVR data size
19
AVR just has 8-bit data
Programmer or compiler has to break larger data into 8-bit units
![Page 20: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/20.jpg)
20
A simple programWrite a program that calculates 19 + 95
LDI R16, 19 ;R16 = 19
LDI R20, 95 ;R20 = 95
ADD R16, R20 ;R16 = R16 + R20
CPUPC
ALU
registers
R1R0
R15
R2
…
R16R17
…
R30R31
Instruction Register
Instruction decoder
SREG: I T H S V N CZ
20
![Page 21: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/21.jpg)
Code memory
21
The program after compiling is stored in a ROM (flash memory)
To keep the code even when the system is powered offData is stored in another memory (SRAM)
In AVR each code memory location is 2-bytes
In Atmega32, 32K flash memory is organized as 16Kx16 words
Needs 14-bit PC
![Page 22: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/22.jpg)
Instruction size
22
Almost all instructions are 2 bytesExample:
1110: machine code for LDIKkkk…= imidiate valuedddd= destination register
![Page 23: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/23.jpg)
Another example
23
![Page 24: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/24.jpg)
32-bit instructions
24
![Page 25: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/25.jpg)
ATmega32
25
16 MHz clock frequency44 pins32 KB instruction memory (Flash)1KB data memory (EEPROM)2048 B data memory (SRAM)SPI, USART, and I2C serial ports3 timers8 10-bit ADC channelsAnalog comparator4 PWM ports…….
![Page 26: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/26.jpg)
ATMega32 pins
4 8-bit ports
PA, PB, PC, PD
Multiplexed with other in-outs
26
![Page 27: Microprocessors, Lecture 3](https://reader031.vdocument.in/reader031/viewer/2022012411/616b77818c8b9e6e5c315953/html5/thumbnails/27.jpg)
AVR programming
27
Assembly: AVR Studio
C: Code Vision