Arsh Preet Singh

44
A PROJECT REPORT  ON  EMBEDDED SYSTEM SUMMER TRAINING  AT LOTUS EDUCATION Patiala  SUBMI TTED BY :- SUBMITTED TO:- ECE DEPTT. BHAWANPREET SINGH MAND 008816119245[8263] E.C.E. – 3 (M) RIMT-Mandi Gobindgarh  

Transcript of Arsh Preet Singh

Page 1: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 1/44

A

PROJECT REPORT 

 

ON 

  EMBEDDED SYSTEM

SUMMER TRAINING 

 AT 

LOTUS EDUCATION

Patiala

 

SUBMITTED BY :- SUBMITTED TO:- ECE 

DEPTT.

BHAWANPREET SINGH MAND

008816119245[8263] 

E.C.E. – 3(M)

RIMT-Mandi Gobindgarh 

Page 2: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 2/44

CONTENTS

 

MICROCONTROLLER & EMBEDDED SYSTEM

1.The 8051 Microcontrollers

(a) TYPES OF MICROCONTROLLER

(b) IMPORTANT FEATURES AND APPLICATION

2. EMBEDDED SYSTEM

3. I/O PORT

(a) PORT 0

(b) PORT 1

(c) PORT 2

(d) PORT 3

4. 8051 Addressing Modes

5.Arithmetic & Logic Instructions

(a) CHECKSUM

6. 8051 Programming in C

(a) SIGNED & UNSIGNED CHAR

7. 8051 Timer/Counter Programming in C

8. 8051 Interfacing to External Memory

(a) ROM(READ ONLY MEMORY)

(b) RAM(RANDOM ACCESS MEMORY)

9. LCD and Keyboard Interfacing

Page 3: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 3/44

COMPANY PROFILE

Introduction

With the arrival of 21st Century the world has moved towards another 

renaissance with communication technologies merging with

information technologies and in not so distant future with consumer 

electronics.

In the rapidly developing filed of telecommunications, Punjab

Communications Limited(PUNCOM)has been taking giant strides tobridge the gap between information processing and mobility,

permitting the society to share the benefits of information age.

PUNCOM is one of the India's premier communication and

information technology company. It has a turnover of around 35

million USD, a significant installed base of telecom solution. In India

plus client base, which covers almost every major industrial and

infrastructure segment in India, located most modern city Chandigarh.

Page 4: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 4/44

PUNCOM has one of India's most sophisticated manufacturing and

software development facilities. It initially started of as a single

product venture, now has transformed into a multi product company,

manufacturing a wide range of sophisticated multiplexing switches

and transmission products providing total telecommunication solution

to customers. Puncom also offers a wide range of software packages

customized for communication products.

PUNCOM mission is to provide technologically superior products and

services of high quality on time cost effectively and consistently to

achieve investors and most important customers' confidence.

Consistent track record of high productivity and its strong financial;

position has made MNCS vie for equity of PUNCOM at various times.

Page 5: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 5/44

Potential Venture In Technology 

PunCom's mission is continuous advancement in the areas of 

communication and information technology industry encompassing

telecommunications, software constancy, and voice processing.

Puncom has one of India's most sophisticated manufacturing and

software development facilities. For this purpose, the manufacturingfacilities are equipped with the latest state-of -art machines like:

Automated SAD Assembly Lines

Multiplayer PCB Assembly Lines

Wave Soldering Machines

Telecomm Protocol Analyzers

 About Telecom Division

Page 6: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 6/44

Anticipating the future and understanding its technological crossroads

and freeways is a strong PUNCOM trait. Over a period of time,

PUNCOM has conceived, designed and developed a range of highly

sophisticated telecom products and during the process equipped with

expertise of the higher class. These products are well researched in

meeting the needs of the specific target, segment and quickly

creating a niche for them.

 

Since the inception in 1981 the telecom division has been the

backbone of the company. PUNCOM today has one of the best

manufacturing facilities in India. It has 2,50,000 Sq. ft. of air-

conditioned space, full backup power, Automated SMT assembly

lines, and wave soldering machines.

Company R &D is engaged in the development of new technologies

to meet the ever-growing communication need. Besides, a number of 

new technology tie-ups are at advanced stage.

Page 7: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 7/44

 About Software division

In 1989,PUNCOM had set up its Information System Division(ISD)

foreseeing the convergence of telecom and company

technologies.This division has since accumulated valuable skills and

experience through implementation of diverse range of information

technology projects for the domestic and international market.

PUNCOM ISD has following technology group to address the current

and future needs of the domestic and international software markets.

Internet Group

Computer Telephony Integration GroupNetwork Management System(NMS) Group

Firmware (DSP's micro controllers assembly) Group

RDBMS Group

Page 8: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 8/44

As an acknowledgment of our premier position on the software maps

of Punjab, the government of Punjab has asked to associate in

setting up the software park(STP),to accelerate the growth of 

software development industry in this part of the country.

Major Activities

The company has the following major areas of activities:

• Manufacturing

• Equipment supply and after sales services

• System Design and engineering

• Education and turnkey projects involving field maintenance

• Survey, Installation commissioning and annual maintenance

contacts

• Research and Development

• Training

• Constancy in system and network Planning

• Customized software solution

Page 9: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 9/44

Technological Alliances

The international business community’s trust on PUNCOM as a valuable

partner is amply demonstrated by the long list of technology alliances we

have, among these are

Daewoo Corp., South Korea

CIT ALCAREL, France

ECI Telecom, Israel

MICOM, USA

MULTIPOINT, UK

ARE, ITALY

DSC Comm., USA

KOKUSAI Electronics Co., Japan

MATRA Macron Pace, USA

HITRON, Twain

ANT BOSCH, Germany

Manufacturing Facilities

Puncom has highest precision automatic & semiautomatic machinery

and testing instruments. In all functional areas of manufacturing.

State of the art technology is combined with the most sophisticated

manufacturing processes to make products tha. These processes

have given some of our products a service life of well over a hundred

Page 10: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 10/44

years thereby a setting new standards in product quality.

Product Portfolios

In its endeavor to create technologically sound state of art products,

the company earlier had collaborations with some of the world's

reputed named in the telecommunications like Granger Associates,

USA,ARE Italy and India's very own C-DOT. Recently the company

has entered into collaborations with ECI Telecom of Israel for 

advanced SDH Equipment M/s Dana phone A/s for mobile

Communication Equipment and Exartech of Twain for gain

equipment.

PUNCOM has strong product portfolios, which cover all the aspects

of the telecom market. Few of these are mentioned below:

Switching Products:

• Electronics Private Automatics Branch Exchange with direct

Inward dialing facility(128/256 parts)

Rural Automatics Exchange(128/256 parts)• Medium Size Digital Exchange(400 to 1500 lines)

• Large Size Digital Exchange (1500 to 10,000 lines)

• Remote Switching Units(RSU)

Page 11: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 11/44

List of Clients:

Department of Telecommunications(DOT)(Indian PTT)

Mahanagar Telephone Nigam Limited(MTNL)

Videsh Sanchar Nigam Limited(VSNL)

Indian Railways

Indian Oil Corporation(IOC)

National Thermal Power Corporation(NTPC)

Steel Authority of India(SAIL)

Bharat Electronics Limited(BEL)

State Electronics Undertakings

Konkan Railways Corporation Limited

Defence Services

Meltron

Page 12: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 12/44

 

PunCom and its Clients

The reputation for excellence has extended to selected 

customers in Europe and Middle East as well. The

company has today a total of 48 specific clients in India

and abroad.

PLATFORM AND ENVIRONMENTS 

DOS, UNIX, SUN OS, Windows 98, Windows NT, LINUX, QNX,

Novell Network Databases, Oracle, Sybase (Replication Server,

SQL Server and Open Server), MS Access, Clipper Languages

C, C++, Assembly, FORTRAN Front Ends, Developer 2000,

Power Builder, Visual Basic, Delphi, Visual C++, Case Tool

Page 13: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 13/44

Designer 2000, S-Designer GIS map info, Map Basic Internet

Post Script, HTML, JAVA, CGI, Perl Network, TMN are the

most commonly used platforms and environments which the

PunCom uses for its production.

Expertise

Application Software

Manufacturing Solution

Financial Institution

Power System

education & Examination Institutions

Process Industry

Sales & Distribution

KEY STRENGTH 

400 Employee including 250 engineers

Air-conditioned assembly.

Standby captive power generation: 3 Mw.

Capital equipment: US$11.2 MILLON.

Capability: bit rate -- 2.5 Gbit/s

Frequency -- 40 GHz

Assembly lines: SMT -- two

Conventional -- three

Page 14: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 14/44

Most peaceful work force

Sales in India: 99%, exports: 1%

Turn-Key Products

Mobile train radio for railway

Optical fiber and mobile radio for gas authority of India Limited

Microwave/UHF radio for DOT , railway , defence

Optical fiber system for railway

MAX-L digital exchange unto 3.5k capacities for DOT

Circle level maintained contrast

Acceptance testing for GSM mobile network

PLCC & VSS-2100 network for power Grid Corporation of India Ltd.

Key Activities

Equipment design and Development

Equipment assembly & distribution

Contract assembly

Equipment integration, testing

Field installation

Maintain Contracts

Equipment Repair 

Page 15: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 15/44

Software Design & development

Quality Assurance

Quality assurance plan is an integral part of each project carried out

at PUNCOM. The quality checks are carried out at all stages of 

manufacturing i.e. receipt ,assembly and testing . Puncom has

climatic and vibration testing facilities.

In recognition of sterling quality of its products as well as the entire

manufacturing processes, Puncom has been awarded ISO 9002

Certification for its ongoing products in multiplexing ,switching and

radio fields and has been awarded ISO 9001 Certification for its

product for software design and development.

Research & Development 

The entrepreneurial process of translating business opportunity into

results has helped PAL design and capture voice processing in

the market. In order to match the present product to the various

needs of the customers, research, and development develops new

products that meet the needs of the customers. These products are

Page 16: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 16/44

developed in the manner that is highly cost effective and competitive.

Company R & D is engaged in development of new technologies to

meet the ever growing communication needs. Besides, a number of 

new products and tie ups are at an advance stage.

 After sale service & Training 

The company has established in house repair center in order toprovide effective servicing facilities, for ensuring minimum down

time .The company also imparts training to its customers ,which

involve familiarizing them with installation ,commissioning and trouble

shooting procedure for carrying out their maintenance activities.

HRD

The company lays stress on progressive human resource

management with a strong emphasis on training and development

both in India and abroad.

Exports

With the proven excellent performance ,quality and low cost products

Page 17: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 17/44

have found strong potential in the developing countries .Our export

strength is right from equipment supply to providing turn key of 

equipment .The company has exported RAXs to Nepal

telecommunication Corporation ,Trans-MUX ETISALAT, UAE and

DTL to ARE, Italy.

Page 18: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 18/44

MICROused in pers

microcont

containing

Page 19: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 19/44

8051

The Intel

microcont

in embedd

Page 20: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 20/44

Types

As of 200

and vendo

Page 21: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 21/44

MPOR

It provides

logic, time

•  -

Page 22: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 22/44

MBED

An embed

one or a fe

computing 

Page 23: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 23/44

1. MICROPROCESSOR & MICROCONTROLLER 

▪ General-Purpose microprocessors

Contains

-No RAM

-No ROM

-No I/O ports

▪ Microcontroller has

-CPU

▪Microco -RAM

-ROM

-I/O ports

-Timer 

-ADC and other peripherals

Page 24: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 24/44

3. In put / Out put PORT :

The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins

All the ports upon RESET are configured as input, ready to be used

as input ports.

●When the first 0 is written to a port, it becomes an output

● To reconfigure it as an input, a 1 must be sent to the port

●To use any of these ports as an input port, it must be programmed

● It can be used for input or output, each pin must be connected

externally to a 10K ohm pull-up resistor.

(a) PORT - 0 

●This is due to the fact that P0 is an open

drain, unlike P1, P2, and P3 Port 0 is also designated as AD0-

AD7,allowing it to be used for both address and data.

(a) PORT – 1

● Port 1 can be used as input or output

● In contrast to port 0, this port does not need any pull-up resistors

since it already has pull-up resistors internally.

Page 25: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 25/44

(b) PORT – 2 

● Port 2 can be used as input or output

● Just like P1, port 2 does not need any pull-up resistors since it

already has pull-up resistors internally

(c) PORT – 3

● Port 3 can be used as input or output

●Port 3 does not need any pull-up resistors

▪ In reading a port 

● Some instructions read the status of port pins

● Others read the status of an internal port latch

● Therefore, when reading ports there are two possibilities:

● Read the status of the input pin

● Read the internal latch of the output port

● Confusion between them is a major source of errors in 8051

programming

● Especially where external hardware is Concerned

● The ports in 8051 can be accessed by the Read-modify-write

technique

●This feature saves many lines of code by combining in a single

instruction all three actions

1. Reading the port

Page 26: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 26/44

2. Modifying it

3. Writing to the port

4. 8051 ADDRESSING MODES  

- The CPU can access data in various ways, which are called

addressing modes

- Immediate

- Register 

- Direct

- Register indirect

- Indexed

●The bit-addressable RAM location are 20H to 2FH

● These 16 bytes provide 128 bits of RAM bit-addressability,

since 16 × 8 = 128 ƒ 0 to 127 (in decimal) or 00 to 7FH

● The first byte of internal RAM location 20H has bit address 0 to

7H

● The last byte of 2FH has bit address 78H to 7FH

● Internal RAM locations 20-2FH are both byte-addressable and

bit-addressable

Page 27: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 27/44

● Bit address 00-7FH belong to RAM byte addresses 20-2FH

● Bit address 80-F7H belong to SFR P0, P1, …

● While all of the SFR registers are byte-

addressable, some of them are also bit-addresable

● The P0 – P3 are bit addressable

● We can access either the entire 8 bits or any single bit of I/O

ports P0, P1, P2, and P3 without altering the rest

● When accessing a port in a single-bit manner, we use the syntax

SETB X.Y

● X is the port number P0, P1, P2, or P3

● Y is the desired bit number from 0 to 7 for data bits D0 to D7

ex. SETB P1.

● In many applications, the size of program code does not leave any

room to share the 64K-byte code space with data.

- The 8051 has another 64K bytes of memory space set aside

exclusively for data storageƒ This data memory space is referred to

as external memory and it is accessed only by the MOVX instruction

● The 8051 has a total of 128K bytes of memory space - 64K bytes of 

code and 64K bytes of data-The data space cannot be shared

between code and data.

● Indexed addressing mode is widely used in accessing data

elements of look-up table entries located in the program ROM.

●The instruction used for this purpose is MOVC A,@A+DPTR

Page 28: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 28/44

● Use instruction MOVC, “C” means code

● The contents of A are added to the 16-bit register DPTR to form

the 16-bit address of the needed data

5 sets bit 5 of port 1 high

The 8052 has another 128 bytes of on-chip RAM with addresses 80 –

FFH

It is often called upper memory ƒ Use indirect addressing mode,

which uses R0 and R1 registers as pointers with values of 80H

or higher – MOV @R0, A and MOV @R1, A

The same address space assigned to the

SFRs ƒ Use direct addressing mode

 – MOV 90H, #55H is the same as MOV P1, #55H

5.ARITHMETIC & LOGIC INSTRUCTIONS 

●The instruction ADD is used to add two operands

● Destination operand is always in register A

● Source operand can be a register,immediate data, or in memory

Page 29: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 29/44

●The instruction ADD is used to add two operands

● Destination operand is always in register A

Source operand can be a register, immediate data, or in memory

● Memory-to-memory arithmetic operations

are never allowed in 8051 Assembly

language

▪ In unsigned number addition, we must

monitor the status of CY (carry)

● Use JNC or JC instructions

● In signed number addition, the OV

(overflow) flag must be monitored by

the programmer 

●JB PSW.2 or JNB PSW.2

● To make the 2’s complement of a

number 

●CPL A ;1’s complement (invert)

●ADD A,#1 ;add 1 to make 2’s comp.

● To make the 2’s complement of a

number 

●CPL A ;1’s complement (invert)

●ADD A,#1 ;add 1 to make 2’s comp.

●CPL A ;complements the register A

●This is called 1’s complement

● To get the 2’s complement, all we

have to do is to to add 1 to the 1’s

complement

Page 30: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 30/44

●MOV A, #55H

●CPL A ;now A=AAH

●;0101 0101(55H)

●;becomes 1010 1010(AAH

●The actions of comparing and jumping

are combined into a single instruction

called CJNE (compare and jump if not

equal.

●The CJNE instruction compares two

●operands, and jumps if they are not equal

Page 31: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 31/44

(a) CHECKSUM 

To calculate the checksum byte of a series of bytes of data

Add the bytes together and drop the carries.

Take the 2’s complement of the total sum, and it becomes the last

byte of the series. To perform the checksum operation, add all the

bytes, including the checksum byte.

The result must be zero.

If it is not zero, one or more bytes of data have been changed. Many

ADC (analog-to-digital converter)

chips provide output data in binary (hex).

To display the data on an LCD or PC screen, we need to convert it to

ASCII ƒ Convert 8-bit binary (hex) data to decimal digits, 000 – 255ƒ

Convert the decimal digits to ASCII digits, 30H – 39H

Page 32: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 32/44

6. 8051 PROGRAMMING IN C 

Compilers produce hex files that is

downloaded to ROM of microcontroller 

● The size of hex file is the main concern

ƒ Microcontrollers have limited on-chip ROM

ƒ Code space for 8051 is limited to 64K bytes

●C programming is less time consuming,

but has larger hex file size

●The reasons for writing programs in C

● It is easier and less time consuming to

write in C than Assembly

● C is easier to modify and update

● You can use code available in function

libraries

● C code is portable to other microcontroller 

with little of no modification.

The character data type is the most

natural choice

● 8051 is an 8-bit microcontroller 

Unsigned char is an 8-bit data type in

the range of 0 – 255 (00 – FFH)

● One of the most widely used data types

for the 8051

ƒ Counter value

Page 33: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 33/44

ƒ ASCII characters

C compilers use the signed char as the

default if we do not put the keyword

unsigned.

(a) SIGNED & UNSIGNED CHAR 

●The signed char is an 8-bit data type

● Use the MSB D7 to represent – or +

●Give us values from –128 to +127

●We should stick with the unsigned char 

unless the data needs to be

represented as signed numbers

temperature.

Write an 8051 C program to send values of –4 to +4 to port P1.

Solution:

Singed numbers

#include <reg51.h>

void main(void)

{

char mynum[]={+1,-1,+2,-2,+3,-3,+4,-4};

unsigned char z;

for (z=0;z<=8;z++)

P1=mynum[z];

}

Page 34: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 34/44

●The unsigned int is a 16-bit data type

● Takes a value in the range of 0 to 65535

(0000 – FFFFH)

● Define 16-bit variables such as memory addresses

● Set counter values of more than 256

● Since registers and memory accesses are in 8-bit chunks, the

misuse of int variables will result in a larger hex file

●There are two ways to create a time delay in 8051 C

● Using the 8051 timer 

● Using a simple for loop

be mindful of three factors that can affect the accuracy of the delay

ƒ The 8051 design

 – The number of machine cycle

 – The number of clock periods per machine cycle

ƒ The crystal frequency connected to the X1 – X2

input pinsƒ Compiler choice

 – C compiler converts the C statements and

functions to Assembly language instructions

 –  Different compilers produce different code.

Write an 8051 C program to get a byte of data form P1, wait 1/2

second, and then send it to P2.

Solution:

#include <reg51.h>

void MSDelay(unsigned int);

Page 35: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 35/44

void main(void)

{

unsigned char mybyte;

P1=0xFF; //make P1 input port

while (1)

{

mybyte=P1; //get a byte from P1

MSDelay(500);

P2=mybyte; //send it to P2

}

}

●One of the new features of the 8052 was an extra 128 bytes of RAM

space

● The extra 128 bytes of RAM helps the 8051/52 C compiler to

manage its registers and resources much more

effectively

● We compile the C programs for the 8052 microcontroller 

● Use the reg52.h header file

● Choose the8052 option when compiling the program.

●Serializing data is a way of sending a byte of data one bit at a time

through a single pin of microcontroller 

●Using the serial port (Chap. 10)

● Transfer data one bit a time and control the sequence of data and

spaces in between them

Page 36: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 36/44

ƒ In many new generations of devices such as

LCD, ADC, and ROM the serial versions are

becoming popular since they take less space on a PCB.

7. TIMER/COUNTER:-

● The 8051 has two timers/counters, they can be used either as

● Timers to generate a time delay or as

●Event counters to count events happening outside the

microcontroller 

Both Timer 0 and Timer 1 are 16 bits wide

● Since 8051 has an 8-bit architecture, each

16-bits timer is accessed as two separate registers of low byte and

high byte.

Page 37: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 37/44

●Accessed as low byte and high byte

● The low byte register is called TL0/TL1

and

●The high byte register is called TH0/TH

●Accessed like any other register 

ƒ MOV TL0,#4FH

ƒ MOV R5,TH0

●Both timers 0 and 1 use the same register, called TMOD (timer 

mode), to set the various timer operation modes

●TMOD is a 8-bit register 

●The lower 4 bits are for Timer 0

●The upper 4 bits are for Timer 1

●To generate a time delay

1. Load the TMOD value register indicating

which timer (timer 0 or timer 1) is to be

Page 38: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 38/44

used and which timer mode (0 or 1) is

selected

2. Load registers TL and TH with initial count

value

3. Start the timer 

4. Keep monitoring the timer flag (TF) with

the JNB TFx,target instruction to see

if it is raised

ƒ Get out of the loop when TF becomes high

5. Stop the timer 

6. Clear the TF flag for the next round

7. Go back to Step 2 to load TH and TL

Again.

●Timers can also be used as counters counting events happening

outside the8051

●When it is used as a counter, it is a pulse outside of the 8051 that

increments the TH, TL registers

● TMOD and TH, TL registers are the same as for the timer 

discussed previously.

Page 39: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 39/44

●To speed up the 8051, many recent versions of the 8051 have

reduced the number of clocks per machine cycle from 12 to four, or 

even one

●The frequency for the timer is always

1/12th the frequency of the crystal

Attached to the 8051, regardless of the 8051 version.

Example -

A switch is connected to pin P1.2. Write an 8051 C program to

monitor SW and create the following frequencies on pin P1.7:

SW=0: 500Hz

SW=1: 750Hz, use Timer 0, mode 1 for both of them.

Solution:

#include <reg51.h>

sbit mybit=P1^5;

sbit SW=P1^7;

void T0M1Delay(unsigned char);

Void main (void) {

SW=1;

while (1) {

mybit=~mybit;

if (SW==0)

T0M1Delay(0);

else

T0M1Delay(1);

}

}

Page 40: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 40/44

8. 8051 INTERFACING TO EXTERNAL MEMORY  :-

● The number of bits that a semiconductor memory chip can store

is called chip capacity.

● It can be in units of Kbits (kilobits), Mbits (megabits), and so on

● This must be distinguished from the storage capacity of 

computer systems.

● While the memory capacity of a memory IC chip is always given

bits, the memory capacity of a computer system is given in bytes

ƒ 16M memory chip – 16 megabits

ƒ A computer comes with 16M memory – 16 Megabytes

One of the most important characteristics of a memory chip is the

speed at which its data can be accessed.

● To access the data, the address is presented to the address pins,

the READ pin is activated, and after a certain amountof time has

elapsed, the data shows up at the data pins.

● The shorter this elapsed time, the better,and consequently, the

more expensive the memory chip

● The speed of the memory chip is commonly referred to as its

access time

(a) ROM (READ ONLY MEMORY)

ROM is a type of memory that does not

lose its contents when the power is

turned off 

Page 41: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 41/44

● ROM is also called nonvolatile memory

There are different types of read-only

memory

● PROM

● EPROM

● EEPROM

● Flash EPROM

●Mask ROM

(b) RAM (RANDOM ACCESS MEMORY)

RAM memory is called volatile memory since cutting off the power 

to the IC will result in the loss of data

● Sometimes RAM is also referred to as RAWM (read and write

memory), in contrast to ROM, which cannot be written to

There are three types of RAM

● Static RAM (SRAM)

●NV-RAM (nonvolatile RAM)

●Dynamic RAM (DRAM)

The CPU provides the address of the data desired, but it is the job

of the decoding circuitry to locate the selected memory block

● Memory chips have one or more pins called CS (chip select), which

must be activated for the memory’s contents to be access.

9. LCD AND KEYBOARD INTERFACING:-

Page 42: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 42/44

LCD is finding widespread use

replacing LEDs

● The declining prices of LCD

● The ability to display numbers, characters, and graphics

● Incorporation of a refreshing controller into the LCD, thereby

relieving the CPU of the task of refreshing the LCD

● Ease of programming for characters and Graphics

Keyboards are organized in a matrix of rows and columns

● The CPU accesses both rows and columns through ports

Therefore, with two 8-bit ports, an 8 x 8 matrix of keys can be

connected to a microprocessor 

● When a key is pressed, a row and a column make a contact

Otherwise, there is no connection between rows and columns

In IBM PC keyboards, a single microcontroller takes care of 

hardware and software interfacing.

A 4x4 matrix connected to two ports

●The rows are connected to an output port and the columns are

connected to an input port

It is the function of the microcontroller to scan the keyboard

continuously to detect and identify the key pressed.

To detect a pressed key, the microcontroller grounds all rows by

Providing 0 to the output latch, then it reads the columns

Page 43: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 43/44

● If the data read from columns is D3 – D0 = 1111, no key has been

pressed and the process continues till key press is detected

● If one of the column bits has a zero, this means that a key press

has occurred.

For example, if D3 – D0 = 1101, this means that a key in the D1

column has been pressed.

Starting with the top row, the microcontroller grounds it by

providing a low to row D0 only

● It reads the columns, if the data read is all 1s, no key in that row is

activated and the process is moved to the next row

It grounds the next row, reads the columns, and checks for any

zero

● This process continues until the row is identified

After identification of the row in which the key has been pressed.

BIBLOGRAPHY

Page 44: Arsh Preet Singh

8/8/2019 Arsh Preet Singh

http://slidepdf.com/reader/full/arsh-preet-singh 44/44

1. The 8051 Microcontroller 

and Embedded System By: Muhammad Ali Mazidi

2. Microcontroller and

Embedded System By: Deepak Arora

3. Embedded System By: Jack Ghossle

4. Programming 16 Bit

Microcontrollers in C By: Luclo Dl. Jaslo

5. PICAXE Microcontroller By: David Lincolin

6. MSP430 Microcontroller 

Basics By: John H. Davies