You are on page 1of 92

PICK AND PLACE ROBOT USING RFID

MajorMajor-project
Submitted in partial fulfillment of the requirements for the award of the degree of

BACHELOR OF TECHNOLOGY
In

Electronics and Communication Engineering


By
V.RANADHEER
K.ESHWARCHAND
T.ROHIT KUMAR
M.VINUTHAN
K.RAJESH

(09474T1509)
(09474T1516)
(09474T1508)
(09474T1512)
(09474T1507)

Under the guidance of


Mr. B. RAMPRASAD.
Assistant Professor

Department of Electronics & Communication Engineering

WARANGAL INSTITUE OF TECHNOLOGY AND SCIENCE


(Approved by AICTE New Delhi Affiliated to Kakatiya University, Warangal)
Mdl: Atmakur, Dist. Warangal 506 342

WARANGAL INSTITUE OF TECHNOLOGY AND SCIENCE


(Approved by AICTE New Delhi Affiliated to Kakatiya University, Warangal)
Mdl: Atmakur, Dist. Warangal 506 342

Department of Electronics & Communication Engineering

BONAFIDE CERTIFICATE

Certified that the project MICRO CONTROLLER BASED PICK AND


PLACE ROBOT is the bonafide work of . who carried out
the project under my supervision from May to June in partial fulfillment of the
requirements for the award of B.Tech Electronics &Communication Engineering to
Kakatiya University, Warangal.
Certified further, that to the best of my knowledge the work reported here in does
not form part of any dissertation on basis of which a degree was conferred on an earlier
occasion on this or any other candidate.
Internal Guide
Mr.B.RAMPRASAD
Assistant Professor
Department of ECE

Head of the Department


Mr.M.PRANAY
Professor & HOD
Department of ECE

DECLARATION

The project entitled PICK AND MOVE ROBOT is a record of the bonafide
work undertaken by us towards partial fulfillment of the award of
Degree of Bachelor of Technology. The results in this project work have not been
submitted to any other University or Institute for the award of any Degree or Diploma.

V.RANADHEER
K.ESHWARCHAND

(09474T1509)
(09474T1516)

T.ROHIT KUMAR
M.VINUTHAN
K.RAJESH

(09474T1508)
(09474T1512)
(09474T1507)

ABSTRACT

Library has many connotations. A library is a collection of information resources


and services, organized for use, and maintained by a public body, institution, or private
individual. In the more traditional sense, it means a collection of books.

Typically we need a librarian to pick the books and hand it over to the person to
whom the books are being issued. This might be an easy task incase the library floor area
is small. Also, to search for the books by humans takes a lot of time as many a times the
books gets overlooked by the human eye.

To automate this process of book finding and picking we suggest a robot with an
arm with some degrees of freedom which will be able to findout the book with the
required tag and then pick it and place it on the table.
Here we will be placing the books in a rack and all the books will be tagged by
RFID tags and an RFID reader will be placed under the robot. The robot will perform a
brute force method search and incase the book is found, the robotic arm will lower until
the IR obstacle sensor placed over the arm detects the book and then the gripper will close
the jaws to get an hold of the book and then the robotic arm is lifted after which the robot
moves in the reverse direction to the place it started from and places the book.
The same principal can be used in the supermarkets to make an automated item
collector.

In this case, the proposed robot will make the life of the librarian a lot simpler and
the books can be tagged easily. The essential requirement in this project is the correct
designing and fabrication of the lever, connecting Arms, motors, the gripping mechanism
and the load bearing capacities.

ACKNOWLEDGEMENT
First and foremost, our sincere thanks to MR.M.PRANAY Head of the department
of Electronics and Communication Engineering, Warangal Institute Of Technology &
Science for providing this opportunity to carry out the present project work and for her
encouragement and advice during the course of this work.
We indebted to our internal project guides Mr.B.RAMPRASAD, Mr.T.SUNIL
KUMAR, Assistant Professors of Electronics and Communication Engineering, for his
excellent guidance, constant inspiration and encouragement in the completion of this
dissertation.
We would like to express our thanks to all the Faculty members, Staff of
Department of Electronics & Communication Engineering, who have rendered valuable
help in making this project a successful one.

ABSTRACT

In this modern society now a days, there are a lot of research have been done to develop a high
technology stuff. One of them is robotic. Robot now a days helping people a lot in everyday works.
Most of work done by people had been replaced by robot especially in industry. All the robot
applications today are also include robot application in library. This will help all the book arrangement
since now a days all the big library having almost hundred thousands of books and sometimes millions
of it. In this project the robot had been design to have movements such as, taking book and
transferring it.

ix

TABLE OF CONTENTS

CHAPTER

TITLE

TITLE PAGE
DECLARATION
DEDICATION

iv
v
vii

ABSTRAK

viii

ABSTRACT

viiii
xi

LIST OF TABLES

xiiii

LIST OF FIGURES

xiv

LIST OF ABBREVIATIONS

xvi

LIST OF SYMBOLS

xvii

LIST OF APPENDICES

iiii

ACKNOWLEDGEMENT

TABLE OF CONTENTS

PAGE

xviii

INTRODUCTION

1.1

Background Study

1.2

Project Objectives

1.3

Problem Statement

1.4

Scope of Works

1.5

Thesis Outline

LITERATURE REVIEW

x
2.1

Library Robot

2.2

Robot Arms

2.2.1 Degrees of Freedom (DOF)

2.2.2 Mobile Manipulators

Solenoid

2.3

2.4

2.5

2.3.1 How Solenoids Work

10

2.3.2 Electromechanical solenoids

11

2.3.3 Push and Pull Type Solenoids

12

2.3.4 Solenoid Applications

12

Electrical Component

13

2.4.1 Capacitors

13

2.4.2 Diodes

15

Motors

17

2.5.1 DC Motors

17

2.5.1.1 Speed

17

2.5.1.2 Torque

18

2.5.1.3 Pulse Width Modulation

18

2.5.2 Stepper Motors

19

2.5.3 Servo Motors

19

2.5.4 DC Motor Braking

20

2.5.4.1 Controls Method

20

2.5.4.2 Mechanical Method

21

2.5.4.3 Electronic Method

21

2.6

Radio-frequency identification (RFID)

22

2.7

RFID in Libraries

23

2.8

Infrared Light Emitting Diode (IR LED)

25

2.9

Photodiodes

26

2.10 PIC 16F877A Microcontroller

27

2.10.1 Device Overview

28

2.10.2 Memory Organization

29

2.11 Programming Tools

29

2.11.1 MPLAB IDE

29

2.11.2 Tiny Bootloader

30

xi
3

METHODOLOGY AD APPROACH

3.1
3.2

31

Project Overview

31

3.1.1 Library Robot Overview

32

Material Selection

33

3.2.1 Motor

33

3.2.1.1 Geared Motor

33

3.2.1.1 Power Window Motor

34

3.2.2 Electronic Component

35

3.2.3 Frame

35

3.2.4 Other Material

36

3.3 Electronic Design

38

3.3.1 Power Supply

38

3.3.2 Reset Circuit

39

3.3.3 Crystal Oscillator Circuit

40

3.3.4 IR Sensor

41

3.3.5 Relay

43

3.3.6 PIC18F4520 Port Usage

44

3.4 Hardware Development

45

3.4.1 Circuit Development

45

3.4.2 Frame Development

46

3.5

Motor Allocation

49

3.6

Motor Intersection

50

3.7

Mechanism Movement

51

3.8

Line Following

53

3.8.1 Base for Line Following

53

3.8.2 Line Following Sensor

54

3.8.3 Theory of Operation

54

3.8.4 Sensor Placement

56

Other Designs

57

3.9

3.10 Software Development

58

xii
4

RESULT AND DISCUSSION

60

4.1

Result

60

4.2

Discussion

61

4.2.1 The Whole Robot

61

4.2.2 Electronic Circuit

63

4.2.3 Mechanism

65

4.2.4 Line Following

65

CONCLUSION

5.1 Suggestion For Future Work

68

69

REFERENCES

70

APPENDIX

71

xiii

LIST OF TABLES

TABLE NO.

TITLE

PAGE

Table 2.1: PIC18F4520 device features

10

Table 3.1: List of components for robot circuit

12

Table 3.2: List of components for power supply circuit

16

Table 3.3: List of components for reset circuit

17

Table 3.4: List of components for crystal oscillator circuit

20

Table 3.5: List of components for first circuit for transmitter

21

Table 3.6: List of components for receiver

23

Table 3.7: List of components for relay

24

Table 3.8: PIC18F4520 Port Usage

25

Table 3.8: List of components for power supply unit

26

Table 3.9: PIC 16F877A port usage

27

xiv

LIST OF FIGURES

FIGURE NO.

TITLE

PAGE

Figure 2.1: CAPM robot

Figure 2.2: Conveyor robot

Figure 2.3: Library robot

Figure 2.4: Robot arm with multi degree I

Figure 2.5: Robot Arm with multi degree II

Figure 2.6: Robot arm with one degree

Figure 2.7: Mobile manipulators

Figure 2.8: Solenoid

Figure 2.9: Principle of solenoid I

10

Figure 2.10: Principle of solenoid II

11

Figure 2.11: Capacitor I

14

Figure 2.12: Capacitor II

15

Figure 2.13: Diodes

15

Figure 2.14: Diode working principle

16

Figure 2.15: Motor

20

Figure 2.16: Motor relay

21

Figure 2.17: The pin diagrams of PIC 18F4520

27

Figure 3.1: Robot overview

32

Figure 3.5: DC geared motor

33

Figure 3.3: Power window motor

34

Figure 3.4: Aluminum

36

Figure 3.5: Polyethylene

37

Figure 3.6: Wheel

37

Figure 3.7: Hard board

37

Figure 3.8: Fishing Cord

38

xv
Figure 3.9: Schematic of Power Supply

39

Figure 3.10: Schematic of Reset Circuit

40

Figure 3.11: Schematic of Crystal Oscillator Circuit

41

Figure 3.12: Circuit design for transmitter

41

Figure 3.13: Circuit design for receiver

42

Table 3.14: List of components for relay

43

Figure 3.15: Circuit Implemented

46

Figure 3.16: Circuit back view

46

Figure 3.17: The basic frame

47

Figure 3.18: Gripper design

48

Figure 3.18: Gripper design

48

Figure 3.19: Gripper from top view

48

Figure 3.20: Location of power window

49

Figure 3.21: Location of DC geared motor

50

Figure 3.22: Motor intersection

51

Figure 3.23: The fishing cord tied with PE

52

Figure 3.24: Connection between PE, motor and fishing cord

52

Figure 3.25: Line following base

53

Figure 3.26: Light reflecting off a white and black surface

55

Figure 27: Top view of a robot uses three pairs of emitter and detector sensors for
line following

56

Figure 3.28: Sensor location

57

Figure 3.29: Battery and circuit location

58

Figure 3.30: Flow chart

59

Figure 4.1: Robot grip book

62

Figure 4.2: Robot extending upward and backward

63

Figure 4.3: Direction for line following

66

Figure 4.4: Custer and rubber location

66

Figure 4.5: Line following programming

67

xvi

LIST OF ABBREVIATION

CPU

- Central Processing Unit

EEPROM

- Electrically Erasable Programming ROM

G%D

- Ground

I/O

- Input /Output

IR

- Infrared

IR LED

- Infrared Light Emitting Diode

MCU

- Microcontroller Unit

PIC

- Peripheral Interface Controller

PCB

- Printed Circuit Board

ROM

- Read Only Memory

PE

- Polyethylene

xvii

LIST OF SYMBOLS

Farad

Pico

Nano

MHz

Mega hertz

Ohm

D.O.F

Degree of Freedom

DC

Direct Current

Micro

Voltage

xviii

LIST OF APPENDICES

APPENDIX

TITLE

PAGE

APPENDIX A Progamming Source Code

70

APPENDIX B Data sheet and Manual

72

CHAPTER 1

INTRODUCTION

1.1 Background Study

Nowadays, robot is widely used to complete human task. Most of industry are using robot to
increase their production. Many researchers are working in this field to get a variety robot to fulfill
human needs. As we know in this era of globalization reading become the most important part in daily
life. Libraries become the important place for some community. This phenomenon leads the some library
to have a lot of books and the numbers of books can reach millions sometimes. Because of too many
books we need a better management to handle all this books. Library helper robot is the best technology
that can give a better way in handling all the books. Since the labour costs are increasing nowadays it is
the suitable time to have this library robot to replace a librarian.

1.2 Project Objectives

There are four objectives that have been set for this project. The first objective is to design and develop a
library robot that can pick out grip and transfer

2
the books. The second objective is to improve the arms and the stability of the previous project gripper. For
the third objective is to design it more practically and the last objective is to develop implement the
application of RFID.

1.3 Problem Statements

For the previous project in library robot design there some unpractical usage for lifting books. For
that robot we have to put the books to the robot to move it to somewhere else and lack of stability.
Improvement will be made in this problem and the arms also can take the stack books. The problem may
occur if there is different size or different weight. This problem maybe can be countered by put all the
books details through the barcodes and the RFID will sense all the details.

1.4 Scope of Works

In this project the scopes can be divided by three parts. The first part is to design and build the
hardware. The hardware part included design the arm, the pusher and the frame. The second part is to
design and develop the circuitry for the mechanical parts. For the last part is to develop the software.
There is two area of developing the software which is programming the PIC and programming the RFID.

3
1.5

Thesis Outline

The thesis is divided into four main chapters which are:

i.

Introduction
This chapter consists of the introduction and some reviews of the background of the project.

ii.

Literature Review
This chapter discusses the details of software and hardware that are used in the project.

iii.

Methodology and Approach


This chapter explains the implementation of project.

iv.

Result and Discussion


This chapter contains result of project, project discussion, constrain during project development
and future improve for this hardware project.

v.

Conclusion
This chapter concludes the entire project of Design and Develop a Library Robot.

CHAPTER 2

LITERATURE REVIEW

This chapter explains the research that has been studied in the hardware and software development
in designing Design and Develop a Library Robot.

2.1

Library Robot

A robot is a mechanical or virtual, artificial agent. It is usually an electromechanical system,


which, by its appearance or movements, conveys a sense that it has intent or agency of its own. The word
robot can refer to both physical robots and virtual software agents.

Researchers in the Digital Knowledge Center of the Milton S. Eisenhower Library have
developed, in cooperation with engineers from the Whiting School of Engineering, a working prototype
of a library retrieval robot, which is called Comprehensive Access to Print Materials, or CAPM.

5
As more and more print materials are moved to off site storage facilities, research universities face
the challenge of maintaining large collections of materials, while maintaining access by library users. The
CAPM robot, which can now retrieve materials from a test storage shelf and deliver it to a scanning bed,
will one day be able to retrieve and scan materials, based on users' requests. Here the picture in Figure
2.1 [1].

Figure 2.1: CAPM robot

Other example of library robot is using conveyor system. Here the picture in Figure 2 how
this library having this kind of robot.

Figure 2.2: Conveyor robot

In Figure 3 shows another example of library robot.

Figure 2.3: Library robot

8051 Architecture

8051 ARCHITECTURE:
The generic 8051 architecture supports a Harvard architecture, which contains
two separate buses for both program and data. So, it has two distinctive memory spaces of
64K X 8 size for both programmed and data. It is based on an 8 bit central processing
unit with an 8 bit Accumulator and another 8 bit B register as main processing blocks.
Other portions of the architecture include few 8 bit and 16 bit registers and 8 bit
memory locations.
Each 8051 device has some amount of data RAM built in the device for internal
processing. This area is used for stack operations and temporary storage of data.
This bus architecture is supported with on-chip peripheral functions like I/O ports,
timers/counters, versatile serial communication port. So it is clear that this 8051
architecture was designed to cater many real time embedded needs.
FEATURES OF 8051 ARCHITECTURE


Optimized 8 bit CPU for control applications and extensive Boolean processing
capabilities.

64K Program Memory address space.

64K Data Memory address space.

128 bytes of on chip Data Memory.

32 Bi-directional and individually addressable I/O lines.

Two 16 bit timer/counters.

Full Duplex UART.

6-source / 5-vector interrupt structure with priority levels.

On chip clock oscillator.


Now we may be wondering about the non-mentioning of memory space meant for the
program storage, the most important part of any embedded controller. Originally this
8051 architecture was introduced with on-chip, one time programmable version of
Program Memory of size 4K X 8. Intel delivered all these microcontrollers (8051) with
users program fused inside the device. The memory portion was mapped at the lower
end of the Program Memory area. But, after getting devices, customers couldnt change
any thing in their program code, which was already made available inside during
device fabrication.

BLOCK DIAGRAM OF 8051

Figure 4.1 - Block Diagram of the 8051 Core

So, very soon Intel introduced the 8051 devices with re-programmable type of
Program Memory using built-in EPROM of size 4K X 8. Like a regular EPROM, this
memory can be re-programmed many times. Later on Intel started manufacturing these
8031 devices without any on chip Program Memory.

MICROCONTROLLER LOGIC SYMBOL

ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address during
accesses to external memory. ALE is emitted at a constant rate of 1/6 of the oscillator frequency,
for external timing or clocking purposes, even when there are no accesses to external memory.
(However, one ALE pulse is skipped during each access to external Data Memory.) This pin is
also the program pulse input (PROG) during EPROM programming.
PSEN : Program Store Enable is the read strobe to external Program Memory. When the device
is executing out of external Program Memory, PSEN is activated twice each machine cycle
(except that two PSEN activations are skipped during accesses to external Data Memory). PSEN
is not activated when the device is executing out of internal Program Memory.
EA/VPP: When EA is held high the CPU executes out of internal Program Memory (unless the
Program Counter exceeds 0FFFH in the 80C51). Holding EA low forces the CPU to execute out
of external memory regardless of the Program Counter value. In the 80C31, EA must be
externally wired low. In the EPROM devices, this pin also receives the programming supply
voltage (VPP) during EPROM programming.
XTAL1: Input to the inverting oscillator amplifier.
XTAL2: Output from the inverting oscillator amplifier.

The 8051s I/O port structure is extremely versatile and flexible. The device has 32 I/O
pins configured as four eight bit parallel ports (P0, P1, P2 and P3). Each pin can be used
as an input or as an output under the software control. These I/O pins can be accessed
directly by memory instructions during program execution to get required flexibility.
These port lines can be operated in different modes and all the pins can be made to
do many different tasks apart from their regular I/O function executions. Instructions,
which access external memory, use port P0 as a multiplexed address/data bus. At the
beginning of an external memory cycle, low order 8 bits of the address bus are output
on P0. The same pins transfer data byte at the later stage of the instruction execution.
Also, any instruction that accesses external Program Memory will output the
higher order byte on P2 during read cycle. Remaining ports, P1 and P3 are available for
standard I/O functions. But all the 8 lines of P3 support special functions: Two external
interrupt lines, two counter inputs, serial ports two data lines and two timing control
strobe lines are designed to use P3 port lines. When you dont use these special
functions, you can use corresponding port lines as a standard I/O. Even within a single
port, I/O operations may be combined in many ways. Different pins can be configured as
input or outputs independent of each other or the same pin can be used as an input or as
output at different times. You can comfortably combine I/O operations and special
operations for Port 3 lines.
All the Port 3 pins are multifunctional. They are not only port pins, but also serve the
functions of various special features as listed below:
Port Pin Alternate Function
P3.0 RxD (serial input port)
P3.1 TxD (serial output port)
MEMORY ORGANISATION
The alternate functions can only be activated if the corresponding bit latch in the port SFR
contains a 1. Otherwise the port pin remains at 0.All 80C51 devices have separate address spaces
for program and data memory, as shown in Figures 1 and 2. The logical separation of program
and data memory allows the data memory to be accessed by 8-bit addresses, which can be

quickly stored and manipulated by an 8-bit CPU. Nevertheless, 16-bit data memory addresses
can also be generated through the DPTR register.
Program memory (ROM, EPROM) can only be read, not written to. There can be up to
64k bytes of program memory. In the 80C51, the lowest 4k bytes of program are on-chip. In the
ROM less versions, all program memory is external. The read strobe for external program
memory is the PSEN (program store enable). Data Memory (RAM) occupies a separate address
space from Program Memory. In the 80C51, the lowest 128 bytes of data memory are on-chip.
Up to 64k bytes of external RAM can be addressed in the external Data Memory space. In the
ROM less version, the lowest 128 bytes are on-chip. The CPU generates read and write signals,
RD and WR, as needed during external Data Memory accesses.
External Program Memory and external Data Memory may be combined if desired by
applying the RD and PSEN signals to the inputs of an AND gate and using the output of the gate
as the read strobe to the external Program/Data memory.
BASIC REGISTERS
A number of 8052 registers can be considered "basic." Very little can be done without
them and a detailed explanation of each one is warranted to make sure the reader understands
these registers before getting into more complicated areas of development.

The Accumulator: If you've worked with any other assembly language you will be familiar with
the concept of an accumulator register.
The Accumulator, as its name suggests, is used as a general register to accumulate the
results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most
versatile register the 8052 has due to the sheer number of instructions that make use of the
accumulator. More than half of the 8052's 255 instructions manipulate or use the Accumulator in
some way. For example, if you want to add the number 10 and 20, the resulting 30 will be stored
in the Accumulator. Once you have a value in the Accumulator you may continue processing the
value or you may store it in another register or in memory.
The "R" Registers: The "R" registers are sets of eight registers that are named R0, R1, through
R7. These registers are used as auxiliary registers in many operations. To continue with the
above example, perhaps you are adding 10 and 20. The original number 10 may be stored in the

Accumulator whereas the value 20 may be stored in, say, register R4. To process the addition
you would execute the command:
ADD A, R4
After executing this instruction the Accumulator will contain the value 30. You may think of the
"R" registers as very important auxiliary, or "helper", registers. The Accumulator alone would
not be very useful if it were not for these "R" registers.
The "R" registers are also used to store values temporarily. For example, lets say you want to
add the values in R1 and R2 together and then subtract the values of R3 and R4. One way to do
this would be:
MOV A, R3

; Move the value of R3 to accumulator

ADD A, R4

; add the value of R4

MOV R5, A

; Store the result in R5

MOV A, R1

; Move the value of R1 to Acc

ADD A, R2

; add the value of R2 with A

SUBB A, R5

; Subtract the R5 (which has R3+R4)

As you can see, we used R5 to temporarily hold the sum of R3 and R4. Of course, this isn't the
most efficient way to calculate (R1+R2) - (R3 +R4) but it does illustrate the use of the "R"
registers as a way to store values temporarily.
As mentioned earlier, there are four sets of "R" registers-register bank 0, 1, 2, and 3. When the
8052 is first powered up, register bank 0 (addresses 00h through 07h) is used by default. In this
case, for example, R4 is the same as Internal RAM address 04h. However, your program may
instruct the 8052 to use one of the alternate register banks; i.e., register banks 1, 2, or 3. In this
case, R4 will no longer be the same as Internal RAM address 04h. For example, if your program
instructs the 8052 to use register bank 1, register R4 will now be synonymous with Internal RAM
address 0Ch. If you select register bank 2, R4 is synonymous with 14h, and if you select register
bank 3 it is synonymous with address 1Ch.
The concept of register banks adds a great level of flexibility to the 8052, especially when
dealing with interrupts (we'll talk about interrupts later). However, always remember that the
register banks really reside in the first 32 bytes of Internal RAM.

The B Register The "B" register is very similar to the Accumulator in the sense that it may hold
an 8-bit (1-byte) value. The "B" register is only used implicitly by two 8052 instructions: MUL
AB and DIV AB. Thus, if you want to quickly and easily multiply or divide A by another
number, you may store the other number in "B" and make use of these two instructions.
Aside from the MUL and DIV instructions, the "B" register are often used as yet another
temporary storage register much like a ninth "R" register.
The Program Counter The Program Counter (PC) is a 2-byte address that tells the 8052
where the next instruction to execute is found in memory. When the 8052 is initialized PC
always starts at 0000h and is incremented each time an instruction is executed. It is important to
note that PC isn't always incremented by one. Since some instructions are 2 or 3 bytes in length
the PC will be incremented by 2 or 3 in these cases.
The Program Counter is special in that there is no way to directly modify its value. That is
to say, you can't do something like PC=2430h. On the other hand, if you execute LJMP 2430h
you've effectively accomplished the same thing.
It is also interesting to note that while you may change the value of PC (by executing a
jump instruction, etc.) there is no way to read the value of PC. That is to say, there is no way to
ask the 8052 "What address are you about to execute?" As it turns out, this is not completely true:
There is one trick that may be used to determine the current value of PC. This trick will be
covered in a later chapter.
The Data Pointer: The Data Pointer (DPTR) is the 8052s only user-accessible 16-bit (2-byte)
register. The Accumulator, "R" registers, and "B" register are all 1-byte values. The PC just
described is a 16-bit value but isn't directly user-accessible as a working register.
DPTR, as the name suggests, is used to point to data. It is used by a number of commands
that allow the 8052 to access external memory. When the 8052 accesses external memory it
accesses the memory at the address indicated by DPTR.
While DPTR is most often used to point to data in external memory or code memory,
many developers take advantage of the fact that it's the only true 16-bit register available. It is
often used to store 2-byte values that have nothing to do with memory locations.

The Stack Pointer: The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit
(1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the
stack should be taken from.
When you push a value onto the stack, the 8052 first increments the value of SP and then
stores the value at the resulting memory location. When you pop a value off the stack, the 8052
returns the value from the memory location indicated by SP and then decrements the value of SP.
This order of operation is important. When the 8052 is initialized SP will be initialized to
07h. If you immediately push a value onto the stack, the value will be stored in Internal RAM
address 08h. This makes sense taking into account what was mentioned two paragraphs above:
First the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed
value at that memory address (08h).
ADDRESSING MODES
The addressing modes in the 80C51 instruction set are as follows:
Direct Addressing: In direct addressing the operand is specified by an 8-bit address field in the
instruction. Only internal Data RAM and SFRs can be directly addressed.
Indirect Addressing: In indirect addressing the instruction specifies a register which contains the
address of the operand. Both internal and external RAM can be indirectly addressed. The address
register for 8-bit addresses can be R0 or R1 of the selected bank, or the Stack Pointer. The
address register for 16-bit addresses can only be the 16-bit data pointer register, DPTR.
Register Instructions

The register banks, containing registers R0 through R7, can be accessed

by certain instructions which carry a 3-bit register specification within the opcode of the
instruction. Instructions that access the registers this way are code efficient, since this mode
eliminates an address byte. When the instruction is executed, one of the eight registers in the
selected bank is accessed. One of four banks is selected at execution time by the two bank select
bits in the PSW.
Register-Specific Instructions Some instructions are specific to a certain register. For example,
some instructions always operate on the Accumulator, or Data Pointer, etc., so no address byte is
needed to point to it. The opcode itself does that. Instructions that refer to the Accumulator as A
assemble as accumulator specific opcodes.
Immediate Constants

The value of a constant can follow the opcode in Program Memory. For example,
MOV A, #100
loads the Accumulator with the decimal number 100. The same number could be specified in hex
digits as 64H.

Indexed Addressing

Only program Memory can be accessed with indexed addressing, and it can only be read.
This addressing mode is intended for reading look-up tables in Program Memory A 16-bit base
register (either DPTR or the Program Counter) points to the base of the table, and the
Accumulator is set up with the table entry number. The address of the table entry in Program
Memory is formed by adding the Accumulator data to the base pointer. Another type of indexed
addressing is used in the case jump instruction. In this case the destination address of a jump
instruction is computed as the sum of the base pointer and the Accumulator data.
CENTRAL PROCESSING UNIT

The CPU is the brain of the microcontrollers reading users programs and executing
the expected task as per instructions stored there in. Its primary elements are an 8 bit
Arithmetic Logic Unit (ALU ) , Accumulator (Acc ) , few more 8 bit registers , B
register, Stack Pointer (SP ) , Program Status Word (PSW) and 16 bit registers, Program
Counter (PC) and Data Pointer Register (DPTR).
The ALU (Acc) performs arithmetic and logic functions on 8 bit input variables.
Arithmetic operations include basic addition, subtraction, and multiplication and division.
Logical operations are AND, OR, Exclusive OR as well as rotate, clear, complement and
etc. Apart from all the above, ALU is responsible in conditional branching decisions, and
provides a temporary place in data transfer operations within the device.
B-register is mainly used in multiply and divides operations. During execution, B
register either keeps one of the two inputs or then retains a portion of the result. For
other instructions, it can be used as another general purpose register.

Program Status Word (PSW) keeps the current status of the ALU in different bits. Stack
Pointer (SP) is an 8 bit register. This pointer keeps track of memory space where the
important register information is stored when the program flow gets into executing a
subroutine. The stack portion may be placed in any where in the on-chip RAM. But
normally SP is initialized to 07H after a device reset and grows up from the location
08H. The Stack Pointer is automatically incremented or decremented for all PUSH or
POP instructions and for all subroutine calls and returns.
Program Counter (PC) is the 16 bit register giving address of next instruction to be
executed during program execution and it always points to the Program Memory space.
Data Pointer (DPTR) is another 16 bit addressing register that can be used to fetch any 8
bit data from the data memory space. When it is not being used for this purpose, it can
be used as two eight bit registers.
TIMERS/COUNTERS
8051 has two 16 bit Timers/Counters capable of working in different modes. Each
consists of a High byte and a Low byte which can be accessed under software. There
is a mode control register and a control register to configure these timers/counters in
number of ways.
These timers can be used to measure time intervals, determine pulse widths or
initiate events with one microsecond resolution up to a maximum of 65 millisecond
(corresponding to 65, 536 counts). Use software to get longer delays. Working as counter,
they can accumulate occurrences of external events (from DC to 500 KHz) with 16 bit
precision.
SERIAL PORTS
Each 8051 microcomputer contains a high speed full duplex (means you can
simultaneously use the same port for both transmitting and receiving purposes) serial
port which is software configurable in 4 basic modes: 8 bit UART; 9 bit UART; inter
processor Communications link or as shift register I/O expander.
For the standard serial communication facility, 8051 can be programmed for UART
operations and can be connected with regular personal computers, teletype writers,
modem at data rates between 122 bauds and 31 kilo bauds. Getting this facility is made

very simple using simple routines with option to elect even or odd parity. You can also
establish a kind of Inter processor communication facility among many microcomputers in
a distributed environment with automatic recognition of address/data. Apart from all
above, you can also get super fast I/O lines using low cost simple TTL or CMOS shift
registers.

MICROCONTROLLER
Micro controller is a true computer on a chip the design incorporates all of the features found
in a microprocessor CPU: arithmetic and logic unit, stack pointer, program counter and registers.
It has also had added additional features like RAM, ROM, serial I/O, counters and clock circuit.
Like the microprocessor, a microcontroller is a general purpose device, but one that is
meant to read data, perform limited calculations on that data and control its environment based
on those calculations. The prime use of a microcontroller is to control the operation of a machine
using a fixed program that is stored in ROM and that does not change over the lifetime of the
system.
The design approach of a microcontroller uses a more limited set of single byte and double
byte instructions that are used to move code and data from internal memory to ALU. Many
instructions are coupled with pins on the IC package; the pins are capable of having several
different functions depending on the wishes of the programmer.

The microcontroller is concerned with getting the data from and on to its own pins; the
architecture and instruction set are optimized to handle data in bit and byte size.

FUNCTIONAL BLOCKS OF A MICROCONTROLLER

CRITERIA FOR CHOOSING A MICROCONTROLLER

1.

The first and foremost criterion for choosing a microcontroller is that it must meet task at
hands efficiently and cost effectively. In analyzing the needs of a microcontroller based project
we must first see whether it is an 8-bit, 16-bit or 32-bit microcontroller and how best it can
handle the computing needs of the task most effectively. The other considerations in this
category are:
(a) Speed: The highest speed that the microcontroller supports
(b) Packaging: Is it 40-pin DIP or QPF or some other packaging format?
This is important in terms of space, assembling and prototyping the
End product.
(c) Power Consumption: This is especially critical for battery-powered
Products.
(d) The amount of RAM and ROM on chip
(e) The number of I/O pins and timers on the chip.
(f)

Cost per unit: This is important in terms of final product in which a microcontroller is

used.
2.

The second criteria in choosing a microcontroller are how easy it is to develop products
around it. Key considerations include the availability of an assembler, debugger, a code efficient
C language compiler, emulator, technical support and both in house and outside expertise. In
many cases third party vendor support for chip is required.

3.

The third criteria in choosing a microcontroller is it readily available in needed quantities


both now and in future. For some designers this is even more important than first two criterias.
Currently, of leading 8bit microcontrollers, the 89C51 family has the largest number of
diversified (multiple source) suppliers. By suppliers meant a producer besides the originator of
microcontroller in the case of the 89C51, which was originated by Intel, several companies are
also currently producing the 89C51. Viz: INTEL, PHILIPS, These companies include PHILIPS,
SIEMENS, and DALLAS-SEMICONDUCTOR. It should be noted that Motorola, Zilog and

Microchip Technologies have all dedicated massive resource as to ensure wide and timely
availability of their product since their product is stable, mature and single sourced. In recent
years they also have begun to sell the ASIC library cell of the microcontroller.
2.2

Robot Arms

The robot arm is probably the most mathematically complex robot that could ever build.

2.2.1 Degrees of Freedom (DOF)

The degree of freedom, or DOF, is a very important term to understand. Each degree of freedom is a joint
on the arm, a place where it can bend or rotate or translate. We can typically identify the number of degrees of
freedom by the number of actuators on the robot arm. Now this is very important when building a robot arm we
want as few degrees of freedom allowed for our application. This is because each degree requires a motor, often
an encoder, and exponentially complicated algorithms and cost. Here the example of robot arms that have a few
degrees and one degree [2].

Figure 2.4: Robot arm with multi degree I

Figure 2.5: Robot Arm with multi degree II

Figure 2.6: Robot arm with one degree

2.2.2 Mobile Manipulators

A moving robot with a robot arm is a sub-class of robotic arms. They work just like other robotic
arms, but we just add up the mobile part at the base.

Figure 2.7: Mobile manipulators

2.4

Electrical Component

Figure 2.11: Capacitor I

2.4.1 Capacitors

Now suppose we want to control how the current in your circuit changes (or not changes) over time.
Radio signals require very fast current changes. Robot motors cause current fluctuations in our circuit
which we need to control. What do we do when batteries cannot supply current as fast as we circuit drains
them? How do we prevent sudden current spikes that could fry your robot circuitry?

The solution to this is capacitors.

15

Figure 2.12: Capacitor II

Capacitors are somewhat complex in theory, but most people can get by on the basics
which I will explain here. Capacitors are like electron storage banks. If your circuit is running
low, it will deliver electrons to your circuit. If our circuit is in excess (such as when our robot
motors are turned off), it will store electrons. In our water analogy, think of this as a water tank
with water always flowing in, but with drainage valves opening and closing. Since capacitors
take time to charge, and time to discharge, they can also be used for timing circuits.

2.4.2 Diodes

Figure 2.13: Diodes

Diodes are what we would use to ensure current flows in only a single direction. A great water analogy to
a diode is a dam. Water never flows up a damn. But the analogy goes even further. With diodes, there is always a
voltage across it (typically .7V forward voltage). Meaning if we have a diode come after a 7.2V

16
battery, the voltage would then be 6.5V. This is just like a dam in that the water level will always drop.
Doesnt current already always flow in only a single direction? No. RC circuits, or circuits involving AC
power, or circuits that are noisy (such as with motors), involve currents that changes directions. So why
would we only want current to flow in a single direction? Many reasons. The main reason, we need to
protect our circuitry from noise. A microcontroller would fry if current went the wrong way. Motor drivers
and MOSFETs would too. Diodes are also useful for dropping high voltages to a lower more usable voltage.

This below chart represents the current vs voltage curve typical of diodes. As we can see, the
current passing through a diode changes non-linearly as voltage changes linearly.

Figure 2.14: Diode working principle

There is another special diode called a zener diode. With the water analogy, a zener diode is like a dam,
but with a pump at the bottom pumping water back to the top. Zener diodes allow current to flow in reverse as
well as forward. The forward voltage is still around .7V, but there is a different reverse voltage of around
negative ~2.3V. You will probably never need to use a zener diode.

17

2.5

Motors

This chapter introduces several types of motors commonly used in robotic and related applications.
DC motors are inexpensive, small, and powerful motors that are used widely. Gear train reductions are
typically needed to reduce the speed and increase the torque output of the motor. Stepper motors are not
part of the 6.270 kit but commonly used in robotics, particular in mechanisms that perform linear
positioning, such as copy and hard disk drive head motors and X-Y tables. Servo motors are used in radio
control airplanes to control the position of wing aps and similar devices. A servo motor includes a built-in
gear train and is capable of delivering high torques directly. The output shaft of a servo does not rotate
freely as do the shafts of DC motors and stepper motors, but rather is made to seek a particular angular
position under electronic control.

DC Motor
DC motors are configured in many types and sizes, including brush less, servo, and gear
motor types. A motor consists of a rotor and a permanent magnetic field stator. The magnetic field is
maintained using either permanent magnets or electromagnetic windings. DC motors are most commonly
used

in

variable

speed

and

torque.

Motion and controls cover a wide range of components that in some way are used to
generate and/or control motion. Areas within this category include bearings and bushings, clutches and
brakes, controls and drives, drive components, encoders and resolves, Integrated motion control, limit
switches, linear actuators, linear and rotary motion components, linear position sensing, motors (both AC
and DC motors), orientation position sensing, pneumatics and pneumatic components, positioning stages,
slides and guides, power transmission (mechanical), seals, slip rings, solenoids, springs.

Motors are the devices that provide the actual speed and torque in a drive system. This
family includes AC motor types (single and multiphase motors, universal, servo motors, induction,
synchronous, and gear motor) and DC motors (brush less, servo motor, and gear motor) as well as linear,
stepper and air motors, and motor contactors and starters.
In any electric motor, operation is based on simple electromagnetism. A current-carrying
conductor generates a magnetic field; when this is then placed in an external magnetic field, it will
experience a force proportional to the current in the conductor, and to the strength of the external
magnetic field. As you are well aware of from playing with magnets as a kid, opposite (North and South)
polarities attract, while like polarities (North and North, South and South) repel. The internal
configuration of a DC motor is designed to harness the magnetic interaction between a current-carrying
conductor and an external magnetic field to generate rotational motion.

Let's start by looking at a simple 2-pole DC electric motor (here red represents a magnet or
winding with a "North" polarization, while green represents a magnet or winding with a "South"
polarization).

Fig 25: Block Diagram of the DC motor


Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator, commutator, field
magnet(s), and brushes. In most common DC motors (and all that Beamers will see), the external
magnetic field is produced by high-strength permanent magnets1. The stator is the stationary part of the
motor -- this includes the motor casing, as well as two or more permanent magnet pole pieces. The rotor
(together with the axle and attached commutator) rotates with respect to the stator. The rotor consists of
windings (generally on a core), the windings being electrically connected to the commutator. The above
diagram shows a common motor layout -- with the rotor inside the stator (field) magnets.
The geometry of the brushes, commutator contacts, and rotor windings are such that when
power is applied, the polarities of the energized winding and the stator magnet(s) are misaligned, and
the rotor will rotate until it is almost aligned with the stator's field magnets. As the rotor reaches
alignment, the brushes move to the next commutator contacts, and energize the next winding. Given
our example two-pole motor, the rotation reverses the direction of current through the rotor winding,
leading to a "flip" of the rotor's magnetic field, and driving it to continue rotating.
In real life, though, DC motors will always have more than two poles (three is a very
common number). In particular, this avoids "dead spots" in the commutator. You can imagine how with
our example two-pole motor, if the rotor is exactly at the middle of its rotation (perfectly aligned with the
field magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is a moment where the
commutator shorts out the power supply (i.e., both brushes touch both commutator contacts
simultaneously). This would be bad for the power supply, waste energy, and damage motor components
as well. Yet another disadvantage of such a simple motor is that it would exhibit a high amount of
torque ripple" (the amount of torque it could produce is cyclic with the position of the rotor).

Fig 26: Block Diagram of the DC motor having two poles only
So since most small DC motors are of a three-pole design, let's tinker with the workings of
one via an interactive animation (JavaScript required):

Fig 27: Block Diagram of the DC motor having Three poles

You'll notice a few things from this -- namely, one pole is fully energized at a time (but two
others are "partially" energized). As each brush transitions from one commutator contact to the next, one
coil's field will rapidly collapse, as the next coil's field will rapidly charge up (this occurs within a few
microsecond). We'll see more about the effects of this later, but in the meantime you can see that this is a
direct result of the coil windings' series wiring:

Fig 28: Internal Block Diagram of the Three pole DC motor


There's probably no better way to see how an average dc motor is put together, than by just
opening one up. Unfortunately this is tedious work, as well as requiring the destruction of a perfectly
good motor. This is a basic 3-pole dc motor, with 2 brushes and three commutator contacts

H-BRIDGE:

DC motors are typically controlled by using a transistor configuration called


an "H-bridge". This consists of a minimum of four mechanical or solid-state switches, such as two NPN
and two PNP transistors. One NPN and one PNP transistor are activated at a time. Both NPN and PNP
transistors can be activated to cause a short across the motor terminals, which can be useful for slowing
down the motor from the back EMF it creates.

Basic Theory
H-bridge. Sometimes called a "full bridge" the H-bridge is so named because it has four switching
elements at the "corners" of the H and the motor forms the cross bar.

The key fact to note is that there are, in theory, four switching elements within the bridge. These four
elements are often called, high side left, high side right, low side right, and low side left (when traversing
in clockwise order).
The switches are turned on in pairs, either high left and lower right, or lower left and high right, but never
both switches on the same "side" of the bridge. If both switches on one side of a bridge are turned on it
creates a short circuit between the battery plus and battery minus terminals. If the bridge is sufficiently
powerful it will absorb that load and your batteries will simply drain quickly. Usually however the
switches in question melt.
To power the motor, you turn on two switches that are diagonally opposed. In the picture to the right,
imagine that the high side left and low side right switches are turned on.
The current flows and the motor begins to turn in a "positive" direction. Turn on the high side right and
low side left switches, then Current flows the other direction through the motor and the motor turns in the
opposite direction.
Actually it is just that simple, the tricky part comes in when you decide what to use for switches.
Anything that can carry a current will work, from four SPST switches, one DPDT switch, relays,
transistors, to enhancement mode power MOSFETs.
One more topic in the basic theory section, quadrants. If each switch can be controlled independently
then you can do some interesting things with the bridge, some folks call such a bridge a "four quadrant
device" (4QD get it?). If you built it out of a single DPDT relay, you can really only control forward or
reverse. You can build a small truth table that tells you for each of the switch's states, what the bridge
will do. As each switch has one of two states, and there are four switches, there are 16 possible states.
However, since any state that turns both switches on one side on is "bad" (smoke issues forth: P), there
are in fact only four useful states (the four quadrants) where the transistors are turned on.

High Side Left High Side Right Low Side Left Low Side Right Quadrant Description
On

Off

Off

On

Forward Running

Off

On

On

Off

Backward Running

On

On

Off

Off

Braking

Off

Off

On

On

Braking

The last two rows describe a maneuver where you "short circuit" the motor which causes the motors
generator effect to work against itself. The turning motor generates a voltage which tries to force the
motor to turn the opposite direction. This causes the motor to rapidly stop spinning and is called
"braking" on a lot of H-bridge designs.
Of course there is also the state where all the transistors are turned off. In this case the motor coasts freely
if it was spinning and does nothing if it was doing nothing.

Implementation
1. Using Relays:
A simple implementation of an H Bridge using four SPST relays is shown. Terminal A is High
Side Left, Terminal B is High Side Right, Terminal C is Low Side Left and Terminal D is Low
Side Right. The logic followed is according to the table above.
Warning: Never turn on A and C or B and D at the same time. This will lead to a short circuit of
the battery and will lead to failure of the relays due to the large current.

2. Using Transistors:
We can better control our motor by using transistors or Field Effect Transistors (FETs). Most of
what we have discussed about the relays H-Bridge is true of these circuits. See the diagram
showing how they are connected. You should add diodes across the transistors to catch the back
voltage that is generated by the motor's coil when the power is switched on and off. This fly back
voltage can be many times higher than the supply voltage!
For information on building an H-Bridge using Transistors, have a look here.
Warning: If you don't use diodes, you could burn out your transistors. Also the same warning as
in the diode case. Don't turn on A and C or B and D at the same time.

Transistors, being a semiconductor device, will have some resistance, which causes them to get
hot when conducting much current. This is called not being able to sink or source very much
power, i.e.: Not able to provide much current from ground or from plus voltage.
Mosfets are much more efficient, they can provide much more current and not get as hot. They
usually have the fly back diodes built in so you don't need the diodes anymore. This helps guard
against fly back voltage frying your ICs.
To use Mosfets in an H-Bridge, you need P-Channel Mosfets on top because they can "source"
power, and N-Channel Mosfets on the bottom because then can "sink" power.
It is important that the four quadrants of the H-Bridge circuits be turned on and off properly.
When there is a path between the positive and ground side of the H-Bridge, other than through the
motor, a condition exists called "shoot through". This is basically a direct short of the power
supply and can cause semiconductors to become ballistic, in circuits with large currents flowing.

There are H-bridge chips available that are much easier, and safer, to use than designing your own
H-Bridge circuit.
1. Using H-Bridge Devices
The L293 has 2 H-Bridges (actually 4 Half H-Bridges), can provide about 1 amp to each and
occasional peak loads to 2 amps.
The L298 has 2 h-bridges on board, can handle 1amp and peak current draws to about 3amps. The
LMD18200 has one h-bridge on board, can handle about 2 or 3 amps and can handle a peak of
about 6 amps. There are several more commercially designed H-Bridge chips as well.
Once a Half H-bridge is enabled, it truth table is as follows:
INPUT OUTPUT
A

So you just give a High level when you want to turn the Half H-Bridge on and Low level when
you want to turn it off. When the Half H-Bridge is on, the voltage at the output is equal to Vcc2.If
you want to make a Full H-Bridge, you connect the motor (or the load) between the outputs of
two Half H-Bridges and the inputs will be the two inputs of the Half H-Bridges.
Suppose we have connected Half H-Bridges 1 and 2 to form a Full H-Bridge. Now the truth table
is as follows:

INPUT

INPUT

OUTPUT

OUTPUT

1A

2A

1Y

2Y

Description

Braking (both terminals


of motor are Gnd)
Forward Running

Backward Running
Braking (both terminals
of motor at Vcc2

2) L293D Motor Driver IC:


Since two motors are used to drive The back wheels of the robot independently, there is a need for Two
H-bridges. Instead of implementing the above H-bridge controlCircuit twice, an alternative is to use an
integrated circuit (IC), which Provides more than one
H-bridges. One such IC is L293D, which has 2 H-Bridges in it. It can supply 600Ma continuous and
1.2A peak Currents. It is suitable for switching applications up to 5 kHz. These Features make it ideal for
our application. Another option is to use IC L298, which can drive 2A continually and 3A peak currents.
The Diagram of L293D is shown in Figure 2It can be observed from the figure that L293D has a similar
configuration to the circuit in

Figure 1

Figure 1

3) Motor Driver Connections: The motor driver requires 2 control


inputs for each motor. Since we drive 2 motors, we need 4 controls

Inputs from the microcontroller. Since it has many pins which can be configured as outputs, there are
many options for implementation.For example, in our robot the last 4 bits of Port B (RB4, RB5,
RB6,RB7 - Pins 37 to 40) are used to control the rotation direction of the motors . The enable pins of the
motor driver are connected to the PWM outputs of the microcontroller (Pins 16and 17). This is because,
as was mentioned above, by changing the width of the pulse (implying changing the enable time of the
driver) one can change the speed of the motor. The truth table for motor driver is as shown in Table II,
where H = high, L = low, and Z =high output impedance state.

Since the motors are reverse aligned, in order to have the robot Move forward they must be configured
such that one of them turns forward and the other one turns backward. In case of any requirement for the
robot to move backward, it is sufficient to just reverse the

TABLE II

THE TRUTH TABLE OF THE MOTOR DRIVER

Input

enable

output

TABLE III
DRIVER CONTROL INPUTS

Direction

Input 1

Input 2

Input 3

Input 4

Forward

Backward

Outputs of the control pins. For example, in our robot while moving forward, inputs of the motor driver
have states shown in the first row Of Table III, whereas for backward movement, the states shown in the
second row of Table III is applied.

ZIGBEE

ZigBee is a low-cost, low-power, wireless mesh networking proprietary standard. The low
cost allows the technology to be widely deployed in wireless control and monitoring applications,
the low power-usage allows longer life with smaller batteries, and the mesh networking provides
high reliability and larger range.
The ZigBee Alliance, the standards body that defines ZigBee, also publishes application
profiles that allow multiple OEM vendors to create interoperable products. The current list of
application profiles either published or in the works are:

Home Automation

ZigBee Smart Energy

Commercial Building Automation

Telecommunication Applications

Personal, Home, and Hospital Care

Toys

ZigBee coordinator(ZC): The most capable device, the coordinator forms the root of the
network tree and might bridge to other networks. There is exactly one ZigBee coordinator in each

network since it is the device that started the network originally. It is able to store information
about the network, including acting as the Trust Centre & repository for security keys.
ZigBee Router (ZR): As well as running an application function a router can act as an
intermediate router, passing data from other devices.
ZigBee End Device (ZED): Contains just enough functionality to talk to the parent node (either
the coordinator or a router); it cannot relay data from other devices. This relationship allows the
node to be asleep a significant amount of the time thereby giving long battery life. A ZED
requires the least amount of memory, and therefore can be less expensive to manufacture than a
ZR or ZC.

Protocols
The protocols build on recent algorithmic research (Ad-hoc On-demand Distance Vector,
neuRFon) to automatically construct a low-speed ad-hoc network of nodes. In most large
network instances, the network will be a cluster of clusters. It can also form a mesh or a single
cluster. The current profiles derived from the ZigBee protocols support beacon and non-beacon
enabled networks.
In non-beacon-enabled networks (those whose beacon order is 15), an unslotted CSMA/CA
channel access mechanism is used. In this type of network, ZigBee Routers typically have their
receivers continuously active, requiring a more robust power supply. However, this allows for
heterogeneous networks in which some devices receive continuously, while others only transmit
when an external stimulus is detected. The typical example of a heterogeneous network is a
wireless light switch: the ZigBee node at the lamp may receive constantly, since it is connected
to the mains supply, while a battery-powered light switch would remain asleep until the switch is
thrown. The switch then wakes up, sends a command to the lamp, receives an acknowledgment,
and returns to sleep. In such a network the lamp node will be at least a ZigBee Router, if not the
ZigBee Coordinator; the switch node is typically a ZigBee End Device.
In beacon-enabled networks, the special network nodes called ZigBee Routers transmit periodic
beacons to confirm their presence to other network nodes. Nodes may sleep between beacons,
thus lowering their duty cycle and extending their battery life. Beacon intervals may range from
15.36 milliseconds to 15.36 ms * 214 = 251.65824 seconds at 250 kbit/s, from 24 milliseconds to
24 ms * 214 = 393.216 seconds at 40 kbit/s and from 48 milliseconds to 48 ms * 214 = 786.432

seconds at 20 kbit/s. However, low duty cycle operation with long beacon intervals requires
precise timing, which can conflict with the need for low product cost.
In general, the ZigBee protocols minimize the time the radio is on so as to reduce power use. In
beaconing networks, nodes only need to be active while a beacon is being transmitted. In nonbeacon-enabled networks, power consumption is decidedly asymmetrical: some devices are
always active, while others spend most of their time sleeping.
ZigBee devices are required to conform to the IEEE 802.15.4-2003 Low-Rate Wireless Personal
Area Network (WPAN) standard. The standard specifies the lower protocol layersthe physical
layer (PHY), and the medium access control (MAC) portion of the data link layer (DLL). This
standard specifies operation in the unlicensed 2.4 GHz, 915 MHz and 868 MHz ISM bands. In
the 2.4 GHz band there are 16 ZigBee channels, with each channel requiring 5 MHz of
bandwidth. The center frequency for each channel can be calculated as, FC = (2405 + 5 * (ch 11)) MHz, where ch = 11, 12, ..., 26.
The radios use direct-sequence spread spectrum coding, which is managed by the digital stream
into the modulator. BPSK is used in the 868 and 915 MHz bands, and orthogonal QPSK that
transmits two bits per symbol is used in the 2.4 GHz band. The raw, over-the-air data rate is 250
kbit/s per channel in the 2.4 GHz band, 40 kbit/s per channel in the 915 MHz band, and 20 kbit/s
in the 868 MHz band. Transmission range is between 10 and 75(up to 1500meteres for zigbee
pro.)meters (33 and 246 feet), although it is heavily dependent on the particular environment.
The maximum output power of the radios is generally 0 dBm (1 mW).
The basic channel access mode is "carrier sense, multiple access/collision avoidance"
(CSMA/CA). That is, the nodes talk in the same way that people converse; they briefly check to
see that no one is talking before they start. There are three notable exceptions to the use of
CSMA. Beacons are sent on a fixed timing schedule, and do not use CSMA. Message
acknowledgments also do not use CSMA. Finally, devices in Beacon Oriented networks that
have low latency real-time requirements may also use Guaranteed Time Slots (GTS), which by
definition do not use CSMA.

Software and hardware

The software is designed to be easy to develop on small, inexpensive microprocessors. The radio
design used by ZigBee has been carefully optimized for low cost in large scale production. It has
few analog stages and uses digital circuits wherever possible.
Even though the radios themselves are inexpensive, the ZigBee Qualification Process involves a
full validation of the requirements of the physical layer. This amount of concern about the
Physical Layer has multiple benefits, since all radios derived from that semiconductor mask set
would enjoy the same RF characteristics. On the other hand, an uncertified physical layer that
malfunctions could cripple the battery lifespan of other devices on a ZigBee network. Where
other protocols can mask poor sensitivity or other esoteric problems in a fade compensation
response, ZigBee radios have very tight engineering constraints: they are both power and
bandwidth constrained. Thus, radios are tested to the ISO 17025 standard with guidance given by
Clause 6 of the 802.15.4-2006 Standard. Most vendors plan to integrate the radio and
microcontroller onto a single chip.

Controversy
An academic research group has examined the Zigbee address formation algorithm in the 2006
specification, and argues[6] that the network will isolate many units that could be connected. The
group proposed an alternative algorithm with similar complexity in time and space.
A white paper published by a European manufacturing group (associated with the development
of a competing standard, Z-Wave) claims that wireless technologies such as ZigBee, which
operate in the 2.4 GHz RF band, are subject to significant interference - enough to make them
unusable. It claims that this is due to the presence of other wireless technologies like Wireless
LAN in the same RF band. The ZigBee Alliance released a white paper refuting these claims.
After a technical analysis, this paper concludes that ZigBee devices continue to communicate
effectively and robustly even in the presence of large amounts of interference.
Advantages:
low cost allows the technology to be widely deployed in wireless control and monitoring
applications.
low power-usage allows longer life with smaller batteries,.
mesh networking provides high reliability and larger range.

Applications:
Home Automation
ZigBee Smart Energy
Telecommunication Applications
Personal Home
Hospital Care

MAX-232

RS232 (serial port).

RS-232 (Recommended Standard - 232) is a telecommunications standard for binary serial


communications between devices. It supplies the roadmap for the way devices speak to each
other using serial ports. The devices are commonly referred to as a DTE (data terminal
equipment) and DCE (data communications equipment); for example, a computer and modem,
respectively.
RS232 is the most known serial port used in transmitting the data in communication and
interface. Even though serial port is harder to program than the parallel port, this is the most
effective method in which the data transmission requires less wires that yields to the less cost.
The RS232 is the communication line which enables the data transmission by only using three
wire links. The three links provides transmit, receive and common ground...
The transmit and receive line on this connecter send and receive data between the computers.
As the name indicates, the data is transmitted serially. The two pins are TXD & RXD. There are
other lines on this port as RTS, CTS, DSR, DTR, and RTS, RI. The 1 and 0 are the data which
defines a voltage level of 3V to 25V and -3V to -25V respectively.
The electrical characteristics of the serial port as per the EIA (Electronics Industry Association)
RS232C Standard specifies a maximum baud rate of 20,000bps, which is slow compared to
todays standard speed. For this reason, we have chosen the new RS-232D Standard, which was
recently released.
The RS-232D has existed in two types. i.e., D-TYPE 25 pin connector and D-TYPE 9 pin
connector, which are male connectors on the back of the PC. You need a female connector on

your communication from Host to Guest computer. The pin outs of both D-9 & D-25 are show
below

D-Type-9

D-Type-25 Pin outs

pin no.

pin no.

Function

RD

Receive Data (Serial data input)

TD

Transmit Data (Serial data output)

RTS

Request to send (acknowledge to modem


that UART is ready to exchange data

CTS

Clear to send (i.e.; modem is ready to


exchange data)

DSR

Data ready state (UART establishes a link)

SG

Signal ground

DCD

Data Carrier detect (This line is active


when modem detects a carrier

20

DTR

Data Terminal Ready.

22

RI

Ring Indicator (Becomes active when


modem detects ringing signal from PSTN

Rs232

When communicating with various micro processors one needs to convert the RS232 levels
down to lower levels, typically 3.3 or 5.0 Volts. Here is a cheap and simple way to do that. Serial
RS-232 (V.24) communication works with voltages -15V to +15V for high and low. On the
other hand, TTL logic operates between 0V and +5V . Modern low power consumption logic
operates in the range of 0V and +3.3V or even lower.

RS-232

TTL

Logic

-15V -3V +2V +5V High


+3V +15V 0V +0.8V Low

Thus the RS-232 signal levels are far too high TTL electronics, and the negative RS-232
voltage for high cant be handled at all by computer logic. To receive serial data from an RS-232
interface the voltage has to be reduced. Also the low and high voltage level has to be
inverted. This level converter uses a Max232 and five capacitors. The max232 is
quite cheap (less than 5 dollars) or if youre lucky you can get a free sample from Maxim. The
MAX232 from Maxim was the first IC which in one package contains the necessary drivers and
receivers to adapt the RS-232 signal voltage levels to TTL logic. It became popular, because it
just needs one voltage (+5V or +3.3V) and generates the necessary RS-232 voltage levels.
MAX 232 PIN DIAGRAM

+---\/---+
1 -|C1+ Vcc|- 16
2 -|V+ gnd|- 15
3 -|C1- T1O|- 14
4 -|C2+ R1I|- 13
5 -|C2- R1O|- 12
6 -|V- T1I|- 11
7 -|T2O T2I|- 10
8 -|R2I R2O|- 9

RS232 INTERFACED TO MAX 232

J2

13
8 R1IN
R2IN

T1OUT
TXD P3.1
C4

14
T1OUT 7
T2OUT

P3.0 RXD
T1OUT

1
3 C1+
4 C15 C2+
C2-

C5
0.1uf
C6
0.1uf

12
R1OUT 9
R2OUT

10
11 T2IN
T1IN

5V

C1
1uf

16

U3

VC C

5
4
3
2
1

2
6 V+
V-

0.1uf

GND

9
8
7
6

15

C7
MAX3232
0.1uf

Rs232 is 9 pin db connector, only three pins of this are used ie 2,3,5 the transmit pin of rs232 is
connected to rx pin of microcontroller

Max232 interfaced to microcontroller

MAX232 is connected to the microcontroller as shown in the figure above 11, 12 pin are
connected to the 10 and 11 pin ie transmit and receive pin of microcontroller

http://en.wikipedia.org/wiki/File:Phonerelay.pngREGULATED POWER SUPPLY

A variable regulated power supply, also called a variable bench power supply, is one
where you can continuously adjust the output voltage to your requirements. Varying the
output of the power supply is the recommended way to test a project after having double
checked parts placement against circuit drawings and the parts placement guide.
This type of regulation is ideal for having a simple variable bench power supply. Actually
this is quite important because one of the first projects a hobbyist should undertake is the
construction of a variable regulated power supply. While a dedicated supply is quite
handy ,it's much handier to have a variable supply on hand, especially for testing.
Mainly the ARM controller needs 3.3 volt power supply. To use these parts we need to
build a regulated 3.3 volt source. Usually you start with an unregulated power To make a
3.3 volt power supply, we use a LM317 voltage regulator IC (Integrated Circuit). The IC
is shown below.

CIRCUIT FEATURES:-

Vout range

1.25V - 37V

Vin - Vout difference

3V - 40V

Operation ambient temperature 0 - 125C


Output Imax

<1.5A

Minimum Load Currentmax

10mA

A current-limiting circuit constructed with LM317

http://en.wikipedia.org/wiki/File:Lm317_front.png
http://en.wikipedia.org/wiki/File:Lm317_front.png

Part pinout of LM317 showing its constant voltage reference


LM317 is the standard part number for an integrated three-terminal adjustable linear voltage
regulator. LM317 is a positive voltage regulator supporting input voltage of 3V to 40V and
output voltage between 1.25V and 37V. A typical current rating is 1.5A although several lower
and higher current models are available. Variable output voltage is achieved by using a
potentiometer or a variable voltage from another source to apply a control voltage to the control
terminal. LM317 also has a built-in current limiter to prevent the output current from exceeding
the rated current, and LM317 will automatically reduce its output current if an overheat condition
occurs under load. LM317 is manufactured by many companies, including National
Semiconductor, Fairchild Semiconductor, and STMicroelectronics.
Although LM317 is an adjustable regulator, it is sometimes preferred for high-precision fixed
voltage applications instead of the similar LM78xx devices because the LM317 is designed with
superior output tolerances. For a fixed voltage application, the control pin will typically be biased
with a fixed resistor network, a Zener diode network, or a fixed control voltage from another
source. Manufacturer datasheets provide standard configurations for achieving various design
applications, including the use of a pass transistor to achieve regulated output currents in excess
of what the LM317 alone can provide.

LM317 is available in a wide range of package forms for different applications including heat
sink mounting and surface-mount applications. Common form factors for high-current
applications include TO-220 and TO-3. LM317 is capable of dissipating a large amount of heat at
medium to high current loads and the use of a heat sink is recommended to maximize the lifespan
and power-handling capability.
LM337 is the negative voltage complement to LM317 and the specifications and function are
essentially identical, except that the regulator must receive a control voltage and act on an input
voltage that are below the ground reference point instead of above it.

BLOCK DIAGRAM

RFID
The RFID Reader Module can be used in a wide variety of hobbyist and commercial applications,
including access control, automatic identification, robotics navigation, inventory tracking, payment
systems, and car immobilization.
1. Fully-integrated, low-cost method of reading passive RFID transponder tags
2. 1-wire, 2400 baud Serial TTL interface to PC, BASIC Stamp and other processors
3. Requires single +5VDC supply
4. Bi-color LED for visual indication of activity
5. 0.100 pin spacing for easy prototyping and integration

Radio Frequency Identification (RFID) is a generic term for non-contacting technologies that use
radio waves to automatically identify people or objects. There are several methods of identification,
but the most common is to store a unique serial number that identifies a person or object on a
microchip that is attached to an antenna. The combined antenna and microchip are called an "RFID
transponder" or "RFID tag" and work in combination with an "RFID reader" (sometimes called an
"RFID interrogator").
An RFID system consists of a reader and one or more tags. The reader's antenna is used to transmit
radio frequency (RF) energy. Depending on the tag type, the energy is "harvested" by the tag's
antenna and used to power up the internal circuitry of the tag. The tag will then modulate the
electromagnetic waves generated by the reader in order to transmit its data back to the reader. The
reader receives the modulated waves and converts them into digital data. In the case of the Parallax
RFID Reader Module, correctly received digital data is sent serially through the SOUT pin.
There are two major types of tag technologies. "Passive tags" are tags that do not contain their own
power source or transmitter. When radio waves from the reader reach the chips antenna, the
energy is converted by the antenna into electricity that can power up the microchip in the tag

(known as "parasitic power"). The tag is then able to send back any information stored on the tag
by reflecting the electromagnetic waves as described above. "Active tags" have their own power
source and transmitter.
The power source, usually a battery, is used to run the microchip's circuitry and to broadcast a
signal to a reader. Due to the fact that passive tags do not have their own transmitter and must
reflect their signal to the reader, the reading distance is much shorter than with active tags.
However, active tags are typically larger, more expensive, and require occasional service. The RFID
Reader Module is designed specifically for low-frequency (170 kHz) passive tags.

ELECTRONIC CONNECTIONS
The Parallax RFID Reader Module can be integrated into any design using only four connections
(VCC, /ENABLE, SOUT, GND).

Communication Protocol
Implementation and usage of the RFID Reader Module is straightforward. BASIC Stamp 1, 2, and
SX28AC/DP code examples (SX/B) are included at the end of this documentation.
The RFID Reader Module is controlled with a single TTL-level active-low /ENABLE pin. When the
/ENABLE pin is pulled LOW, the module will enter its active state and enable the antenna to
interrogate for tags.
The current consumption of the module will increase dramatically when the module is active.
A visual indication of the state of the RFID Reader Module is given with the on-board LED. When
the module is successfully powered-up and is in an idle state, the LED will be GREEN. When the
module is in an active state and the antenna is transmitting, the LED will be RED.
The face of the RFID tag should be held parallel to the front or back face of the antenna (where the
majority of RF energy is focused). If the tag is held sideways (perpendicular to the antenna) you'll
either get no reading or a poor reading. Only one transponder tag should be held up to the antenna
at any time. The use of multiple tags at one time will cause tag collisions and confuse the reader.
The two tags available in the Parallax store have a read distance of approximately 3 inches. Actual
distance may vary slightly depending on the size of the transponder tag and environmental
conditions of the application.
RFID Tags Available From Parallax
54 mm x 85 mm Rectangle Tag (#28141)

50 mm Round Tag (#28142)

Software Used:
Introduction to Embedded C:
Data Types:

U people have already come across the word Data types in C- Language. Here also the
functionality and the meaning of the word is same except a small change in the prefix of their labels.
Now we will discuss some of the widely used data types for embedded C- programming.

Data Types

Size in Bits

Data Range/Usage

unsigned char

8-bit

0-255

signed char

8-bit

-128 to +127

unsigned int

16-bit

0 to 65535

signed int

16-bit

-32,768 to +32,767

sbit

1-bit

SFR bit addressable only

bit

1-bit

RAM bit addressable only

sfr

8-bit

RAM

addresses

80-FFH

only

Unsigned char:
The unsigned char is an 8-bit data type that takes a value in the range of 0-255(00-FFH). It is used
in many situations, such as setting a counter value, where there is no need for signed data we should use
the unsigned char instead of the signed char. Remember that C compilers use the signed char as the
default if we do not put the key word.

Signed char:
The signed char is an 8-bit data type that uses the most significant bit (D7 of D7-D0) to represent
the or + values. As a result, we have only 7 bits for the magnitude of the signed number, giving us

values from -128 to +127. In situations where + and are needed to represent a given quantity such as
temperature, the use of the signed char data type is a must.

Unsigned int:
The unsigned int is a 16-bit data type that takes a value in the range of 0 to 65535 (0000FFFFH).It is also used to set counter values of more than 256. We must use the int data type unless we
have to. Since registers and memory are in 8-bit chunks, the misuse of int variables will result in a larger
hex file. To overcome this we can use the unsigned char in place of unsigned int.

Signed int:
Signed int is a 16-bit data type that uses the most significant bit (D15 of D15-D0) to represent the
or + value. As a result we have only 15 bits for the magnitude of the number or values from -32,768 to
+32,767.

Sbit (single bit):


The sbit data type is widely used and designed specifically to access single bit addressable
registers. It allows access to the single bits of the SFR registers.

(II)

I/O PROGRAMMING IN EMBEDDED C:

In this topic we look at C- programming of the I/O ports and also both byte and bit I/O
programming.

Byte size I/O

As we know that ports P0-P3 are byte accessible, we use the P0-P3 labels as defined in the header
file.
Bit addressable I/O programming

The I/O ports of P0-P3 are bit- addressable, so we can access a single bit without disturbing the
rest of the port. We use the sbit data type to access a single bit of P0-P3.the format is Px^y where x is the
port and y is the bit.

Accessing SFR addresses 80-FFH

Another way to access the SFR RAM space 80-FFH is to use the sfr data type. This is shown in
the below example .Both the bit and byte addresses for the P0-P3 ports are given in the table. Notice in
the given example that there is no #include<reg51.h> statement which allows us to access any byte of the
SFR RAM space 80-FFH.

Single Bit Addresses of Ports

P0

Addr

P1

Addr

P2

Addr

P3

Addr

Ports
Bit

P0.0

80H

P1.0

90H

P2.0

A0H

P3.0

B0H

D0

P0.1

81H

P1.1

91H

P2.1

A1H

P3.1

B1H

D1

P0.2

82H

P1.2

92H

P2.2

A2H

P3.2

B2H

D2

P0.3

83H

P1.3

93H

P2.3

A3H

P3.3

B3H

D3

P0.4

84H

P1.4

94H

P2.4

A4H

P3.4

B4H

D4

P0.5

85H

P1.5

95H

P2.5

A5H

P3.5

B5H

D5

P0.6

86H

P1.6

96H

P2.6

A6H

P3.6

B6H

D6

P0.7

87H

P1.7

97H

P2.7

A7H

P3.7

B7H

D7

III DATA CONVERTION PROGRAMS IN EMBEDDED C

Many micro-controllers have a real time clock (RTC) where the time and date are kept even when
the power is off. These time and date are often in packed BCD by RTC. To display them they must be
converted to ASCII. So, in this topic we are showing application of logic and instructions in the
conversion of BCD and ASCII.

ASCII numbers
On ASCII key boards, when the key 0 is activated, 0110000 (30h) is provided to the
system. Similarly 31h (0110001) is provided for the key 1, and so on as shown in the table

Packed BCD to ASCII conversion

The RTC provides the time of day (hour, minutes, seconds) and the date (year, month, day)
continuously, regardless of whether the power is ON or OFF. In the conversion procedure the packed
BCD is first converted to unpacked BCD. Then it is tagged with 0110000 (30h).

ASCII code for Digits 0-9

Key

ASCII (hex)

Binary

BCD (unpacked)

30

011 0000

0000 0000

31

011 0001

0000 0001

32

011 0010

0000 0010

33

011 0011

0000 0011

34

011 0100

0000 0100

35

011 0101

0000 0101

36

011 0110

0000 0110

37

011 0111

0000 0111

38

011 1000

0000 1000

39

011 1001

0000 1001

ASCII to packed BCD conversion


To convert ASCII to packed BCD it is first converted to unpacked and then combined to make
packed BCD. For example 4 and 7 on the keyboard give 34h and 37h respectively the goal is to produce
47h or 0100 0111 which is packed BCD.

Key

ASCII

unpacked BCD

packed BCD

34

00000100

37

00000111

01000111 or 47h

Checksum byte in ROM


To ensure the integrity of ROM contents, every system must perform the checksum calculation.
The process of checksum will detect any corruption of the contents of ROM. One of the cause of the
ROM corruption is current surge either when the system is turned on or during operation. To ensure data
integrity in ROM the checksum process uses, what is a checksum byte. There is an extra byte that is
tagged to the end of the series of data.

To calculate the checksum byte of a series of bytes of data, the following steps can be used
1) Add the bytes together and drop the carries.
2) Take the 2s complement of the total sum. This is the checksum byte , which becomes the last
byte of the series

Binary (hex) to decimal and ASCII conversion in embedded C

In C-language we use a function call printf which is standard IO library function doing
the conversions of data from binary to decimal, or vice versa. But here we are using our own functions
for conversions because it occupies much of memory.

One of the most commonly used is binary to decimal conversion. In devices such as ADC chips
the data is provided to the controller in binary. In order to display binary data we need to convert it to
decimal and then to ASCII. Since the hexadecimal format is a convenient way of representing binary data
we refer to binary data as hex. The binary data 00-FFH converted to decimal will give us 000 to 255.

One way to do this is to divide it by 10 and keep the remainder, for example 11111101 or FDH is
253 in decimal. The following is one version of the algorithm for conversion of hex (binary) to decimal.

Quotient

Remainder

FD/0A

19

3(low digit) LSD

19/0A

5(middle digit)

2(high digit) (MSD)

SOFTWARE USED:
Embedded C:
Data Types:
U people have already come across the word Data types in C- Language. Here also the
functionality and the meaning of the word is same except a small change in the prefix of their labels.
Now we will discuss some of the widely used data types for embedded C- programming.

Data Types

Size in Bits

Data Range/Usage

unsigned char

8-bit

0-255

signed char

8-bit

-128 to +127

unsigned int

16-bit

0 to 65535

signed int

16-bit

-32,768 to +32,767

sbit

1-bit

SFR bit addressable only

bit

1-bit

RAM bit addressable only

sfr

8-bit

RAM

addresses

80-FFH

only

Unsigned char:
The unsigned char is an 8-bit data type that takes a value in the range of 0-255(00-FFH). It is used
in many situations, such as setting a counter value, where there is no need for signed data we should use
the unsigned char instead of the signed char. Remember that C compilers use the signed char as the
default if we do not put the key word.

Signed char:

The signed char is an 8-bit data type that uses the most significant bit (D7 of D7-D0) to represent
the or + values. As a result, we have only 7 bits for the magnitude of the signed number, giving us
values from -128 to +127. In situations where + and are needed to represent a given quantity such as
temperature, the use of the signed char data type is a must.

Unsigned int:
The unsigned int is a 16-bit data type that takes a value in the range of 0 to 65535 (0000FFFFH).It is also used to set counter values of more than 256. We must use the int data type unless we
have to. Since registers and memory are in 8-bit chunks, the misuse of int variables will result in a larger
hex file. To overcome this we can use the unsigned char in place of unsigned int.

Signed int:
Signed int is a 16-bit data type that uses the most significant bit (D15 of D15-D0) to represent the
or + value. As a result we have only 15 bits for the magnitude of the number or values from -32,768 to
+32,767.

Sbit (single bit):


The sbit data type is widely used and designed specifically to access single bit addressable
registers. It allows access to the single bits of the SFR registers.

(II)

I/O PROGRAMMING IN EMBEDDED C:


In this topic we look at C- programming of the I/O ports and also both byte and bit I/O
programming.

Byte size I/O

As we know that ports P0-P3 are byte accessible, we use the P0-P3 labels as defined in the header
file.
Bit addressable I/O programming

The I/O ports of P0-P3 are bit- addressable, so we can access a single bit without disturbing the
rest of the port. We use the sbit data type to access a single bit of P0-P3.the format is Px^y where x is the
port and y is the bit.

Accessing SFR addresses 80-FFH

Another way to access the SFR RAM space 80-FFH is to use the sfr data type. This is shown in
the below example .Both the bit and byte addresses for the P0-P3 ports are given in the table. Notice in
the given example that there is no #include<reg51.h> statement which allows us to access any byte of the
SFR RAM space 80-FFH.

Single Bit Addresses of Ports

P0

Addr

P1

Addr

P2

Addr

P3

Addr

Ports
Bit

P0.0

80H

P1.0

90H

P2.0

A0H

P3.0

B0H

D0

P0.1

81H

P1.1

91H

P2.1

A1H

P3.1

B1H

D1

P0.2

82H

P1.2

92H

P2.2

A2H

P3.2

B2H

D2

P0.3

83H

P1.3

93H

P2.3

A3H

P3.3

B3H

D3

P0.4

84H

P1.4

94H

P2.4

A4H

P3.4

B4H

D4

P0.5

85H

P1.5

95H

P2.5

A5H

P3.5

B5H

D5

P0.6

86H

P1.6

96H

P2.6

A6H

P3.6

B6H

D6

P0.7

87H

P1.7

97H

P2.7

A7H

P3.7

B7H

D7

(III) DATA CONVERTION PROGRAMS IN EMBEDDED C


Many micro-controllers have a real time clock (RTC) where the time and date are kept even when
the power is off. These time and date are often in packed BCD by RTC. To display them they must be
converted to ASCII. So, in this topic we are showing application of logic and instructions in the
conversion of BCD and ASCII.

ASCII numbers

On ASCII key boards, when the key 0 is activated, 0110000 (30h) is provided to the
system. Similarly 31h (0110001) is provided for the key 1, and so on as shown in the table

Packed BCD to ASCII conversion

The RTC provides the time of day (hour, minutes, seconds) and the date (year, month, day)
continuously, regardless of whether the power is ON or OFF. In the conversion procedure the packed
BCD is first converted to unpacked BCD. Then it is tagged with 0110000 (30h).

ASCII code for Digits 0-9

Key

ASCII (hex)

Binary

BCD (unpacked)

30

011 0000

0000 0000

31

011 0001

0000 0001

32

011 0010

0000 0010

33

011 0011

0000 0011

34

011 0100

0000 0100

35

011 0101

0000 0101

36

011 0110

0000 0110

37

011 0111

0000 0111

38

011 1000

0000 1000

39

011 1001

0000 1001

ASCII to packed BCD conversion


To convert ASCII to packed BCD it is first converted to unpacked and then combined to make
packed BCD. For example 4 and 7 on the keyboard give 34h and 37h respectively the goal is to produce
47h or 0100 0111 which is packed BCD.

Key

ASCII

unpacked BCD

34

00000100

packed BCD

37

00000111

01000111 or 47h

Checksum byte in ROM


To ensure the integrity of ROM contents, every system must perform the checksum calculation.
The process of checksum will detect any corruption of the contents of ROM. One of the cause of the
ROM corruption is current surge either when the system is turned on or during operation. To ensure data
integrity in ROM the checksum process uses, what is a checksum byte. There is an extra byte that is
tagged to the end of the series of data.

To calculate the checksum byte of a series of bytes of data, the following steps can be used
1) Add the bytes together and drop the carries.
2) Take the 2s complement of the total sum. This is the checksum byte , which becomes the last
byte of the series

Binary (hex) to decimal and ASCII conversion in embedded C

In C-language we use a function call printf which is standard IO library function doing
the conversions of data from binary to decimal, or vice versa. But here we are using our own functions
for conversions because it occupies much of memory.

One of the most commonly used is binary to decimal conversion. In devices such as ADC chips
the data is provided to the controller in binary. In order to display binary data we need to convert it to
decimal and then to ASCII. Since the hexadecimal format is a convenient way of representing binary data
we refer to binary data as hex. The binary data 00-FFH converted to decimal will give us 000 to 255.

One way to do this is to divide it by 10 and keep the remainder, for example 11111101 or FDH is
253 in decimal. The following is one version of the algorithm for conversion of hex (binary) to decimal.

Quotient

Remainder

FD/0A

19

3(low digit) LSD

19/0A

5(middle digit)
2(high digit) (MSD)

ABOUT SOFTWARE
Softwares used are:
*Keil software for c programming
*Express PCB for lay out design
*Express SCH for schematic design
What's New in Vision3?
Vision3 adds many new features to the Editor like Text Templates, Quick Function Navigation, and
Syntax Coloring with brace high lighting Configuration Wizard for dialog based startup and debugger
setup. Vision3 is fully compatible to Vision2 and can be used in parallel with Vision2.
What is Vision3?
Vision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug
embedded programs. It encapsulates the following components:

A project manager.

A make facility.

Tool configuration.

Editor.

A powerful debugger.

To help you get started, several example programs (located in the \C51\Examples, \C251\Examples,
\C166\Examples, and \ARM\...\Examples) are provided.

HELLO is a simple program that prints the string "Hello World" using the Serial Interface.

MEASURE is a data acquisition system for analog and digital systems.

TRAFFIC is a traffic light controller with the RTX Tiny operating system.

SIEVE is the SIEVE Benchmark.

DHRY is the Dhrystone Benchmark.

WHETS is the Single-Precision Whetstone Benchmark.

Additional example programs not listed here are provided for each device architecture.

Building an Application in Vision2


To build (compile, assemble, and link) an application in Vision2, you must:
1.

Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2).

2.

Select Project - Rebuild all target files or Build target.


Vision2 compiles, assembles, and links the files in your project.

Creating Your Own Application in Vision2


To create a new project in Vision2, you must:
1. Select Project - New Project.
2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device
Database.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the source files
to the project.
6. Select Project - Options and set the tool options. Note when you select the target device from the
Device Database all special options are set automatically. You typically only need to configure
the memory map of your target hardware. Default memory model settings are optimal for most
applications.
7. Select Project - Rebuild all target files or Build target.
Debugging an Application in Vision2
To debug an application created using Vision2, you must:
1. Select Debug - Start/Stop Debug Session.
2. Use the Step toolbar buttons to single-step through your program. You may enter G, main in the
Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step, Go, Break, and so on.
Starting Vision2 and Creating a Project
Vision2 is a standard Windows application and started by clicking on the program icon. To create a new
project file select from the Vision2 menu.
Project New Project. This opens a standard Windows dialog that asks you
for the new project file name.

We suggest that you use a separate folder for each project. You can simply use the icon Create New
Folder in this dialog to get a new empty folder. Then select this folder and enter the file name for the new
project, i.e. Project1. Vision2 creates a new project file with the name PROJECT1.UV2 which contains
a default target and file group name. You can see these names in the Project.
Window Files.
Now use from the menu Project Select Device for Target and select a CPU for your project. The Select
Device dialog box shows the Vision2 device database. Just select the micro controller you use. We are
using for our examples the Philips 80C51RD+ CPU. This selection sets necessary tool options for the
80C51RD+ device and simplifies in this way the tool Configuration.
Building Projects and Creating a HEX Files
Typical, the tool settings under Options Target are all you need to start a new application. You may
translate all source files and line the application with a click on the Build Target toolbar icon. When you
build an application with syntax errors, Vision2 will display errors and warning messages in the Output
Window Build page. A double click on a message line opens the source file on the correct location in a
Vision2 editor window. Once you have successfully generated your application you can start
debugging.

After you have tested your application, it is required to create an Intel HEX file to download the
software into an EPROM programmer or simulator. Vision2 creates HEX files with each build process
when Create HEX files under Options for Target Output is enabled. You may start your PROM
programming utility after the make process when you specify the program under the option Run User
Program #1.
CPU Simulation
Vision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read, write, or code
execution access. The Vision2 simulator traps and reports illegal memory access.
In addition to memory mapping, the simulator also provides support for the integrated peripherals of the
various 8051 derivatives. The on-chip peripherals of the CPU you have selected are configured from the
Device.

Database selection
you have made when you create your project target. Refer to page 58 for more Information about
selecting a device. You may select and display the on-chip peripheral components using the Debug menu.
You can also change the aspects of each peripheral using the controls in the dialog boxes.

Start Debugging
You start the debug mode of Vision2 with the Debug Start/Stop Debug Session command. Depending
on the Options for Target Debug Configuration, Vision2 will load the application program and run the
startup code Vision2 saves the editor screen layout and restores the screen layout of the last debug
session. If the program execution stops, Vision2 opens an editor window with the source text or shows
CPU instructions in the disassembly window. The next executable statement is marked with a yellow
arrow. During debugging, most editor features are still available.

For example, you can use the find command or correct program errors. Program source text of your
application is shown in the same windows. The Vision2 debug mode differs from the edit mode in the
following aspects:
_ The Debug Menu and Debug Commands described on page 28 are Available. The additional debug
windows are discussed in the following.
_ The project structure or tool parameters cannot be modified. All build Commands are disabled.
Disassembly Window
The Disassembly window shows your target program as mixed source and assembly program or just
assembly code. A trace history of previously executed instructions may be displayed with Debug View
Trace Records. To enable the trace history, set Debug Enable/Disable Trace Recording.
If you select the Disassembly Window as the active window all program step commands work on CPU
instruction level rather than program source lines. You can select a text line and set or modify code
breakpoints using toolbar buttons or the context menu commands.
You may use the dialog Debug Inline Assembly to modify the CPU instructions. That
allows you to correct mistakes or to make temporary changes to the target program you are debugging.

Steps for executing the Keil programs:


1.

Click on the Keil uVision Icon on Desktop

2.

The following fig will appear

3.

Click on the Project menu from the title bar

4.

Then Click on New Project

5.

Save the Project by typing suitable project name with no extension in u r own folder sited in
either C:\ or D:\

6.

Then Click on Save button above.

7.

Select the component for u r project. i.e. Atmel

8.

Click on the + Symbol beside of Atmel

9.

Select AT89C51 as shown below

10.

Then Click on OK

11.

The Following fig will appear

12.

Then Click either YES or NOmostly NO

13.

Now your project is ready to USE

14.

Now double click on the Target1, you would get another option Source group 1 as shown in
next page.

15.

Click on the file option from menu bar and select new

16.

The next screen will be as shown in next page, and just maximize it by double clicking on its
blue boarder.

17.

Now start writing program in either in C or ASM

18.

For a program written in Assembly, then save it with extension . asm and for C based
program save it with extension .C

19.

Now right click on Source group 1 and click on Add files to Group Source

20.

Now you will get another window, on which by default C files will appear.

21.

Now select as per your file extension given while saving the file

22.

Click only one time on option ADD

23.

Now Press function key F7 to compile. Any error will appear if so happen.

24.

If the file contains no error, then press Control+F5 simultaneously.

25.

The new window is as follows

26.

Then Click OK

27.

Now Click on the Peripherals from menu bar, and check your required port as shown in fig
below

28.

Drag the port a side and click in the program file.

29.

Now keep Pressing function key F11 slowly and observe.

30.

You are running your program successfully