Sunteți pe pagina 1din 49

CHAPTER 1 INTRODUCTION

1.1 INTRODUCTION TO EMBEDDED SYSTEM 1.1.1 DEFINITION


Combination of Software and hardware, designed to perform a particular task. Examples: Printer, Timers, Remote controls, Digital locks, Lighting control, Keyboard. An embedded controller is a controller (or computer) that is embedded into some device for some purpose other than to provide general purpose computing. Perform a single set of functions. Works in a time constrained environment. Provides high-performance and reliability Mostly Embedded systems have low cost because they are mass produced in millions. Some Embedded systems have mechanical moving parts like disk drives as they are less reliable as compared to solid state parts such as Flash memory.

1.1.2 WHAT IS EMBEDDED TECHNOLOGY


July 12, 2001 Simply put, embedded technology is software or hardware that is hidden embedded in a large device or system. It typically refers to a fixed function device, as compared with a PC, which runs general-purpose applications. Embedded technology is nothing new. It's all around us and has been for years. An early example of embedded technology is the engine control unit in a car, which measures what settings to give the engine. Your coffeemaker has embedded technology in the form of a microcontroller, which is what tells it to make the coffee at 6 a.m. The vending machine has it too. Overall, billions of devices woven into everyday life use embedded technology. In the past, embedded technology existed in standalone devicesvending machines and copiers that did their jobs with little regard for what went on around them. But as technology has learned to connect devices (mobile phones, PDAs and so on) to the

Internet and to each other, embedded technology's potential has grown. Suddenly it's not so much about what devices do on their own, but about what they're connected to and what actions those

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 1

connections let them perform. Cell phone companies figured that out a long time ago, which is why cell phones are cheap and the service, plans are expensive. It's not the phone Itself that matters, but the connectivity to a vast network of other phones, other people and the Internet. Similarly, your PDA is just a PDA; until you download software that lets you find a local restaurant or manage your finances. Embedded technology has the ability to affect the way you do business and the way you interact with your customers, no matter what your industry. Let's say you make freezersthe big, expensive kind that grocery stores buy. You sell one and you're done with that customer. When it breaks, the customer calls a service person, who probably comes from somewhere other than your company. But let's say the freezer knows (because embedded technology had been programmed to discover) that it's about to go on the fritz. Let's say the refrigerator alerts the customer before it breaks (the technological equivalent of taking aspirin at the hint of a headache). Better yet, let's say the freezer alerts the manufacturer (you), and you are able to send a service person to do preventative work and save a lot of Haagen-Dazs from melting. Embedded technology allows all of that to happen. You, the freezer company, have transformed yourself from a product company to a product and services company. The possibilities go beyond that. Programming devices to communicate with businesses (as in the freezer example above) can eliminate the need for costly call centers. Copy machines that can order their own replacement cartridges will save businesses time and money. Remember, the fact that the technology is embedded isn't what's important, and neither is the device. The devices are merely vessels. Embedded technology, if it's connected to the enterprise, makes sure information gets to the right place

1.2 APPLICATION
Telecom
Mobile phone systems (handsets and base stations), Modems, Routers

Automotive applications
Braking systems, Traction control, Airbag release systems, Enginemanagement units, Steer-by-wire systems, Cruise control applications

Domestic appliances
Dishwashers, Televisions, Washing machines, Microwave ovens, Page 2

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Video recorders, Security systems, Garage door controllers, Calculators, Digital watches, VCRs, Digital cameras, Remote Controls, Treadmills.

Robotic
Fire fighting robo, Automatic floor cleaner, Robotic arm

Aerospace applications
Flight control systems, Engine controllers, Autopilots, Passenger in-flight entertainment systems

Medical equipment
An aesthesia monitoring systems, ECG monitors, Pacemakers, Drug delivery systems, MRI scanners

Defence systems
Radar systems, Fighter aircraft flight control systems, Radio systems, Missile guidance systems

Office Automation
Laser printers, Fax machines, Pagers, Cash registers, Gas pumps, Credit/Debit card readers, Thermostats, Grain analyzers

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 3

1.3 APPLICATION AREA

Fig.1.1

Application Area.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 4

1.4

MARKET REQUIREMENT: -

Embedded Market Globally

Fig.1.2 Market Reqirement Page 5

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

The world market for embedded systems development is around $250 billion and is expected to grow at a CAGR of 26% Cisco, Wind River Systems, Sun Microsystems, Integrated Systems, Microware Systems, and QNX Software Systems are among the prominent developers of embedded systems. According to a study, for future of Embedded Systems Technologies, the market for embedded systems is expected to grow at an average annual growth rate (AAGR) of 16% over the period

Memory

Embedded boards Development tools

Embedded Software Real-time operating systems

Embedded processors Microcontroller (MCU), Microprocessor (MPU), and Digital signal processor (DSP)

Fig.1.3 Market Distribution of Embedded Systems

1.5FUTURE OF EMBEDDED SYSTEMS IN INDIA At present India exports embedded systems worth to the tune of $10 billion and this could grow to $50 billion within two to three years. India has a bright future in embedded systems as the availability of skilled manpower is in abundance. Embedded system requires considerable domain knowledge, say in automotive, telecom or medical for which the system has to be designed.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 6

1.6EMBEDDED SYSTEM VS. GENERAL COMPUTING SYSTEM


Embedded Systems (ES) usually run out of ROM ES have resource constraints. ES are infrequently reprogrammed ES often work in reactive mode ES have hard reliability and correctness constraints

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 7

CHAPTER 2
MICROCONTROLLER 2.1 MICROCONTROLLER
Microprocessors are intended to be general purpose digital computers .Micro controllers are intended to be special purpose digital controllers .It has a fixed program stored in ROM and doesnt change over the life time of system. Eight bit CPU with registers A and B Sixteen bit program counter and data pointer. Eight bit program status word. Eight bit stack pointer. Internal ROM of 4K.Internal RAM of 128 bytes: -Four register banks, each containing eight registers -Sixteen bytes, which may be addressed at bit level -Eighty bytes of general-purpose data memory Thirty two input/output pins arranged as four 8-bit ports: P0-P3.Two 16-bit timer/counters: T0 and T1.Full duplex serial data receiver/Transmitter: SBUF.Control register:TCON,

TMOD,SCON,PCON,IP,and One-Two external and three internal interrupt sources. Oscillator and clock circuits.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 8

Microcontroller is a single chip computer.

Fig.2.1 Types Of Microcontroller

2.1.1 History of the 8051


Developed by Intel Corporation in the year 1981. First 8-bit microcontroller called as 8051 It was called as a System on a chip Intel refers to it as MCS-51

2.2 MICROCONTROLLER CAN BE : 4 bit microcontroller 8 bit microcontroller HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 9

16 bit microcontroller 32 bit microcontroller 2.2.1 4 BIT MICROCONTROLLERS: Most popular microcontroller made in terms of production numbers Economical Application: appliances and toys

2.2.2 8 BIT MICROCONTROLLERS: Represent a transition zone between dedicated, high-volume, 4-bit micro-controllers and the high performance 16 bit microcontrollers 8 bit word size adequate for many computing tasks and control or monitoring applications. Application: simple appliance control, high-speed machine control, data collection

2.2.3 16 BIT MICROCONTROLLERS: Provide faster response and more sophisticated calculations Applications: control of servomechanism like robot arms

2.2.4 32 BIT MICROCONTROLLERS: Design emphasis is more on high speed computation features and not on chip features like RAM, ROM, Timers, etc Applications: robotics, highly intelligent instrumentation, avionics, image processing, telecommunications, automobiles, etc ssExample : Intel 80960, ARM

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 10

2.3 PIN DIAGRAM OF 8051

Fig.2.2 Pin Diagram Of 8051

Fig.2.3 Inbuilt structure of microcontroller

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 11

2.3.1 Difference between microprocessor and microcontroller Microprocessor Micro-controller

1. contain no on chip ram,rom,i/o, timer, 1. Contain on chip ram, rom,i/o,timer,serial serial port. 2. used in general purpose application 3. dont provide data storage facilty. 4. the structure of p is given below port. 2. used in specific purpose application 3. provides data storage facility. 4. the structure of p is given below

2.4 8051 MICROCONTROLLER

FEATURES OF THE 8051


8 Bit data path and ALU. On chip flash memory. 4K X 8 ROM - Program memory. 128 x 8 RAM - Data memory. Multiple 16-bit Timer/Counter. Full duplex UART (Serial port). On chip clock oscillator. 32 I/O pins Six Interrupt sources

8052 MICROCONTROLLER
Has all the features of 8051 along with extra 128 bytes of RAM, a timer and an extra 4K bytes of on chip ROM Page 12

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

8051 is upward compatible to 8052

8031 MICROCONTROLLER
ROM-less 8051 i.e. contains 0 K bytes of on chip ROM An external ROM must be added to make it functional

2.5 VERSIONS OF 8051 C


8751 microcontroller: 4K bytes of on chip UV-EPROM, requires PROM burner,as well as UV-EPROM to erase its contents and takes 20 min erase cycle. AT89C51 from Atmel Corporation: On chip ROM flash memory, erase cycle in seconds,furnish fastdevelopment. DS5000 from Dallas Semiconductor: On chip ROM in form of NV-RAM form. In NV-RAM has ability to change the ROM contents one byte at a time. OTP(one time programmable) version of the 8051: For mass production, low cost. 8051 family from Philips: One of the largest selections of 8051 microcontrollers, various features like ADC, DAC, extended I/O, both OTP and flash

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 13

2.6 8051 ARCHITECTURE 2.6.1 HARDWARE DETAILS 2.6.1.1 PIN DIAGRAM

Fig. 2.4. Pin and Block Diagram Of 8051

2.7 PIN DESCRIPTION Port 1- pins (1-8): Input/output pins Contains internal pull-ups. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 14

Port 3- pins (10-17) Input/output pins. Contains internal pull-ups. Alternate functions to provide signals such as interrupts. Port 2- pins (21-28): Input/output port. Contains internal pull-ups. Used both as I/O port and higher address byte Port 0- pins (32-39): . . input/output pins. Required external Pull- up resisters of 10 k.

Used both as I/O port and higher address byte PSEN- (pin 29): Program store enable Active low input Used while accessing external memory. Connected to OE pin of external ROM. ALE- (pin 30): Address Latch Enable

Active high. Used for de-multiplexing the address and data by connecting G pin

of the 74LS373. EA - (pin 31): Active low input. To access external ROM, it must be GND. XTAL1and XTAL2 - (pin 19 and pin 18): Provides clock to quartz crystal oscillator. RST- (pin 9): Reset Active high input. Terminate all activities of us. Sets PC to 0. Requires minimum 2 machine cycles. VCC - (pin 40) GND (pin 20) Page 15

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

2.8 CRYSTAL STRUCTURE OF 8051:

GND at 20 XTAL 1 pin19 and XTAL at pin 18

Fig. 2.5 Reset Circuit

RESET CIRCUIT OF 8051

RESET pin Active high. On applying a high pulse to this pin, micro controller will reset and terminate all activities. INPUT pin Minimum 2 machine cycles required to make RESET Value of registers after RESET

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 16

Fig. 2.6 Reset Switch

2.9 MEMORY ORGANISATION

2.9.1 DATA MEMORY 00-7FH: Direct /indirect addressable. 80H-FFH: Direct addressable 28 bytes are used for SFRs . SFRs lie between 80H-FFH. The unused locations are reserved & must not be used by programmer. 32 locations are bit addressable including 16 SFRs. External RAM-up to 64k can be attached.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 17

Fig. 2.7 Data Memory Description Of 8051

2.9.1.2 INTERNAL DATA MEMEORY Lower 128 bytes: 00H- 7FH Four register banks: 00H to 1FH Bit addressable area: 20H to 2FH General purpose area: 30H to 7FH SFR address space: 80H to FFH

2.10 8051 REGISTERS

2.10.1 General purpose register 2.10.2 Special Function register

2.10.1 GENERAL PURPOSE REGISTER


Registers (R0-R7): Set of 8 auxiliary registers, namely R0, R1, and R7. There are 4 such banks in lower RAM. Data Pointer (DPTR): Made of two 8-bit registers, namely DPH and DPL, Used to furnish memory address for internal and Page 18

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

external code access and external data access. Program Counter (PC): 16-bit register holds the address of the next program instruction to be executed, automatically incremented after each instruction fetch. Stack Pointer (SP): 8-bit register, used to hold an internal RAM address called the top of the stack.

2.10.2 SPECIAL FUNCTION REGISTER


SFR lies between 80 to FF hex. Not all address space of 80 to FF is used by SFR. The unused locations 80H to FFH are reserved & must not be used by the programmer. 16 addresses are bit addressable. Special function registers. Full instruction set including Variety of addressing modes. Arithmetic Instruction Logical Instruction Branching Instruction Data movement Instruction 6 interrupt sources.

2.11 SPECIAL FUNCTION REGISTERS


SFR registers can be seen as a sort of control panel for managing and monitoring the microcontroller. Every register and each of the belonging bits has its name, specified address in RAM and strictly defined role (e.g. controlling the timer, interrupt, serial connection, etc). Although there are 128 available memory slots for allocating SFR registers, the basic core shared by 8051 MCUs has but 22 registers. The rest has been left open intentionally to allow future upgrades while retaining the compatibility with earlier models. This fact makes possible to use programs developed for obsolete models long ago.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 19

Fig. 2.8 Address Description Of Special Function Registers

2.11.1 CPU REGISTER:


ACC: Accumulator. B: B registers. PSW: Program Status Word. SP: Stack Pointer. DPTR: Data Pointer (DPH, DPL). INTERRUPT CONTROL: IE: Interrupt Enable. IP : Interrupt Priority.

2.11.2 I/O PORT: P0: Port 0.


Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance inputs. Port 0 may also be configured to be the multiplexed low order address/data bus during accesses to external Page 20

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

program and data memory. In this mode P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming, and outputs the code bytes during program verification. External pull-ups are required during program verification.

P1: Port 1.
Port 1 is an 8-bit bi-directional I/O port with internal pullups.The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs,Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups.Port 3 also receives some control signals for Flash programming and verification.

P2: Port 2.
Port 2 is an 8-bit bi-directional I/O port with internal pullups.The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pullups.Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.

P3: Port 3.
Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 also serves the functions of various special features of the AT89S52 as listed below:

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 21

Fig.2.9 Port Pins Of 8051

ALE/PROG
Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation ALE is emitted at a constant rate of 1/6 the oscillator frequency, and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external Data Memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode. .

PSEN
Program Store Enable is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN is activated twice each machine Cycle, except that two PSEN activations are skipped during each access to external data memory.

EA/VPP
External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 22

bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions.

STACK POINTER
The Stack Pointer register is 8 bits wide. It is incremented before data is stored during PUSH and CALL executions. While the stack may reside anywhere in on-chip RAM, the Stack Pointer is initialized to 07H after a reset. This causes the stack to begin at locations 08H.

INTERNAL RAM:
The 128-byte internal RAM, is organized into three distinct areas:

1. Thirty-two bytes from address 00h to 1Fh that make up 32 working registers organized as four banks of eight registers each. 2 .A bit addressable area of 16 bytes occupies RAM byte addresses 2oh to 2fh, forming a total of 128 addressable bits. 3. A general purpose RAM area above the bit area, from 30h to 7Fh, adressable as bytes.

Fig. 2.10 Register Bank Page 23

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

INTERNAL ROM:
In 8051 data memory and program code memory are two different entities.Internal ROM occupies code addresses 0000h to 0FFFh . If program address exceeds 0FFFh then 8051 automatically fetches code from external program memory.Code bytes could also be fetched exclusively from external memory 0000h to FFFFh ,by connecting the EA pin to ground.

TIMERS:
TMOD: Timer mode. TCON: Timer control. TH0: Timer 0 high byte. TL0: Timer 0 low byte. TH1: Timer 1 high byte. TL1: Timer 1 low byte.

SBUF: SERIAL DATA REGISTERS.


Setting the Baud Rate Once you have selected the mode of UART, you need to set the Baud Rate. Baud Rate in modes 0 and 2 depends solely on the frequency of quartz crystal. Crystals designed specifically for this purpose can be found in the market. Although their frequencies might seem a bit exotic at first (e.g. 11.059 MHz), they produce standard rates for serial communication after the clock has been divided by the controller. Baud Rate in modes 1 and 3 is determined by timers T1 and/or T2. Timer T1 is most commonly used in "Auto-Reload" mode (TMOD = 0010xxxx). In this case, rate is determined by the frequency of overflow occurrence, and can be calculated according to the formula: Quartz oscillator frequency Baud Rate = 384 * (256 - TH1)

If bit SMOD in register PCON is set, rate will be doubled: Quartz oscillator frequency Baud Rate = 192 * (256 - TH1) Page 24

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Here, bits which are automatically set upon overflow are of no use, and should be cleared to avoid causing an interrupt. If timer T2 is used for setting the Baud Rate, its bits will always have priority, allowing the microcontroller to send and receive data at different rates: RCLK TCLK Mode of work 0 0 Rates of sending and receiving are equal and set by timer T1 only 0 1 1 1 0 1 Receiving rate is set by T1, sending rate is set by T2 Receiving rate is set by T2, sending rate is set by T1 Rates of sending and receiving are equal and set by timer T2 only

OTHER:
PCON: Power control & misc.

A, B REGISTERS A (Accumulator):
8-bit register & used as working register for The arithmetic, logical instruction. Can be used as general purpose register. Necessary for some instructions.

B REGISTERS:
8-bit register and can be used as general purpose Register. Necessary for the instructions MUL and DIV.

. TMOD : TIMER MODE REGISTER


GATE: Permits INTx pin to enable/disable counter. C/T : Set for counter operation, reset for timer operation. M1, M0: 00: Emulate 8048 counter/timer (13-bits). 01:16-bit counter/timer. Page 25

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

10: 8-bit auto-reload mode 11: Timer 0 = two 8-bit timers. Timer 1 Counting disabled. Timing function allowed. Can be used as Baud Rate generator. This register sets mode for timers T0 and T1. As shown in the image below, lower 4 bits bit 3) are associated with T0, while the higher 4 bits (bit4 - bit7) are associated with T1. (bit 0 -

Fig.2.11 Tmod Description

The following table gives details on bits 0 - 7:

Bit 7

Bit Name GATE1

Purpose

Timer

1 Timer works only if INT1 (P3.3) is set T1 0 Timer works regardless of INT1 (P3.3)

C/T1

1 Timer counts impulses on T1 (P3.5) T1 0 Timer counts impulses of internal

oscillator 5 4 3 T1M1 T1M0 GATE0 Timer mode Timer mode T1 T1

1 Timer works only if INT0 (P3.2) is set T0 0 Timer works regardless of INT0 (P3.2)

C/T0

1 Timer counts impulses on T0 (P3.4) T0 0 Timer counts impulses of internal

oscillator 1 T0M1 Timer mode 0 T0M0 Timer mode T0 T0

Four bits from the previous table determine the operating mode of timers T0 and T1. There are 4 of these modes, and each will be covered in details. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 26

T0M1 T0M0 Mode Description 0 0 1 1 0 1 0 1 0 1 2 3 13-bit Timer 16-bit Timer 8-bit auto-reload Split mode

TIMER MODE
Timer Mode 0 : Emulates 8048 counter/timer (13-bits). 8-bit counter (TL0 or TL1). 5-bit prescaler (TH0 or TH1). Timer Mode 1: Simple 16-bit counter. Timer Mode 2: 8-bit auto-reload. Counter in TL0 or TL1. Reload value in TH0 or TH1. Provides a periodic flag or interrupt. Timer Mode 2: Split timer mode

TCON: TIMER CONTROL REGISTER


TF1, TF0: Overflow flags for Timer 1 and Timer 0. TR1, TR0: Run control bits for Timer 1 and Timer 0. Set to run Reset to hold. IE1, IE0: Edge flag for external interrupts 1 and 0. * Set by interrupt edge, cleared when interrupt is processed. IT1, IT0: Type bit for external interrupts. * Set for falling edge interrupts, reset for 0 level interrupts. * = not related to counter/timer operation. TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 TCON is another register in direct control of the timers. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 27

Fig.2.12 Tcon Description Of the 8 bits, TCON uses only 4 bits for controlling the timers, while the other 4 are associated with interrupts. Bit 7 Bit Name TF1 Purpose This bit is automatically set in case of overflow in Timer T1 6 TR1 1 - Timer T1 is on 0 - Timer T1 is off 5 TF0 This bit is automatically set in case of overflow in Timer T0 4 TR0 1 - Timer T0 is on 0 - Timer T0 is off T0 T0 T1 Timer T1

SCON: SERIAL CONTROL REGISTER


SM0, SM1 = Serial Mode Specifier: 00 = Mode 0 : Shift register I/O expansion. 01 = Mode 1 : 8-bit UART with variable baud rate. 10 = Mode 2 : 9-bit UART with fixed baud rate. 11 = Mode 3 : 9-bit UART with variable baud rate. SM2: Mode 0: Not used. Mode 1: 1 = Ignore bytes with no stop bit. Mode 2, 3: 0 = Set receive interrupt (RI) on all bytes. : 1 = Set RI on bytes where bit 9 = 1. REN = Enables receiver. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 28

TB8 = Ninth bit transmitted (in modes 2 and 3). RB8 = Ninth bit received:

Mode 0 : Not used. Mode 1 : Stop bit. Mode 2,3 : Ninth data bit. - TI = Transmit interrupt flag. - RI = Receive interrupt flag.

IE: INTERRUPT ENABLE REGISTER


EA: Global interrupt enable. ES: Serial interface. ET1: Timer 1. EX1: External interrupts 1. ET0: Timer 0. EX0: External interrupts 0. 0 = Disabled. 1 = Enabled.

IE (INTERRUPT ENABLE)

Fig.2.12.1 Intrrupt Enable Description Following table describes the bits of register IE

(same rule applies to all bits - logical state of 1 enables the appropriate interrupt): Bit EA ET2 ES ET1 Purpose Enables/disables all interrupt sources Timer T2 interrupt UART Timer T1 interrupt

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 29

EX1 ET0 EX0

External interrupt: pin INT1 Timer T0 interrupt External interrupt: pin INT0

INTERRUPT PRIORITIES
It cannot be predicted with absolute certainty when will interrupt request take place. If multiple interrupts are enabled, it's quite possible to have interrupt requests during execution of another interrupt routine. In such cases, controller needs to resolve whether to proceed with the current interrupt routine, or to enter a new one, based on a priority check. Our microcontroller can differentiate between three priority levels: 1. Reset. If there is a request for reset, all processes are halted and the controller behaves as if the power had just been turned on. 2. Priority 1 interrupts. Can be interrupted only by reset. 3. Priority 2 interrupts. Can be interrupted by any of above.

IP (INTERRUPT PRIORITY)

Fig. 2.13

Intrrupt Priority Description

SFR

register

IP

determines

the

priority

of

existing

interrupt

sources

(Same rule applies to all bits : logical state of 1 assigns higher priority to the appropriate interrupt): Bit PT2 PS PT1 PX1 PT0 Purpose Timer T2 interrupt priority Serial port interrupt priority Timer T1 interrupt priority External interrupt INT1 priority Timer T0 interrupt priority

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 30

PX0

External interrupt INT0 priority

If two interrupt requests collide, the one with higher priority has precedence in execution. If both interrupts are of same priority, the one with the later request has to hold one and let the controller handle the first one.

HOW DOES INTERRUPT EXECUTE?


Upon receiving an interrupt request, following scenario takes place: 1. Current instruction is executed first. 2. Address of the instruction that would be executed next if there was no interrupt request is put away to stack. 3. Depending on the interrupt in question, program counter will take value of one of possible 6 vectors (addresses) according to the table below.

Interrupt source IE0 TF0 IE1 TF1 RI, TI, SPIF TF2, EXF2

Vector (address in hex) 3h Bh 13h 1Bh 23h 2Bh

These addresses should hold the appropriate subroutines for handling the interrupts. In practice, instead of actual routines, they only point to the location of appropriate routines in the code. 4. Upon accomplishing the interrupt routine, address of the next instruction to be executed is retrieved from the stack, and the program proceeds from the location where it was interrupted.

PCON: POWER CONTROL REGISTER


POWER DOWN OPERATION Setting PD bit stops oscillator. Page 31

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

RAM contents are saved. Exit via Reset. Some (newer) 80C51 derivatives allow Power-Down wakeup via Interrupt.

IDLE MODE OPERATION


Setting IDL gates clocks off, leaves oscillator running. All register and RAM contents are saved. Interrupt sources remain active: Serial interface. External interrupts. Timers. Exit with any enabled interrupt or Reset. GF0, GF1 are general purpose software flags. SMOD serial interface control bit. Doubles baud rate in modes 1,2, and 3. Only SMOD available on NMOS parts.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 32

CHAPTER 3
PROGRAMMING LANGUAGE 3.1 PROGRAMMING IN 8051 3.1.1OBJECTIVE:
Introduction To Programming Language Addressing Modes Instruction set 8051 data types and directive Programming Tools & Techniques

3.2 PROGRAMMING LANGUAGES


3.2.1 Machine Language 3.2.2 Assembly Language 3.2.3 High level language

3.2.1 MACHINE LANGUAGE


A program that consists of 0s and 1s is Called Machine Language. Deals directly with the internal structure of computer. CPU can work only in machine language.

3.2.2ASSEMBLY LANGUAGE
Defined by a set of rules that specify the symbols that can be used and they may be combined to form a line of code. The instruction has a specific format. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 33

[Label] mnemonics operand [comment] Better understanding then machine language.

3.2.3HIGH LEVEL LANGUAGE


The language whose instruction set is more compatible with Human languages and human thought processes. HLL offers three significant advantages over machine language(Simplicity, uniformity and portability). In HLL the programmer need not to be concern with internal detail of computer. E.g. BASIC,PASCAL,C,C++,JAVA and numerous other. Compiler is needed to convert it into machine language.

3.3 ASSEMBLY LANGUAGE SYNTAX


[Label:] Mnemonic [Operands] [Comment]

3.3.1 LABEL
Name of label should be meaningful giving the refection of the code functionality E.g.. (LED_ON: Label indicates the switch ON the led) First character should be an alphabet. No. of character should not be more than 8 Character. Reserve words must not be used as label.

3.3.2 MNEMONIC & OPERANDS


Mnemonics are assembly opcode specific to C/ P e.g. MOV All the three opcodes Page 34

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

LDI are used to move the STA data/address The operand can be data or address. Mnemonics can be of 1 byte & operands can be byte.

3.3.3 COMMENT
Begin with semicolon comment indicator. Comments should be small and meaningful. Assembler ignores comments, but they are indispensable to programmer.

3.4 ADRESSING MODES


The various ways of accessing data are called addressing modes Immediate addressing mode Register addressing mode Direct addressing mode Register indirect addressing mode Indexed addressing mode

3.4.1 IMMEDIATE ADDRESSING MODE


The operand comes immediately after the opcode. Immediate data must be preceded by the pound sign ( # ). Can be used to load information into any of the registers and memory location. MOV A,#25H MOV R0,#65H MOV 30H,#20H

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 35

3.4.2 REGISTER ADDRESSING MODE


Involves the use of registers to hold the data to be manipulated. MOV A,R0 MOV R1,A ADD A,R6

3.4.3DIRECT ADDRESSING MOD


Eaddress is known. The address is given as a part of instruction. MOV 30H, A; Save content of A in RAM location 30h MOV R0, 40H MOV A, 2

3.4.4REGISTER INDIRECT ADDRESSING MODE


A register is used as a pointer to the data. As the register hold the address of RAM location , they must be preceded by @ sign. Only register R0,R1 are used for this purpose MOV A,@R0 ; Move content of RAM location whose address is held by R0 into A. MOV @R1,B ; Move contents of B into RAM location whose address is held by R1.

3.4.5 INDEXED ADDRESSING MODE


Used in accessing data elements of look-up table located in ROM space. The 16 bit register DPTR and A are used to form the address of data element stored in on chip ROM. The instruction used for this purpose is MOVMOVC A,@A+DPTR Page 36

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

3.4.6 To use C-language instead of assembly language:The presence of C-language instead of assembly language to prepare the source code gives designers and programmers a better ease to write the source code hence increase the efficiency of the circuit and hence the output.

8051 IDE
8051 IDE (Integrated Development Environment) combines a text editor, Assembler and S/W simulator into a single Program. All program needed to develop 8051 program are available and controllable from this single IDE running on windows.

KEY FEATURES
Editor Assembler Simulator

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 37

CHAPTER 4
INTERFACING 4.1 INTERFACING OF LED 4.1.1 LIGHT EMITTING DIODE:Light emitting diodes, commonly called LEDs do dozens of different jobs and are found in all kinds of devices. Among other things, they form the numbers on digital clocks, transmit information from remote controls, light up watches and tell you when your appliances are turned on.

Solid state LED light sources are known as p-n semiconductor devices. By doping a substrate material with different materials, a p-n junction is formed within the semiconductor crystal. The dopant in the n region provides mobile negative charge carriers (electrons), while the dopant in the p region provides mobile positive charge carriers (holes). Within a semiconductor crystal, when a forward voltage is applied to the p-n junction from the p region to the n region, the charge carriers inject across the junction into a zone where they recombine and convert their excess energy into light. The materials used at the junction determine the wavelength of the emitted light. LEDs come in a variety of colures.

4.2 DIODE:A diode is the simplest sort of semiconductor device. A semiconductor is a device with a varying ability to conduct electrical current. Most semiconductors are made of poor conductor that has had impurities added to it. The process of adding impurities is called doping. A semiconductor with extra electrons is called N-type material. A semiconductor with extra holes is called P-type material. A diode comprises a section of n-type material bonded to a section of p-type material, this arrangement conducts electricity in only one direction.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 38

Light is a form of energy that can be released by an atom. It is made up of many small particle-like packets that have energy and momentum but no mass. These particles, called photons, are the most basic units of light. Photons are released as a result of moving electrons. Electrons move in orbital around the nucleus. As free electrons moving across a diode can fall into empty holes from the P-type layer. This involves a drop from the conduction band to a lower orbital, so the electrons release energy in the form of photons .

This happens in any diode, but the photons are seen when the diode is composed of certain material. Visible light emitting diodes, such as ones that light up numbers in a digital clock are made of materials characterized by a wider gap between the conduction band and the lower orbital. The size of the gap determines the frequency of photon; it determines the color of the light. LEDs have several advantages over conventional incandescent lamps. They dont have a filament that burn out, their small plastic bulb makes them a lot more durable. Main advantage is the efficiency. LEDs generate very little heat.

The spectral power distribution of an LED is fairly narrow, with half-bandwidths of around 20 to 50 nm, depending upon the substrate material. This means that LEDs produce highly saturated, nearly monochromatic light. White LEDs are a recent development, constructed by adding a phosphor to a blue LED. Some of the blue light is converted by the phosphor into broader- spectrum yellow which results in light that has a bluish-white appearance. White light can also be generated by mixing the light generated by blue, green and red LEDs.

Materials used in early LEDs to generate specific colors are listed as follows, with the peak spectral wavelength generated by the LED and the material used (IESNA, 1993): Deep blue; 470 nm; SiC Blue; 490 nm; GaN Red (super bright); 650 nm; AlGaAs More recently, a promising material for red, amber and yellow LEDs has been identified. Aluminum indium gallium phosphide (AlInGaP: commonly pronounced like "allen gap") is used to develop long visible wavelength - yellow, amber and red - LEDs.

LEDs are low-voltage, low-current devices. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 39

4.2.1 DIODE TESTING:


The conduction of a semiconductor diode can determined quickly using one of the methods that are following: 1. Using DDM(digital display meter) 2. The ohmmeter section of a multimeter. 3. A curve tracer Out of above these above these methods, diode checking by a multimeter is most common and widely used. In this method, the forward resistance of a semiconductor diode is measured which is very low in comparison to reverse bias-level. Thus, if measure the resistance of a diode using the connections indicated below, we can expect a relatively low level. The resulting ohmmeter indication will be a function of current established through the diode by the internal battery of the ohmmeter circuit. The higher is the current, the less the resistance

level while the opposite condition occurs in case of reverse-bias. A high resistance in both directions obviously indicated an open switch condition, while a very low resistance reading in both directions will probably indicate a shorted device.

4.2.2DETECTION OF DIODE:By detection of a diode, we mean how to check the polarity or the function of a particular diode.

1. POLARITY IDENTIFICATION:Different identification schemes are used for different types of diodes. Generally a white or black band can be seen at cathode but for an LED an anode pin is of greater length than cathode pin. 2. Two classification systems are also available to identify the function of a diode. a) European System: In this type of system, three letters are used as codes in which first letter tells the type of semiconductor that is A- for Germanium(Ge) B- for Silicon(Si) Page 40

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Second letter tells the function of a diode that is A- General Purpose Z- Zener B- Tuning Q- LED

Third letter is for the series. For example BA implies Silicon tuning diode. b) American System:In this system, code 1N is used as first two letters For example 1N4001, 1N4007 etc. The main drawback of this system is that it does not show the function of a diode. So, to check the function data sheet of a diode has to be used.

4.3 DIODE CONFIGURATION:Diode can be used in any of the following configurations: 1. Common Anode: In this configuration, +5v dc remains fixed while the ground is supplied by microcontroller. The concept of current sinking is followed in this case and that is why it is preferred over common cathode. 2. Common Cathode: In this type, ground is fixed while a +5v is supplied by the microcontroller. The concept of current source is followed in this case. Both of the configurations are shown below:
0Vdc

V1 R1 1k R2 1k D2 1 D3 1 R3 2 1k R4 2 1k D4 1 D5 1

COMMON ANODE

uC

COMMON CATHODE

Fig 4.1 Diode Configuration

\
Page 41

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

4.4 INTERFACING OF SEVEN SEGMENTS

4.4.1 SEVEN SEGMENT


A seven-segment display (abbreviation: "7-seg(ment) display"), less commonly known as a sevensegment indicator, is a form of display device that is an alternative to the more complex dot-matrix displays. Seven-segment displays are commonly used in electronics as a method of displaying decimal numeric feedback on the internal operations of devices.

Fig.4.2 concept and visual structure

A typical 7-segment LED display component, with decimal point. A seven segment display, as its name indicates, is composed of seven elements. Individually on or off, they can be combined to produce idealized representations of the Hindu-Arabic numerals. Each of the numbers 0, 6, 7 and 9 may be represented by two or more different glyphs on seven-segment displays. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top and bottom. Additionally, the seventh segment bisects the rectangle horizontally. There are also fourteen-segment displays and sixteen-segment displays (for full alphanumerics); however, these have mostly been replaced by dot-matrix displays. Often the seven segments are arranged in an oblique, or italic, arrangement, which aids readability. HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION Page 42

The segments of a 7-segment display are referred to by the letters A to G, as follows: AAAAAA F F F B B B

GGGGGG E E E C C C

DDDDDD DP where the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers. For many applications, dot-matrix LCDs have largely superseded LED displays, though even in LCDs 7-segment displays are very common. Unlike LEDs, the shapes of elements in an LCD panel are arbitrary since they are formed on the display by a kind of printing process. Seven-segment displays are of two types:

4.4.2. COMMON ANODE:


In this type of displays, dc voltage given to it remains fixed while control signals are supplied by other device that is (logic LOW) by microcontroller. The ML1542 series is used for such displays.

4.4.3. COMMON CATHODE:


In this type of displays, control signals issued by microcontroller are in the form of logic HIGH. ML5611 series is used for such displays.

Fig.4.3

Internal

structures of seven segment

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 43

4.4.4SINGLE SEVEN SEGMENT:


4.4.5CIRCUIT:

Fig. 4.4 Interfacing with seaven segment

4.5.INTERFACING OF DC MOTOR WITH MICROCONTROLLER


This section begins with an overview of the basic operation of DC motors. Then we describe how to interface a DC motor to the 8051. Finally, we use C language programs to demonstrate the concept of pulse width modulation (PWM) and show how to control the speed and direction of a DC motor. Page 44

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

4.5.1.DC MOTOR: A direct current (DC) motor is another widely used


device that translates electrical pulses into mechanical movement. In the DC motor we have only + and - leads. Connecting them to a DC voltage source moves the motor in one direction. By reversing the polarity, the DC motor will move in the opposite direction. One can easily experiment with the DC motor. For example, small fans used in many motherboards to cool the CPU are run by DC motors. By connecting their leads to the + and - voltage source, the DC motor moves. While a stepper motor moves in steps of 1 to 15 degrees, the DC motor moves continuously. In a stepper motor, if we know the starting position we can easily count the number of steps the motor has moved and calculate the final position of the motor. This is not possible in a DC motor. The maximum speed of a DC motor is indicated in rpm and is given in the data sheet. The DC motor has two rpms: no-load and loaded. The manufacturer's data sheet gives the no-load rpm. The no-load rpm can be from a few thousand to tens of thousands. The rpm is reduced when moving a load and it decreases as the load is increased. For example, a drill turning a screw has a much lower rpm speed than when it is in the no-load situation. DC motors also have voltage and current ratings. The nominal voltage is the voltage for that motor under normal conditions, and can be from 1 to 150V, depending on the motor. As we increase the voltage, the rpm goes up. The current rating is the current consumption when the nominal voltage is applied with no load, and can be from 25mA to a few amps. As the load increases, the rpm is decreased, unless the current or voltage provided to the motor is increased, which in turn increases the torque. With a fixed voltage, as the load increases, the current (power) consumption of a DC motor is increased. If we overload the motor it will stall, and that can damage the motor due to the heat generated by high current consumption.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 45

4.5.2 UNIDIRECTIONAL CONTROL:


Figure shows the DC motor rotation for clockwise (CW) and counterclockwise (CCW) rotations.

Fig.4.5 DC MOTER

4.5.3CIRCUIT DIAGRAM:

Fig4.6 interfacing with DC motor

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 46

CHAPTER 5 5.1RESULT
Microcontrollers producers have been struggling for a long time for attracting more and more choosy customers. Every couple of days a new chip with a higher operating frequency, more memory and more high-quality A/D converters comes on the market. Nevertheless, by analyzing their structure it is concluded that most of them have the same (or at least very similar) architecture known in the product catalogs as 8051 compatible. What is all this about? The whole story began in the far 80s when Intel launched its series of the microcontrollers labeled with MCS 051. Although, several circuits belonging to this series had quite modest features in comparison to the new ones, they took over the world very fast and became a standard for what nowadays is meant by a word microcontroller. The reason for success and such a big popularity is a skillfully chosen configuration which satisfies needs of a great number of the users allowing at the same time stable expanding (refers to the new types of the microcontrollers). Besides, since a great deal of software has been developed in the meantime, it simply was not profitable to change anything in the microcontrollers basic core. That is the reason for having a great number of various microcontrollers which actually are solely upgraded versions of the 8051 family. What is it what makes this microcontroller so special and universal so that almost all the world producers manufacture it today under different name?

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 47

5.2 CONCLUSION
The training in the DUCAT INSITUTEgave a thorough knowledge about micro controllers. This training increased my knowledge in how micro controllers are useful as well as used in the real world.

I am sure that this training would help me a lot in future.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 48

REFERENCES Books
Microcontrollers Microcontrollers Linear Integrated Circuit Electronics Devices & Circuits Electronics For You -By Muhammad Mazidi -By U.S.Shah -By Gayakwad -By J. Boylstead - Monthly Magazine

Various Websites are:


www.google.com www.downloaddatasheets.com www.atmel.com www.discovercircuits.com www.howstuffworks.com www.analog.com

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION

Page 49

S-ar putea să vă placă și