Sei sulla pagina 1di 47

1.

INTRODUCTION

 1.1 Objective:
 Aim of this project is to allow the servo motor to move to an angle specified
by the user. The pulse train required to rotate the servo is produced
by AT89C51 microcontroller. The desired angle of rotation is provided
through a 4x3 keypad interfaced to the microcontroller and 16x2 LCD is to
display the angle of rotation entered by the user.
 To learn how to write an assembly language and combining with
the hardware.
 To learn and develop knowledge in designing the different applications
by using the microcontroller.

 1.2 What is a servo motor?

Fig.1.2 Servo Motor

MBICT/<EC>/<Servo Motor Rotation> Page 1


A Servo is a small device that incorporates a three wire DC motor, a gear
train, a potentiometer,an integrated circuit, and an output shaft bearing
(Shown in Fig.1.2). Of the three wires that stick out from the motor casing,
one is for power, one is for ground, and one is a control input line. The shaft
of the servo can be positioned to specific angular positions by sending a
coded signal. As long as the coded signal exists on the input line, the servo
will maintain the angular position of the shaft. If the coded signal changes,
then the angular position of the shaft changes. Servos come in different sizes
but use similar control schemes and are extremely useful in robotics. The
motors are small and are extremely powerful for their size. It also draws
power proportional to the mechanical load. A lightly loaded servo, therefore,
doesn’t consume much energy. A very common use of servos is in Radio
Controlled models like cars, airplanes, robots, and puppets. They are also
used in powerful heavy-duty sail boats. Servos are rated for Speed and
Torque. Normally there are two servos of the same kind, one geared towards
speed (sacrificing torque), and the other towards torque (sacrificing speed).

Servos are constructed from three basic pieces; a motor, a potentiometer


(variable resister) that is connected to the output shaft, and a control board.
The potentiometer allows the control circuitry to monitor the current angle of
the servo motor. The motor, through a series of gears, turns the output shaft
and the potentiometer simultaneously. The potentiometer is fed into the
servo control circuit and when the control circuit detects that the position is
correct, it stops the motor. If the control circuit detects that the angle is not
correct, it will turn the motor the correct direction until the angle is correct.
Normally a servo is used to control an angular motion of between 0 and 180
degrees. It is not mechanically capable (unless modified) of turning any
farther due to the mechanical stop build on to the main output gear. The
amount of power applied to the motor is proportional to the distance it needs

MBICT/<EC>/<Servo Motor Rotation> Page 2


to travel. So, if the shaft needs to turn a large distance, the motor will run at
full speed. If it needs to turn only a small amount, the motor will run at a
slower speed. This is called proportional control.

 1.3 Servo Motor System

Fig.1.3 Servo Motor System

The DC motor is connected with a gear mechanism which provides feedback to


a position sensor which is mostly a potentiometer. From the gear box, the output
of the motor is delivered via servo spline to the servo arm. The potentiometer
changes position corresponding to the current position of the motor. So the
change in resistance produces an equivalent change in voltage from the
potentiometer. A pulse width modulated signal is fed through the control wire.
The pulse width is converted into an equivalent voltage that is compared with
that of signal from the potentiometer in an error amplifier. The difference signal
is amplified and provided to the DC motor. So the signal applied to the DC

MBICT/<EC>/<Servo Motor Rotation> Page 3


servo motor is a damping wave which diminishes as the desired position is
attained by the motor.

 1.4 Basic operation

Servos are controlled by sending an electrical pulse of variable width, or pulse


width modulation (PWM), through the control wire. There is a minimum pulse,
a maximum pulse, and a repetition rate. A servo motor can usually only turn 90
degrees in either direction for a total of 180 degree movement. The motor's
neutral position is defined as the position where the servo has the same amount
of potential rotation in the both the clockwise or counter-clockwise direction.
The PWM sent to the motor determines position of the shaft, and based on the
duration of the pulse sent via the control wire; the rotor will turn to the desired
position. The servo motor expects to see a pulse every 20 milliseconds (ms) and
the length of the pulse will determine how far the motor turns. For example, a
1.5ms pulse will make the motor turn to the 90-degree position. Shorter than
1.5ms moves it to 0 degrees, and any longer than 1.5ms will turn the servo to
180 degrees (Shown in Fig.1.4).

Fig.1.4 Variable Pulse Width Control Servo Position

MBICT/<EC>/<Servo Motor Rotation> Page 4


2. LITERATURE SURVEY

 2.1 Block Diagram:

Fig. 2.1 Block diagram of Servo Motor rotation through keypad

 Description

Power Supply: It will be +5V DC power supply & given to the whole circuit.

Input: It will be 4×3 keypad & connect with the 8051 microcontroller. When
the circuit is powered, the user to enter the angle of rotation . The user can enter
the angle in degrees through keypad and the angle of rotation is accepted by the
microcontroller.

Microcontroller: It will be 8051 microcontroller used. In 40 pin AT89C51,


there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-
directional ports, i.e., they can be used as both input and output ports. The first
pin of port P1(P1^0) of AT89C51 microcontroller is set as the output pin to
provide signal to the servo motor. Port P0 and P2 are used to interface keypad
and data pins of LCD, respectively. Port P1^3, P1^4 and P1^5 are connected to
RS, RW and LCD respectively.

Driver IC: It will be LM324. Before connecting to the control wire of servo,
the output from the microcontroller (P1^0) is fed through a comparator IC
(LM324) so that the signal is protected from any loss due to overloading.

MBICT/<EC>/<Servo Motor Rotation> Page 5


LCD Display: It will be 16×2 character display. The angle entered by the user
is also displayed on the LCD screen and servo moves to the user defined
angular position through keypad.

MBICT/<EC>/<Servo Motor Rotation> Page 6


 2.2 Circuit Diagram:

Fig.2.2 Circuit diagram of Servo Motor rotation through keypad

 Description

This project allows the servo motor to move to an angle specified by the user.
The pulse train required to rotate the servo is produced
by AT89C51 microcontroller. The desired angle of rotation is provided through
a 4x3 keypad interfaced to the microcontroller. A 16x2 LCD is also connected
with the microcontroller to display the angle of rotation entered by the user.

MBICT/<EC>/<Servo Motor Rotation> Page 7


The servo motor is controlled by feeding pulse width modulated (PWM) signal
at the control wire of the servo motor. In addition a 4.8V (ideally 5V) DC
supply is provided to the red lead of the servo. The black lead of the servo is
connected to Ground. The first pin of port P1 (P1^0)
of AT89C51 microcontroller is set as the output pin to provide control signal to
the servo motor. Before connecting to the control wire of servo, the output from
the microcontroller is fed through a comparator IC (LM324) so that the signal is
protected from any loss due to overloading. Ports P0 and P2 are used to
interface keypad and data pins of LCD, respectively. Ports P1^3, P1^4 and P1^5
are connected to RS, RW and EN pins of LCD, respectively.

Here keypad is organized as a matrix of switches in rows and column. There are
4X3 matrix keypad and a 16x2 LCD for displaying the output of keypad. The
circuit diagram shows the connection of keypad with the controller. Port P0 is
used to scan input from the keypad. The concept of interfacing keypad with the
microcontroller is simple. Every number is assigned two unique parameters, i.e.,
row and column number (n(R, C). Initially all the rows are set to zero by the
controller and the columns are scanned to check if any key is pressed. In case no
key is pressed the output of all the columns will be high. Whenever a key is
pressed the row and column corresponding to the key will get short, resulting in
the output of the corresponding column goes to go low (since we have made all
the rows zero). This gives the column number of the pressed key. Once the
column number is detected, the controller set’s all the rows to high. Now one by
one each row is set to zero by controller and the earlier detected column is
checked if it becomes zero. The row corresponding to which the column gets
zero is the row number of the digit. This process is very fast and even if the
switch is pressed for a very small duration of time the controller can detect the
key which is pressed. The controller displays the number corresponding to the
row and column on the LCD.

MBICT/<EC>/<Servo Motor Rotation> Page 8


When LCD interfaced with microcontroller (AT89C51), the control pins (pin 4-
6) are controlled by pins 2-4 of P0 port. Pin 3 is connected to a preset of 10k to
adjust the contrast on LCD screen. When the circuit is powered, the LCD
prompts the user to enter the angle of rotation. The user can enter the angle in
degrees through keypad. The angle entered by the user is also displayed on the
LCD screen. As the user presses ‘*’ button of keypad, the angle of rotation is
accepted by the microcontroller and the servo moves to the user defined angular
position. If an angle greater than 180° is entered, the difference of the input with
180° is considered as the angle of rotation.

 2.3 Details of Component:

2.3.1 LM324 IC

Fig.2.3.1 Pin diagram

MBICT/<EC>/<Servo Motor Rotation> Page 9


Table 2.3.1 Pin description

LM324 is a 14pin IC consisting of four independent operational amplifiers (op-


amps) compensated in a single package. Op-amps are high gain electronic
voltage amplifier with differential input and, usually, a single-ended output. The
output voltage is many times higher than the voltage difference between input
terminals of an op-amp. These op-amps are operated by a single power
supply LM324 and need for a dual supply is eliminated. They can be used as
amplifiers, comparators, oscillators, rectifiers etc. The conventional op-amp
applications can be more easily implemented with LM324.

 Features
 Wide power supply range:
Single supply 3V to 32V
or dual supplies ±1.5V to ±16V

MBICT/<EC>/<Servo Motor Rotation> Page 10


 Very low supply current drain (700 μA)—essentially Independent of
supply voltage
 Differential input voltage range equal to the power supply voltage

 Advantages

 Eliminates need for dual supplies


 Allows directly sensing near GND and VOUT also goes to GND
 Compatible with all forms of logic

2.3.2 16×2 LCD

Fig.2.3.2 Pin diagram

MBICT/<EC>/<Servo Motor Rotation> Page 11


Pin No Function Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
3 Contrast adjustment; through a variable resistor VEE

4 Selects command register when low; and data register when high Register Select

5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulse is given Enable
7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led-

Table 2.3.2 Pin description

LCD (Liquid Crystal Display) screen is an electronic display module and find a
wide range of applications. A 16x2 LCD display is very basic module and is
very commonly used in various devices and circuits. These modules are
preferred over seven segments and other multi segment LEDs. The reasons
being: LCDs are economical; easily programmable; have no limitation of
displaying special & even custom characters animations and so on.
Here 16x2 LCD means it can display 16 characters per line and there are 2 such
lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has
two registers, namely, Command and Data.

1. The command register – It stores the command instructions given to the


LCD. A command is an instruction given to LCD to do a predefined task
like initializing it, clearing its screen, setting the cursor position,
controlling display etc.

MBICT/<EC>/<Servo Motor Rotation> Page 12


2. The data register – It stores the data to be displayed on the LCD. The data
is the ASCII value of the character to be displayed on the LCD.

 Features
 5 x 8 dots with cursor
 Built-in controller (KS 0066 or Equivalent)
 + 5V power supply (Also available for + 3V)
 1/16 duty cycle
 N.V. optional for + 3V power supply

2.3.3 AT89C51 Microcontroller:

Fig.2.3.3 Pin diagram

MBICT/<EC>/<Servo Motor Rotation> Page 13


Bit Function Pin

P1.0 to P1.7 8 bit I/O port(P1) Pins 1 to 8

Reset Reset 9

P3.0 to P3.7 8 bit I/O port(P3) Pins 10 to 17

Crystal 1 Quartz Crystal Oscillator 18 &19

Crystal 2

Ground Ground(0V) 20

P2.0 to P2.7 High Order address bits 21 to 28


when interfacing with
external memory; 8 bit
I/O port(P2) Pins

PSEN Program Store Enable; 29


Read from external
program memory

ALE Address Latch Enable 30

EA External Access Enable; 31


Vcc for internal program
execution

P0.7 to P0.0 Low Order address bits 32 to 40


when interfacing with
external memory;

8 bit I/O port(P0) Pins

Table 2.3.3(1) Pin description

MBICT/<EC>/<Servo Motor Rotation> Page 14


Features 8051

RAM(byte) 128

ROM 4K

TIMERS 2

Serial Port 1

I/O Pins 32

Interrupt Sources 6

Table 2.3.3(2) Features of 8051

A microcontroller is an economical computer-on-a-chip built for dealing with


specific tasks, such as displaying or receiving information through LEDs or
remote controlled devices. The most commonly used set of microcontrollers
belong to 8051 Family. 8051 Microcontrollers continue to remain a preferred
choice for a vast community of hobbyists and professionals. AT89C51 is an 8-
bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has
4KB of Flash programmable and erasable read only memory (PEROM) and 128
bytes of RAM. It can be erased and program to a maximum of 1000 times.

In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All
these ports are 8-bit bi-directional ports, i.e., they can be used as both input and
output ports. Except P0 which needs external pull-ups, rest of the ports have
internal pull-ups. When 1s are written to these port pins, they are pulled high by
the internal pull-ups and can be used as inputs. These ports are also bit
addressable and so their bits can also be accessed individually.

MBICT/<EC>/<Servo Motor Rotation> Page 15


Port P0 and P2 are also used to provide low byte and high byte addresses,
respectively, when connected to an external memory. Port 3 has multiplexed
pins for special functions like serial communication, hardware interrupts, timer
inputs and read/write operation from external memory. AT89C51 has an inbuilt
UART for serial communication. It can be programmed to operate at different
baud rates. Including two timers & hardware interrupts, it has a total of six
interrupts.

2.3.4 Preset

Fig.2.3.4 Preset

A preset is a three legged electronic component which can be made to offer


varying resistance in a circuit. The resistance is varied by adjusting the rotary
control over it. The adjustment can be done by using a small screw driver or a
similar tool. The resistance does not vary linearly but rather varies in
exponential or logarithmic manner. Such variable resistors are commonly used
for adjusting sensitivity along with a sensor. The variable resistance is obtained
across the single terminal at front and one of the two other terminals. The two
legs at back offer fixed resistance which is divided by the front leg. So

MBICT/<EC>/<Servo Motor Rotation> Page 16


whenever only the back terminals are used, a preset acts as a fixed resistor.
Presets are specified by their fixed value resistance.

2.3.5 4×3 Keypad

Fig.2.3.5 Circuit Diagram Fig.2.3.5 Matrix Keypad

Keypad is organized as a matrix of switches in rows and column. Here we are


using a 4X3 matrix keypad. Keypad is a widely used input device with lots of
application in our everyday life. From a simple telephone to keyboard of a
computer, ATM, electronic lock, etc., keypad is used to take input from the user
for further processing. In this article we are interfacing keypad with the
AT89C51 and displaying the corresponding number on LCD. This module can
be further used in a number of systems to interfaced keypad with
microcontroller and other processors to get desired output.

MBICT/<EC>/<Servo Motor Rotation> Page 17


3. IMPLEMENTATION OF WORK

3.1 Hardware System

C
E
D

I
H
A

Fig. 3.1 Hardware Design

MBICT/<EC>/<Servo Motor Rotation> Page 18


Sr No. Components

A Servo Motor ; (Rotation Limit-


0° to 180°)

B AT89C51 Microcontroller

C LCD Display

D 4×3 Keypad

E Preset ; 10k

F Crystal ; 11.0592MHz

G Resistor; 10kΩ

H LM324 IC

I Capacitor ; 10µF

Table 3.1 Hardware Component Overview

Power Supply that is to produce limited voltage supplied to microcontroller(IC).


This is important because IC will burn out if the supply voltage more than 5 volt. Resistor
of 10kΩ is used to bias the switch in order to have voltage drop as input signals to
IC. Servos do not rotate continually. Their rotation is restricted in between the
fixed angles. Here we are using servo motor which has rotation limit in between
0° to 180°. The process of servo motor rotation through keypad is done by LCD
and Keypad interfacing with 8051 microcontroller. Crystal oscillator is an
electronic circuit that uses the mechanical resonance of a vibrating crystal of
piezoelectric material to create an electrical signal with a very precise frequency.
In this project, the frequency is used to keep track of time and provide a stable clock
signal.

MBICT/<EC>/<Servo Motor Rotation> Page 19


 3.2 Software System:
We have used Keil µvision software tool to make the codes, for the
simulation of the code and for burning the code in the micro-controller and
another is Proteus software tool to make pcb layout design the tools are as
below:

3.2.1 keil µvision

The new Keil µVision4 has been designed to enhance developer's productivity,
enabling faster, more efficient program development.
µVision4 introduces a flexible window management system, enabling you to
drag and drop individual windows anywhere on the visual surface including
support for Multiple Monitors. It is an integrated embedded software
development environment for project management, program editing, debugging,
and simulation. It is an excellent development tools for beginner students and
professionals for the 8051 microcontroller embedded software development.
There are some features of this tool as listed below.

 Multiple Monitor and flexible window management system


 System Viewer - display device peripheral register information
 Debug Restore Views - create and save multiple debug window layouts
 Multi-Project Workspace - simplify working with numerous projects

Keil µVision 4 is cross compiler for the AT89C51 microcontroller families. The
compiler simulated the program and also converts the program in to hex file
which is used to burn in the microcontroller. The Keil µVision 4 we uses is of
6Kb of size means we can run a code up to a size of 6Kb. It supports the all the
microcontroller of C51 families.

MBICT/<EC>/<Servo Motor Rotation> Page 20


Fig. 3.2.1(1) KEIL µvision-4

Fig. 3.2.1(2) Project Window Of Keil

MBICT/<EC>/<Servo Motor Rotation> Page 21


3.2.2 Proteus

Proteus is software for microprocessor simulation, schematic capture,


and printed circuit board (PCB) design. Proteus PCB design combines the ISIS
schematic capture and ARES PCB layout programs to provide a powerful,
integrated and easy to use suite of tools for professional PCB Design.
All Proteus PCB design products include an integrated shape based auto
router and a basic SPICE simulation capability as standard. More advanced
routing modes are included in Proteus PCB Design Level 2 and higher whilst
simulation capabilities can be enhanced by purchasing the Advanced
Simulation option and/or micro-controller simulation capabilities. Here we are
using Proteus 7.4 professional tool for PCB design layout.

Fig. 3.2.2 Proteus PCB design

MBICT/<EC>/<Servo Motor Rotation> Page 22


3.2.3 Flow Chart

There is two language can be use in order to program the IC, that is either low
level language that is assembly or high level language such as C programming
and IC Basic Pro. Both of the method has an advantage and disadvantages. In
this project is using the high level language & the size of program can exceed
1K.

In this project, programming is the most important part to achieve a stopwatch.


Before write a program, it is necessary to have a flow chart of the program
stopwatch. The figure 3.2.3 shows the flow chart of the program stopwatch.
After get the flowchart, the program code can be written now. The full program
is shown in next chapter. Here the software that needed to write the C language
programming.

When the program is executed, data starts to read from LCD. Here when the
circuit is powered, the LCD prompts the user to enter the angle of rotation. The
user can enter the angle in degrees through keypad. The angle entered by the
user is also displayed on the LCD screen. As the user presses ‘*’ button of
keypad, the angle of rotation is accepted by the microcontroller and the servo
moves to the user defined angular position. If an angle greater than 180° is
entered, the difference of the input with 180° is considered as the angle of
rotation. If user enter the angle that is greater than 360° then it is accepted by
microcontroller and it gives difference of the input with 180°. So this difference
is considered as the angle of rotation . Then again user enter the degree which is
less than equal to 180°.

MBICT/<EC>/<Servo Motor Rotation> Page 23


Fig. 3.2.3 Flow Chart

MBICT/<EC>/<Servo Motor Rotation> Page 24


3.2.4 Printed Circuit Board Construction:

Printed circuit board is used extensively in all types of electronic equipment.


It’s has helped in producing smaller and more reliable electronic equipment. A
printed circuit board serves two basic functions. It provides both the mounting
space for the component and connects them together.

The simplest type of printed circuit board is the single side board. It consists of
a thin conductive foil cladding on one side of a rigid non-conductive laminate.
Component is positioned on the insulator side of the board. Lead access holes
are drilled through both the laminate material and conductive foil for each
component lead. These lead are passed through holes and then they are bent and
soldered to the foil and excess lead is trimmed. The foil cladding is previously
processed into conductive path to provide the required wiring for working
circuit.

Fig. 3.2.4 PCB layout of Servo Motor


Rotation4.through
Resultskeypad
Analysis

MBICT/<EC>/<Servo Motor Rotation> Page 25


 4.1 Result Analysis of Servo Motor Rotation through keypad :

 When the circuit is powered, the LCD prompts the user to enter the angle
of rotation. The user can enter the angle in degrees through keypad.
(Figure1)

Figure 1

 When user enter the angle in degrees through keypad. Then angle entered
by the user is also displayed on the LCD screen. As the user presses ‘*’
button of keypad, the angle of rotation is accepted by the
microcontroller and the servo moves to the user defined angular position.
Here user enter the angle in 0° and 90°. (Figure 2 and Figure 3)

MBICT/<EC>/<Servo Motor Rotation> Page 26


Figure 2

Figure 3

MBICT/<EC>/<Servo Motor Rotation> Page 27


 If an angle greater than 180° is entered, the difference of the input with
180° is considered as the angle of rotation. Here if user enter 270° angle
then motor rotate with 270°-180°=90°. (Figure 4 and Figure 5)
Figure 4

Figure 5

MBICT/<EC>/<Servo Motor Rotation> Page 28


 If an angle greater than 360°(e.g 500°) is entered, the difference of the
input with 180° is considered as the angle of rotation. Thus 500°-
180°=320° but it is also greater than 180°. So that again differences of the
input with 180° is considered as the angle of rotation. Thus 320°-
180°=140° . (Figure 6 and Figure 7)

Figure 6

Figure 7

MBICT/<EC>/<Servo Motor Rotation> Page 29


 4.2 Software Coding:

// Program to rotate servo to user defined angular position

// 0 degree = 700us

// 180 degree = 5500us

// Timer1 pulse after 50us -23

#include<reg51.h>

#define dataport P2 // Data port for LCD

#define key P0 // Port for Keypad

#define port P1

sbit output = port^0;

sbit rs = port^3;

sbit rw = port^4;

sbit en = port^5;

sbit col1 = key^4;

sbit col2 = key^5;

sbit col3 = key^6;

sbit row1 = key^0;

MBICT/<EC>/<Servo Motor Rotation> Page 30


sbit row2 = key^1;

sbit row3 = key^2;

sbit row4 = key^3;

int count=0,time=0,check, digit[3];

void delay(unsigned int msec) // Function for delay

int i,j;

for(i=0;i<msec;i++)

for(j=0;j<1275;j++);

void lcd_cmd(unsigned char item) // Function to send command to


LCD

dataport = item;

rs= 0;

rw=0;

en=1;

delay(1);

en=0;

return;

MBICT/<EC>/<Servo Motor Rotation> Page 31


}

void lcd_data(unsigned char item) // Function to send one byte data to


LCD

dataport = item;

rs= 1;

rw=0;

en=1;

delay(1);

en=0;

return;

void lcd_data_string(unsigned char *str) // Function to send string to LCD

int i=0;

while(str[i]!='\0')

lcd_data(str[i]);

i++;

MBICT/<EC>/<Servo Motor Rotation> Page 32


delay(10);

return;

lcd_data_int(int time_val) // Function to send three digit


number

int int_amt;

int_amt = time_val/100;

lcd_data(int_amt+48);

time_val = time_val%100;

int_amt = time_val/10;

lcd_data(int_amt+48);

int_amt = time_val%10;

lcd_data(int_amt+48);

void shape() // Function to make degree sign

lcd_cmd(64);

MBICT/<EC>/<Servo Motor Rotation> Page 33


lcd_data(2);

lcd_data(5);

lcd_data(2);

lcd_data(0);

lcd_data(0);

lcd_data(0);

lcd_data(0);

lcd_data(0);

void timer(int msec) // Function to produce pulse as


defined by user

int i;

TR1=1;

for(i=0;i<msec;i++)

while(TF1==0);

TF1=0;

TR1=0;

MBICT/<EC>/<Servo Motor Rotation> Page 34


}

void digit_set(int num)

if(count==4)

lcd_cmd(0x01);

lcd_data_string("done");

check=num;

else

check=0;

if(count==1)

digit[0]=num;

else

if(count==2)

digit[1]=digit[0];

MBICT/<EC>/<Servo Motor Rotation> Page 35


digit[0]=num;

else

if(count==3)

digit[2]=digit[1];

digit[1]=digit[0];

digit[0]=num;

lcd_data((num+48));

void check_col1() // Col1 check

row1=row2=row3=row4=1;

row1=0;

if(col1==0) // Key 1

MBICT/<EC>/<Servo Motor Rotation> Page 36


delay(10);

count=count+1;

digit_set(1);

row1=1;

row2=0;

if(col1==0) // Key 4

delay(10);

count=count+1;

digit_set(4);

row2=1;

row3=0;

if(col1==0) // Key 7

delay(10);

count=count+1;

digit_set(7);

MBICT/<EC>/<Servo Motor Rotation> Page 37


row3=1;

row4=0;

if(col1==0) // Key *

delay(10);

count=count+1;

if(count==4)

digit_set(10);

else

count=4;

digit_set(10);

row4=1;

void check_col2() //Col2 check

MBICT/<EC>/<Servo Motor Rotation> Page 38


{

row1=row2=row3=row4=1;

row1=0;

if(col2==0) // Key 2

delay(10);

count=count+1;

digit_set(2);

row1=1;

row2=0;

if(col2==0) // Key 5

delay(10);

count=count+1;

digit_set(5);

row2=1;

row3=0;

if(col2==0) // Key 8

MBICT/<EC>/<Servo Motor Rotation> Page 39


{

delay(10);

count=count+1;

digit_set(8);

row3=1;

row4=0;

if(col2==0) // Key 0

delay(10);

count=count+1;

digit_set(0);

row4=1;

void check_col3() // Col3 check

row1=row2=row3=row4=1;

row1=0;

MBICT/<EC>/<Servo Motor Rotation> Page 40


if(col3==0) // Key 3

delay(10);

count=count+1;

digit_set(3);

row1=1;

row2=0;

if(col3==0) // Key 6

delay(10);

count=count+1;

digit_set(6);

row2=1;

row3=0;

if(col3==0) // Key 9

delay(10);

count=count+1;

MBICT/<EC>/<Servo Motor Rotation> Page 41


digit_set(9);

row3=1;

row4=0;

if(col3==0) // Key #

delay(10);

count=count+1;

lcd_data_string("wrong data");

lcd_cmd(0x01);

lcd_data_string("enter degree:");

lcd_cmd(0xc5);

count=0;

row4=1;

void keypad()

if(col1==0)

check_col1();

MBICT/<EC>/<Servo Motor Rotation> Page 42


else

if(col2==0)

check_col2();

else

if(col3==0)

check_col3();

delay(10);

void main()

int i;

col1=col2=col3=1;

TMOD=0x20; // MODE2

TH1= -23; // 50 usec timer

shape();

output=0;

lcd_cmd(0x38);

lcd_cmd(0x0e);

lcd_cmd(0x01);

delay(100);

MBICT/<EC>/<Servo Motor Rotation> Page 43


while(1)

count=0;

lcd_cmd(0x01);

lcd_data_string("enter degree:");

lcd_cmd(0xc5);

check=0;

digit[0]=0;

digit[1]=0;

digit[2]=0;

while(check!=10)

row1=row2=row3=row4=0;

while(col1==1 && col2==1 && col3==1);

keypad();

time=(digit[0]+(digit[1]*10)+(digit[2]*100));

lcd_cmd(0xc4);

time=time%180;

lcd_data_int(time);

MBICT/<EC>/<Servo Motor Rotation> Page 44


lcd_data(0);

time= time*0.5; // (110-14)/180=0.53

/* for(i=0;i<200;i++)

output=1;

timer(14);

output=0;

timer(360);

}*/

delay(100);

for(i=0;i<80;i++)

output=1;

timer(time+14);

output=0;

timer(360);

timer(3000000);

MBICT/<EC>/<Servo Motor Rotation> Page 45


5. CONCLUSION

After we done our project about servo motor rotation through keypad, we are
able to learn and develop knowledge in designing by used a microcontroller and
different softwares as Keil µVision & Proteus. We are also learn how to
develop skills and knowledge in systematic PCB design approach using Proteus
software. The DC servo motors are presently used world wide in applications
such as X-Y tables, factory automation, coil winders, labeling equipment,
machine tool, insertion machines, robotics, pick and place, packaging,
converting equipment, assembly equipment and laboratory equipment.

MBICT/<EC>/<Servo Motor Rotation> Page 46


REFERENCES

BIBLIOGRAPHY:

http://en.wikipedia.org

http://www.scribd.com

http://www.engineersgarage.com

BOOKS:
The 8051 Microcontroller & Embedded Systems using Assembly & C By Mazidi

MBICT/<EC>/<Servo Motor Rotation> Page 47

Potrebbero piacerti anche