presentation on: "micro-controller 8051 & embedded system"
TRANSCRIPT
DR. C. V. RAMAN UNIVERSITY
KARGI ROAD KOTA BILASPUR (C.G.)
2012-13
Microcontroller 8051&
Embedded System
Presentation On:
IntroductionEmbedded System(8051 Application)
Embedded System (8051 Application)
What is Embedded System?◦ An embedded system is closely
integrated with the main system◦ It may not interact directly with
the environment◦ For example – A microcomputer
in a car ignition control
An embedded product uses a microprocessor or microcontroller to do one task only
There is only one application software that is typically burned into ROM
Examples of Embedded Systems Keyboard Printer video game player MP3 music players Embedded memories to keep configuration
information Mobile phone units Domestic (home) appliances Data switches Automotive controls
MicrocontrollerA microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals.
Microprocessor CPU is stand-alone, RAM,
ROM, I/O, timer are separate designer can decide on the
amount of ROM, RAM and I/O ports.
expansive versatility general-purpose
Microcontroller• CPU, RAM, ROM, I/O and
timer are all on a single chip• fix amount of on-chip ROM,
RAM, I/O ports• Highly bit addressable• for applications in which cost,
power and space are critical• single-purpose
Microprocessor vs. Microcontroller
8051 8052 `8031
RAM (bytes) 128 256128
ROM (kB) 4 4 0 I/O Ports 4 4 4 Timer 2 3 2 Interrupt Source 6 8 6 I/O Pins 32 32
32 Serial Port 1 1 1
* Also we have 8751 mcs in the series which is the UV-EPROM version of 8051 & AT89C51 is the one Atmel Fabrication Flash ROM version of 8051.
Comparison Between Microcontrollers Family:
Types of Microcontrollers
8051 Basic Component 4K bytes internal ROM 128 bytes internal RAM Four 8-bit I/O ports (P0 - P3). Two 16-bit timers/counters One serial interface
RAM
I/O Port Time
r
Serial COM Port
Microcontroller
CPU A single chip
ROM
Three formats are present in market1. DIP – Duel inline package
2. QFP –Quad flat package3. FBGA – Fine ball grid package
FBGA
QFP
DIP
Three criteria in Choosing a Microcontroller Meeting the computing needs of the task
efficiently and cost effectively◦ speed, the amount of ROM and RAM, the number of
I/O ports and timers, size, packaging, power consumption
◦ easy to upgrade◦ cost per unit
Availability of software development tools◦ assemblers, debuggers, C compilers, emulator,
simulator, technical support Wide availability and reliable sources of the
microcontrollers
Employs CISC, Harvard architecture An 8 - bit CPU 40 pin DIP package (40 - physical, 64 - logical) 4K On Chip ROM 128 bytes of On Chip user RAM 32 discrete I/O pins (4 groups of 8; individually accessed) Two 16 bit timers/counters Full duplex UART 6-Interrupts (5 vectored with 2 priority levels) Expandable up to max 64K of ROM Can support up to max 64K of EX-RAM Operating frequency is 24MHz-33MHz. +5V Regulated DC power supply is required to operate. RAM, ROM, I/O ports, one serial port and timers are all On-chip. Low-power Idle and Power-down Modes. 21 special function registers (SFRs). Crystal frequency of 11.0592MHz.
8051 Features
64K external code (program) memory (only read) PSEN
64K external data memory (can be read and write) by RD,WR
Code memory is selectable by EA (internal or external)
External Data & Code Memory
External code memory
ROM
D
74LS373
ALE
P0.0 P0.7
PSEN
A0 A7
D0 D7
P2.0 P2.7
A8 A15
OECS
EA
G
8051
RDWR
External data memory
8051 RAM
D
74LS373
ALE
P0.0 P0.7
PSEN
A0 A7
D0 D7
P2.0 P2.7
A8 A15
RDCS
EA
G
RDWR WR
8051 Foot Print
1234567891011121314151617181920
4039383736353433323130292827262524232221
P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7RST
(RXD)P3.0(TXD)P3.1
(T0)P3.4(T1)P3.5
XTAL2XTAL1
GND
(INT0)P3.2(INT1)P3.3
(RD)P3.7(WR)P3.6
VccP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)P0.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)P2.1(A9)P2.0(A8)
8051(8031)(8751)(8951)
Pin Description of the 8051 The 8051 is a 40
pin device, but out of these 40 pins, 32 are used for I/O.
24 of these are dual purpose, i.e. they can operate as I/O or a control line or as part of address or date bus.
IMPORTANT PINS (I/O Ports) One of the most useful features of the 8051 is that it contains
four I/O ports (P0 - P3)
Port 0 ( pins 32-39 ): P0 ( P0.0 ~ P0.7 )◦ 8-bit R/W - General Purpose I/O◦ Or acts as a multiplexed low byte address and data bus for external
memory design
Port 1 ( pins 1-8 ) : P1 ( P1.0 ~ P1.7 )◦ Only 8-bit R/W - General Purpose I/O
Port 2 ( pins 21-28 ): P2 ( P2.0 ~ P2.7 )◦ 8-bit R/W - General Purpose I/O◦ Or high byte of the address bus for external memory design
Port 3 ( pins 10-17 ): P3 ( P3.0 ~ P3.7 )◦ General Purpose I/O◦ if not using any of the internal peripherals (timers) or external
interrupts.
Each port can be used as input or output (bi-direction)
IMPORTANT PINS PSEN (out): Program Store Enable, the read
signal for external program memory (active low). ALE (out): Address Latch Enable, to latch
address outputs at Port0 and Port2 EA (in): External Access Enable, active low to
access external program memory locations 0 to 4K
RXD,TXD: UART pins for serial I/O on Port 3◦ XTAL1 & XTAL2: Crystal inputs for internal
oscillator. These 2 pins provide external clock.
◦Way 1 : using a quartz crystal oscillator ◦Way 2 : using a TTL oscillator
Pins of 8051 Vcc ( pin 40 ):
◦Vcc provides supply voltage to the chip. ◦The voltage source is +5V.
GND ( pin 20 ): ground RST ( pin 9 ): reset
◦ input pin and active high ( normally low ) . The high pulse must be high at least 2
machine cycles.◦ power-on reset. Upon applying a high pulse to RST, the
microcontroller will reset and all values in registers will be lost.
Pins of 8051 /EA ( pin 31 ): external access
◦There is no on-chip ROM in 8031 and 8032 .◦The /EA pin is connected to GND to indicate
the code is stored externally.◦/PSEN & ALE are used for external ROM.◦For 8051, /EA pin is connected to Vcc.◦“/” means active low.
/PSEN ( pin 29 ): program store enable◦This is an output pin and is connected to the
OE pin of the ROM.
Pins of 8051 ALE ( pin 30 ): address latch enable
◦It is an output pin and is active high.◦8051 port 0 provides both address and data.◦The ALE pin is used for de-multiplexing the address
and data by connecting to the G pin of the 74LS373 latch.
Port 3 Alternate Functions
Microcontroller Architectures
CPUProgram + Data
Address Bus
Data Bus
Memory
Von NeumannArchitecture
CPUProgram
Address Bus
Data Bus
HarvardArchitecture
Memory
Data
Address Bus
Fetch Bus
0
0
0
2n
Block Diagram of 8051 MicrocontrollerOscillator and timing
4096 Bytes Program Memory
(ROM)
128 BytesData Memory
(RAM)
Two 16 Bit Timer/Event
Counters
8051 CPU
64 K Byte Bus Expansion
Control
Programmable I/O
Programmable Serial Port Full Duplex UART
Synchronous Shifter
Internal data bus
External interrupts
subsystem interrupts
Control Parallel portsAddress Data BusI/O pins
Serial InputSerial Output
Memory Space of 8051/8031
On-Chip MemoryInternal RAM
RAM memory space allocation in the 8051
7FH
30H
2FH
20H
1FH
17H
10H
0FH
07H
08H
18H
00HRegister Bank 0
(Stack )Register Bank 1
Register Bank 2
Register Bank 3
Bit-Addressable RAM
Scratch pad RAM
Bit Addressable RAM
Summary of the 8051 on-chip data memory(RAM)
DENOTION NAMES HEX
*A ACCUMULATOR E0*B ARITHMATIC REG. F0DPH ADDRESSING EXT. MEMORY(HIGH) 83DPL ADDRESSING EXT. MEMORY(LOW) 82*IE INTERRUPT ENABLE CONTROL A8*IP INTERRUPT PRIORITY B8
*P0 I/O PORT LATCH 80*P1 I/O PORT LATCH 90*P2 I/O PORT LATCH 8A*P3 I/O PORT LATCH 9A
PCON POWER CONTROL 87*PSW PROGRAM STATUS WORD D0
special function registers (SFRs)
*SCON SERIAL PORT CONTROL 98SBUF SERIAL DATA BUFFER 99
SP STACK POINTER 81
TMOD TIMER/COUNTER MODE CONTROL 8B *TCON TIMER/COUNTER CONTROL 89
TH0 TIMER O HIGH BYTE 8CTLO TIMER 0 LOWER BYTE 8ATH1 TIMER 1 HIGH BYTE 8DTL1 TIMER 1 LOWER BYTE 8B
> *= Bit addressable> Total No. Of SFRs =21 (11 are Bitwise & Bytewise )
(Remaining 10 are Bytewise only )
Register Banks Four banks of 8 byte-sized registers, R0 to R7 Addresses are :
18 - 1F for bank 310 - 17 for bank 208 - 0F for bank 100 - 07 for bank 0 (default)
Active bank selected by bits [ RS1, RS0 ] in PSW. Permits fast “context switching” in interrupt service routines (ISR).
Timer and CounterTMOD Register
TCON Register:
SCON (Serial CONtrol) register
These two bits of SCON register determine the framing of data by specifying the number of bits per character and start bit and stop bits.
There are 4 serial modes. SM0 SM1 0 0 Serial Mode 0 0 1 Serial Mode 1;(8 bit data, 1 stop bit, 1 start bit) 1 0 Serial Mode 2 1 1 Serial Mode 3
SM0, SM1
REN (Receive Enable) also referred as SCON.4. When it is High ,it allows the 8051 to receive data on the RxD pin.
So to receive and transfer data REN must be set to 1.
When REN=0,the receiver is disabled. This is achieved as below : SETB SCON.4 &
CLR SCON.4
REN, TI, RI
TI (Transmit interrupt) is the D1 bit of SCON register.When 8051 finishes the transfer of 8-bit character, it raises the TI flag to indicate that it is ready to transfer another byte.
RI (Receive interrupt) is the D0 bit of the SCON register.When the 8051 receives data serially ,via RxD, it gets rid of the start and stop bits and places the byte in the SBUF register. Then it raises the RI flag bit to indicate that a byte has been received and should be picked up before it is lost.
Contd…
An interrupt is an external or internal event that disturbs the microcontroller to inform it that a device needs its service.
8051 Interrupts
If two interrupt sources interrupt at the same time, then interrupt with the highest PRIORITY gets serviced first.
All interrupts have a power on default priority order. 1. External interrupt 0 (INT0)2. Timer interrupt0 (TF0)3. External interrupt 1 (INT1)4. Timer interrupt1 (TF1)5. Serial communication (RI+TI)
Interrupt Priorities
Interrupt
Global Interrupt Enable – must be set to 1 for any interrupt to be enabled
Interrupt enables for the 5 original 8051 interrupts:Timer 2
Serial (UART0)Timer 1
External 1Timer 0
External 01 = Enable0 = Disable
IP.7: reservedIP.6: reservedIP.5: Timer 2 interrupt priority bit )8052 only(IP.4: Serial port interrupt priority bitIP.3: Timer 1 interrupt priority bitIP.2: External interrupt 1 priority bitIP.1: Timer 0 interrupt priority bitIP.0: External interrupt 0 priority bit
Interrupt Priorities (IP) Register
--- PX0PT0PX1PT1PSPT2---
RS-232 interface (UART)Introduction: The RS-232 interface is the Electronic
Industries Association (EIA) standard for the interchange of serial binary data between two devices.
It was initially developed by the EIA to standardize the connection of computers with telephone line modems.
Three wires are sufficient: send data, receive data, and signal ground.
The remaining lines can be hardwired on or off permanently.
The signal transmission is:1. Bipolar2. Requiring two voltages(from 5 to 25 volts, of opposite polarity).
RS-232 stands for Recommended Standard. Serial communication devices are divided into
two types. Data Communication Equipment(DCE) Ex: modem, adapter Data Terminal Equipment(DTE) Ex: computer, terminal
Range & Specifications Maximum length of cable b/w TxD and
RxD should not exceed 100 feet.(One reason why the range of the RS-232-
C standard is limited is the need to charge and discharge the capacitance of the cable connecting the TxD and RxD.
The connector used is 25 pin connector with a specific arrangement of wires.
MAX232 (Level Convertor)* Usually, all
Digital ICs work on TTL or CMOS
voltage Level which can’t be
used to communicate over
RS232 protocol. So, a voltage convertor is
needed to convert such levels.* The most
commonly used RS-232 level convertor is
MAX232.* It consist two Tx
& Rx and is capable of Full
Duplex UART communication.
Interfacing to PC
Seven Segment Configurations
The most commonly used Seven segment display is Common Anode now days & suitable with 8051.
Code for Common AnodeSeven Segment Display
Seven segment Interfacing with 8051
Interfacingwith LCD
A LCD(2x16)(Liquid Crystal Diode) having 16pins and that are:1. 8 Data pins (D0-D7)2. 3 Control pins (RS, R/W, E)3. Supply pin (Vcc) & ground pin (GND)4. Contrast setting pin (VEE)5. LED+ & LED- pins
LCD contd..
Initialize LCD & wait/delay. Display ON, Cursor ON & wait. Clear LCD & wait. Shift cursor to the left & wait. Set cursor on Line1 or Line2 at the
position desired & wait. Send/Write the data LCD for display.
LCD Algorithms :
LCD Commands
Interfacingwith Keypad (4x4)
It is not part of the C language as such. Rather, it is a C language extension i.e. the subject of a technical report by the ISO working group named “Extensions for the Programming Language C to Support Embedded Processors”.
It Aims to provide portability and access to common performance ,increasing features of processors used in the domain of DSP, other electronics & embedded processing.
Embedded C
The hardware I/O extension is a portability feature of Embedded C. Its goal is to allow easy porting of device-driver code between systems.
KEIL software EMBEDDFD C(Using C51 cross compiler)
Key Words: To facilitate many of the features of the 8051.
C51 adds a number of new keywords to the scope of the language. The following is the list of keywordsAt sbit idatasfr bdata interruptsfr16bit largesmallcode taskdata - xdata
Embedded C contd..
Memory Areas: The 8051 architecture supports several physically separate memory areas or memory spaces for program and data.
There are memory spaces that may be:* INTERNAL DATA MEMORY* EXTERNAL DATA MEMORY* PROGRAM MEMORY
Embedded C contd..
1. Internal(a) data-1 byte space in internal RAM.(b) bdata-Bit addressable(c)idata-If data should be saved indirectly to the internal memory.
2. External(a) xdata-It uses dptr (16) register.(b) pdata-It uses R0,R1(8) register.
3. Program Memory(a) code-when have to access the code section of memory.
Embedded C contd..
Applications of Microcontrollers
Recent Wonders
Recent Wonders contd...
Its not an exaggeration if I say that ,today there is no electronic gadget on the earth which is designed without a Microcontroller. Ex: communication devices, digital entertainment, portable devices etc.
Conclusion:
Surabhi Vaishnav(7th Sem, ECE Discipline)
Presented by: