A
Project Report
ON
Interfacing of LED, ADC, STEPPER MOTOR with 8051
Microcontroller
Submitted By:
1
Government Polytechnic Pune-16
(An Autonomous Institute of Govt. of Maharashtra)
CERTIFICATE
This is to certify that
(PROF.MRS.S.P.PHADNAIK)
Project Guide
(PROF.MRS.M.A.CHIGTERI) (PROF.MR.NANDANWAR)
H.O.D PRINCIPAL
2
ACKNOWLEDGEMENT
THANKING YOU.
3
CONTENT:
1. Acknowledgment 3
2. Introduction to 8051 Microcontroller 5
8051 Pin diagram and Description
8051 Internal Architecture
3.LED Interfacing With 8051 Microcontroller 9
Circuit Principle
Circuit Diagram
Circuit Component
Circuit Design
How to operate?
Circuit Applications
4. ADC Interfacing With 8051 Microcontroller 12
Circuit component
ADC 0804
LCD
Circuit Diagram
Circuit Description
Working
Output Analysis
5. Stepper motor Interfacing With 8051 Microcontroller 17
Stepper Motor Control using Microcontroller
Circuit Principle
Circuit Components
Stepper Motor Control using 8051
Microcontroller Circuit Design
How to Operate this Stepper Motor
Driver Circuit?
Stepper Motor Control Applications
6. PCB Design 21
7. PCB Circuit Diagram 23
8.Advantages & Disadvantages 24
9. Program Code 25
10.Conclusion 37
11.Referance 38
4
8051 MICROCONTROLLER
A micro controller is an integrated circuit or a chip with a processor and other support devices
like program memory, data memory, I/O ports, serial communication interface etc integrated
together. Unlike a microprocessor (ex: Intel 8085), a microcontroller does not require any
external interfacing of support devices. Intel 8051 is the most popular microcontroller ever
produced in the world market.
Introduction :
Intelfirst produced a microcontroller in 1976 under the name MCS-48, which was an 8 bit
microcontroller. Later in 1980 they released a further improved version (which is also 8 bit),
under the name MCS-51. The most popular microcontroller 8051 belongs to the MCS-51 family
of microcontrollers by Intel. Following the success of 8051, many other semiconductor
manufacturers released microcontrollers under their own brand name but using the MCS-51 core.
Global companies and giants in semiconductor industry like Microchip, Zilog, Atmel, Philips,
and Siemens released products under their brand name. The specialty was that all these devices
could be programmed using the same MCS-51 instruction sets. They basically differed in support
device configurations like improved memory, presence of an ADC or DAC etc. Intel then
released its first 16 bit microcontroller in 1982, under name MCS-96
5
8051 Pin Diagram &Description:
For describing pin diagram and pin configuration of 8051, we are taking into consideration a 40
pin DIP (Dual inline package). Now let’s go through pin configuration in detail.
Pin-40: Named as Vcc is the main power source. Usually its +5V DC.
Pins 32-39: Known as Port 0 (P0.0 to P0.7) – In addition to serving as I/O port, lower order
address and data bus signals are multiplexed with this port (to serve the purpose of external
memory interfacing). This is a bi directional I/O port (the only one in 8051) and external pull up
resistors are required to function this port as I/O.
Pin-31:-ALE Address Latch Enable is used to demultiplex the address-data signal of port 0 (for
external memory interfacing.) 2 ALE pulses are available for each machine cycle.
Pin-30:- EA/ External Access input is used to enable or disallow external memory interfacing. If
there is no external memory requirement, this pin is pulled high by connecting it to Vcc.
6
Pin- 29:- PSEN or Program Store Enable is used to read signal from external program memory.
Pins- 21-28:- Known as Port 2 (P 2.0 to P 2.7) – in addition to serving as I/O port, higher order
address bus signals are multiplexed with this quasi bi directional port.
Pins 18 and 19:- Used for interfacing an external crystal to provide system clock.
Pins 10 – 17:- Known as Port 3. This port also serves some other functions like interrupts, timer
input, control signals for external memory interfacing RD and WR, serial communication signals
RxD and TxD etc. This is a quasi bi directional port with internal pull up.
Pin 9:- As explained before RESET pin is used to set the 8051 microcontroller to its initial
values, while the microcontroller is working or at the initial start of application. The RESET pin
must be set high for 2 machine cycles.
Pins 1 – 8:- Known as Port 1. Unlike other ports, this port does not serve any other functions.
Port 1 is an internally pulled up, quasi bi directional I/O port.
7
8051 Internal Architecture:
The system bus connects all the support devices with the central processing unit. 8051 system
bus composes of an 8 bit data bus and a 16 bit address bus and bus control signals. From the
figure you can understand that all other devices like program memory, ports, data memory, serial
interface, interrupt control, timers, and the central processing unit are all interfaced together
through the system bus. RxD and TxD (serial port input and output) are interfaced with port 3.
8
LED Interfacing with 8051
Light Emitting Diodes are the mostly commonly used components in many applications. They
are made of semiconducting material. This is the basic interfacing of LEDs to the 8051 family
microcontrollers.
Circuit Principle:
The main principle of this circuit is to interface LEDs to the 8051 family micro controller.
Commonly, used LEDs will have voltage drop of 1.7v and current of 10mA to glow at full
intensity. This is applied through the output pin of the micro controller.
Circuit Diagram:
9
Circuit Components:
AT89C51 microcontroller.
8 LEDs – D1 to D8.
8 Resistors – R1 to R8.
Crystal oscillator.
2 Capacitors – C1 and C2.
Circuit Design:
The circuit mainly consists of AT89C51 microcontroller. AT89C51 belongs to the family of
8051 microcontroller. It is an 8-bit microcontroller. This microcontroller has 4KB of Flash
Programmable and Erasable Read Only Memory and 128 bytes of RAM. This can be
programmed and erased maximum 1000times. It has two 16 bit timers/counters. It supports
USART communication protocol. It has 40 pins. There are four ports are designated as P0, P1,
P2, P3. In this circuit, LEDs are connected to the port P0. Port P0 will not have internal pull- ups,
while the other ports have internal pull-ups. The controller is connected with external crystal
oscillator to pin 18 and 19 pins. Crystal pins are connected to the ground through capacitors of
33pf.Light Emitting Diodes are the semi-conductor light sources. Commonly used LEDs will
have a cut-off voltage of 1.7V and current of 10mA. When an LED is applied with its required
voltage and current it glows with full intensity. The Light Emitting Diode is similar to the normal
PN diode but it emits energy in the form of light. The colour of light depends on the band gap of
the semiconductor. The following figure shows “how an LED glows?”
10
Thus, LED is directly connected to the AT89C51 microcontroller. The negative terminal of the
LED is connected to the ground through a resistor. Value of this resistor is calculated using the
following formula.
Generally, microcontrollers output a maximum voltage of 5V. Thus the value of resistor
calculated for this is 330 Ohms. Thus this can be connected either to the cathode or anode of the
LED.
How to Operate?
Initially, burn the code into the microcontroller.
Now, connect the LEDs to the port0 of the microcontroller.
Switch on the circuit.
Thus one can observe LEDs glowing.
Now, switch off the circuit.
Circuit Applications:
LEDs are widely used in many applications like in seven segments.
They are used in dot matrix displays.
They can be used for street lights.
They are used as indicators.
They can be used in traffic lights.
11
ADC Interfacing with 8051
ADC is the Analog to Digital converter, which converts analog data into digital format; usually
it is used to convert analog voltage into digital format. Analog signal has infinite no of values
like a sine wave or our speech, ADC converts them into particular levels or states, which can be
measured in numbers as a physical quantity. Instead of continuous conversion, ADC converts
data periodically, which is usually known as sampling rate. The major advantage, of using ADC
is that, we noise can be efficiently eliminated from the original signal and digital signal can
travel more efficiently than analog one. That’s the reason that digital audio is very clear, while
listening.
Components :
8051 Microcontroller (AT89C51)
ADC 0804
16x2 LCD
Resistor (1k,10k)
POT(10k x4)
Capacitor(10uf,1000uf)
Bread board or PCB
11.0592 MHz Crystal
Power
Connecting wires
12
ADC 0804:
ADC0804 is an 8 bit successive approximation analogue to digital converter from National
semiconductors. The features of ADC0804 are differential analogue voltage inputs, 0-5V input
voltage range, no zero adjustment, built in clock generator, reference voltage can be externally
adjusted to convert smaller analogue voltage span to 8 bit resolution etc. The pin out diagram of
ADC0804 is shown in the figure below.
ADC receives analog signal from the source. This analog signal is received from one of the 8
input channels of ADC0804. Then this signal is processed accordingly and converted to
corresponding digital signal. This signal is then sent to the microcontroller and the output is
displayed using LCD
13
LCD:
Liquid Crystal Display (LCD) is very commonly used electronic display module and having a
wide range of applications such as calculators, laptops, mobile phones etc. 16×2 character lcd
display is very basic module which is commonly used in electronics devices and projects. It can
display 2 lines of 16 characters. Each character is displayed using 5×7 or 5×10 pixel matrix.
LCD can be interfaced with microcontroller in 4 Bit or 8 Bit mode. These differs in how data is
send to LCD. In 8 bit mode to write a character, 8 bit ASCII data is send through the data lines
D0 – D7 and data strobe is given through E of the LCD. LCD commands which are also 8 bit are
written to LCD in similar way.
CIRCUIT DIAGRAM:
14
Circuit Description:
Circuit of “Interfacing ADC0808 with 8051” is little complex which contains more connecting
wire for connecting device to each other. In this circuit we have mainly used AT89C51 as 8051
microcontroller, ADC0804, Potentiometer and LCD.A 16x2 LCD is connected with 89C51
microcontroller in 4-bit mode. Control pin RS, RW and En are directly connected to pin P2.0,
GND and P2.2. And data pin D4-D7 is connected to pins P2.4, P2.5, P2.6 and P2.7 of
89C51.ADC0804 output pin are directly connected to port P1 of AT89C51. P3.2.ALE (Address
latch enable), SC (Start conversion), EOC (End of conversion), OE (Output enable) and clock
pins are connected at P3.3, P3.4, P3.5, P3.6 and P3.
Working:
In this project we have interfaced three channels of ADC0804. And for demonstration we have
used three variable resistors. When we power the circuit then microcontroller initialize the LCD
by using appropriate command, gives clock to ADC chip, selects ADC channel by using address
line and send start conversion signal to ADC. After this ADC first reads selected ADC channel
input and gives its converted output to microcontroller. Then microcontroller shows its value at
Ch1 position in LCD. And then microcontroller changes ADC channel by using address line.
And then ADC reads selected channel and send output to microcontroller. And show on LCD as
name Ch2. And like wise for other channels.
15
Output Analysis:
As ADC 0808 is an 8-bit ADC, so the numbers of steps is 256. Correspondingly the step size
(smallest change that can be detected by an ADC) becomes equal to
5/256=19.53mV
So, the smallest change in voltage that can be detected by the ADC is 19.53mV.
16
Stepper Motor Control using 8051
Microcontroller
A stepper motor is a brushless and synchronous motor which divides the complete rotation into
number of steps. Each stepper motor will have some fixed step angle and motor rotates at this
angle. Here the interfacing of stepper to 8051 and ULN 2003 is explained. It has many
applications in the field of robotics and mechatronics. The total rotation of the motor is divided
into steps. The angle of a single step is known as the stepper angle of the motor. There are two
types of stepper motors Unipolar and Bipolar. Due to the ease of operation unipolar stepper
motor is commonly used by electronics hobbyists. Stepper Motors can be easily interfaced with a
microcontroller using driver ICs such as L293D or ULN2003.
17
Circuit Components:
AT89C51 micro controller
ULN2003A
Stepper Motor
Crystal
Resistor
Capacitor
The ULN2003A is a current driver IC. It is used to drive the current of the stepper motor as it
requires more than 60mA of current. It is an array of Darlington pairs. It consists of seven pairs
of Darlington arrays with common emitter. The IC consists of 16 pins in which 7 are input pins,
7 are output pins and remaining are VCC and Ground. The first four input pins are connected to
the microcontroller. In the same way, four output pins are connected to the stepper motor.
Stepper motor has 6 pins. In these six pins, 2 pins are connected to the supply of 12V and the
remaining are connected to the output of the stepper motor. Stepper rotates at a given step angle.
Each step in rotation is a fraction of full cycle. This depends on the mechanical parts and the
driving method.
Similar to all the motors, stepper motors will have stator and rotor. Rotor has permanent magnet
and stator has coil. The basic stepper motor has 4 coils with 90 degrees rotation step. These four
coils are activated in the cyclic order. The below figure shows you the direction of rotation of the
shaft. There are different methods to drive a stepper motor. Some of these are explained below.
Full Step Drive: In this method two coils are energized at a time. Thus, here two opposite coils
are excited at a time.
Half Step Drive: In this method coils are energized alternatively. Thus it rotates with half step
angle. In this method, two coils can be energized at a time or single coil can be energized. Thus it
increases the number of rotations per cycle. It is shown in the below figure.
18
How to Operate this Stepper Motor Driver Circuit?
Initially, switch on the circuit.
Microcontroller starts driving the stepper motor.
One can observe the rotation of the stepper motor
The stepper motor has four wires. They are yellow, blue, red and white. These are
energized alternatively as given below.
In full step driving, use the following sequence
To drive the motor in half step angle, use the following sequence
19
20
PCB DESIGN :
21
22
PCB CIRCUIT DIAGRAM :
23
ADVANTAGES:
Interfacing of stepper motor requires less power & at low operating voltage.
Components are chip.
This system is easy to handling.
Operation is easy for understanding.
DISADVANTAGES:
System is costly.
To change the direction of stepper motor we have to change the program code.
24
Program code:
R LCALL init
R LCALL measure_temp
SETB led
MOV R7,#032H
MOV R6,#00H
R LCALL _msdelay
CLR led
MOV R7,#032H
MOV R6,#00H
R LCALL _msdelay
R LCALL stepper
SJMP ?C0001
CLR WRbar
R LCALL L?0028
SETB WRbar
0007 ?C0004:
JB INTRbar,?C0004
000A ?C0005:
SETB RDbar
R LCALL L?0028
CLR RDbar
25
MOV R4,P1
CLR A
E LCALL ?C?FCASTC
R MOV adc+03H,R7
R MOV adc+02H,R6
R MOV adc+01H,R5
R MOV adc,R4
RET
0000 L?0029:
MOV R7,#05H
MOV R6,#00H
CLR A
MOV R5,A
MOV R4,A
0007 ?C0007:
CLR C
MOV A,R5
SUBB A,R7
MOV A,R4
SUBB A,R6
26
JNC ?C0013
CLR A
MOV R3,A
MOV R2,A
0011 ?C0010:
INC R3
CJNE R3,#00H,?C0026
INC R2
0016 ?C0026:
CJNE R2,#04H,?C0010
CJNE R3,#0FBH,?C0010
001C ?C0009:
INC R5
CJNE R5,#00H,?C0027
INC R4
0021 ?C0027:
SJMP ?C0007
0023 ?C0013:
RET
R MOV value,R7
R LCALL lcdready
R MOV ldata,value
27
CLR rs
CLR rw
SETB en
MOV R7,#01H
MOV R6,#00H
R LCALL _msdelay
CLR en
0017 ?C0014:
RET
R MOV value,R7
R LCALL lcdready
R MOV ldata,value
SETB rs
CLR rw
SETB en
MOV R7,#01H
MOV R6,#00H
R LCALL _msdelay
CLR en
0017 ?C0015:
RET
28
SETB busy
CLR rs
SETB rw
0006 ?C0016:
JNB busy,?C0018
CLR en
MOV R7,#01H
MOV R6,#00H
R LCALL _msdelay
SETB en
SJMP ?C0016
0016 ?C0018:
RET
R MOV y,R3
R MOV y+01H,R2
R MOV y+02H,R1
MOV R7,AR5
R LCALL _lcdcmd
R LCALL lcdready
000E ?C0019:
R MOV R3,y
R MOV R2,y+01H
29
R MOV R1,y+02H
E LCALL ?C?CLDPTR
R LCALL lcdready
R MOV R3,y
R MOV R2,y+01H
R MOV R1,y+02H
E LCALL ?C?CLDPTR
MOV R7,A
R LCALL _lcddata
R LCALL lcdready
MOV A,#01H
R ADD A,y+02H
R MOV y+02H,A
CLR A
R ADDC A,y+01H
R MOV y+01H,A
SJMP ?C0019
0039 ?C0021:
RET
R MOV R6,adc1
R MOV R7,adc1+01H
MOV R4,#00H
30
MOV R5,#0AH
E LCALL ?C?SIDIV
R MOV dec1,R5
R MOV R6,adc1
R MOV R7,adc1+01H
MOV R4,#00H
MOV R5,#0AH
E LCALL ?C?SIDIV
R MOV adc1,R6
R MOV adc1+01H,R7
MOV R4,#00H
MOV R5,#0AH
E LCALL ?C?SIDIV
R MOV dec2,R5
R MOV R6,adc1
R MOV R7,adc1+01H
MOV R4,#00H
MOV R5,#0AH
E LCALL ?C?SIDIV
R MOV adc1,R6
R MOV adc1+01H,R7
MOV R4,#00H
MOV R5,#0AH
E LCALL ?C?SIDIV
31
R MOV dec3,R5
R MOV R6,adc1
R MOV R7,adc1+01H
MOV R4,#00H
MOV R5,#0AH
E LCALL ?C?SIDIV
R MOV dec4,R7
R MOV A,dec1
R MOV asc1,A
R MOV A,dec2
ORL A,#030H
R MOV asc2,A
R MOV A,dec3
ORL A,#030H
R MOV asc3,A
R MOV A,dec4
ORL A,#030H
R MOV asc4,A
RET
MOV R3,#0FFH
MOV R5,#081H
32
R LCALL _datawrt_str
MOV R7,#0C6H
R LCALL _lcdcmd
R LCALL adcconv
R MOV R7,adc+03H
R MOV R6,adc+02H
R MOV R5,adc+01H
R MOV R4,adc
E LCALL ?C?CASTF
R MOV adc1,R6
R MOV adc1+01H,R7
R LCALL conv
R MOV R7,asc3
R LCALL _lcddata
R LCALL L?0029
R LCALL _msdelay
R MOV R7,asc2
R LCALL _lcddata
R LCALL L?0029
R MOV R7,asc1
R LCALL _lcddata
MOV R7,#05H
MOV R6,#00H
R LJMP _msdelay
33
; FUNCTION init (BEGIN)
CLR led
CLR s1
CLR s2
CLR s3
CLR s4
MOV R7,#038H
R LCALL _lcdcmd
MOV R7,#0CH
R LCALL _lcdcmd
MOV R7,#01H
R LCALL _lcdcmd
MOV R7,#06H
R LCALL _lcdcmd
SETB INTRbar
MOV P1,#0FFH
SETB RDbar
SETB WRbar
MOV R3,#0FFH
MOV R5,#082H
R LCALL _datawrt_str
MOV R3,#0FFH
34
R MOV R2,#HIGH ?SC_30
MOV R5,#0C2H
R LCALL _datawrt_str
MOV R7,#0F4H
MOV R6,#01H
R LCALL _msdelay
MOV R7,#01H
R LJMP _lcdcmd
SETB s1
CLR s2
CLR s3
SETB s4
MOV R7,#032H
MOV R6,#00H
R LCALL _msdelay
CLR s1
SETB s2
SETB s3
CLR s4
R LCALL _msdelay
CLR s1
SETB s2
35
CLR s3
SETB s4
R LCALL _msdelay
SETB s1
CLR s2
SETB s3
CLR s4
R LJMP _msdelay;
36
CONCLUSION:
Microcontroller are widely used in electronic gadgets and are one of the key elements in
developing any project and thus this project used 8051 microcontroller and will help in teaching
about interfacing of ADC with the 8051 microcontroller to display the analog value of input into
the digital form on the LCD display.
In this project, we gives the analog input to the ADC0804 so then it converts it into the
digital form and the digital value is displayed on the LCD. In the interfacing of LED with 8051
the given led are glows as per the program is loaded. Speed control of stepper motor is done by
using the ULN2003A. So that stepper motor can be running in two conditions half step drive and
full step drive.
This project report contains the circuit diagram and its analysis along with the
microcontroller programming for help. IN this project LED, ADC and STEPPER MOTOR
interfacing with the ATMEL AT89C51 was studied.
Thus we have successfully made a LED glowing, ADC converter, and stepper motor to
run in different conditions.
37
REFERENCES:
[1] S.K, Mandal, “Digital Electronics Principles and Applications,” 2nd Edition, Tata McGraw
Hill, 2011.
[2] PredkoMyke., “Programming and Customizing the 8051 Microcontroller, TATA McGraw
Hill Production”, January 1999, Second Edition.
[3] ADC 0808/0809 8-bit µP compatible A/D converters with 8-channel Multiplexer, National
Instruments, October 1999 Revised March 2013.
[5]www.circuitstoday.com
[6]www.8051projects.com
[7] www.engineersgarage.com
38