AJMP LOOP

advertisement
Microprocessors
Typical microprocessor controlled devices:
Camera, mobile phone, stereo, mp3 player, electronic toys…
High-level microprocessor controlled automation:
DHL and FedEx, Park and Shop, …
What are the similarities ?
Both types use computer control
What is the difference?
Real-time programmable
Basic Architecture of a microprocessor
A simplified computer
Address Bus (16 lines for 8-bit CPU)
Control Bus
Input/Output
(10 lines)
CPU
Data bus (8 lines for 8-bit CPU)
Memory
CPU: Central Processing Unit
(i) Break [complex] task  sequence of [very simple] sub-tasks
each sub-task: dedicated circuit inside the CPU
(ii) Perform each sub-task sequentially, in T units of time (or less)
until all sub-tasks have been done
Clock
Instruction
Register
Work registers
(including Accumulator)
Control Unit
ALU
Status Register
Control Bus
Program
Counter
D7 - D0
A15 - A0
Data Bus
Address Bus
CPU structure
The Accumulator: main register of the ALU
Each ALU operation:
operand (data value)  accumulator
operand  memory
output  accumulator.
The instruction register holds the binary code of the instruction that is
being executed.
The program counter contains the address of the memory location from
which the next instruction code will be taken.
Microprocessors: Control unit
The control unit
controller-sequencer
and
instruction decoder
Clock
Instruction
Register
Work registers
(including Accumulator)
Control Unit
ALU
Status Register
Control Bus
Program
Counter
D7 - D0
A15 - A0
Data Bus
Address Bus
Microprocessor memory
Memory:
Microprocessor memory: on chip [WHY?]
Other memory terms:
- ROM
- PROM (programmable ROM):
- EPROM (erasable PROM: erased/reprogrammed by UV-light)
- RAM
Address bus
A15 - A0
A11
A12
A15
CPU
CS1
CS2
2-4
decoder CS3 CS
CS
A10-A0
A10-A0
CS4
G
RAM
ROM
2048 x 8
2048 x 8
R/W
R/W
D7-D0
D7 - D0
Data bus
D7-D0
Microprocessor: Input and Output
I/O chips are connect the microprocessor to a variety of devices.
EXAMPLES:
memory disks, printers, data-links to other computers,
instrumentation controlling equipment, etc.
Common of I/O chips:
Parallel Input/Output (PIO)
Serial I/O (UART, Universal Asynchronous Receiver/Transmitter)
To CPU
To External Devices
To CPU
To External Devices
RS 232 - C pin no.
Chip select
Read/Write
Address Lines A0
A1
D0
D1
D2
Data Lines D3
D4
D5
D6
D7
CS
R/W
Port A
Port B
PIO
Port C
Chip select
Read/Write
Clock
Address
A0
Lines
A1
D0
D1
D2
Data Lines D3
D4
D5
D6
D7
CS
R/W

Transmit
Receive
2
3
RTS (Request to Send)
4
CTS (Clear to Send)
5
UART
DTR (Data Terminal Ready)
DSR (Data Set Ready)
Ground
20
6
7
Microprocessor: Machine language
OPCODE
OPERANDS
100011 00011 01000 0000000001000100
000000 00001 01000 00110
[in decimal: 35 3
[in decimal: 0 1 8 6]
Line 1.
Operation-code 35 (load some data into a register):
Look at the number stored in register 3
Go to the memory location = [value of register 3] + 68
Get the data from that cell
Store it into register 8.
Line 2.
Operation code 0 (add two numbers).
Add the contents of register 1 and register 8
store answer into register 6.
8
68]
Microprocessor: Assembly language
Machine language:
Difficult to write programs!
Assembly language:
English codes for each opcode and operand
 Easier to program
 Need a way to convert Assembly language  machine language
Microprocessor: Assembly language
[label]
LOOP:
LOOP1:
LIGHT:
opcode [operands]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
[comment]
; turn off the LED
; turn on the LED
Microprocessor: Assembly language
Run the program from memory location (Hexadecimal) 0000)
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assembly language
token (marks the line with a name)
set bit: set the value of a bit = 1
which bit: port 2.7 (pin #7 of outputs)
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assembly language
token (marks the line with a name)
JUMP if NOT: if the bit is not set, i.e. = 0.
which bit: port 0.7 (pin #7 of inputs)
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7, LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assembly language
automatic jump (unconditional jump)
where? to program counter located by LOOP
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assembly language
token (marks the line with a name)
CLEAR: set bit = 0.
which bit: port 2.7 (pin #7 of outputs)
LOOP:
LOOP1:
LIGHT:CLR
[label]
CSEG
SETB
JNB
AJMP
P2.7
AJMP
END
AT 0000H
P2.7
P0.7, LIGHT
LOOP
; turn off the LED
; turn on the LED
LOOP1
opcode [operands]
[comment]
Microprocessor: Assembly language
automatic jump (unconditional jump)
where? to program counter located by LOOP1
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assembly language
terminate program (erase it from RAM)
LOOP:
LOOP1:
LIGHT:
[label]
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7, LIGHT
LOOP
P2.7
LOOP1
opcode [operands]
Question: When will it END ?
; turn off the LED
; turn on the LED
[comment]
Microprocessor: Assemblers
Assembly
programming
software
What’s
happening
here ?
Burning a PROM
Hardwired Microprocessor control
LOOP:
LOOP1:
LIGHT:
CSEG
SETB
JNB
AJMP
CLR
AJMP
END
AT 0000H
P2.7
P0.7,LIGHT
LOOP
P2.7
LOOP1
; turn off the LED
; turn on the LED
power supply
output port, P2.7
input port, P0.7
Processor with program in PROM
How about Computer control ?
Need a special board that can communicate with processor
plug it here
Need a program that can communicate with the board: (device driver)
Connect output sockets on this board to outside actuators/sensors
How about Computer control ??
Need a program that can communicate with the board: (device driver)
How to use the device driver ?
If device driver is written in C++:
Write your program in C++
Link your program to device driver (library)
Your program  device driver
Computer basics
Operating System
Examples:
What does it do ?
Compiler(s)
Examples:
What do they do ?
Application programs
Examples:
What do they do?
Download