Title: Microcontrollers
1Microcontrollers
2What can the 8051 instructions do?
- Arithmetic (add, subtract, multiply, divide)
- Logical Operations (AND, OR, NOT, etc.)
- Data Transfer (move bytes)
- Boolean Variable Manipulation (move bits)
- Program Branching (branch, call subroutines)
3Why does the uP need registers?
- Scratch pad.
- Math.
- Interface with the outside world.
- Timing and counting.
- Keep track of the program and interpret
instructions. - Point to data by holding addresses for easy
reference.
4128 Bytes of On Chip RAM
Lower 64 Bytes
Upper 64 Bytes
5Scratch Pad on Chip RAM
80 byte addressable registers
128 addressable bits
32 register (Rn) addressable bytes
6The 4 Register Banks.
Numbered 0,1,2, and 3Only 1 at a time can be
activatedBank 0 is the default bank.
Rn
1 byte per register
Ri
7The Special Function Register Map
(upper 64 bytes of on chip RAM)
Mnemonic Address
Byte Address
Bit Address
8MOV dest-byte, source-byteCopies bytes from the
source to the destination.
- MOV A, data
- MOV A, Rn
- MOV A, direct
- MOV A, _at_Ri
- MOV Rn, A
- MOV direct, A
- MOV _at_Ri, A
- MOV Rn, data
- MOV Rn, A
- MOV Rn, direct
- MOV direct, data
- MOV direct, _at_Ri
- MOV direct, Rn
- MOV _at_Ri, data
- MOV _at_Ri, A
- MOV _at_Ri, direct
9direct addressing
- direct any 8 bit address 00H to FFH.
- 2 byte instruction
- Can be used for any 8-bit address
- Example MOV A, 45H
- Copies the contents of RAM location 45H into the
accumulator. - Direct addresses may not start with a letter so
use a leading zero as in 0E0H instead of E0H.
10Immediate (data) addressing
- data 8-bit number 00H to FFH.
- 10010110B (a binary number)
- 76H ( a hexadecimal number)
- 118 ( a decimal number)
- Example MOV A, 76H
- Makes the contents of the accumulator become 76H
- Data may not begin with a letter. Use a leading
zero as in 0E0H instead of E0H.
11Register Addressing
- Rn any register in the selected register bank.
(n 0,1,2,3,4,5,6,7)
12Indirect Addressing
- _at_Ri register 0 or register 1 in the selected
register bank. ( i 0,1 only) - Ri contains the address of the data.
13ADD A, source-byte
- Accumulator is always the destination byte.
- If there is a carry from E7, CY goes high.
- If there is an overflow, OV goes high.
- Direct addressing as in ADD A, 7FH
- Immediate addressing as in ADD A. 7FH
14The Stack
- The Stack is a continuous group of RAM memory
locations. - By default, the stack starts at 08H in RAM (Bank
1) and may extend to RAM address 7FH. - Uses the PUSH and POP instructions.
- PUSH places data on the stack
- POP takes data from the stack
15PUSH direct
- Example PUSH 0E0H
- Execution
- First, the stack pointer is incremented (1 is
added). - Second, the contents of RAM memory location E0H
is copied to the address indicated by the stack
pointer.
16POP direct
- Example POP 0E0H
- First the contents of the memory location
indicated by the stack pointer is copied into RAM
memory location E0H. - Second, the stack pointer is decremented (1 is
subtracted).
17The programming process
18.asm files
- Called the source code.
- Written in mnemonic form
- Created with software that is essentially a
simple word processor. - Keyboard entry.
19.obj files
- Called theobject file.
- The output of the assembler.
- In a format called the machine language
20.lst file
- Lists all the opcodes, operands, and addresses.
- Lists all of the programming syntax errors.
21Library files
- Can include any boilerplate code and often used
subroutines.
22.abs files
- Called the absolute file.
- A marriage of all .obj files that have been
linked together.
23.hex file
- Machine code that appears in hexadecimal form.
- Can be loaded into a ROM burner for programming
the ROM chip.
24DB directive
- The DB directive tells the assembler that the
8-bit number that follows is constant data and
not an instruction. - Example DB 28 causes 1CH to be stored in ROM .
25ORG directive
- Indicates the beginning address at which the
program will be placed in ROM.
26EQU directive
- Assigns a literal name to to a number.
- Example THIS_YEAR EQU 2002
- Before assembly, the number 2002 will replace
every instance of THIS_YEAR in the program.
27END directive
- Indicates the last line of the source code.