Beruflich Dokumente
Kultur Dokumente
University of Belgrade
School of Electrical Engineering Department of Computer Science
Authors: Gvozden Marinkovic mgvozden@eunet.yu Nikola Milanovic nikola99@eunet.yu Goran Timotic gogi@beotel.yu Ivan Sokic sokic@eunet.yu Prof. Dr. Veljko Milutinovic vm@etf.bg.ac.yu
Introduction
2/175
Design
Specification Circuit Design Printed Circuit Board Layout Firmware Pilot Run Production
Source
AirBorn Electronics
3/175
Circuit Design
PCB Layout
Prototypes
Program Test
Pilot Run
Source
Production
4/175
AirBorn Electronics
Specification
second phase they describe the product as required: describes the product as it is required to be produced
Source
AirBorn Electronics
5/175
Describe your projects market Describe the market need your product fulfills Estimate the production volume
Source
AirBorn Electronics
6/175
Specification:Technical Ingredients
A Specification reads like a list of project features, describing the unit, and will usually include:
Inputs Controls Outputs Indicators Functions Modes of operation Power Supply Communications Protection Fail safes and replaceable parts Connector types
Source
AirBorn Electronics
7/175
Part 1
Circuit Design
Maps out the electronics and connections in the most readily readable form
The designer needs to do background work:
research specifications of components
The finished circuit diagram is the main document for the design
Source
AirBorn Electronics
8/175
Part 2
Circuit Design
Source
AirBorn Electronics
9/175
Source
AirBorn Electronics
10/175
Part 1
Conventional
Rigid PCB of thickness 1.6mm Wire-leaded components mounted on only one side of the PCB All the leads through holes, soldered and clipped. Easier to debug and repair than Surface mount
Source
AirBorn Electronics
11/175
Part 2
Source
AirBorn Electronics
12/175
Part 3
Source
AirBorn Electronics
13/175
Part 4
Source
AirBorn Electronics
14/175
Part 5
Multi-layer
PCB Laminate manufactured with more than two layers of copper tracks, by using a sandwich construction
Source
AirBorn Electronics
15/175
Part 6
Gold plated
Certain areas on a PCB may be gold plated for use as contact pads
Flexible PCB
Technique used extensively with
membrane keyboards combination connector/circuit boards circuit boards to fit in awkward shapes
Source
AirBorn Electronics
16/175
Part 7
Source
AirBorn Electronics
17/175
Part 8
Phenolic PCB
Phenolic is a cheaper PCB laminate material
Daughterboard
Circuit board mounted to another circuit board
Source
AirBorn Electronics
18/175
Part 1
Source
AirBorn Electronics
19/175
Part 2
Source
AirBorn Electronics
20/175
Part 3
Laminate etching
The laminates are coated with a UV-sensitive photo-resist The track pattern is imaged onto each side of each PCB, using the photoplots and UV light
The bare copper PCB, with tracks and pads now finished, is cleaned
Source
AirBorn Electronics
21/175
Part 4
Source
AirBorn Electronics
22/175
Part 5
Final stages
The PCB is silkscreened with component identification lettering (usually white) The silkscreen legend is dried or cured Any final drilling is done of holes that are not to be plated through, any routing is done, and the laminate is cut into individual
Source
AirBorn Electronics
23/175
PCB Assembly
Assemblies should be
maintainable repairable durable; and easy to install
Source
AirBorn Electronics
24/175
Part 1
PCB Documentation
Front Cover
Title, date, version number, customer details, project features
Bill of material
The parts list
Parts key
A glossary of the part number abbreviations, with package sizes, lead spacing, tolerance notes and preferred types
Source 25/175
AirBorn Electronics
Part 2
PCB Documentation
Drilling diagram
Showing the positioning and size of every hole on the PCB
AirBorn Electronics
26/175
Firmware
Program Test
Source
AirBorn Electronics
27/175
Program Specification
The specification for the Electronic Product being designed will usually also be the specification for the programming required
The program specification will required the writer to go into substantial detail about how the product actually operates, and how it is used A thorough program specification leads straight in to Flow charts and timing diagrams, which are components of Program Design
Source
AirBorn Electronics
28/175
Program Design
The program design stage lays out the structure and algorithms of the firmware
The structure and algorithms may be laid out as:
flowchart
timing diagram
description of a protocol memory map; or equation
Source
AirBorn Electronics
29/175
Writing Code
If the program is well specified and the algorithm design stage has been thorough, the actual code writing stage can become almost mechanical
By defining the software at the outset, before code is written, a much more defined, integrated, set of code can be produced The extra space occupied by comments costs nothing, and if the comments are well laid out there is no possibility that they can detract from understanding the code
Source
AirBorn Electronics
30/175
Program Test
Program testing requires getting diagnostic data out of the target, for analysis
By emulation tools, or through the hardware itself (for instance a serial port)
Source
AirBorn Electronics
31/175
Pilot Run
To test the product further, a Pilot run normally follows the prototyping stage
Small quantity of units are field trialed in a beta test Opportunity to assess the manufacturability of the design,
Source
AirBorn Electronics
32/175
Production
Following the pilot run there will likely be changes to the firmware, and possibly the circuit design, as the unit develops into a stable, final product
This process is controlled by ECOs and version numbers The cost, style of design of the final production, is heavily influenced by the number of units manufactured
Source
AirBorn Electronics
33/175
Components
Capacitors Resistors Transistors Diodes Oscillators and Crystals AD Converters DA Converters LCD (Liquid Crystal Display) Operational Amplifier Sensors and Transducers
34/175
Feedback Oscillators
Loop Gain How Feedback Oscillators Work?
Quartz Crystal
Crystal Parameters Equivalent Circuit Load Capacitance Series vs. Parallel Crystals Frequency Tolerance
35/175
AD Converters
Converts analog input to a digital value and outputs it as serial or parallel data
Basic attributes
number of channels for analog input approximation type resolution (number of bits) conversion speed serial or parallel output operating temperature range errors (linearity, differential linearity, total)
36/175
DA Converters
37/175
Used in low power devices (voltage 2-3V) Layer of liquid crystal (10-12m thick) is formed between two glass plates When applied, electrical field polarizes molecules of liquid crystal and the chosen segment becomes visible Beside low power devices, LCD is becoming a standard option for desktop monitors - flat panel TFT LCD (clearer picture with higher resolution) Problem: viewing angle
38/175
Operational Amplifier
Realization with differential amplifier (IC or discrete logic) Circuits with negative or positive feedback (amplifiers and oscillators) Basic parameters:
gain input and output resistance bandwidth (frequency characteristics) voltage and current drift max. output current
39/175
Classification:
physical property (piezoelectric, photovoltaic, etc.) function (measurement of length, temperature, etc)
Radiant, gravitational, mechanical, thermal, electrical, magnetic, molecular, atomic, nuclear The signal is fed into an input transducer, which changes the form of energy, usually into electrical. A modifier, usually an amplifier, and an output transducer then convert the energy into a form to be displayed or recorded.
40/175
input transducer
modifier
output transducer
modifying
41/175
Microcontrollers
Highly integrated chip includes all or most parts needed for controller A typical microcontroller has:
bit manipulation easy and direct access to I/O quick and efficient interrupt processing
42/175
Worldwide Microcontroller shipments - in millions of dollars '95 4-bit 8-bit 1826 5634 '96 1849 6553 1628 '97 1881 7529 2191 '98 1856 8423 2969 '99 1816 9219 3678 00 1757 9715 4405
16-bit 1170
Source
43/175
Worldwide Microcontroller shipments - in millions '95 4-bit 8-bit 16-bit 1100 1803 157 '96 1100 2123 227 '97 1096 2374 313 '98 1064 2556 419 '99 1025 2681 501 00 970 2700 585
Source
44/175
Applications
Flavors
signal processing,
video processing, and other tasks.
46/175
Part 1
Popular Microcontrollers
8048 (Intel)
8051 (Intel and others) 80c196 (MCS-96) 80186,80188 (Intel) 80386 EX (Intel) 65C02/W65C816S/W65C134S (Western Design Center) MC14500 (Motorola)
47/175
Part 2
Popular Microcontrollers
68HC05 (Motorola)
68HC11 (Motorola and Toshiba) 683xx (Motorola) PIC (MicroChip) COP400 Family (National Semiconductor) COP800 Family (National Semiconductor) HPC Family (National Semiconductor) Project Piranha (National Semiconductor)
48/175
Part 3
Popular Microcontrollers
Z8 (Zilog)
HD64180 (Hitachi) TMS370 (Texas Instruments) 1802 (RCA) MuP21 (Forth chip) F21 (Next generation Forth chip)
49/175
Part 1
Programming Languages
Machine/Assembly language
Interpreters Compilers Fuzzy Logic and Neural Networks
50/175
Part 1
Development Tools
Simulators
Resident Debuggers Emulators Java on Embedded Systems
51/175
Choosing microcontoller
Technical support Development tools Documentation Purchasing more devices at one manufacturer (A/D, memory, etc.)
Additional features (EEPROM, FLASH, LCD driver, etc.)
52/175
Microcontrollers
external inerrupts
interrupt control
ROM
RAM
timer 1 timer 0
counter inputs
CPU
OSC
bus control
4 I/O ports
serial port
TxD RxD P0 P2 P1 P3
address/ data
53/175
Intel 8051
RAR
128x8 RAM
4Kx8 ROM
DPH DPL
P2 LATCH PORT2
RAM BUFFER
SENSE AMPS
INTERNAL BUS
ALU ROM
IR PLA
2 or 3 16-bit timer/counters
programmable full-duplex serial port 32 I/O lines (four 8-bit ports) RAM ROM/EPROM in some models
PSW
TMP2
TMP1
CONTROL SP ALU
P0 LATCH PORT0
SCON SBUF(REC)
SBUF(XMIT)
IE IP
INTERRUPT CONTROL
P3 LATCH PORT3
SERIAL PORT
54/175
Part 1
PORT 0
XTAL2
ALE/PROG
SECONDARY FUNCTIONS
RxD TxD
PORT 3
INT0 INT1 T0 T1 WR RD
PORT 2
PORT 1
ADDRESS BUS
55/175
Part 2
P2.0-P2.7 - Port 2
Bi-directional I/O port with internal pull-ups Pins that have 1s written to them float and can be used as high-impedance inputs. Port 2 emits high-order address byte during accesses to external program and data memory
P3.0-P3.7 - Port 3
Bi-directional I/O port with internal pull-ups Pins that have 1s written to them float and can be used as high-impedance inputs.
56/175
Part 3
RST - Reset
A high on this pin for two machine cycles resets the devices
XTAL1 - Crystal 1
Input to the inverting oscillator amplifier and input to internal clock generator circuits
XTAL2 - Crystal 2
Output from the inverting oscillator amplifier
57/175
Part 1
Vcc P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.6/AD6 EA ALE PSEN P2.7/A15 P2.6/A14 P2.5/A13 P2.4/A12 P2.3/A11 P2.2/A10 P2.1/A9 P2.0/A8
Dual In-Line Package Plastic Lead Chip Carrier Plastic Quad Flat Pack
P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 RST RxD/P3.0 TxD/ P3.1 INT0/P3.2 INT1/P3.3 T0/P3.4 T1/P3.5 WR/P3.6 RD/P3.7 XTAL2 XTAL1 Vss
58/175
Part 2
44
34
39
33
PQFP
PLCC
17 18 1 NIC 2 P1.0 3 P1.1 4 P1.2 5 P1.3 6 P1.4 7 P1.5 8 P1.6 9 P1.7 10 RST 11 P3.0/RxD 12 NIC 13 P3.1/TxD 14 P3.2/INT0 15 P3.3/INT1
29 28 31 P2.7/A15 32 PSEN 33 ALE 34 NIC 35 EA 36 P0.7/AD7 37 P0.6/AD6 38 P0.5/AD5 39 P0.4/AD4 40 P0.3/AD3 41 P0.2/AD2 42 P0.1/AD1 43 P0.0/AD0 44 VCC
11
23
16 P3.4/T0 17 P3.5/T1 18 P3.6/WR 19 P3.4/RD 20 XTAL2 21 XTAL1 22 VSS 23 NIC 24 P2.0/A8 25 P2.1/A9 26 P2.2/A10 27 P2.3/A11 28 P2.4/A12 29 P2.5/A13 30 P2.6/A14
12 1 P1.5 2 P1.6 3 P1.7 4 RST 5 P3.0/RxD 6 NIC 7 P3.1/TxD 8 P3.2/INT0 9 P3.3/INT1 10 P3.4/T0 11 P3.5/T1 12 P3.6/WR 13 P3.4/RD 14 XTAL2 15 XTAL1
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
VSS NIC P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 PSEN ALE NIC EA P0.7/AD7
22 31 P0.6/AD6 32 P0.5/AD5 33 P0.4/AD4 34 P0.3/AD3 35 P0.2/AD2 36 P0.1/AD1 37 P0.0/AD0 38 VCC 39 NIC 40 P1.0 41 P1.1 42 P1.2 43 P1.3 44 P1.4
59/175
Part 1
RAR
128x8 RAM
4Kx8 ROM
DPH DPL
P2 LATCH PORT2
RAM BUFFER
SENSE AMPS
INTERNAL BUS
P0 LATCH PORT0
SCON SBUF(REC)
SBUF(XMIT)
IE IP
INTERRUPT CONTROL
P3 LATCH PORT3
SERIAL PORT
60/175
Part 2
61/175
Part 3
Instruction types:
Arithmetic Operations Logic Operations for Byte Variables Data Transfer Instructions Boolean Variable Manipulation Program Branching and Machine Control
62/175
Part 4
Most operations allow several addressing modes, bringing total number of instructions to 111, encompassing 255 of the 256 possible 8-bit instruction opcodes 8051 instruction set fares well at both real-time control and data intensive algorithms
63/175
Part 1
Architecture supports several distinct physical address spaces functionally separated at the hardware level:
On - chip program memory On - chip data memory Off - chip program memory Off - chip data memory On chip special function registers
64/175
Part 2
65/175
Part 3
External RAM
External RAM is any random access memory which is found off-chip External RAM is slower
To increment an Internal RAM location by 1 requires only 1 instruction and 1 instruction cycle To increment a 1-byte value stored in External RAM requires 4 instructions and 7 instruction cycles
While Internal RAM is limited to 128 bytes (256 bytes with an 8052), the 8051 supports External RAM up to 64K
66/175
Part 4
On-chip memory
Two types:
Internal RAM; and Special Function Register (SFR) memory
Internal RAM is on-chip so it is the fastest RAM available Internal RAM is volatile, when the 8051 is reset this memory is cleared Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor
67/175
Part 1
PORT 2 : High byte of address held for the duration of read or write cycle PORT 0 : time multiplexed low byte of address with data byte Signal ALE: used to capture the address byte into an external latch
EA
PORT2
A8-A15
A8-A15
A8-A15
PORT0
AD0-AD7 LATCH
A0-A7
A0-A7
A0-A7
Static RAM
"0"
ALE 8051
LE
CS RD WR
"0"
CS OE
D0-D7
PSEN RD WR
68/175
ROM
Part 2
ALE
ALE
RD
P0
A0-A7
A0-A7
INS. IN P0
A0-A7
FLOAT
data in
FLOAT
P2
A8-A15
A8-A15
P2
A8-A15
A8-A15
69/175
Part 1
Up to 64K of Program Memory PSEN: read strobe for all external program fetches PSEN: not activated for internal program fetches Depending on EA pin lowest bytes can be either in the on-chip ROM or in an external ROM
0xFFFF
EA = 0 0x0000
EXTERNAL
EA = 1
PSEN
70/175
Part 2
Boot address - 0x0000 Each interrupt is assigned a fixed location in Program Memory If interrupt is not going to used, its service location is available as general purpose Program Memory
INTERRPUT LOCATIONS
71/175
Part 3
Port 0 and Port 2 are dedicated to bus functions during external Program Memory fetches
PORT0 EA
AD0-AD7 A0-A7
INSTR
LATCH
ALE PORT2
LE
A8-A15
ADDR
PSEN 8051
OE EROM
72/175
Part 1
Up to 64K Data Memory Access to Data memory use RD or WR to strobe the memory
0xFFFF
INTERNAL 0xFF
0x00
0x0000
RD WR
73/175
EXTERNAL
Part 2
Internal Memory Addresses are one byte wide 128 bytes address space (256 - Intel 8052) Direct addressing higher then 0x7F access one memory space, indirect addressing higher then 0x7F access a different memory space Upper 128 and SFR space occupying same block of addresses, although they are physically separate entities
INTERNAL 0xFF
UPPER 128
0x7F SPECIAL FUNCTION REGISTERS PORTS STATUS BITS CONTOL BITS TIMER REGISTERS STACK POINTER ACCUMULATOR (ETC.)
LOWER 128
0x00
74/175
Part 3
The lowest 32 bytes are grouped into 4 banks of 8 registers Program instructions call out these registers R0 through R7 Two bits in the PSW selects register bank
Register instructions are shorter
0x2F
11
0x18 0x17
10
0x10 0x0F
01
0x08 0x07
00
0x00
75/175
Part 1
76/175
Part 2
Part 3
Accumulator (A)
Accumulator register
B Register (B)
Used during multiply and divide operations
The Stack Pointer is initialized on 0x07 after a reset, and this causes stack to begin at location 0x08
Data Pointer(DPTR)
Consist high byte (DPH) and low byte (DPL) It may be manipulated as a 16-bit register or as two independent 8-bit registers
PSW
Contains program status information
78/175
Part 4
Control Registers
IP: Interrupt priority IE: Interrupt enable TMOD Timer/Counter mode TCON Timer/Counter control PCON Power control
79/175
6
AC
5
F0
4
RS1
3
RS0
2
OV
1
-
0
P
Auxiliary Carry flag is used for BCD operations Flag 0 is available to user for general purposes The contest of (RS1, RS2) enable working register banks as follows: 00 - Bank 0 [0x00-0x07], 01 - Bank 1 [0x08-0x0f], 10 - Bank 2 [ 0x10-0x17], 11 - Bank 3 [0x18-0x1F]
80/175
S6
P1 P2
S1
P1 P2
S2
P1 P2
S3
P1 P2
S4
P1 P2
S5
P1 P2
S6
P1 P2
S1
P1 P2
S2
P1 P2
S3
P1 P2
S4
P1 P2
S5
P1 P2
ALE
The internal clock generator defines the sequence of states that make up a machine cycle A machine cycle consists of 6 states, numbered S1 through S6 Each state time lasts for two oscillator periods Each state is then divided into a Phase 1 and Phase 2 half
81/175
Part 1
+5V +5V
Q2
The address latch bit is updated by direct addressing instructions The value read is OR-tied function of Q1 and the external device To use a pin for input latch must be set
SET
R1
R2
Q
Q1
I/O PIN
Q CLR
BUS CYCLE TIMING INPUT BUFFER
ENB
READ
82/175
The output buffers of Ports 0, 1, 2 and 3 can each drive 4 LS TTL inputs Can be driven by open-collector and open-drain outputs
0-to-1 transitions will not be fast since there is little current pulling the pin up
Port 0 output buffers can each drive 8 LS TTL inputs (external bus mode) As port pins PORT 0 requires external pull-ups to be able to drive any inputs bit
83/175
There are few special needs common among control-oriented computer systems:
keeping tracks of elapsed time maintaining a count of signal transitions measuring the precise width of input pulses communicating with other systems
84/175
Part 1
Two 16-bit Timer/Counter registers Timer: Register is incremented every machine cycle (1 machine cycle = 12 oscillator periods) Counter: Register is incremented in response to 1-to-0 transition at its corresponding external input pin (T0, T1)
External input is sampled at S5P2 of every machine cycle When the samples show high in one cycle and low in the next, the count is incremented The new count value is appears in S3P1 of the following detection cycle Max count rate is 1/24 of oscillator frequency
Part 2
GATE: Gating control when set C/T: Counter or Timer Selector M1 M0:
00: 8-bit Timer/Counter with 5-bit prescaler 01: 16-bit Timer/Counter 10: 8-bit auto reload Timer/Counter 11: (Timer0) TL0 is 8-bit Timer/Counter controlled by Timer0 control bits TH0 is 8-bit timer only controlled by Timer1 control bits 11: (Timer1) Timer/Counter is stopped
TIMER0 TIMER1
GATE C/T M1 M0
86/175
Part 3
Part 4
TF1
INTERRUPT
TR1 GATE
MODE 0
INT1 PIN
88/175
Part 5
TR1 GATE
MODE 1
INT1 PIN
89/175
Part 6
TF1
INTERRUPT
MODE 2
INT1 PIN
90/175
Part 7
TR0 GATE
MODE 3
1/12 fosc TH0 (8 bits) TF1 INTERRUPT
INT0 PIN
TR1
91/175
Part 1
Full-duplex Serial port receive and transmit registers are both accessed at Special Function Register SBUF
Writing to SBUF loads the transmit register Reading from SBUF accesses a physically separated receive register
92/175
Part 2
SM0 SM1:
00: Mode 0, Shift register, fosc//12 01: Mode 1, 8-bit UART, variable 10: Mode 2, 9-bit UART, fosc//32 or fosc//64 11: Mode 3, 9-bit UART, variable
Part 3
TB8: 9th data bit that will be transmitted in Mode2 and Mode3
Set/Clear by software
RB8: 9th data bit that was received in Mode2 and Mode3 In Mode 1, if SM2=0, is the stop bit that was received TI: Transmit interrupt flag
Set by hardware. Must be cleared by software
94/175
Part 4
MODE 0:
Serial data enters and exits through RXD TXD outputs shift clock 8 bits are transmitted/received: 8 data bits (LSB first) The baud rate is fixed at 1/12 oscillator frequency
MODE 1:
Serial data enters through RXD, exits through TXD 10 bits are transmitted/received: start bit(0), 8 data bits (LSB first), stop bit(1) On receive the stop bit goes into RB8 in SCON register The baud rate is variable
95/175
Part 5
MODE 2:
Serial data enters through RXD, exits through TXD 11 bits are transmitted/received: start bit(0), 8 data bits (LSB first), a programmable 9th bit, stop bit(1) On transmit, the 9th bit is TB8 in SCON register On receive, the 9th bit goes into RB8 in SCON register The baud rate is programmable to either 1/32 or 1/64 the oscillator frequency
MODE 3:
Same as MODE 2 in all respects except baud rate The baud rate is variable
96/175
Part 6
Mode 0 Baud Rate = Oscillator frequency/12 Mode 2 Baud Rate =[(2SMOD)/64]*Oscillator frequency
SMOD is bit in Special Function Register PCON
Mode 1 and Mode3 baud rate is determined by Timer 1 overflow rate Mode 1,3 Baud Rate =[(2SMOD)/32]* Timer 1 Overflow Rate
Timer mode, auto-reload : Timer Overflow Rate=Oscillator frequency/[12*(256-TH1)]
97/175
Part 7
Part 1
ES: Serial Port interrupt enable bit ET: Timer interrupt enabled bit EX: External interrupt enable bit
99/175
Part 2
2 external
(INT0, INT1) 2 timers (TF0, TF1)
INT0 IT0=1
IE0
TF0
TF1
RI TI
100/175
Part 3
External interrupts
INT0
IT0=0 IE0
Level-activated or transition-activated IT0=1 depending on bits IT0, IT1 in register TCON The flags that generate these interrupts are IE0, IE1 in TCON Cleared by hardware if the interrupt was transition-activated if the interrupt was level-activated, external source controls request bits If external interrupt is level-activated, the external source has to hold request active, until the requested interrupt is actually generated. External source has to deactivate the request before interrupt service is completed, or else another interrupt will be generated
101/175
Part 4
Timer interrupts
Interrupts are generated by TF0 and TF1 in register TCON When a timer interrupt is generated, the flag that generated it is cleared by hardware when the service routine is vectored to
TI RI
102/175
Part 5
Priority bit=1: High Priority; Priority bit=0: Low Priority PS: Serial Port priority bit PT: Timer priority bit PX: External priority bit
103/175
Part 6
A low-priority interrupt can be interrupted by a higher priority interrupt, but not by another low-priority interrupt A high priority interrupt cannot be interrupted by any other interrupt source If two requests are received simultaneously, the request of higher priority level is serviced If requests of the same priority level are received simultaneously, an internal polling sequence determines which request is serviced
``priority within level'' structure is only used to resolve simultaneous requests of the same priority level.
104/175
Part 7
105/175
Part 8
The INT0 and INT1 levels are inverted and latched into the Interrupt Flags IE0 and IE1 at S5P2 of every machine cycle Serial Port flags RI and TI are set at S5P2 The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow If a request is active and conditions are right, a hardware subroutine call to the requested service routine will be the next instruction to be executed In a single-interrupt system, the response time is always more than 3 cycles and less than 9 cycles
106/175
Part 1
The reset input is the RST pin, which has a Schmitt Trigger input Accomplished by holding the RST pin high for at least two machine cycles (24 oscillator periods) while the oscillator is running The RST pin is sampled during S5P2 of every machine cycle While the RST pin is high, the port pins, ALE and PSEN are weakly pulled high Driving the ALE and PSEN pins to 0 while reset is active could cause the device to go into an indeterminate state
107/175
Part 2
ALE
PSEN P0
IN S. IN IN S. IN IN S. IN IN S. IN IN S. IN IN S. IN
A0-A7
A0-A7
A0-A7
A0-A7
A0-A7
11 OSC. PERIODS
19 OSC. PERIODS
108/175
RST pin must be held high long enough to allow the oscillator to start up plus two machine cycles The oscillator start-up time depend on the oscillator frequency Port pins will be in a random state until the oscillator has started and the internal reset algorithm has written 1s to them Powering up the device without a valid reset could cause the CPU to start executing instructions from an indeterminate location
109/175
110/175
One Time Programmable It is standard EPROM without erasing window It is used for limited production
111/175
Supports in-system and in-board code changes Electrically erasable Reduces code inventory and scrap Simplifies the task of upgrading code and reduces upgrade cycle time Provides just-in-time system software downloads Truly non-volatile
112/175
Intel 8051 microcontrollers have an on-chip oscillator resonators are connected between XTAL1 and XTAL2 pins external oscillators (HMOS or CMOS)
8051 XTAL2
C1
C2
XTAL1 VSS
113/175
114/175
CHMOS versions provides power reduced modes of operations There are two power reducing modes Idle and Power Down In the Idle mode oscillator continues to ran Interrupt, Timer and Serial Port blocks continue to be clocked clock signal is gated off to the CPU In the Power Down mode the oscillator is frozen
115/175
Part 1
116/175
Part 2
A A A A A A A
Part 3
118/175
Part 4
119/175
Part 5
120/175
Part 6
Part 7
122/175
Part 8
C, bit
Operations on PSW
X
123/175
Immediate Addressing
Direct Addressing Indirect Addressing
refers to Internal RAM, never to an SFR
MOV A,#20h
MOV A,30h MOV A,@R0
External Direct
only two commands that use External Direct DPTR holds the correct external memory address
MOVX A,@DPTR
MOVX @DPTR,A
External Indirect
Code Indirect
124/175
Part 1
125/175
Part 2
Program Memory
code specifier refers to to the 64Kbyte code memory Accessed by opcode MOVC @A+DPTR
Program Memory is read only; it cannot be written to It can reside within 8051 CPU, it may be external, or both Program code, including all functions and library routines are stored in program memory
126/175
Part 3
Data Memory
Up to 256 bytes of internal data memory are available depending upon the 8051 derivate data refers to the first 128 bytes of internal memory
idata refers to all 256 bytes of internal data memory generated by indirect addressing
bdata refers to 16 bytes of bit-addressable memory in the internal data memory (20h to 2Fh)
127/175
Part 4
pdata specifier refers to only 1 page of 256 bytes of external data memory
128/175
Part 5
sfr16 access 2 SFRs as 16-bit SFR (8051 derivatives) sbit allows to access individual bits within an SFR
129/175
Part 6
static bit done_flag=0; sbit EA= oxAF; /*defines EA to be the SFR bit at 0xAF*/
sbit
sfr P0 = 0x80; /* Port-0, address 80h*/ sfr P2 = 0xA0; /* Port-2, address 0A0h */
sfr16
130/175
Part 7
Memory Models
SmallModel all variables, by default, reside in the internal data memory All objects, as well as stack must fit into internal RAM Compact Model all variables, by default, reside in one page of external data memory Can accommodate a maximum of 256 variables Slower then small model Large Model all variables, by default, reside in external data memory The Data Pointer (DPTR) is used for addressing Memory access is inefficient Generates more code then small and compact model
131/175
Part 8
Memory-specific Pointers
Include a memory type specification in the pointer declaration May be used to access variables in the declared memory area only
132/175
Part 9
133/175
Part 10
134/175
Part 11
Argument Number 1 2 3
135/175
Part 12
Description
MSB in R6, LSB in R7 MSB in R4, LSB in R7 32-bit IEEE format Memory type in R3, MSB R2, LSB R1
136/175
Part 13
#pragma small /*default small model */ extern int calc (char i, int b) large reentrant; extern int func (char i, float f) large; extern void *tcp (char xdata *xp, int ndx) small; int mtest (int i, int y){ /*small model*/ return (i*y + y*i + func(-1, 4.75);} int large_func (int i, int k) large { /*large model*/ return (mtest(i,k) * 2)}
137/175
Part 14
138/175
Part 15
Register Bank Access The REGISTERBANK control directive allows you to specify which default register bank to use Upon reset, 8051 loads the PSW with 00h, which selects register bank 0. To change this, you sholud:
Modify the startup code to select a different bank Specify the REGISTERBANK control directive along with the new register bank number
By default, C51 generates code that accesses the registers R0-R7 using absolute addresses To make a function insensitive to the current bank, it must be compiled using the NOAREGS control directive
139/175
Part 16
Interrupt Functions
Part 17
Reentrant Function can be shared by several processes at the same time. When a reentrant function is executing, another process can interrupt it and then begin to execute that same function. The reentrant functions may be called recursively: int calc (char i, int b) reentrant { int x; x=table[i]; return (x*b); } Reentrant functions can be called simultaneously by two or more processes. Reentrant functions are often required in real-time applications or when interrupt and non-interrupt code must share a function.
141/175
Part 18
Functions may be selectively defined as reentrant, using the reentrant attribute. For each reentrant function, a reentrant stack area is simulated in internal or external memory. The following rules apply to reentrant functions:
bit type arguments or local variables may not be used must not be called from alien functions or using alien attribute may have other attributes like using or interrupt return addresses are stored in the 8051 hardware stack functions using different memory models may be intermixed each of three reentrant models (small, compact and large) contains its own reentrant stack and SP
142/175
Part 19
Control directives are used to control the operation of the compiler and can be specified after the filename on the command line or within a source file using the #pragma directive: C51 testfile.c SYMBOLS CODE DEBUG or #pragma SYMBOLS CODE DEBUG
Directive categories:
source controls define macros on the command line and determine the name of the file to be compiled) object controls affect the form and content of the generated object module; allow you to specify the optimizing level or include debugging information in the object file listing controls govern various aspects of the listing file (format and specific content)
143/175
Part 20
The C51 is an optimizing compiler. The C51 provides six different levels of optimizing:
constant folding, simple access optimizing, jump optimizing dead code elimination, jump negation data overlaying peephole optimizing register variables, extended access optimizing, local common subexpression elimination, case/switch optimizing global common subexpression elimination, simple loop optimizing loop rotation
144/175
Part 21
General optimizations:
constant folding: several constant values occurring in an expression or address calculation are combined as a constant jump optimizing: jumps are inverted or extended to the final target addresses when the program efficiency is thereby increased dead code elimination: code which cannot be reached is removed register variables: automatic variables and function arguments are located in registers when possible parameter passing via registers: a maximum of three function arguments can be passed in registers global common subexpression elimination: identical subexpressions or address calculations that occur multiple times in a function are calculated only once
145/175
Part 22
146/175
Part 23
147/175
Part 24
You can easily interface C51 to routines written in 8051 assembler For an assembly routine to be called form C, it must be aware of the parameter passing and return value conventions used in C
Function parameters By default C functions pass up to three parameters in registers. The remaining parameters are passed in fixed memory locations. Functions that pass parameters in registers are prefixed with the underscore character (_functionName)
148/175
Part 25
func1 (int a) - a is passed in R6 and R7 func2 (int b, int c, int *d) - b is passed in R6&R7, c in R4 & R3, d in R1, R2 & R3 func3 (long e, long f) - e is passed in R4, R5, R6 & R7, f cannot be located in registers func4(float g, char h) - g is passed in R4, R5, R6 & R7, h cannot be passed in registers
149/175
Part 26
Parameter passing in fixed memory locations Parameters passed to assembly routines in fixed memory locations use segments named ?function_name?BYTE and ?function_name?BIT to hold the parameter values passed to the function function_name.
Function return values Function return values are always passed using CPU registers: return type register
bit char/unsigned char/1-byte pointer int/unsigned int/2-byte pointer long/unsigned long/float generic pointer carry flag R7 R6 & R7 R4 - R7 R1-R3
150/175
Part 27
151/175
AMD
OKI Philips
Siemens SMC
SSI
Matra
Microchip
152/175
Watch Dog Timers Clock Monitor Resident Program Loader Software protection P Supervisory Circuit
153/175
Provides a means of graceful recovery from a system problem If the program fails to reset the watchdog at some predetermined interval, a hardware reset will be initiated Especially useful for unattended systems
154/175
Clock Monitor
If the input clock is too slow, a clock monitor can shut the microcontroller down Usually software controlled status (on/off)
155/175
Loads a program by initializing program/data memory from either a serial or parallel port Eliminates the erase/burn/program cycle (typical with EPROMs) Allows system updating from an offsite location
156/175
Software protection
Protect unauthorized snooping (reverse engineering, modifications, piracy, etc. Only OTPs and Windowed devices option
157/175
Part 1
P Supervisory Circuit
Functions:
P reset (active low or high) Manual reset input Two stage power fall warning Backup-battery switchover Write protection of RAM 2.275 threshold detector Battery OK flag indicator Watch Dog timer
PF1 PF0 Vcc WDI GND MR LOW LINE RESET
1 2 3 4 5 6 7 8 16 15 14
MAXIM MAX807
13 12 11 10 9
158/175
Part 2
P Supervisory Circuit
PIN 1 2 3 4 5 6 7 8 NAME PFI PFO VCC WDI GND MR LOW LINE RESET (H) FUNCTION Power-Fall Input Power-Fall Output Input Supply Voltage Watchdog Input Ground Manual-Reset Input Low-Line Comparator Input Active-High Reset Output
159/175
Part 3
P Supervisory Circuit
PIN 9 10 11 12 13 14 15 16 NAME RESET (L) WDO CE OUT CE IN BATT ON BATT BATT OK OUT FUNCTION Active-Low Reset Output Watchdog Output Chip-Enable Output Chip-Enable Input Battery On Output Backup-Battery Input Battery OK Signal Output (Vbatt>2.265) Output Supply Voltage to CMOS RAM
160/175
Part 4
P Supervisory Circuit
+5V
0.1uF 0.1uF
Vcc BATT OUT ON BATT CMOS RAM CE OUT OTHER SYSTEM RESET SOURCES PUSH BUTTON SWITCH MR ADDRESS DECODE ADDRESS I/O NMI(INT) RESET INT REAL TIME CLOCK
CE IN MAXIM MAX807 WDI LOW LINE RESET +12V RESET BATT OK PFI PFO WDO GND
uP
+12V FAILURE WATCHDOG FAILURE
161/175
Comparative Characteristics
Manufacturer Atmel Dallas Clock [MHz]
24
V [V]
2.7 to 6
ROM [KB]
2 to 8
RAM [bytes]
128 to 256 256-byte to 1.2 kbyte 128 to 256
I/O
32
Timers/ Counters
Up to 3
communication
full duplex serial port two serial USARTs
Additional Features
25 to 33
0 to 16
Intel
0.5 to 24
2.7 to 6
0 to 32
24 to 56
2 to 3
serial port
42
4 to 32
32
2 to 3
watchdog, power monitor, address and data encryption 4 to 8 channel 8bit ADC, watchdog, PWM ROM protection and secret tag, watchdog
24 18 to 40
0 to 16 8 to 32
32 56
2 to 3 3 to 4
162/175
circuit diagram
pcb layout
163/175
Specification
The idea is to design a small, simple PCB for test purposes. The device will have: 8 driver outputs (ie. LEDs, relays)
a speaker output
a light sensor input 3 extra inputs optional serial port The device will be based on Atmel AT89C2051microprocessor, a 20 pin 8051 variant with FLASH program memory.
164/175
Circuit Diagram
165/175
Circuit Description
The battery power supply is connected on terminals T1 &T2. While the circuit diagram specifies
3v/4.5v battery, the part ULN2803 needs 4.5v-5v battery to get proper operation.
Capacitor C1 provides a reset signal to the microprocessor. XTAL1 provides the oscillator timing component for the microprocessor. It is important to use a crystal for XTAL1, not a ceramic resonator - prototype testing shows that a ceramic resonator gives problems unless capacitors to ground are placed on X1 & X2.
Diode D1 provides some protection for the microprocessor in case of transients or misconnection of the battery
166/175
Circuit Description
SW1 is in parallel with the LiteOn input - pushing SW1 is like illuminating TR1
Resistors R12 & R13 pull up the open collector outputs P1.0 and P1.1 of IC1
IC2 is the driver IC, with several hundred milliamps drive capability on each output R1-R8 limit the current that can be taken from each output of IC2, and are most useful when LEDs are connected directly to pins L1-L8. If other devices are used, such as relays, the values may of R1-R8 may have to be changed, or replaced with links. 167/175
R10 limits the current from IC1 into the base of TR3
PCB Diagram
Central to the board are the two IC's: The AT89C2051 (in an IC socket) and ULN2803 driver. The bank of resistors to the right of the ULN2803 are primarily for limiting the current through LEDs, when they are being driven direct from the outputs. You may wish to use another value instead of the 27 ohm shown on the circuit. The circuitry to the left of the CPU is primarily for the light sensor - this is just a simple darlington phototransistor, sensitivity pot and switch transistor. 168/175
169/175
170/175
171/175
172/175
Parts description
RB.06/.15 - Radial polarised capacitor, 0.060 inch pitch lead space, 0.15 inch diameter RB.1/.2 - Radial polarised capacitor, 0.1 inch (2.5mm) pitch lead spacing, 0.2 inch (5mm) diameter DIODE0.3 - Axial diode, 0.3 inch (7.5mm) pitch lead spacing DIP20 - IC, standard 0.3 inch pitch 20 pin DIP package DIP18 - IC, standard 0.3 inch pitch 18 pin DIP package TP - Test point or terminal PCLAMINATE - The part being specified here is the etched PCB laminate
173/175
Parts notes
2.2UF50VMM - Radial polarised capacitor, Microminiature style, eg Rubycon, elna AT89C2051 - Atmel microprocessor, see Atmel site for data and a programmer ULN2803A - Manufacturer: Allegro (formerly known as Sprague) 27E - Resistor, value 27 ohm - substitute if required for different outputs MEL12 - Phototransistor - many substitutes will work, but darlington types offer the best sensitivity. We have used BP103B (Farnell 212-763 in Australia). Flat goes toward TR2 for two leaded devices.
3.57945Mhz - Frequency depends on application program. Use a crystal, rather than a ceramic resonator (otherwise fit extra capacitors to gnd on X1 and X2). 174/175
175/175