Professional Documents
Culture Documents
Technology
Embed is defined as inserting or implanting subspace (small
structure) into whole space (larger structure). And embedded
technology means embedding smaller circuits to larger one
to
make
one
complete
circuit.
In
todays
world
the
Microprocessors
A microprocessor is a general-purpose digital computer
central processing unit (CPU). Although popularly known as a
computer on a chip is in no sense a complete digital
computer. The block diagram of a microprocessor CPU is
shown, which contains arithmetic and logical unit (ALU), a
program counter (PC), a stack pointer (SP), some working
registers, a clock timing circuit and interrupts circuits. Out of
the CPU it is connected to different peripherals to complete
its operations.
Fig. shows
microprocessor
the
block
diagram
of
typical
Microcontrollers
Figure shows the block diagram of a typical microcontroller,
which is a true computer on a chip. The design incorporates
all of the features found in Micro-processor CPU: ALU, PC, SP,
and registers. It also added the other features needed to
Fig. shows
microcontroller
the
block
diagram
of
typical
8051 MICROCONTROLLER
The 8051 Microcontrollers Architecture consists of these
specific features
8-bit data bus
16-bit address bus
32 general purpose registers each of 8 bits
16 bit timers (usually 2, but may have more, or less).
3 internal and 2 external interrupts.
Bit as well as byte addressable RAM area of 16 bytes.
Four 8-bit ports, (short models have two 8-bit ports).
16-bit program counter and data pointer
3
8051 models may also have a number of special, modelspecific features, such as UARTs, ADC, Op-Amps, etc...
PIN DESCRIPTION
Ports
There are 4 8-bit ports: P0, P1, P2 and P3.
the
ALE
disable
bit
has
no
effect
if
the
Programming
The programming language used by us was C and I.D.E.
(Integrated development environment) which we were using
8
IDE
and
Debugger
combines
project
system.
Vision2
Integrated
Development
by the linker.
iii.)
linker,
HEX
converter,
debugger,
and
the
other
the
file
was
programmed
into
the
into
the
microcontroller.
Initially
the
10
Power Supply
The power supply supplies the required energy for both the
microcontroller and the associated circuits. It is the most
essential part of the circuit because to run its constituent
ICs circuit has to be provided with power. These ICs can run
on DC power. Hence the required D.C supply has to be
generated. The main parts of a power supply unit and their
function are as follows:
11
the
unidirectional
semiconductor
alternating
one.
This
diodes
voltage
function
signal
is
connected
into
provided
in
a
by
bridge
12
LCD Display
Liquid crystal displays (LCD) are widely used in recent years
as compares to LEDs. This is due to the declining prices of
LCD, the ability to display numbers, characters and graphics,
incorporation of a refreshing controller into the LCD, their by
relieving the CPU of the task of refreshing the LCD and also
the ease of programming for characters and graphics. HD
44780 based LCDs are most commonly used. LCD pin
description. The LCD discuss in this section has the most
common connector used for the Hitachi 44780 based LC1D is
14 pins in a row and modes of operation and how to program
and interface with microcontroller is describes in this section.
LCD pin description
The LCD discuss in this section has the most common
connector used for the Hitachi 44780 based LCD is 14 pins in
a row and modes of operation and how to program and
interface with microcontroller is describes in this section.
13
14
15
msecs
for
clearing
the
display
or
moving
the
16
17
Interfacing of MCU with LED:A light-emitting diode (LED) is a semiconductor diode that emits incoherent
narrow spectrum light when electrically biased in the forward direction of
the p-n junction. This effect is a form of electroluminescence. An LED is
usually a small area source, often with extra optics added to the chip that
shapes its radiation pattern. The color of the emitted light depends on the
composition and condition of the semiconducting material used, and can be
infrared, visible, or near-ultraviolet. An LED can be used as a regular
household light source
18
VCC
D 1
LED
D 2
U ?
LED
39
38
37
36
35
34
33
32
D 3
LED
D 4
1
2
3
4
5
6
7
8
LED
D 5
LED
D 6
19
18
9
Y ?
LED
31
C R Y STAL
C ?
C AP N P
D 7
LED
40
P
P
P
P
P
P
P
P
0 .0 /A
0 .1 /A
0 .2 /A
0 .3 /A
0 .4 /A
0 .5 /A
0 .6 /A
0 .7 /A
D
D
D
D
D
D
D
D
P
P
P
P
P
P
P
P
1 .0 /T2
1 .1 /T 2 -E X
1 .2
1 .3
1 .4
1 .5
1 .6
1 .7
XTA L1
XTA L2
R ST
0
1
2
3
4
5
6
7
P 2 .0 /A 8
P 2 .1 /A 9
P 2 .2 /A 1 0
P 2 .3 /A 1 1
P 2 .4 /A 1 2
P 2 .5 /A 1 3
P 2 .6 /A 1 4
P 2 .7 /A 1 5
P 3 .0 /R XD
P 3 .1 /T XD
P 3 .2 /IN T O
P 3 .3 /IN T 1
P 3 .4 /TO
P 3 .5 /T1
P 3 .6 /W R
P 3 .7 /R D
PSEN
A L E /P R O G
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
29
30
E A /V P P
AT89C 52
20
R 1
R
D 8
LED
RELAY
19
21
phase
3
D11
1
6
5
VCC
R2
MCT2E
1
2
R4
BC-369
VCC
J4
5 NC
4
NO
1
2
HEATER
RELAY
From P3.0 of
microcontroller
22
Note the RA0 and RA1 port bits are connected to both the
A1, A0 Switches, the transistor drivers to select the display
digits.
To drive the display, the RA0 and RA1 bits are configured as
outputs. To input from the two switches, the RA0 and RA1
bits are configured as inputs. The two 10K resistors prevent
damage to the port when configured as outputs and a switch
is closed.
USER INTERFACE
23
D.C. MOTOR
Working Principle:
The principle upon which the DC motor works is very simple.
If a current carrying conductor is placed in a magnetic field,
mechanical force is experienced on the conductor, the
direction of which is given by the Fleming's left hand rule
and hence the conductor moves in the direction of force.
When the motor is connected to the DC supply
mains a direct current passes through the brushes and the
commutator to the armature winding; while it passes
through the commutator it is converted into AC so that the
group of conductors under successive field poles carries
24
Permanent
magnet
motors:
It
consists
of
an
III.
25
fine
wire
so
as
to
provide
large
26
Stepper Motor
Motion Control, in electronic terms, means to accurately
control the movement of an object based on speed, distance,
load, inertia or a combination of all these factors. There are
numerous types of motion control systems, including;
Stepper Motor, Linear Step Motor, DC Brush, Brushless,
Servo, Brushless Servo and more.
A stepper motor is an electromechanical device
which converts electrical pulses into discrete mechanical
movements. Stepper motor is a form of ac. motor .The shaft
or spindle of a stepper motor rotates in discrete step
increments when electrical command pulses are applied to it
in the proper sequence. The motors rotation has several
direct relationships to these applied input pulses. The
sequence of the applied pulses is directly related to the
direction of motor shafts rotation. The speed of the motor
shafts rotation is directly related to the frequency of the
input pulses and the length of rotation is directly related to
the number of input pulses applied [39].
27
28
change
of
the
stator.
Notice
that
while
29
Rotor Alignment
Step
1
2
3
4
Winding A
Winding B
Winding C
0
1
1
1
0
1
1
1
0
1
1
1
Input Sequence to the Windings
Winding D
1
1
1
0
30
31
Project Description
Project features:
Interfaced with 8 different devices.
Access protected with password.
Taking different work from different devices with the
help of MCU.
INTERFACED DEVICES
Seven devices are interfaced with one MCU
LCD
5 switches
LEDs
Relay(interfaced with 220v device)
Stepper motor
DC motor
7-segment
32
Schematic Diagram of
Project
33
Source code
Header Files
1. Delay.h
void ms_delay(unsigned char n)
{
unsigned char i,j;
for(j=0;j<n;j++)
{
for(i=0;i<200;i++)
{
_nop_();
}
}
}
void sec_delay(unsigned char n)
{
unsigned char i;
for(i=0;i<n;i++)
{
ms_delay(250);
34
ms_delay(250);
ms_delay(250);
ms_delay(250);
}
}
2. LCD.h
#define lcd P1
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit s4=P3^3;
sbit s5=P3^4;
sbit rs=P3^5;
sbit rw=P3^6;
sbit e=P3^7;
void lcd_cmd(unsigned char a)
{
ms_delay(2);
lcd=a;
rs=0;
rw=0;
e=1;
ms_delay(2);
e=0;
}
void lcd_data(unsigned char a)
35
{
ms_delay(2);
lcd=a;
rs=1;
rw=0;
e=1;
ms_delay(2);
e=0;
}
void lcd_initialize()
{
lcd_cmd(0x38);
ms_delay(2);
lcd_cmd(0x0C);
ms_delay(2);
lcd_cmd(0x06);
ms_delay(2);
lcd_cmd(0x01);
ms_delay(2);
lcd_cmd(0x80);
ms_delay(2);
}
void lcd_puts(unsigned char *s)
{
unsigned char i;
36
for(i=0;s[i]!='\0';i++)
{
lcd_data(s[i]);
}
}
unsigned char lcd_pwd(unsigned char loc)
{
unsigned char i=0;
while(s5==1)
{
if(s1==0)
i=1;
if(s2==0)
i=2;
if(s3==0)
i=3;
if(s4==0)
i=4;
lcd_cmd(loc);
lcd_data(i+48);
}
lcd_cmd(loc);
lcd_data('*');
ms_delay(250);
return(i);
}
37
3. Scroll.h
unsigned char index=0,turn=0;
code unsigned char line[118]={"
WELCOME
"};
PROJECT
"};
void scroll()
{
unsigned char i;
for(i=0;i<=75;i++)
{
lcd_cmd(0xc0);
while(index<16)
{
lcd_data(line2[index+turn]);
index++;
}
turn++;
index=0;
ms_delay(150);
38
if(turn==75)
turn=0;
}
for(i=0;i<=131;i++)
{
lcd_cmd(0x80);
while(index<16)
{
lcd_data(line[index+turn]);
index++;
}
lcd_cmd(0xc0);
index=0;
while(index<16)
{
lcd_data(line1[index+turn]);
index++;
}
turn++;
index=0;
ms_delay(125);
if(turn==131)
turn=0;
}
39
4. Stepper.h
sbit st1=P0^0;
sbit st2=P0^1;
sbit st3=P0^2;
sbit st4=P0^3;
void stepfwd(unsigned char i)
{
unsigned char a;
for(a=0;a<i;a++)
{
st1=1;st2=0;st3=0;st4=0;
ms_delay(150);
st1=0;st2=1;st3=0;st4=0;
ms_delay(150);
st1=0;st2=0;st3=1;st4=0;
ms_delay(150);
st1=0;st2=0;st3=0;st4=1;
ms_delay(150);
}
}
void stepback(unsigned char i)
{
unsigned char a;
for(a=0;a<i;a++)
{
40
st1=0;st2=0;st3=0;st4=1;
ms_delay(150);
st1=0;st2=0;st3=1;st4=0;
ms_delay(150);
st1=0;st2=1;st3=0;st4=0;
ms_delay(150);
st1=1;st2=0;st3=0;st4=0;
ms_delay(150);
}
}
void stepper()
{
step:lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("s1 s2 s3 s4 ");
lcd_cmd(0xc0);
lcd_puts("fwd rev f-b b-f");
ms_delay(250);
while(s5==1)
{
if(s1==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("FORWD RUN");
stepfwd(12);
41
}
if(s2==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("REVERSE RUN");
stepback(12);
}
if(s3==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("FWD-REVERSE RUN");
stepfwd(12);
stepback(12);
}
if(s4==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("REVERSE-FWD RUN");
stepback(12);
stepfwd(12);
}
goto step;
}
42
5. Sevensegment.h
#define seg P2
void sevenseg()
{
unsigned char i=0;
unsigned
char
a[10]={0xc0,0xF9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x
80,0x90};
seg: lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("s1 s2 s3 s4 ");
lcd_cmd(0xc0);
lcd_puts("inc dec fwd dwn");
ms_delay(250);
while(s5==1)
{
if(s1==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("INCREMENT");
i++;
ms_delay(200);
if(i>9)
i=0;
43
seg=a[i];
ms_delay(250);
}
if(s2==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("DECREMENT");
i--;
ms_delay(200);
if(i==255)
i=9;
seg=a[i];
ms_delay(250);
}
if(s3==0)
{
unsigned char j;
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("UP COUNT");
for(j=0;j<10;j++)
{
i++;
if(i>9)
i=0;
44
seg=a[i];
sec_delay(1);
}
}
if(s4==0)
{
char j;
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("DOWN COUNT");
for(j=9;j>=0;j--)
{
i--;
if(i==255)
i=9;
seg=a[i];
sec_delay(1);
}
}
goto seg;
}
P2=0xff;
}
6. Dcmotor.h
sbit dc=P0^5;
void dcspeed(unsigned char ton)
45
{
dc=1;
ms_delay(ton);
dc=0;
ms_delay(100-ton);
}
void dcspeedctrl()
{
dc:
lcd_cmd(0x01);
lcd_puts("SPD s1 s2 s3 s4 ");
lcd_cmd(0xc0);
lcd_puts(" % 10 25 50 100");
ms_delay(250);
while(s5==1)
{
if(s1==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("10 % speed");
dcspeed(10);
}
if(s2==0)
{
lcd_cmd(0x01);
46
lcd_cmd(0x80);
lcd_puts("25 % speed");
dcspeed(25);
}
if(s3==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("50 % speed");
dcspeed(50);
}
if(s4==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("100 % speed");
dcspeed(100);
}
if(s1==1 && s2==1 && s3==1 && s4==1)
{
goto dc;
}
}
}
7. Relay.h
47
sbit relay=P0^6;
unsigned char i;
void relayinterface()
{
rel: lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("s1 s2 s3 s4 SEC ");
lcd_cmd(0xc0);
lcd_puts("5 10 15 20 ON ");
ms_delay(250);
while(s5==1)
{
if(s1==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("5 SECONDS ON");
relay=1;
sec_delay(5);
relay=0;
}
if(s2==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("10 SECONDS ON");
48
relay=1;
sec_delay(10);
relay=0;
}
if(s3==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("15 SECONDS ON");
relay=1;
sec_delay(15);
relay=0;
}
if(s4==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("20 SECONDS ON");
relay=1;
sec_delay(20);
relay=0;
}
goto rel;
}
}
8. Led.h
49
void led()
{
unsigned char a,b,d,k;
le:
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("s1 s2 s3 s4 ");
lcd_cmd(0xc0);
lcd_puts("run X sdgls e-o");
ms_delay(250);
while(s5==1)
{
if(s1==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("RUNNING LIGHTS");
d=0x7f;
for(k=0;k<8;k++)
{
seg=d;
ms_delay(250);
ms_delay(250);
d=d>>1;
d=d|0x80;
}
d=0xfe;
50
for(k=0;k<8;k++)
{
seg=d;
ms_delay(250);
ms_delay(250);
d=d<<1;
d=d|0x01;
}
}
if(s2==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("X - PATTERN");
a=0x7f;
b=0xfe;
for(k=0;k<8;k++)
{
seg=a&b;
a=a>>1;
b=b<<1;
a=a|0x80;
b=b|0x01;
ms_delay(250);
ms_delay(250);
51
}
}
if(s3==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("SAND GLASS");
b=0xff;
for(k=0;k<8;k++)
{
a=0x7f;
for(d=0;d<(8-k);d++)
{
seg=a&b;
ms_delay(250);
ms_delay(250);
a=a>>1;
a=a|0x80;
}
b=b<<1;
}
}
if(s4==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
52
lcd_puts("EVEN ODD");
for(k=0;k<5;k++)
{
seg=0xaa;
ms_delay(250);
ms_delay(250);
seg=0x55;
ms_delay(250);
ms_delay(250);
}
}
seg=0xff;
goto le;
}
}
53
Main Program
#include<intrins.h>
#include<reg51.h>
#include<delay.h>
#include<lcd.h>
#include<scroll.h>
#include<stepper.h>
#include<sevensegment.h>
#include<dcmotor.h>
#include<relay.h>
#include<led.h>
sbit led1=P0^4;
sbit seg1=P0^7;
void main()
{
54
");
lcd_cmd(0xc0);
pwd[0]=lcd_pwd(0xc0);
sec_delay(1);
55
pwd[1]=lcd_pwd(0xc1);
sec_delay(1);
pwd[2]=lcd_pwd(0xc2);
sec_delay(1);
pwd[3]=lcd_pwd(0xc3);
sec_delay(1);
if(pwd[0]==1&&pwd[1]==2&&pwd[2]==4&&pwd[3]=
=3)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts(" WELCOME TO THE ");
lcd_cmd(0xc0);
lcd_puts("
SYSTEM
");
sec_delay(1);
while(s5==1)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("s1 s2 s3 s4 ");
lcd_cmd(0xc0);
lcd_puts("stp mtr 7sg 220v");
sec_delay(1);
lcd_cmd(0x01);
lcd_cmd(0x80);
56
lcd_puts("
s1&s2
");
lcd_cmd(0xc0);
lcd_puts("
LED
");
57
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("Motor speed ctrl");
sec_delay(1);
dcspeedctrl();
ms_delay(150);
}
else if(s3==0)
{
seg1=0;
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("Seven segment");
sec_delay(1);
sevenseg();
ms_delay(150);
seg1=1;
}
else if(s4==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("Relay Interfaced");
sec_delay(1);
relayinterface();
58
ms_delay(150);
}
led1=0;
seg1=0;
//
seg=0x7f;
sec_delay(1);
led1=1;
seg1=1;
//
seg=0xff;
}
sec_delay(1);
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("THANKS
FOR ");
lcd_cmd(0xc0);
lcd_puts("YOUR ATTENTION");
sec_delay(6);
}
else
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("Invalid Password");
sec_delay(1);
lcd_cmd(0x01);
lcd_cmd(0x80);
59
lcd_puts("ATTEMPTS LEFT
");
lcd_cmd(0xc8);
lcd_data(2-z+48);
sec_delay(1);
z++;
if(z==3)
{
z=0;
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("System Locked");
sec_delay(1);
mxc:
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("ENTER MAIN CODE");
lcd_cmd(0xc0);
pwd[0]=lcd_pwd(0xc0);
sec_delay(1);
pwd[1]=lcd_pwd(0xc1);
sec_delay(1);
pwd[2]=lcd_pwd(0xc2);
sec_delay(1);
pwd[3]=lcd_pwd(0xc3);
sec_delay(1);
60
if(pwd[0]==1&&pwd[1]==2&&pwd[2]==3&&pwd[3]=
=4)
goto pwd;
else
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("Invalid Password");
sec_delay(1);
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("ATTEMPTS LEFT
");
lcd_cmd(0xc8);
lcd_data(2-z+48);
sec_delay(1);
z++;
if(z==3)
{
while(1)
{
if(s1==0
&&
61
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_puts("
ENTRY BLOCKED ");
sec_delay(2);
}
}
}
goto mxc;
}
}
goto pwd;
}
}
}
62
Bibliography
1. 8051
microcontroller
and
its
applications,
63