0% found this document useful (0 votes)
129 views37 pages

Microcontroller Lab Manual

It helps to know about the microcontroller.

Uploaded by

tryucando01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views37 pages

Microcontroller Lab Manual

It helps to know about the microcontroller.

Uploaded by

tryucando01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

NATIONAL INSTITUTE OF TECHNOLOGY PUDUCHERRY

(An Institution of National Importance, Ministry of Education)


THIRUVETTAKUDY, KARAIKAL – 609 609.

EE280 – COMPUTER ORGANISATION AND


MICROCONTROLLERS

ACADEMIC YEAR: 2022 – 2023

Name : ……………………………………………………………………

Roll No : ……………………………………………………………………

Branch : ELECTRICAL AND ELECTRONICS ENGINEERING

Course : B.Tech Semester : IV

1
NATIONAL INSTITUTE OF TECHNOLOGY PUDUCHERRY
(An Institution of National Importance, Ministry of Education)
THIRUVETTAKUDY, KARAIKAL – 609 609.

BONAFIDE CERTIFICATE

Certified that this is a bonafide record of practical work done by

Mr./Ms. ……………………………………………………………....bearing Roll No.

……………………. of Fourth semester B.Tech class of Electrical and Electronics

Engineering Department in the EE208 - COMPUTER ORGANISATION AND

MICROCONTROLLERS during the year 2022-2023

Submitted for the End Semester Practical Examination held on…………………..

Faculty In-charge

2
INDEX
Page Date of Date of
Date Name of the Experiment Remarks
No. Experiment Submission

3
4
INTRODUCTION TO 8051 MICROCONTROLLER

8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built


with 40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-
bit timers. It consists of are four parallel 8-bit ports, which are programmable as well as addressable
as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller having
crystal frequency of 12 MHz.

The 8051 memory is organized in a Harvard Architecture. Both the code memory space
and data memory space begin at location 0x00 for internal or external memory which is different
from the Princeton Architecture where code and data share same memory space. The advantage of
the Harvard Architecture is not only doubling the memory capacity of the microcontroller with
same number of address lines but also increases the reliability of the microcontroller, since there
are no instructions to write to the code memory which is read only.

1. Features of 8051 Microcontroller


An 8051 microcontroller comes bundled with the following features.

• 64K bytes on-chip program memory (ROM)


• 128 bytes on-chip data memory (RAM)
• Four register banks
• 128 user defined software flags
• 8-bit bidirectional data bus
• 16-bit unidirectional address bus
• 32 general purpose registers each of 8-bit
• 16 bit Timers (usually 2, but may have more or less)
• Three internal and two external Interrupts
• Four 8-bit ports,(short model have two 8-bit ports)
• 16-bit program counter and data pointer

5
2. Architecture Of 8051 Microcontroller

Figure 1.4 shows the architecture block diagram of 8051.

2.1 8051 Memory Organization


8051 microcontroller has an internal program of 4K size and if needed an external memory
can be added (by interfacing) of size 60K maximum. So in total 64K size memory is available for
8051 micro controller. By default, the External Access (EA) pin should be connected Vcc so that
instructions are fetched from internal memory initially. When the limit of internal memory (4K) is
crossed, control will automatically move to external memory to fetch remaining instructions. If the
programmer wants to fetch instruction from external memory only (bypassing the internal
6
memory), then he must connect External Access (EA) pin to ground (GND).

2.2 Timers and Counters


Timer means which can give the delay of particular time between some events. For
example on or off the lights after every 2 sec. This delay can be provided through some assembly

program but in microcontroller two hardware pins are available for delay generation. These
hardware pins can be also used for counting some external events. How much times a number is
repeated in the given table is calculated by the counter.

In MC8051, two timer pins are available T0 and T1, by these timers we can give the delay
of particular time if we use these in timer mode. We can count external pulses at these pins if we
use these pins in counter mode. 16 bits timers are available. Means we can generate delay between
0000H to FFFFH. Two special function registers are available. If we want to load T0 with 16 bit
data then we can load separate lower 8 bit in TL0 and higher 8 bit in TH0. Inthe same way for T1.
TMOD, TCON registers are used for controlling timer operation.

2.3 Serial Port


There are two pins available for serial communication TXD and RXD. Normally TXD is used
for transmitting serial data which is in SBUF register, RXD is used for receiving the serial data.
SCON register is used for controlling the operation.

2.4 Input Output Ports


There are four input output ports available P0, P1, P2, P3. Each port is 8 bit wide and has
special function register P0, P1, P2, P3 which are bit addressable means each bit can be set or reset
by the Bit instructions (SETB for high, CLR for low) independently. The data at any port which is
transmitting or receiving is in these registers. The port 0 can perform dual works. It is also used as
Lower order address bus (A0 to A7) multiplexed with 8 bit data bus P0.0 to P0.7 is AD0 to AD7
respectively the address bus and data bus is demultiplex by the ALE signal and latch which is
further discussed in details. Port 2 can be used as I/O port as well as higher order address bus A8
to A15. Port 3 also have dual functions it can be worked as I/O as well as each pin of P3 has
specific function. P3.0 – RXD – {Serial I / P for Asynchronous communication Serial O / P for
synchronous communication. P3.1 – TXD – Serial data transmit. P3.2 – INT0 – External Interrupt
0. P3.3 – INT1 – External Interrupt 1. P3.4 – T0 – Clock input for counter 0. P3.5 – T1 – Clock
input for counter 1. P3.6 – WR – Signal for writing to external memory. P3.7
7
– RD – Signal for reading from external memory. When external memory is interfaced with 8051
then P0 and P2 can’t be worked as I/O port they works as address bus and data bus, otherwise they
can be accessed as I/O ports.

2.5 Oscillator
It is used for providing the clock to MC8051 which decides the speed or baud rate of MC.
We use crystal which frequency vary from 4MHz to 30 MHz, normally we use 11.0592 MHz
frequency.

2.6 Interrupts
Interrupts are defined as requests because they can be refused (masked) if they are not
used, that is when an interrupt is acknowledged. A special set of events or routines are followed to
handle the interrupts. These special routines are known as interrupt handler or interrupt service
routines (ISR). These are located at a special location in memory. • INT0 and INT1 are the pins
for external interrupts.

3. Pin Diagram Of 8051 microcontrollers:

8
3.1 Pin Description
The EA' (External Access) pin is used to control the internal or external memory access.
The signal 0 is for external memory access and signal 1 for internal memory access. The PSEN'
(Program Store Enable) is for reading external code memory when it is low (0) and EA is also
0. The ALE (Address Latch Enable) activates the port 0 joined with port 2 to provide 16 bit
external address bus to access the external memory. The ALE multiplexes the P0: 1 for latching
address on P0 as A0-A7 in the 16 bit address buss, 0 for latching P0 as data I/O. P0.x is named
ADx because P0 is multiplexed for Address bus and Data bus at different clock time. WR'
provides the signal to write external data memory RD' provides the signal to read external data
and code memory.
• PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The
other ports P0, P2 and P3 have dual roles in addition to their basic I/O function.
• PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be
used for general purpose I/O if no external memory presents.
• PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.
• PORT P3 (Pins 10 to 17): In addition to acting as a normal I/O port,

➢ P3.0 can be used for serial receive input pin(RXD) • P3.1 can be used for serial

transmit output pin(TXD) in a serial port,

➢ P3.2 and P3.3 can be used as external interrupt pins(INT0’ and INT1’),

➢ P3.4 and P3.5 are used for external counter input pins(T0 and T1),

➢ P3.6 and P3.7 can be used as external data memory write and read control signal

pins(WR’ and RD’)read and write pins for memory access.

9
OUTPUT - ADDITION (Without Carry):
DATA (Without Carry)
03
INPUTS
02
OUTPUT

OUTPUT - ADDITION (With Carry):


DATA (With Carry)
A0
INPUTS
F0
OUTPUT
CARRY

OUTPUT - SUBTRACTION (Without Carry):

DATA (Without Carry)


05
INPUTS
02
OUTPUT

10
EX. NO:
8 BIT ADDITION, SUBTRACTION, MULTICATION AND
DATE: DIVISION

AIM:
To perform Addition, Subtraction, Multiplication and Division of 8 bit numbers using 8051
Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller
2. Keyboard

ADDITION (Without Carry):


PROGRAM:
8000: MOV A,#03
8002: MOV B,#02
8005: ADD A,B
8007: SJMP 8007

ADDITION (With Carry):


PROGRAM:
8000: MOV A,#A0
8002: MOV B,#F0
8005: ADD A,B
8007: MOV DPTR,#4000
800A: MOVX @DPTR,A
800B: SJMP 800B

SUBTRACTION (Without Carry):


PROGRAM:

8000: MOV A,#05


8002: MOV B,#02
8005: SUBB A,B
8007: SJMP 8007

11
OUTPUT - SUBTRACTION (With Carry):
DATA (With Carry)
A0
INPUTS
A2
OUTPUT
BORROW

OUTPUT – MULTIPLICATION:
DATA
INPUTS 03
02
OUTPUT

OUTPUT - DIVISION
DATA
INPUTS 03
02
QUOTIENT
OUTPUT
REMAINDER

12
SUBTRACTION (With Carry):
PROGRAM:
8000: MOV A,#A0
8002: MOV B,#A2
8005: SUBB A,B
8007: MOV DPTR,#4000
800A: MOVX @DPTR,A
800B: SJMP 800B

MULTIPLICATION
PROGRAM:
8000: MOV A,#03
8002: MOV B,#02
8005: MUL AB
8006: SJMP 8006

DIVISION
PROGRAM:
8000: MOV A,#03
8002: MOV B,#02
8005: DIV AB
8006: SJMP 8006

RESULT:
Thus the 8 bit Addition, Subtraction, Multiplication and Division are performed and verified
using 8051 Microcontroller.

13
TABLE - ASCENDING ORDER:

INPUT OUTPUT
LOCATION DATA LOCATION DATA
51H 05 51H 01
52H 03 52H 02
53H 02 53H 03
54H 01 54H 04
55H 04 55H 05

14
EX. NO:
SORTING OF NUMBERS
DATE:

AIM:
To perform sorting of given numbers in ascending and descending order using 8051
Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller
2. Keyboard
ASCENDING ORDER:
PROGRAM:
8000: MOV A,#05
8002: MOV R2,A
8003: DEC R2
L3 8004: MOV A,R2
8005: MOV R3,A
8006: MOV R0,#51
L2 8008: MOV A,@R0
8009: MOV R4,A
800A: INC R0
800B: MOV A,@R0
800C: MOV R5,A
800D: SUBB A,R4
800E: JNC 8016
8010: MOV A,R4
8011: MOV @R0,A
8012: DEC R0
8013: MOV A,R5
8014: MOV @R0,A
8015: INC R0
L1 8016: DJNZ R3,8008
8018: DJNZ R2,8004
801A: SJMP 801A

15
TABLE - ASCENDING ORDER:

INPUT OUTPUT
LOCATION DATA LOCATION DATA
51H 05 51H 05
52H 03 52H 04
53H 02 53H 03
54H 01 54H 02
55H 04 55H 01

16
DESCENDING ORDER:
PROGRAM:
8000: MOV A,#05
8002: MOV R2,A
8003: DEC R2
L3 8004: MOV A,R2
8005: MOV R3,A
8006: MOV R0,#51
L2 8008: MOV A,@R0
8009: MOV R4,A
800A: INC R0
800B: MOV A,@R0
800C: MOV R5,A
800D: SUBB A,R4
800E: JC 8016
8010: MOV A,R4
8011: MOV @R0,A
8012: DEC R0
8013: MOV A,R5
8014: MOV @R0,A
8015: INC R0
L1 8016: DJNZ R3,8008
8018: DJNZ R2,8004
801A: SJMP 801A

RESULT:
Thus, the sorting of given numbers in ascending and descending order was done using 8051
Microcontroller.

17
SQUARE WAVE:
FLOWCHART:

Start

Send data 00H to DAC

DAC output equals to 0V

Delay Time

Send data FFH to DAC

Delay Time

GRAPH:

TRIANGLE WAVE:
GRAPH:

18
EX. NO:
DIGITAL TO ANALOG CONVERTER – WAVE GENERATION
DATE:

AIM:
To write and execute an assembly language program to generate square wave, triangle wave
and sawtooth wave using 8051 Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller trainer kit
2. Digital to Analog interface kit
3. Keyboard
PROGRAM:
SQUARE WAVE:

8200: 90 FF C0 MOV DPTR,#FFC0 ; Get DAC port address in DPTR


8203: 74 00 MOV A,#00 ; Data to set DAC output to 0 level
8205: F0 MOVX @DPTR,A ; Send data to DAC
8206: 78 FF MOV R0,#FF ; Off time delay
8208: D8 FE DJNZ R0,8208
820A: 74 FF MOV A,#FF ; Data to set DAC output to 1 level
820C: F0 MOVX @DPTR,A ; Send data to DAC
820D: 78 FF MOV R0,#FF ; On time delay
820F: D8 FE DJNZ R0,820F
8211: 80 F0 SJMP 8203

TRIANGLE WAVE:

8240: 90 FF C0 MOV DPTR,#FFC0 ; Get DAC port address in DPTR


8243: 74 00 MOV A,#00 ; Data to set DAC output to 0V
8245: F0 MOVX @DPTR,A ; Send data to DAC
8246: 04 INC A ; Increment DAC data
8247: B4 FF FB CJNZ A,#FF,8245 ; Repeat until Acc becomes FFH
824A: F0 MOVX @DPTR,A
824B: 14 DEC A ; Decrement Acc content
824C: B4 00 FB CJNE A,#00,824A ; Repeat until Acc becomes 00H
824F: 80 F2 SJMP 8203 ; Repeat the above process
TRIANGLE WAVE:
19
FLOWCHART:

Start

Load Acc with 00H

Send to DAC

INC Acc by 1

No
Is status = 00H?

Yes

Load Acc with FFH

Send to DAC

DEC Acc by 1

No
Is Acc = 00H?

Yes

SAWTOOTH WAVE:

GRAPH:

20
SAWTOOTH WAVE:

FLOWCHART:

Start

Load Acc with 00H

Send to DAC

INC Acc by 1

SAWTOOTH WAVE:

8260: 90 FF C0 MOV DPTR,#FFC0 ; Get DAC port address in DPTR


8263: 74 00 MOV A,#00 ; Data to set DAC output to 0V
8265: F0 MOVX @DPTR,A ; Send data to DAC
8266: 04 INC A ; Increment DAC data
8267: 80 FC SJMP 8265 ; Repeat the process

RESULT:
Thus the assembly language program to generate square wave, triangle wave and sawtooth
wave was written and executed using 8051 Microcontroller.

21
DISPLAY THE ROOM TEMPERATURE
FLOWCHART:

Start

Set th Mux to select channel 0

Set Run/Hold to 1

Read status

Is status = 1

Set Run/Hold to 0

Read Lower Byte

Read Higher Byte

Display the data room temperature on the


trainer display

22
EX. NO:
ANALOG TO DIGITAL CONVERTER
DATE: DISPLAY THE ROOM TEMPERATURE

AIM:
To perform analog to digital conversion to display the room temperature using 8051
Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller trainer kit
2. Analog to Digital interface kit
3. Keyboard
DISPLAY THE ROOM TEMPERATURE:
PROGRAM:
8050: 12 10 00 LCALL 1000 ; Clear LCD display
8053: 90 03 08 MOV DPTR,#0308 ; Select Line 2, position 8
8056: 12 10 30 LCALL 1030 ; Locate cursor
8059: 74 00 MOV A,@00 ; Select ADC channel 0
805B: 12 81 00 LCALL 8100 ; Read room temperature
805E: 12 81 50 LCALL 8150 ; Convert ADC result into decimal
8061: 12 80 76 LCALL 8076 ; Left shift decimal result 4 bits
8064: E8 MOV A,R0 ; Get temperature MSB in Acc
8065: 12 10 50 LCALL 1050 ; Display MSB of decimal output
8068: 74 2E MOV A,#2E ; ASCII code for ‘.’
806A: 12 10 40 LCALL 1040 ; Display ‘.’
806D: E9 MOV A,R1 ; Get LSB of decimal output
806E: 12 10 50 LCALL 1050 ; Display LSB
8071: 12 80 A0 LCALL 80A0 ; Delay between samples
8074: 80 DD SJMP 8053 ; Repeat temperature display process

SHIFT LEFT INPUT BY 4 BITS:


8076: E5 82 MOV A,DPL ; Get DPL in Acc
8078: C4 SWAP A ; Swap nibbles
8079: C0 E0 PUSH ACC ; Store upper nibble of DPL
807B: 54 0F ANL A,#0F ; in R0 lower nibble
807D: F8 MOV R0,A

23
807E: E5 83 MOV A,DPH
8080: C4 SWAP A ; Get lower nibble of DPH in
8081: 54 F0 ANL A,#F0 ; Acc upper nibble
8083: 48 ORL A,R0 ; Combine R0
8084: F8 MOV R0,A ; Store MSB in R0
8085: D0 E0 POP ACC
8087: 54 F0 ANL A,#F0
8089: F9 MOV R1,A ; Store LSB in R1
808A: 22 RET

DELAY:
80A0: 78 0A MOV R0,#0A ; Load outer loop count in R0
80A2: 79 FF MOV R1,#FF ; Load inner loop count in R1
80A4: D9 FE DJNZ R1,80A4 ; Decrement register R1 until 0
80A6: D8 FA DJNZ R0,80A2 ; Repeat DL1 loop R0 times
80A8: 22 RET

READ ROOM TEMPERATURE:


8100: 90 FF C8 MOV DPTR,#FFC8 ; DPTR = ADC channel selection port
8103: C0 E0 PUSH ACC ; Save channel number
8105: F0 MOVX @DPTR,A ; Select the input channel
8106: 78 FF MOV R0,#FF
8108: D8 FE DJNZ R0,8108 ; Wait for some time
810A: 44 10 ORL A,#10
810C: F0 MOVX @DPTR,A ; Give the start conversion puls
810D: 90 FF C8 MOV DPTR,#FFC8
8110: E0 MOVX A,@DPTR ; Get the status from ADC
8111: 54 40 ANL A,#40
8113: 60 FB JZ 8110 ; Repeat until status line goes high
8115: D0 E0 POP ACC
8117: 54 0F ANL A,#0F
8119: 90 FF C8 MOV DPTR,#FFC8
811C: F0 MOVX @DPTR,A ; Disable start conversion
24
811D: 90 FF C8 MOV DPTR,#FFC8
8120: E0 MOVX A,@DPTR ; Get the high byte of ADC result
8121: C0 E0 PUSH ACC
8123: 90 FF C0 MOV DPTR,#FFC0
8126: E0 MOVX A,@DPTR ; Get low byte of ADC result
8127: F5 82 MOV DPL,A ; Store low byte in DPL
8129: D0 E0 POP ACC
812B: 54 0F ANL A,#0F ; Mask unwanted bits and store
812D: F5 83 MOV DPH,A ; High byte in DPH
812F: 22 RET

OUTPUT:

Room Temperature =

RESULT:
Thus, the room temperature was displayed using ADC interface and 8051 Microcontroller.

25
INTERFACING SEVEN SEGMENT DISPLAY:

FLOWCHART:

Start

Move date to be displayed to Acc

Store Acc on stack


Swap Acc contents
Mask higher nibble

Get seven segment display code


Corresponding to Acc contents

Send it ti output port FFC0H

Restore Acc.
Mask higher nibble

Get corresponding seven segment code

Send it to output port FFC8H

End

26
EX. NO:
INTERFACING SEVEN SEGMENT DISPLAY
DATE:

AIM:
To write and perform an assembly language program to display numbers on seven segment
display using 8051 Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller trainer kit
2. Seven segment display interface
3. Keyboard
THEORY:
Seven segment display is a form of electronic display for displaying decimal numbers that is
an alternate to the more complex dot matrix displays.
PROGRAM:
8000: 75 81 40 MOV SP,#40 ; Initialize stack pointer
8003: 74 12 MOV A,#12 ; Move data to be displayed
8005: 12 80 0A LCALL 800A ; Display the data
8008: 80 FE SJMP 8008 ; Halt

DISP_2DIGIT:

800A: 90 80 24 MOV DPTR,#8024


800D: C0 E0 PUSH ACC
800F: C4 SWAP A ; Convert high nibble to lower
8010: 54 0F ANL A,#0F ; Mask high nibble
8012: 93 MOVC A,@A+DPTR ; Get corresponding seven segment code
8013: 90 FF C0 MOV DPTR,#FFC0 ; Move output port address for digit 1
8016: F0 MOVX @DPTR,A ; Send the seven segment code
8017: D0 E0 POP ACC
8019: 90 80 24 MOV DPTR,#8024
801C: 54 0F ANL A,#F0
801E: 93 MOVC A,@A+DPTR ; Get corresponding seven segment code
801F: 90 FF C8 MOV DPTR,#FFC8 ; Move output port address for digit 1
8022: F0 MOVX @DPTR,A ; Send the seven segment code
8023: 22 RET

27
OUTPUT:

28
SEVEN SEGMENT DISPLAY CODES TABLE:

8024: C0 F9 A4 B0 .byte 0xC0, 0xF9, 0xA4, 0xB0


8024: 99 92 82 F8 .byte 0x99, 0x92, 0x82, 0xF8
802C: 80 90 88 83 .byte 0x80, 0x90, 0x88, 0x83
8030: C6 A1 86 8E .byte 0xC6, 0xA1, 0x86, 0x8E

RESULT:
Thus the assembly language program to display numbers on seven segment display was
written and verified using 8051 Microcontroller.

29
CLOCK WISE DIRECTION:
FLOWCHART:

Start

Move Acc = 66H

Move Acc contents to output port

Small Delay

Rotate Acc contents right by one bit

COUNTER CLOCK WISE DIRECTION:


FLOWCHART:

Start

Move Acc = 66H

Move Acc contents to output port

Small Delay

Rotate Acc contents left by one bit

30
EX. NO:
INTERFACING STEPPER MOTOR
DATE:

AIM:
To interface stepper motor with 8051 Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller trainer kit
2. Stepper motor interface kit
3. Keyboard
THEORY:
Basically, Stepper motors are electromechanical converters. They differ from the constant speed

motors in the spindle movement. Here the movement of the spindle will be in steps. They respond in a

well-defined way to certain digital signals fed to their control electronics. Stepper motors may be used

as an open system without feedback for control purposes. A stepping motor may therefore replace a

conventional DC servo system with feedback.

A stepper motor may be classified as Unipolar or Bipolar according to the rotating field

generated. Another classification depends on the material from which the rotor is constructed, either

Permanent magnet or soft iron type.

The operating voltage of the stepper motor is 5V. The motor works with a step angle of 11.25

degrees. The stepper motor has built in gears and it works with a gear ratio of 1:64. This implies the

fact that for every step of shaft movement, you need to give 64 step movement to the motor.

Number of steps required for 90-degree movement of the shaft:

Angle to be rotated Step angle 90


------------------------------------ X 60 = ----------------- X 64 = 512 steps
Step Angle 11.25

31
ROTATE 90 DEGREES IN COUNTER CLOCK WISE DIRECTION:
FLOWCHART:

Start

Move Acc = 66H


Initialize a count ((degree to be
rotate/degree per step)* 64)

Move Acc contents to port

Small delay

Restore Acc. Contents left by one bit

Decrement counter

Is status = 1

End

32
PROGRAM:
CLOCK WISE DIRECTION:
8000: 90 FF CO MOV DPTR,#FFC0 ; Port address = FFC0H
8003: 74 66 MOV A,#66 ; Store data to energize phase 2 & Phase 3
8005: F0 MOVX @DPTR,A ; Send data to port lines
8006: 11 0B ACALL 800B ; Delay between two steps
8008: 03 RR A ; Rotate right Acc, to get next data
8009: 80 FA SJMP 8005 ; Repeat the above process for ever

COUNTER CLOCK WISE DIRECTION:


8040: 90 FF CO MOV DPTR,#FFC0 ; Port address = FFC0H
8043: 74 66 MOV A,#66 ; Store data to energize phase 2 & Phase 3
8045: F0 MOVX @DPTR,A ; Send data to port lines
8046: 11 0B ACALL 800B ; Delay between two steps
8048: 23 RL A ; Rotate left Acc, to get next data
8049: 80 FA SJMP 8005 ; Repeat the above process for ever

ROTATE 90 DEGREES IN COUNTER CLOCK WISE DIRECTION:


8060: 90 FF C0 MOV DPTR,#FFC0
8063: 74 66 MOV A,#66 ; Move initial data to Acc
8065: 7B 02 MOV R3,#02 ; MSB count (( Degree/step)*64)
8067: 7A FF MOV R2,#FF ; LSB count
8069: F0 MOVX @DPTR,A ; Set it to output port
806A: 11 0B ACALL 800B ; Wait for small delay
806C: 23 RL A ; Rotate left the data in Acc
806D: DA FA DJNZ R2,8069 ; Decrement count and repeat until 0
806F: DB F6 DJNZ R3,8067 ; Decrement count and repeat until 0
8071: 80 FE SJMP 8071 ; Halt

33
DELAY:
800B: 78 10 MOV R0,#0A ; Load outer loop count in R0
800D: 79 FF MOV R1,#FF ; Load inner loop count in R1
800F: D9 FE DJNZ R1,#800F ; Decrement register R1 until it becomes 0
8011: D8 FA DJNZ R0,800D ; Repeat DL1 loop R0 times
8013: 22 RET

RESULT:
Thus, the stepper motor was interfaced with 8051 microcontroller.

34
EX. NO:
INTERFACING TRAFFIC LIGHT
DATE:

AIM:
To interface traffic light with 8051 Microcontroller.

APPARATUS REQUIRED:
1. NG Platinum 8051 Microcontroller trainer kit
2. Traffic light interface kit
3. Keyboard
THEORY:
The Traffic Light Interface card is designed to control the traffic where four roads cross each
other. The card is designed in such a manner, that the user can understand the control operations very
easily. Interfacing of the card to the Microprocessor/Microcontroller is done through the bus lines
present in the trainer itself. The card is connected to the trainer through 50 pin FRC connector.
The Traffic Light Interface Card consists of Red, Yellow and Green LEDs for the STOP,
READY and GO signals. For indicating pedestrian signs such as DON'T WALK and WALK, LEDS
Red and Green are used respectively. IC ULN2003 is used to drive the LEDs.
FLOWCHART:

35
PROGRAM:
TRAFFIC LIGHT CONTROL:
8000: 79 09 MOV R1,#09 ; Move loop count to register R1
8002: 78 37 MOV R0,#37 ; Starting address for display table
8004: 75 A0 80 MOV P2,#80
8007: E2 MOVX A,@R0 ; Read the display data for road 1
8008: 90 FF 80 MOV DPTR,#FF80
800B: F0 MOVX @DPTR,A ; Send the display data for road 1
800C: 08 INC R0
800D: E2 MOVX A,@R0 ; Read the display data for road 1
800E: 90 FF 84 MOV DPTR,#FF84
8011: F0 MOVX @DPTR,A ; Send the display data for road 1
8012: 08 INC R0
8013: E2 MOVX A,@R0 ; Read the display data for road 1
8014: 90 FF 88 MOV DPTR,#FF88
8017: F0 MOVX @DPTR,A ; Send the display data for road 1
8018: 08 INC R0
8019: E2 MOVX A,@R0 ; Read the display data for road 1
801A: 90 FF 8C MOV DPTR,#FF8C
801D: F0 MOVX @DPTR,A ; Send the display data for road 1
801E: 08 INC R0
801F: E2 MOVX A,@R0 ; Read the delay data
8020: 08 INC R0
8021: 11 27 ACALL 8027 ; Call the delay routine
8023: D9 E2 DJNZ R1,8007
8025: 80 D9 SJMP 8000 ; Repeat the process again

DELAY ROUTINE:
8027: 7A 05 MOV R2,#05
8029: 7B FF MOV R3,#FF ; Move 0FFH to R3
802B: 7C FF MOV R4,#FF ; Move 0FFH to internal R4
802D: DC FE DJNZ R4,#802D ; Repeat until it becomes 0
802F: DB FA DJNZ R3,#802B ; Decrement R3 & repeat until 0
36
8031: DA F6 DJNZ R3,#8029 ; Decrement R2 & repeat until 0
8033: D5 E0 F1 DJNZ ACC,8027
8036: 22 RET

BIT PATTERN FOR SWITCHING ON LEDs:


8037: 12 14 14 14 05 0x12, 0x14, 0x14, 0x14, 05
803C: 11 14 14 14 14 0x11, 0x14, 0x14, 0x14, 20
8041: 14 12 14 14 05 0x14, 0x12, 0x14, 0x14, 05
8046: 14 11 14 14 14 0x14, 0x11, 0x14, 0x14, 20
804B: 14 14 12 14 05 0x14, 0x14, 0x12, 0x14, 05
8050: 14 14 11 14 14 0x14, 0x14, 0x11, 0x14, 20
8055: 14 14 14 12 05 0x14, 0x14, 0x14, 0x12, 05
805A: 14 14 14 11 14 0x14, 0x14, 0x14, 0x11, 20
805F 0C 0C 0C 0C 14 0x0C, 0x0C, 0x0C, 0x0C, 20

RESULT:
Thus, the traffic light kit was interfaced with 8051 Microcontroller.

37

You might also like