Professional Documents
Culture Documents
2KB SRAM (for data volatile; data lost on power off) 1KB EEPROM (for persistent data storage holds data after power off) 32KB Flash (organized as 16K of 16-bit words for persistent program code)
Digital input (for reading discrete external signals on each pin (0v or 5v) as data values 0 or 1) Digital output (for writing binary data values as discrete output signals (0v or 5v) Analog input (for reading continuous external signals (0v-5v) as data values) Serial/Parallel (for reading or writing streams of bytes) Pulse accumulator (for counting #changes of external signals)
CS-280 Dr. Mark L. Hornick 2
Inside an IC package
Inside an IC package
Atmel Atmega32
Arithmetic Logic Unit (ALU) performs the actual arithmetic, logical, and bit-functions
Memory SRAM, EEPROM, Flash Clock circuit internal/external I/O Input/Output; video, serial, parallel, USB, SCSI, etc.
Organized as 16K 2-byte words Because program instructions are either 2 (common) or 4 (less common) bytes long
$3C00
Most general-purpose microprocessors (like in your PC) use a von Neumann Architecture
1.
Data and instructions are both stored in the same main memory
2.
The content of any part of memory is addressable by location without regard to what is stored in that location program or data
Instructions are executed sequentially. In case of accidental or intentional programming errors, data can be executed a common attack used by viruses
Data CPU
3.
+ Program
Microcontroller Components
Main Memory
Program data occupies a different and separate memory from the program itself.
2.
3.
Different timing, size, and structure for program instructions and data Concurrent access to data and instructions (increases speed) Clear partitioning of data and instructions (better security)
When the device is powered-on, the Program Counter is set to 0. The instruction at the location in Flash Memory at the address indicated by the Program Counter is fetched and placed in the Instruction Register The opcode and operands within the instruction are extracted by the Instruction Decoder The control lines from the I.D. activate the particular circuitry within the ALU that is capable of processing that particular opcode. The ALU executes the instruction. The Program Counter is automatically incremented and the cycle repeats.
CS-280 Dr. Mark L. Hornick 11
12
An Assembler converts human-readable assembly language instructions into machine-executable instruction that are stored in Program Flash Memory
add r20, r5
ADD R20, R5
Lets consider the case of how the ADD instruction is represented as a machine-executable instruction
Example: ADD R20, R5 A 16-bit machine instruction is generated (by the assembler) for this particular case
Machine instructions consist of an numeric opcode and operands The opcode in this case is 000011 (3) Each register operand is represented by 5 bits
5 bits are required to represent all possible register values from 0-31 ddddd represent the 5 bits that represent the destination register value (20) rrrrr represent the 5 bits that represent the source register value (5)
0000
11rd
dddd
rrrr Note: The bits ddddd and rrrrr are split in this instruction
This 16-bit binary word can be expressed in hexadecimal as 0x450d (with the high byte being rightmost) CS-280
Dr. Mark L. Hornick
14
The ALU can only directly operate on data that has been fetched into the Registers. It cannot directly operate on SRAM or EEPROM data.
We (the programmer) must first load some values into these registers. Once way of doing this is with the following instructions:
ldi r20, 2 ; load value 2 into r20 lds r5, 0x60 ; load value at SRAM addr 0x60 into r5 add r20, r5 ; add them; result is in r20
Following the add, we normally store the sum (the value in r20) someplace (like in SRAM). More on how to do that laterhow would you guess it might work?
15
16
Special-purpose Registers can also be operated upon directly by the ALU (with certain specific instructions)
Stack pointer (SP, 16-bit)
Stores return address of subroutine/interrupt calls Storing temporary data and local variables
Program counter (PC, 16-bit) Holds address of next program instruction to be loaded and executed Automatically incremented when the ALU executes an instruction
Status Register (SREG, 8-bit) Contains information of result of most recent ALU operation
CS-280 Dr. Mark L. Hornick 17
Editor (for writing programs in assembly language) Assembler (like a compiler, but much simpler) Program downloader (loads the assembled code to the Atmega32) Debugger
Monitor (remote debugging on the actual Atmega32) Simulator (local dubugging using a simulation of the running Atmega32)
18