Sie sind auf Seite 1von 51

Chapter 1: EMBEDDED SYSTEMS

1.1 INTRODUCTION
An embedded system is a combination of hardware and software design to meet a specific need with performance in a given time frame. It is a specialized computer system that is a part of larger system on machine. Typically an embedded system is housed on a single microcontroller board with programs stored in ROM. Virtually all appliances which have a digital interface watches, microwaves, carsutilize embedded systems include an operating system, but many are so specialized that the entire logic can be implemented as a single program. An embedded controller is a controller (or computer)that is embedded into some device for some purpose other than to provide general purpose computing. It is a special purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal computer, an embedded system performs pre-defined tasks, usually with very specific requirements. Since the system is dedicated to a specific task, design engineers can optimize it, reducing the size and cost of product. Embedded systems are often mass produced, so the cost savings may be multiplied by millions of items. Hand held computers or PDAs are generally considered embedded devices because of the nature of their hardware design, even though they are more expandable in software terms. This line of definition continues to blur as devices expand. Embedded systems are a combination of hardware as well as software. The software written for embedded systems is often called firmware, and is stored in ROM or FLASH memory chips rather than a disk drive. It often runs with limited hardware resources: small or no keyboard, screen, and little RAM memory. Embedded systems are designed to do some specific task, rather than be a general purpose computer for multitasks. Some also have real-time performance constraints that must be met, for reasons such as safety and usability: others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs.

INSIDE THE CPU:


1

REGISTERS: These are used to store information temporarily, which could be address or data.

ALU: Arithmetic logic Unit- performs arithmetic operations such as addition, subtraction, division, multiplication and logical operations AND, OR, XOR, NOT.

PROGRAM COUNTER: It points to the next instruction to be fetched. Increases automatically with execution of each instruction.

INSTRUCTION DECODER: Interprets the instructions fetched into CPU.

DATA BUS:
Used to carry information in and out of CPU. Increase in number of data buses increases speed as well as cost.

ADDRESS BUS:

Used to identify the devices and memory connected to the CPU. Determines the number of locations which it can communicate No. of locations=2^X where X= number of address lines. Ex: 16 address lines make 64k of addressable memory.

RAM:
Random Access Memory Also known as Data Memory. This is a volatile memory and is used to store the data temporarily during the execution of a program.

ROM:
Read Only Memory This is a permanent memory. In embedded systems (micro controllers) the ROM is FLASH ROM also known as CODE MEMORY. The program is stored in this memory, which doesnt have to remain same.

COMPONENTS

EMBEDDED PRODUCTS

INPUT SYSTEM

CONTROL LOGICS FEEDBACK/ERRO R CONNECTION Fig 1.1

OUTPUT SYSTEMS

1.2 CHARACTERISTICS OF EMBEDDED PRODUCTS:


Perform single set of functions. Works in 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 such as disk drives as they are less reliable as compared to solid state parts such as Flash memory.

1.3 APPLICATIONS:
Automatic teller machines(ATM). Avionics, such as inertial guidance systems, flight control hardware/software and other integrated systems in aircraft and missiles. Cellular telephones and telephone switches Engine controllers and antilock brake controllers for automobiles Home automation products, such as thermostats, air conditioners, sprinklers, and security monitoring systems Handheld calculators Household appliances, including microwave ovens, washing machines, television sets, DVD players Handheld computers videogame consoles Even computer peripherals themselves such as routers and printers have embedded processors.

1.4 EMBEDDED PRODUCTS IN TODAYS INDUSTRY:

TELECOM: Mobile phone systems (handsets and base stations), modems, routers.

AUTOMOTIVE APPLICATIONS: Braking systems, traction control, Airbag release systems, Engine-management units, Steer-by-wire systems,, Cruise control applications.

DOMESTIC APPLIANCES: Dishwashers, Televisions, Washing machines, Microwave ovens, Video recorders, Security systems, Garage door controller, Calculators, Digital watches, VCRs, digital cameras, Remote controls, Treadmills.

ROBOTIC: Fire fighting robot, Automatic floor cleaner, Robotic arm etc.

AEROSPACE APPLICATIONS: Flight control systems, Engine controllers, Autopilots, Passenger in-flight entertainment systems`

MEDICAL EQUIOMENT: An aesthesia monitoring systems, ECG monitors, Pacemakers, Drug delivery systems, MRI scanners

DEFENSE SYSTEMS:

Radar systems, Fighter aircraft flight control systems,

Radio systems, and missile guidance systems.

OFFICE AUTOMATION: laser printers, fax machines, pagers, cash registers, gas pumps, Credit/Debit card readers, Thermostats, Grain analyzers.

1.5 EMBEDDED SYSTEMS VS. GENERALCOMPUTING SYSTEMS:

An embedded system will have very few resources compared to GENERAL purpose computing systems like desktop computer. The memory capacity and processing power in an embedded system is limited. It is more challenging to develop an application in embedded system due to its constricted environment as compared to developing the same for a desktop system. Embedded system are dedicated to specific task. ES can be implemented using wide variety of processors, even generic or custom. Es are cost sensitive(but so are PC). Es operate have real time constraints. Es have environmental constraints (i.e. supposed to work in diverse environmental conditions). 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. 5

Chapter 2: MICRONTROLLER

2.1 INTRODUCTION
Microcontrollers are single chip computers. The Intel 8051 is a single chip microcontroller (C) which was developed by Intel in 1980 for use in embedded systems. Intel's original versions were popular in the 1980s and early 1990s, but has today largely been superseded by a vast range of faster and/or functionally enhanced 8051-compatible devices manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies (formerly Siemens AG), Maxim Integrated Products (via its Dallas Semiconductor subsidiary), NXP (formerly Philips Semiconductor), Winbond, ST Microelectronics, Silicon Laboratories (formerly Cygnal), Texas Instruments and Cypress Semiconductor. Intel's official designation for the 8051 family of Cs is MCS 51.Intel's original 8051 family was developed using NMOS technology, but later versions, identified by a letter "C" in their name, e.g. 80C51, used CMOS technology and were less power-hungry than their NMOS predecessors - this made them eminently more suitable for battery-powered devices.

2.2 IMPORTANT FEATURES AND APPLICATION

It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a single package.

8-bit data bus - It can access 8 bits of data in one operation (hence it is an 8-bit microcontroller). 16-bit address bus - It can access 216 memory locations - 64 kB each of RAM and ROM.

On-chip RAM - 128 bytes ("Data Memory"). On-chip ROM - 4 kB ("Program Memory"). Four byte bi-directional input/output port. UART (serial port). Two 16-bit Counter/timers. Two-level interrupt priority. Power saving mode. 6

A particularly useful feature of the 8051 core is the inclusion of a boolean processing engine which allows bit-level boolean logic operations to be carried out directly and efficiently on internal registers and RAM. This feature helped to cement the 8051's popularity in industrial control applications. Another valued feature is that it has four separate register sets, which can be used to greatly reduce interrupt latency compared to the more common method of storing interrupt context on a stack.The 8051 UART can be configured to use a 9th data bit that can provide addressable communications in an RS-485 multi-point communications

environment.8051 based microcontrollers typically include one or two UARTs, two or three timers, 128 or 256 bytes of internal data RAM (16 bytes of which are bit-addressable), up to 128 bytes of I/O, 512 bytes to 64 kB of internal program memory, and sometimes a quantity of extended data RAM (ERAM) located in the external data space. The original 8051 core ran at 12 clock cycles per machine cycle, with most instructions executing in one or two machine cycles. With a 12 MHz clock frequency, the 8051 could thus execute 1 million one-cycle instructions per second or 500,000 two-cycle instructions per second. Enhanced 8051 cores are now commonly used which run at six, four, two, or even one clock per machine cycle, and have clock frequencies of up to 100 MHz, and are thus capable of an even greater number of instructions per second. All SILabs, some Dallas and a few Atmel devices have single cycle cores.Even higher speed single cycle 8051 cores, in the range 130 MHz to 150 MHz, are now available in internet downloadable form for use in programmable logic devices such as FPGAs, and at many hundreds of MHz in ASICs, for example the netlist from

www.e8051.com.Common features included in modern 8051 based microcontrollers include built-in reset timers with brown-out detection, on-chip oscillators, self-programmable Flash ROM program memory, bootloader code in ROM, EEPROM non-volatile data storage, IC, SPI, and USB host interfaces, PWM generators, analog comparators, A/D and D/A converters, RTCs, extra counters and timers, in-circuit debugging facilities, more interrupt sources, and extra power saving modes.

PROGRAMMING:
Several C compilers are available for the 8051, most of which feature extensions that allow the programmer to specify where each variable should be stored in its six types of memory, and provide access to 8051 specific hardware features such as the multiple register banks and bit manipulation instructions. Other high level languages such as Forth, BASIC, Pascal/ 7

Object Pascal, PL/M and Modula 2 are available for the 8051, but they are less widely used than C and assembly.

BLOCK DIAGRAM OF MICROPROCESSOR BASED SYSTEM

Fig 2.1

A BLOCK DIAGRAM OF A MICROPROCESSOR

Arithmetic and Logic Unit

Accumulator Working Register (s)

Program Counter

Stack Counter

Clock Circuit

Interrupt Circuits

Contains no RAM, no ROM, no I/O port on chip, hence called generalPurpose microprocessor E.g., x86, 680x0, Pentium family Fig 2.2

MICROPROCESSOR vs. MICROCONTROLLER DIFFERENCE BETWEEN P & C


MICRPROCESSOR 1.Contains no on chip RAM, ROM, I/O, TIMER,Serial Port. 2. Used in General Purpose application.
3.

MICRCONTROLLER 1. Contains on chip RAM, ROM, I/O, TIMER, Serial port . 2. Used in Specific Purpose applications 3. Provides data storage facility. 4. The structure of uC is as given below
CPU RAM ROM

Dont provide data storage facility.

4. The structure of uP is as given below


CPU Gen eral R A M R O M
SE RIA L CO M

pur pos
e uP

I/ O

TI ME R

I/O TIMER SERIAL


COM

In short microcontroller can be defined as:

True computer on a chip Specific-purpose digital computers Design incorporates all the features of a microprocessor like ALU, PC, SP and registers along with RAM ROM, parallel I/O, serial I/O,, timers, clock circuits ADC etc

Types of microcontroller:
4 bit microcontroller 8 bit microcontroller 16 bit microcontroller 32 bit microcontroller

4 BIT MICROCONTROLLERS: It is the most popular microcontroller made in


terms of production. It is most economical and cheaper. It is mainly applicable to toys and small appliances

Manufacturer: Model Hitachi: HMCS40 National: COP42 OKI: MSM6411 TI: TMS 1000 Toshiba: TLCS47

Pins: I/O 28:10 28:23 16:11 28:23 42:35

Counters 1 2

RAM (bytes) 32 64 32 64 128

ROM (bytes) 512 1K 1K 1K 2K

Other features 10 bit ROM Serial bit I/O

LED display Serial bit I/O

Table 2.1

8 BIT MICROCONTROLLERS: IT represents the transition zone between


dedicated, high volume, 4 bit microcontrollers and the high performance 16 bit microcontrollers. 8-bit word size adequate for many computing tasks and control or monitoring applications it is applicable to simple appliances control, high speed machine control, data collection etc. 10

Manufacturer: Model

Pins: I/O

Counters

RAM (bytes)

ROM (bytes)

Other features

Intel : 8048 Intel : 8051 Microchip: PIC16C56 National : COP820 Motorola : 6805 Motorola : 68HC11 Rockwell : 6500/1 Philips : 87C552 Zilog : Z8 Zilog : Z86C83

40:27 40:32 18:12 28:24 28:20 52:40 40:32 68:48 40:32 28:22

1 2 0 1 1 2 1 3 2 2

64 128 25 64 64 256 64 256 128 256

1K 4K 1K 1K 1K 8K 2K 8K 2K 4K

Ext memory to 8K Ext memory to 128K;serial port 25/20 ma sink/source; WDT serial bit I/O

serial ports; ADC; WDT

serial port; ADC; WDT Ext memory to 124K; serial port 8-channel AD; very low cost

Table 2.2

16 BIT MICROCONTROLLERS: It provides faster and more sophisticated


calculations. It is applicable to control of servomechanisms like robot arms.

Manufacturer: Model
Hitachi:H8/532

Pins: I/O
84:65

Counte RAM rs
5 1K

ROM (byte s)
32K

Other features

Ext memory to 1M; serial port; A/D; PWM Ext memory to 64K; serial port; A/D; PWM; WDT Ext memory to 64K; serial port; A/D; PWM

Intel:80C196

68:40

232

8K

National:HPC1616 4

68:52

512

16K

Table 2.3

32 BIT MICROCONTROLLERS: The design emphasis is more on high speed


computation features and not on chip features like RAM, ROM, and Timers etc. it is applicable to robotics, highly intelligent instrumentation, avionics, image, processing,

telecommunications, automobiles Example: Intel 80960, ARM

11

Hardware features 132 Pin ceramic package 20 MHz clock 32 Bit bus Floating point unit 512 Byte instruction cache

Software features efficient procedure calls Fault handling capability Trace events Global registers efficient interrupt vectors

Table 2.4

2.3 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 In 2005, the 8051 microcontroller celebrated it's 25th anniversary. Intel introduced a Single-chip processor, the 4004, in 1971. It was a 4-bit microprocessor, with whopping processing speed of 100 thousand operations per second, and was meant for an electronic calculator. There is a lot of 4-bit processing in calculators, especially if the software is based on BCD arithmetics.Later Intel introduced the 8-bitter 8008 and it's grown-up brother - the famous 8080 (which then was perfected by an ex-Intel employee as Ziploc Z80, one of the best 8-bit microprocessors of all times). In 1976, Intel introduced its first microcontroller, 8048. It integrated the processing core with code and data memory and certain peripherals. The code memory was a 1kB mask ROM (defined by the last metallization mask during the chip processing) or EPROM (after all, Intel invented EPROM), the data memory was 64 bytes of RAM (including the 8-level stack and two pages of eight general purpose registers). Besides general-purpose I/O (see below), peripherals included a timer and an external interrupt (plus the necessary interrupt system).Although the 8048 is clearly an 8-bit architecture, it is said to be an ancestor of the 4-bit 4004 Rather than the 8080. Also it is said to bear remarkable similarities to Fairchild F8 microprocessor. Today, it is hard to say whether something of this is true, but one thing is sure, the 8048 has a Couple of strange features. Using four of its general purpose input/output ports, and adding one or more 8243-type chip - and the I/O expand into another four 4-bit ports. This expansion has not only support in the hardware - dedicated pins on 8048 - but also in the instruction set, 12

having dedicated instructions for I/O operations (including AND OR(!)) via the expander. The 8048 already had a lot of useful features known well to 8051-users: external code memory support; external data memory support (inherently only 256 bytes addressed indirectly by R0 and R1 as there is no 16 bit pointer register such as the DPTR in 8051 - the 8051 inherited this 8-bit external data access); quasibidirectional I/O ports. Maximum clock is 11MHz, but an instruction cycle takes 15 oscillator clocks. The "A" version (advanced) introduced power down mode there were multiple variations of the 8048 around, mostly with different numbering, but generally denoted as the MCS-48 family. 8048 itself denoted a mask-ROM part, 8748 an EPROM part -windowed (CERDIP - erasable) for development, and unwind owed (PDIP) OTP. The rimless part was a bit surprisingly marked 8035 (probably most of the parts sold as rimless were parts with unusable ROM, due to error in the "programmed" firmware). There was a low-cost version with reduced pin count and omitted some of the features as 8021, and versions with more ROM and RAM as 8049 (2kB ROM/128B RAM) and 8050 (4kB ROM/256B RAM); with Rimless versions as 8039 and 8040; and 8049 had also an EPROM version 8749 (the funny thing is, that 8749 came in 1981, one year after 8051/8751). 8048's were second sourced by a number of manufacturers, including NEC, Toshiba, and were cloned also behind the then iron curtain in Czechoslovakia (Tesla MHB8048/8035) and USSR. Application specific versions of 8048 were also built quite early, with adding of various peripherals, such as 8-bit ADC in 8022 and a parallel bus slave interface in 8041/8042.The MCS-48 family was used in a quite wide range of applications. One of the first applications of 8048 was in a gaming console (Magnavox Odyssey2), but there were also more "serious Applications, for example in one of the first car engine "computerized" control units. But the Biggest hit came when IBM decided to use 8048 in its original PC keyboard. Although in the AT keyboard IBM used the (presumably cheaper) 6805, it used 8042 as a co processor on the main board, communicating with the keyboard (and performing a few other specific tasks in Memory management). The 8042 is still present in almost each and every PC even today, but don't search for a chip with "8042" on it - it is integrated in the chipset. It may come as a surprise to somebody, but thanks to this fact the 8048 with its derivatives is most probably the most widespread microcontroller at all. As in the 70s there were no PDF-s and no world-wide web, datasheets and other documentation is Hardly available over the internet. I believe Intel will give out a copy if one really. wants it (there is a "literature request" form at their "museum" pages). However, there seems to be a couple of Enthusiastic people, one of the maintaining a wonderful document called Grokking the MCS-48 System at http://home.mnet-online.de/al/mcs-48/mcs-48.pdf. 13

STANDARD FEATURES OF 8051 MICROCONTROLLER:

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 Introduced by Intel Corporation in 1981 as MCS 51.

Main features of MCS 51:

Feature ROM RAM Timer I/O Pins Serial port Interrupt sources Quantity 4K bytes 128 bytes 2 32 1 6

Table 2.5 Intel allowed other manufacturers to make and market any version of 8051 depending upon the speed and on chip ROM. All versions code compatible Other members of the 8051 family: 8052, 8031.

14

COMPARISON OF 8051 FAMILY MEMBERS:

Feature ROM RAM (bytes) Timers I/O Pins Serial Port Interrupt Sources

8051 4K 128 2 32 1 6

8031 0K 128 2 32 1 6

8052 8K 256 3 32 1 8

Table 2.6

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 fast Development.

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.

15

8051 FAMILY FROM PHILIPS: One of the largest selections of 8051


microcontrollers, various features like ADC, DAC, extended I/O, both OTP and flash.

2.4 CONCEPT OF FLASH MEMORY:


Compared to the earlier implementations, today's Flash memories usually require less complex programming algorithms and they are now divided into several sectors. The benefit of having sectors is that the Flash memory is sector-erasable, meaning you can erase one sector at a time. In the past, erase commands erased the entire memory chip - therefore to keep a working copy of that data during run-time, an application required additional memory. Since Flash memory is integrated on-chip with microcontrollers, its usage became even easier. Having Flash memory and a microcontroller on the same chip opened up the opportunity to take advantage of the "additional intelligence" With the 89C51Rx2 microcontrollers, Philips Semiconductors created a variety of 8051 derivatives with on-chip Flash memory that take best advantage of having a combination of microcontroller and Flash memory on one chip. Philips did this by providing an additional ROM area containing code for handling the Flash programming. The code does not only provide functions to erase or program the Flash memory, it also provides boot code - even with a completely erased Flash, the chip can still execute this boot code and accept inputs via the serial port. Being ROM, this code area is not erasable; applications can rely on it as always being there. It can be used for recovery of a system, by downloading new code into the Flash memory via the serial port. Because of this feature, this code is also referred to as "boot loader".

16

Fig 2.3

8052 MICROCONTROLLER: It has all the features of 8051 along with extra 128 bytes
of RAM, a timer and extra 4K bytes of on chip ROM. 8051 is an upward compatible to 8052.

8031 MICROCONTROLLER: It has ROM-less 8051 which contains 0K bytes of on


chip ROM. An external memory must be added to make it functional.

MICROCONTROLLER (AT89S52): The AT89S52 is an upgraded version of the


micro controller 8051. the main features of 8051 are given as under:8051 micro controller has 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four ports (each 8 bits wide) all on a single chip. The 8051 is an 8-bit processor i.e. the CPU can work on only 8 bits of data at a time. The fixed amount of on-chip ROM, RAM, and number of I/O ports in microcontroller makes them ideal for many applications in which cost and space are critical.

17

FEATURES OF THE AT89S52:


Feature
ROM RAM Timer I/O pins Serial port Interrupt sources 1 6

Quantity
4K bytes 128 bytes 2 32

The only differences in 89S52 and 8051 is that of on-chip ROM and RAM, timers and interrupts. Both the micro controllers are based on the high power CISC architecture of INTELMCS-51.

2.5 8051 ARCHITECTURE:


The 8051 family is one of the most common microcontroller architectures used worldwide. 8051 based microcontrollers are offered in hundreds of variants from many different silicon manufacturers. The 8051 is based on an 8-bit CISC core with Harvard architecture. The 8051 family is one of the most common microcontroller architectures used worldwide. 8051 based microcontrollers are offered in hundreds of variants from many different silicon manufacturers. The 8051 is based on an 8-bit CISC core with Harvard architecture.

18

BLOCK DIAGRAM OF C 8051:

EXTERNAL ONCHI P FLA SH ETC. ON CHIP RAM TIMER1 COUNTER INPUT

INTERRU

CPU
SERIAL PORT

OSC

BUS CONTRO

4 I/O PORTS

P0 P2 P1 P3 ADDRESS/DA TA

TXD RXD

Fig 2.4

19

PIN DIAGRAM:

P1.0 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 GND

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

Vcc P0.0 (AD0) P0.1 (AD1) P0.2 (AD2) P0.3 (AD3) P0.4 (AD4) P0.5 (AD5) P0.6 (AD6) P0.7 (AD7) EA/VPP ALE/PROG 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)

Fig 2.5

PIN DESCRIPTION
Port 1- Pins (1-8)
Input/output pins Contains internal pull-ups. :

Port 3- Pins (10-17)


Input/output pins. Contains internal pull-ups. Alternate functions to provide signals such as interrupts.

20

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.

PSEN- (pin 29)


Active low input

: Program store enable

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.

Fig 2.6 21

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)
Active high input.

: Reset

Terminate all activities of uc. Sets PC to 0. Requires minimum 2 machine cycles.

VCC - (pin 40) GND (pin 20)

22

C2 XTAL2 30 pF

C1 XTAL1 30 pF GND

Fig 2.7

23

CRYSTAL CONNECTION TO AN EXTERNAL CLOCK SOURCE

NC

XTAL2

EXTERNALSIGNAL

XTAL1

GND

Fig 2.8

MEMORY ORGANISATION:
Program Memory Data Memory

PROGRAM MEMORY:
Begins from location 0000h. Each interrupt is assigned a fixed Location in it (0000-0023H). Directly addressable space of Up to 64k bytes. To access external programme Memory, A pin is used. 24

DATA MEMORY:

FFFFH EXTERNAL INTERNAL FFH


INDIRECT ADDRESSING

64K

7FH
DIRECT / INDIRECT ADDRESSIN

OOH

0000 RD WR

Fig 2.9

25

7F 30 2F 20 18 17 10 0F 08 07 R7 R6 R5 R4 R3 R2 R1 00 R0 Fig 2.10 INTERNAL DATA MEMORY Lower 128 bytes : FF. . . . . . . . . F8 07. . . . . . . . . 00 REGISTER BANK 3 REGISTER BANK 2 REGISTER BANK 1

END of RAM

00H- 7FH

Four register banks Bit addressable area General purpose area

: : :

00H to 1FH 20H to 2FH 30H to 7FH

SFR address space

80H to FFH

8051 REGISTERS:
General purpose registers Special function registers

General purpose registers:


26

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 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.

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. Full instruction set including: Arithmetic Instruction Logical Instruction Branching Instruction Data movement Instruction 27

Variety of addressing modes. 6 interrupt sources.

SPECIAL FUNCTION REGISTERS: CPU REGISTER:


ACC -B : Accumulator. : B registers.

- PSW : Program Status Word. - SP : Stack Pointer.

- DPTR : Data Pointer (DPH, DPL).

INTERRUPT CONTROL:
-IE -IP : Interrupt Enable. : Interrupt Priority.

- P1 - P2 - P3

- P0

: Port 0. I/O PORT:

: Port 1. : Port 2. : Port 3.

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

28

SERIAL I/O:
- SCON : Serial port control. - SBUF : Serial data registers.

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.

PSW: Program Status Word


CY AC F0 RS1 RS0 OV ---- P

CY F0 : user). RS1 Select 1. RS0 OV P

Carry Flag.

Flag 0 (available for : Registr

: : :

Register Select 0. Arithmetic Overflow Flag. Accumulator Parity Flag.

29

STACK OPERATION
After POP 0C 0B 0A 72 54 76 0B 0A 54 76 0A 76 0B 0A 39 76 After POP After PUSH 39

09 08

43 6C

09 08

43 6C

09 08

43 6C

09 08

43 6C

Start SP = 0CH

SP = 0BH

SP = 0AH

SP = 0BH

Fig 2.11

SP: Stack Pointer


8- bit Register used to store the address of the top Of stack. As the data is pushed in the stack, the stack pointer will Increment. As the data id popped from the stack, the stack pointer will Decrement. Effected by subroutine call, Interrupt triggering & PUSH, POP instruction.

DPTR: Data Pointer


16- bit Register used to store the address of the 8-bit data in program memory. Consist of a high byte (DPH) and a low byte (DPL). 30

May be manipulated as a 16 bit register or as two Independent 8-bit registers. Used in Index addressing mode.

DPH

DPL

TMOD: Timer Mode Register

GATE

C/T

M1

M0

GATE C/T

M1

M0

Timer 1

Timer 0

GATE: Permits IN TX 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. 10: 8-bit auto-reload mode 11: Timer 0 = two 8-bit timers.
Timer 1 Counting disabled. Timing function allowed. It can be used as Baud Rate generator.

TIMER MODE:
Timer Mode 0 : Emulates 8048 counter/timer (13-bits). 8-bit counter (TL0 or TL1). 5-bit presales (TH0 or TH1). Timer Mode 1 :

Simple 16-bit counter.

31

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

: Auxiliary Carry Flag.

TCON: Timer Control Register

TF1

TR1

TF0 TR0 IE1

IT1

IE0

IT0

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.

SCON: Serial Control Register

SMO

SM1

SM2 REN TB8 RB8 TI

RI

SM0, SM1 = Serial Mode: 00 = Mode 0 01 = Mode 1 : Shift register I/O expansion. : 8-bit UART with variable baud rate. 32

10 = Mode 2

: 9-bit UART with fixed baud rate. : 9-bit UART with variable baud rate.

11 = Mode 3 - 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. - 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.

2.9 IE: Interrupt Enable Register

EA EA ES ET1 EX1 ET0 EX0

----

----

ES

ET1

EX1

ET0

EX0

: Global interrupt enable. : Serial interface. : Timer 1. : External interrupts 1. : Timer 0. : External interrupts 0.

0 = Disabled. 1 = Enabled.

IP: Interrupt Priority Register

-----

-----

----- PS

PT1 PX1 PT0 PX0


33

PS PT1 PX1 PT0 PX0

: Serial interface. : Timer 1. : External interrupts 1. : Timer 0. : External interrupts 0.

0 = Low priority 1 = High Priority.

PCON: Power Control Register

SMOD

----

----

----

GF1 GF0 PD

IDL

POWER DOWN OPERATION


Setting PD bit stops oscillator. 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.

34

MACHINE LANGUAGES:

A program that consists of0s and 1s is called a machine language Deals directly with the internal structure of microprocessor and microcontroller CPU can work only in machine language

ASSEMBLY LANGUAGES:

.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 special format.


[LABEL] mnemonics operand [COMMENT]

Label:

Better understanding than machine language

Name of a label should be meaningful giving the reflection of the code functionality. E.g. (LED_ON: Label indicates the switch ON the LED) First character should be an alphabet. No. character should not be more than 8 characters. Reserve words must not be used as label.

MNEMONIC AND OPERAND:


Mnemonics are assembly opcodes specific to E.g. MOV, ADD, RLC The operand can be data or address

Mnemonics can be of 1 byte or more.

35

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

HIGH LEVEL LANGUAGES:

The language whose instruction set is more compatible with human languages and
human thought processes

HLL offers three significant advantages over machine/assembly language.


SIMPLICITY.UNIFORMITY.PROBABILITY

HLL the programmer need not to be concern with internal detail of microprocessor
and microcontroller

2.10 ADDRESSING MODES:


The various ways of addressing the data are called addressing modes. Immediate Addressing mode Register addressing mode Direct addressing mode Register indirect addressing mode Indexed addressing mode

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 locations. MOV 30H, #23H MOV A, #25H MOV R0, #65H

36

REGISTERS ADDRESSING MODES:


Involves the use of registers to hold the data to be manipulated.

MOV A, R0 MOV R1, A MOV A, R6

DIRECT ADDRESSING MODE:


The data in the RAM memory location and whose address is known. The address is given as apart of instruction

MOV 30H, A MOV R0, 24H MOV A, 28H

: Save content of A in RAM

REGISTER INDIRECT ADDRESSING MODES:


A register is used as a pointer to the data. As the register hold the address of RAM location they must be proceeded by @ sign. Only register R0, R1 are used for this purpose.

MOV A, R0; into A.

Move the content of Ram location whose address is Held by R0

MOV @R1, B; Move contents of B into RAM location whose address is held by R1.

INDEXED ADDRESSING MODE:

Used in accessing data elements of look-up table located in ROM space. The 16-bit register DPTR and ACC are used to form the address of data element stored
on a chip ROM.

The instruction used foe this purpose is MOV A, @A+DPTR.


37

2.11 TYPES OF INSTRUCTION:


Arithmetic Logic Data Transfer Branching

Arithmetic instructions

Mnemonic

Operands

Bytes/cycle

ADD ADDC SUBB

A, Rn A, direct A, @ RI A, #Data

1/1 2/1 1/1 2/1

INC DEC

A Rn Direct @ RI

1/1 1/1 2/1 2/1

INC MUL DIV DA

DPTR AB AB A

1/2 1/4 1/4 1/1

38

LOGIC INSTRUCTIONS:

Mnemonic

Operands

Bytes/Cycle

ANL ORL XRL

A, R A, direct A,@Ri A, #data Direct, A Direct, #data C, bit C, /bit

1/1 2/1 1/1 2/1 2/1 3/2 2/2 2/2 1/1 1/1 2/1 1/1 1/1 1/1 1/1 1/1

CLR CPL

A C Bit

RL RLC RRC SWAP SETB

A A A A C

DATA TRANSFER INSTRUCTION:

Mnemonic

operands

Bytes/Cycles

MOV

A, Rn A, direct A, @ RI A, #data Rn, A

1/1 2/1 1/1 2/1 1/1

39

Rn, direct

2/2 Rn, #data Direct, A Direct, Rn Direct, direct Direct, @ RI Direct, #data 3/2 1/2 1/2 2/2 2/2 1/1 1/1 3/2 2/2 2/1 2/1 2/2

MOVC

A, @ A+DPTR A, @ A+PC

PUSH POP XCH XCHD

Direct direct A, Rn A,@ Ri

2.12 PROGRAMMING TOOLS:

EDITOR: It provides the facility to write the programs and then immediate assemble
or compile the program. It gives us the facility to create new text, open existing text and save the written text.

ASSEMBLER:
number of files.

Assembler is software which convert assembly language program

into machine language program called object code. After assembling it generates a

Asm file---lst file---Obj file---Link file---Hex file ASSEMBLING A PROGRAM:


The program developed by the programmer is stored as asm file. The assembler converts the source file into machine code and produce an object file and list file. The linker links all the object files and produces link files. The link file is fed into an OH (object to hex converter) which creates a hex file. The hex file is programmed into the ROM.

40

COMPILER:
A compiler is a program that translates a high level language program to machine level language instructions A compiler may use an assembly language as an intermediate step in the translation or may translate the program directly to machine code After assembling the code it generates a number of files like c file, asm file, lst file, obj file, rel file, link file, hex file etc depending on the compiler. The most popular microcontroller compilers are SDCC, READS, (PIC), PL/M, from Intel and many more,

PROGRAMMER:
Programmer is a device used to program the hex file generated by assembler/compiler into ROM of microcontroller.

SIMULATOR: It is a program which provides the facility to step through the code to see exactly what is happening as the program runs. The contents of register or variable can altered to change the way the program runs. A simulator cant support real interrupts or devices.

DEBUGGER: It is a tool that is used to help identify and fix problems in a program. It supports step by step execution of the code and viewing the contents of code variables. It allows monitoring of registers memory and program statements.

EMULATOR: an emulator is a sophisticated device that pretends that pretends that it is the
microprocessor itself, while at the same time capturing information. The emulator can either be a stand alone device. with its own display, or it can be a interface to a PC. It makes us assure that the hardware is performing accordingly or not.

41

2.13 IGHT EMITTING DIODES (LED):

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. Collected together, they can form images on a jumbo television screen or illuminate a traffic light. Basically, LEDs are just tiny light bulbs that fit easily into an electrical circuit. But unlike ordinary incandescent bulbs, they don't have a filament that will burn out, and they don't get especially hot. They are illuminated solely by the movement of electrons in a semiconductor material, and they last just as long as a standard transistor.

2.14 PHOTO DIODE:


Photodiode are efficient light detectors that can be made small sizes, good linearity, and high response speed. Photodiode converts light into an electrical signal. Photodiode are faster than photoconductor because they have a pn junction to collect the carriers. Photo dictions mechanism in photodiodes is similar to that in photoconductor in that an electron-hole pair is created by a Photon for which hv>=Eg but it differs in that only the photo carrier That diffuse to the depletion layer are counted and only the minority carriers are collected.

2.15 POWER SUPPLY:


In alternating current the electron flow is alternate, i.e. the electron flow increases to maximum in one direction, decreases back to zero. It then increases in the other direction and then decreases to zero again. Direct current flows in one direction only. Rectifier converts alternating current to flow in one direction only. When the anode of the diode is positive with respect to its cathode, it is forward biased, allowing current to flow. But when its anode is negative with respect to the cathode, it is reverse biased and does not allow current to flow. This unidirectional property of the diode is useful for rectification. A single diode arranged back-to-back might allow the electrons to flow during positive half cycles only and suppress the negative half cycles. Double diodes arranged back-to-back might act as full wave rectifiers 42

as they may allow the electron flow during both positive and negative half cycles. Four diodes can be arranged to make a full wave bridge rectifier. Different types of filter circuits are used to smooth out the pulsations in amplitude of the output voltage from a rectifier. The property of capacitor to oppose any change in the voltage applied across them by storing energy in the electric field of the capacitor and of inductors to oppose any change in the current flowing through them by storing energy in the magnetic field of coil may be utilized. To remove pulsation of the direct current obtained from the rectifier, different types of combination of capacitor, inductors and resistors may be also be used to increase to action of filtering.

NEED OF POWER SUPPLY:


Perhaps all of you are aware that a power supply is a primary requirement for the Test Bench of a home experimenters mini lab. A battery eliminator can eliminate or replace the batteries of solid-state electronic equipment and the equipment thus can be operated by 230v A.C. mains instead of the batteries or dry cells. Nowadays, the use of commercial battery eliminator or power supply unit has become increasingly popular as power source for household appliances like Tran receivers, record player, cassette players, digital clock etc.

2.16 RELAYS:
In industrial application we need to isolate one circuit electrically from another, while still allowing the first circuit to control the second. The way of providing electrical isolation between two circuits is to place a relay between them.

A relay consists of a coil, which may be energized by the low-voltage circuit, and one or more sets of switch contacts, which may be connected to the high-voltage circuit.

Fig 2.12

43

HOW RELAYS WORK:


When a relay is off, the metal arm is at its rest position and so there is contact between the Normally Closed (N.C.) switch contact and the 'common' switch contact.

If a current is passed through the coil, the resulting magnetic field attracts the metal arm and there is now contact between the Normally Open (N.O.) switch contact and the common switch contact.

Metal arm Coil Energized coil

Coil contacts

N.C. contact

Common contact

N.O. contact

There is contact between the common and N.C. contacts

There is now contact between the common and N.O. contacts

The mechanical operation of a relay

Fig 2.13

44

2.17 CRYSTAL OSCILLATORS:


Crystal oscillators are oscillators where the primary frequency determining element is a quartz crystal. Because of the inherent characteristics of the quartz crystal the crystal oscillator may be held to extreme accuracy of frequency stability. Temperature compensation may be applied to crystal oscillators to improve thermal stability of the crystal oscillator. A practical example of a Crystal Oscillator:

Fig 2.14

Fig - Schematic of a Crystal Oscillator

Crystal oscillators are usually, fixed frequency oscillators where stability and accuracy are the primary considerations. For example it is almost impossible to design a stable and accurate LC oscillator for the upper HF and higher frequencies without resorting to some sort of crystal control. Hence the reason for crystal oscillators. This is a typical example of the type of crystal oscillators which may be used for say converters. 45

Some points of interest on crystal oscillators in relation to figure:


The transistor could be a general purpose type with a Ft of at least 150 MHz for HF use. A typical example would be a 2N2222A. The turns ratio on the tuned circuit depicts an anticipated nominal load of 50 ohms. This allows a theoretical 2K5 ohm on the collector.

2.18 OPTOCOUPLERS DESCRIPTION:

The MCT2XXX series opt isolators consist of a gallium arsenide infrared emitting diode driving a silicon phototransistor in a 6-pin dual in-line package.

Fig 2.15 There are many situations where signals and data need to be transferred from one subsystem to another within a piece of electronics equipment, or from one piece of equipment to another, without making a direct electrical connection. Often this is because the source and destination are (or may be at times) at very different voltage levels. Relays provide this kind of isolation, but even small relays tend to be fairly bulky compared with ICs and many of todays other miniature circuit components. Because theyre electromechanical, relays are also not as reliable and only capable of relatively low speed operation. Where small size, higher speed and greater reliability are important, a much better alternative is 46

to use an optocoupler. These use a beam of light to transmit the signals or data across an electrical barrier, and achieve excellent isolation. Optocouplers typically come in a small 6-pin or 8-pin IC package, but are essentially a combination of two distinct devices: an optical transmitter, typically a gallium arsenide LED (light-emitting diode) and an optical receiver such as a phototransistor or lighttriggered diac. The two are separated by a transparent barrier which blocks any electrical current flow between the two, but does allow the passage of light. The basic idea is shown in Fig.1, along with the usual circuit symbol for an optocoupler.

Fig 2.16

Usually the electrical connections to the LED section are brought out to the pins on one side of the package and those for the phototransistor or diac to the other side, to physically separate them as much as possible. This usually allows optocouplers to withstand voltages of anywhere between 500V and 7500V between input and output. Optocouplers are essentially digital or switching devices, so theyre best for transferring either on-off control signals or digital data. Analog signals can be transferred by means of frequency or pulse-width modulation. 47

How theyre used:


Basically the simplest way to visualize an opt coupler is in terms of its two main components: the input LED and the output transistor or diac. As the two are electrically isolated, this gives a fair amount of flexibility when it comes to connecting them into circuit. All we really have to do is work out a convenient way of turning the input LED on and off, and using the resulting switching of the phototransistor/ diac to generate an output waveform or logic signal that is compatible with our output circuitry. An optocouplers drive input LED from a transistor or logic gate/buffer. All thats needed is a series resistor to set the current level when the LED is turned on, as shown in Fig.2. This means we can arrange for the LED, and hence the optocoupler, to be either on or off for a logic high (or low) in the driving circuitry.

Fig 2.17 In some circuits, there may be a chance that at times the driving voltage fed to the input LED could have reversed polarity (due to a swapped cable connection, for example). This can cause damage to the device, because optocoupler LEDs tend to have quite a low reverse voltage rating: typically only 3 - 5V. So if this is a possibility, a reversed polarity diode should be connected directly across the LED as shown in Fig.3.

48

Fig 2.18

FEATURES:

UL recognized (File # E90700). VDE recognized (File # 94766). Add option V for white package (e.g., MCT2V-M). Add option 300 for black package (e.g., MCT2.300). MCT2 and MCT2E are also available in white package by specifying -M suffix, eg. MCT2-M.

APPLICATIONS:

Power supply regulators. Digital logic inputs. Microprocessor inputs.

49

Chapter 3: BIBILIOGRAPHY

WEBSITES
www.electronics-tutorials.com www.electroniccircuits-diagrams.com 2006 www.epanorama.net/links/telephone.html www.tapiex.com/link.htm www.gisdevelopment.net/application/miscellaneous/ma03192.html www.google.com www.8052.com

50

PREFACE
Engineering student gain theoretical knowledge only through their book. Only theoretical knowledge is not sufficient or absolute mastery in any field. It has been experienced that theoretical knowledge is volatile in nature, however practical knowledge make solid foundation in our mind. For the purpose board of technical education, Haryana has pre-scribed a practical training in various industries. So, that we may get more knowledge of Electronics & Communication. The policy behind the practical training is not only to provide the self-job but also produce more technical crops in the country to make the nation developed. So that there will be less import costly advanced technology.

iii

Das könnte Ihnen auch gefallen