0% found this document useful (0 votes)
522 views57 pages

Microcontrollers Lab Manual for EEE Students

This document provides information about experiments to be conducted using the Universal Embedded Trainer (VUET-REV0) board and the 8051 microcontroller. It outlines six modules that cover introductory topics like getting familiar with the board and software, as well as more advanced topics like interfacing peripherals and assembly programming. The first module introduces the features of the VUET board and the Keil and Proteus software tools. It also provides block and pinout diagrams of the board.

Uploaded by

kavitha
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)
522 views57 pages

Microcontrollers Lab Manual for EEE Students

This document provides information about experiments to be conducted using the Universal Embedded Trainer (VUET-REV0) board and the 8051 microcontroller. It outlines six modules that cover introductory topics like getting familiar with the board and software, as well as more advanced topics like interfacing peripherals and assembly programming. The first module introduces the features of the VUET board and the Keil and Proteus software tools. It also provides block and pinout diagrams of the board.

Uploaded by

kavitha
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

1

14EE490 - MICROCONTROLLERS LAB

Manual

Dr.L.Jessi Sahaya Shanthi


Dr.D.Kavitha

EEE DEPARTMENT
THIAGARAJAR COLLEGE OF ENGINEERING,
MADURAI -625 015.
2

LIST OF EXPERIMENTS

MODULE - 0 (1 WEEK)
1. INTRODUCTION TO UNIVERSAL EMBEDDED TRAINER (VUET-REV0)
2. INTRODUCTION TO KEIL SOFTWARE
3. INTRODUCTION TO PROTEUS SOFTWARE

MODULE - I (3 WEEKS)
1. LED INTERFACE WITH 8051 USING EMBEDDED C PROGRAM
2. LCD INTERFACE WITH 8051 USING EMBEDDED C PROGRAM
3. MATRIX KEYPAD INTERFACE WITH 8051 USING EMBEDDED C PROGRAM
4. SEVEN SEGMENT LED INTERFACE WITH 8051 USING EMBEDDED C PROGRAM

MODULE - II (1 WEEK)
PROJECT - 1: INTERFACING MULTIPLE PERIPHERAL DEVICES WITH 8051 FOR AN
APPLICATION

MODULE - III (2 WEEKS)


1. ADC INTERFACE WITH 8051
2. DAC INTERFACE WITH 8051

MODULE - IV (2 WEEKS)
1. ASSEMBLY LANGUAGE PROGRAMMING USING KEIL
2. CREATING DELAYS USING TIMERS
3. SPEED CONTROL OF STEPPER MOTOR/DC MOTOR

MODULE - V (1 WEEK)
PROJECT - 2: REALIZATION OF A MICROCONTROLLER BASED SYSTEM USING PROTEUS
SOFTWARE / LAB HARDWARE

MODULE - VI (1 WEEK)
INTERFACING PERIPHERALS WITH TM4C123 MICROCONTROLLER KIT.
3

CONTENTS

S.NO EXPERIMENTS PAGE NO


MODULE 0
INTRODUCTION TO UNIVERSAL EMBEDDED TRAINER (VUET-REV0)
1 1
2 INTRODUCTION TO KEIL SOFTWARE 12
3 INTRODUCTION TO PROTEUS SOFTWARE 18
MODULE 1
1 LED INTERFACE WITH 8051 USING EMBEDDED C PROGRAM 19
2 LCD INTERFACE WITH 8051 USING EMBEDDED C PROGRAM 23
3 MATRIX KEYPAD INTERFACE WITH 8051 USING EMBEDDED C PROGRAM 30

SEVEN SEGMENT LED INTERFACE WITH 8051 USING EMBEDDED C


4 PROGRAM 35
MODULE II
1 PROJECT - 1: INTERFACING MULTIPLE PERIPHERAL DEVICES WITH 8051
FOR AN APPLICATION 40
MODULE III
1 ADC INTERFACE WITH 8051 41
2 DAC INTERFACE WITH 8051 45
MODULE IV
1 ASSEMBLY LANGUAGE PROGRAMMING USING KEIL 48
2 CREATING DELAYS USING TIMERS 53
3 SPEED CONTROL OF STEPPER MOTOR/DC MOTOR 54
MODEL QUESTIONS 56
VIVA QUESTIONS 57
4

MODULE - 0
1. INTRODUCTION TO UNIVERSAL EMBEDDED TRAINER (VUET-REV0)
2. INTRODUCTION TO PROTEUS SOFTWARE

INTRODUCTION
VUET is a basic embedded trainer for educational purposes. From the
name UET implies Universal Embedded Trainer. As the name represents
universal it has the provision to plug and develop coding for several controllers.

VUET normally have the AVR controller on the base board additionally we
can port 8051 controller to VUET through EURO connector as a PIGGY BACK.
5

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

BOARD FEATURES:

 MCU:89V51RD2 8 bit with 64K Bytes Program Flash, 1024 bytes Data RAM, 1x
UARTs, SPI, 4 channel (PWM/CAPTURE/COMPARE), Four 8bits 5V tolerant I/O,
up to 40MHz operation.
 USB connector for USB Programming and UART Communication

 16 LEDs for user interface

 4x4 Matrix Keypad buttons

 Four seven segment display (LT543) using PCF8574.

 One 12V relay with relevant driver Circuit.

 Two 8 – way DIP switch for user interface.

 Stepper motor Interface with Internal or External voltage selection.

 One 16x2 Alphanumeric LCD display with Connector.

 One 10k trim pot for LCD brightness Control.

 One RTC with battery backup using DS1307 / PCF8583.

 One external EEPROM interface using 24LC512.

 Temperature sensor(LM35) connected to ADC

 On board supply ±12v, 5v

 power supply LED

 RESET button

 SPDT switch for power on off control

 11.0592 MHz crystal on socket

 I/O lines are terminated through a 26 pin FRC connector for external
interface.

Points to remember while working on VUET

1. Since it is a universal trainer we can add upon any AVR or 8051 core based 8
bit controllers.
2. While we are working with AVR controllers remove the PIGGY BACK and
place the AVR controller in a 40 pin IC base, and use RESET key to reset the
system.
6

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

3. Independently are we going to work with 8051 controllers, if any AVR is


plugged in please plugged out the AVR controller and plugged in 8051
though 48 pin EURO connector to VUET.
4. For 8051 controllers use S1 key as a reset key.

BOARD USE REQUIREMENTS:


Cables:

The cable you will need depends on the programmer/debugger you use.
USB A-B cable, if you use USB Programmer.

Software:

 Keil µVersion3.

 Flash Magic software for program Downloading.

Controller FEATURES:

 8051 Central Processing Unit.



 5 V Operating voltage from 0 to 40 MHz

 64 KB of on-chip Flash program memory with ISP (In-System Programming.

 Supports 12-clock (default) or 6-clock mode selection via software or ISP.

 SPI (Serial Peripheral Interface) and enhanced UART.

 PCA (Programmable Counter Array) with PWM and Capture/Compare functions.

 Four 8-bit I/O ports with three high-current Port 1 pins (16 mA each).

 Three 16-bit timers/counters.

 Programmable Watchdog timer (WDT).

 Eight interrupt sources with four priority levels.

 Second DPTR register.

 Low EMI mode (ALE inhibit).

 TTL- and CMOS-compatible logic levels.

 Brown-out detection.

 Low power modes.

 Power-down mode with external interrupt wake-up. 

 Idle mode
7

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Block Diagram

Vi Microsystems Pvt. Ltd.,


8

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

PINOUT Diagram:

Vi Microsystems Pvt. Ltd.,


9

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

POWER SUPPLY CIRCUIT

VSK – AVR can take power from TWO sources:


- External power supply 5.0V DC.
- External power supply ±12V DC

RESET CIRCUIT

VSK – AVR reset circuit includes one 4.7k Pull up resistor with VCC was
connected with the 9th pin of the ATmega32.

CLOCK CIRCUIT

Quartz crystal with name Y1 (11.0592 MHz) is connected to ATmega32 pin


no 12 (X2) and pin 13(X1).

Jumper Description (SP1):

When the 1st and 2nd pins of the Jumper SP1 will short means the
external ADC input gets connected to Digital Thermometer DS18B20.
When the 2nd and 3rd pins of the Jumper SP1 will short means the
internal ADC (PA7) input gets connected to Digital Thermometer
DS18B20.

Jumper Description (SP2):

When the 1st and 2nd pins of the Jumper SP2 will short means the
external ADC input gets connected to Temperature Sensor LM35.
When the 2nd and 3rd pins of the Jumper SP2 will short means the
internal ADC (PA7) input gets connected to Temperature Sensor LM35.

NOTE: while we are working with 8051 don’t be bother about these SP1 and SP2 jumpers.

Jumper Description (SP3):

When the 1st and 2nd pins of the Jumper SP3 will short means the
stepper motor will gets power externally to drive the motor via P1
connector.
If the 2nd and 3rd pin of the Jumper SP3 gets shorted means you must
give power internally from the board.

Vi Microsystems Pvt. Ltd.,


10

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Jumper Description (SP4):

When the 1st and 2nd pins of the Jumper SP4 will short means the
relay driver will gets +5V to drive the relay.
If the 2nd and 3rd pin of the Jumper SP4 will short means the relay
driver will gets +12V to drive the relay.

Jumper Description (SP5):

If you connected Common anode display means you must connect 1st
and 2nd pin of the SP5 Jumper.
If you connected Common cathode display means you must connect
2nd and 1st pin of the SP5 Jumper.

Jumper Description (J1):

When the 1st and 2nd pins of the Jumper SP1 will short means the
external ADC input gets connected to 10KΩ Trimmer.
When the 2nd and 3rd pins of the Jumper SP1 will short means the
internal ADC (PA6) input gets connected to 10KΩ Trimmer.

CONNECTOR DESCRIPTIONS

PWR_JACK (P5):

Pin # Signal Name

1 Power Input

2 GND

USB (P10):

Pin # Signal Name


1 +5V_USB
2 USB_D-
3 USB_D+
4 GND

Vi Microsystems Pvt. Ltd.,


11

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

STEPPER MOTOR CONNECTOR (P1):

PIN # Signal Name


1 MVCC
2 D0
3 D1
4 D2
5 D3

INTRODUCTION TO KEIL
Keil is a German based Software development company. It provides several
development tools like
• IDE (Integrated Development environment)
• Project Manager
• Simulator
• Debugger
• C Cross Compiler , Cross Assembler, Locator/Linker
Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the
multitude of 8051 derivatives. Keil provides following tools for 8051 development
1. C51 Optimizing C Cross Compiler,
2. A51 Macro Assembler,
3. 8051 Utilities (linker, object file converter, library manager),
4. Source-Level Debugger/Simulator,
5. µVision for Windows Integrated Development Environment.
The keil 8051 tool kit includes three main tools, assembler, compiler and linker.
An assembler is used to assemble your 8051 assembly program
A compiler is used to compile your C source code into an object file
A linker is used to create an absolute object module suitable for your in-circuit emulator.

8051 project development cycle: - these are the steps to develop 8051 project using keil

1. Create source files in C or assembly.

2. Compile or assemble source files.

3. Correct errors in source files.

4. Link object files from compiler and assembler.


5. Test linked application.
SOFTWARE WORKING PROCEDURE

1. Install Keil C51 Compiler.


12

2. After installation open the compiler, from the displayed window select
project menu and click New Project for creating new project.

3. By this act a small window is opened to select the appropriate path for
new project, at last gave the project name and save the project.
4. Then select the target for the project, which means to select the working
controller. Our controller is Phillips made with 8051 core, so we want to
select Phillips vendor, from that vendor list select P89V51RD2 controller.

Vi Microsystems Pvt. Ltd., [ 45 ]


13

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

5. Now our project is created, after that we want to create editor window for the
project, for this select file menu and click New from the drop down list.

Vi Microsystems Pvt. Ltd., [ 46 ]


14

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

6. Then save the source file with the extension as *.C

7. After editing the coding select project from the menu and click “Option
for Target ‘Target 1’ “.
8. Now a new window is opened, form that we want to configure the
oscillator frequency as “ 11.0592” as shown below.

Vi Microsystems Pvt. Ltd., [ 47 ]


15

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

9. Then from the same window select output drop list and check the “Create
HEX file” check box.

Vi Microsystems Pvt. Ltd., [ 48 ]


16

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

10. Finally build the project by selecting project menu and click build all
target files.

11. If there is no error the hex file is generated at the same location where the
project is created.

12. Now load the hex file to the controller by using Flash magic Downloader.

Program downloading Procedures

1. Install the Flash Magic setup and open the installed software. Connect the cable.
17

INTRODUCTION TO PROTEUS

About Proteus

It is a software suite containing schematic, simulation as well as PCB designing.

 ISIS is the software used to draw schematics and simulate the circuits in real time.The
simulation allows human access during run time,thus providing real time simulation.
 ARES is used for PCB designing.It has the feature of viewing output in 3D view of the
designed PCB along with components.
 The designer can also develop 2D drawings for the product.

Features

ISIS has wide range of components in its library. It has sources, signal generators,
measurement and analysis tools like oscilloscope, voltmeter, ammeter etc., probes for
real time monitoring of the parameters of the circuit, switches, displays, loads like
motors and lamps, discrete components like resistors, capacitors, inductors,
transformers, digital and analog Integrated circuits, semi-conductor switches, relays,
microcontrollers, processors, sensors etc.

ARES offers PCB designing up to 14 inner layers, with surface mount and through hole
packages. It is embedded with the foot prints of different category of components like
ICs, transistors, headers, connectors and other discrete components. It offers Auto
routing and manual routing options to the PCB Designer. The schematic drawn in the
ISIS can be directly transferred ARES.
18

USING PROTEUS
The basic steps are as follows:
Create a new project in ISIS software
 Place the components from the library in a new project
 Connect them accordingly
 Load HEX file (Can be created using Keil software)
 Simulate the circuit

MODULE I:

IMPORTANT NOTE: 8051 MICROCONTROLLER HAS FOUR PORTS P0, P1, P2


AND P3. IN ALL THE DIAGRAMS, THESE PORTS ARE MENTIONED IN THE NAME
PA, PB, PC AND PD. REPLACE THE PORTS NAME WHEN DRAWING ON THE
OBSERVATION AND RECORD NOTE.

LED INTERFACE WITH 8051 USING EMBEDDED C PROGRAM

Led Interface:

LEDs are surely one of the most commonly used elements in electronics.
LED is an abbreviation for 'Light Emitting Diode'. When choosing a LED, several
parameters should be looked at: diameter, which is usually 3 or 5 mm
(millimetres), working current which is usually about 10mA (It can be as low as
2mA for LEDs with high efficiency - high light output), and colour of course,
which can be red or green though there are also orange, blue, yellow....

LEDs must be connected around the correct way, in order to emit light and the
current-limiting resistor must be the correct value so that the LED is not damaged or
burn out (overheated). The positive of the supply is taken to the anode, and the
cathode goes to the negative or ground of the project (circuit). In order to identify each
lead, the cathode is the shorter lead and the LED "bulb" usually has a cut or "flat" on
the cathode side. Diodes will emit light only if current is flowing from anode to
cathode. Otherwise, its PN junction is reverse biased and current won't flow. In order
to connect a LED correctly, a resistor must be added in series that to limit the amount
of current through the diode, so that it does not burn out. The value of the resistor is
determined by the amount of current you want to flow through the LED. Maximum
current flow trough LED was defined by manufacturer. High-efficiency LEDs can
produce a very good output with a current as low as 2mA.
19
20

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Port Lines Used:

Data Lines: PB0 – PB7 (P1^0 – P1^7)


Control Lines: PA0, PA1 (P0^0, P0^1)

Here PORTB is used to drive the LEDs. In ATMEGA32 have only 32 IO lines only.
It’s not possible to use all the peripherals with that IO lines alone. So we use
74LS273 buffer IC. In that 74LS273 IC we connect all the port lines of PORTB as
inputs and one control line PA0.
21

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)


Example Code:

#include<reg51.h>

#define HIGH 1
#define LOW 0
sbit LEDSET1 = P0^0;
sbit LEDSET2 = P0^1;
unsigned char arr[9]={0x00, 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

void Delay(int x);

void main()
{
int i;
while(HIGH)
{
for(i=0;i<10;i++)
{
P1 = arr[i];
LEDSET1 = HIGH;
LEDSET2 = HIGH;
Delay(100);
LEDSET1 = LOW;
LEDSET2 = LOW;
}
for(i=9;i>0;i--)
{
P1 = arr[i];
LEDSET1 = HIGH;
LEDSET2 = HIGH;
Delay(100);
LEDSET1 = LOW;
LEDSET2 = LOW;
}
P1 = 0xFF;
LEDSET1 = HIGH;
LEDSET2 = HIGH;
Delay(300);
LEDSET1 = LOW;
LEDSET2 = LOW;
}
}
void Delay(int x)
{
int k,l;
for(k = x;k > 0;k--)
for(l = 0;l < x;l++);
}

CODE OUTPUT:
Both rows LEDs will glow one by one as running fashion and the same pattern reversed. After one cylcle of
glowing, all LEDs will glow.
Reference: https://www.youtube.com/watch?v=e0ZCfxlfzlQ&t=17s
22

Liquid Crystal Display (LCD) Interface:

The microcontroller devices are using 'smart LCD' displays to output visual
information. The LCD displays have a standard ASCII set of characters plus
Japanese, Greek and mathematical symbols.

Each of the 640 pixels of the display must be accessed individually and this is done
with a number of surface-mount driver/controller chips mounted on the back of
the display. This saves an enormous amount of wiring and controlling so that only
a few lines are required to access the display to the outside world. We can
communicate to the display via an 8-bit data bus or 4-bit data bus. For a 8-bit data
bus, the display requires a +5V supply plus 11 I/O lines. For a 4-bit data bus it only
requires the supply lines plus seven extra lines. When the LCD display is not
enabled, data lines are tri-state which means they are in a state of high impedance
(as though they are disconnected) and this means they do not interfere with the
operation of the microcontroller when the display is not being addressed. The LCD
also requires 3 "control" lines from the microcontroller.

The Enable (E) line allows access to the display through R/W and RS lines.
When this line is low, the LCD is disabled and ignores signals from R/W and RS.
When (E) line is high, the LCD checks the state of the two control lines and responds
accordingly. The Read, Write (R/W) line determines the direction of data between the
LCD and microcontroller. When it is low, data is written to the LCD. When it is
high, data is read from the LCD. With the help of the Register select (RS) line, the

LCD interprets the type of data on data lines. When it is low, an instruction is being

written to the LCD. When it is high, a character is being written to the LCD.

Logic status on control lines:

E: 0 Access to LCD disabled.


23

1 Access to LCD enabled.

R/W: 0 Writing data to LCD.


1 Reading data from LCD.

RS: 0 Instruction.
1 Character.
Writing data to the LCD is done in several steps:

  Set R/W bit to low


 Set RS bit to logic 0 or 1 (instruction or character)
 Set data to data lines (if it is writing)
 Set E line to high
 Set E line to low
 Read data from data lines (if it is reading).

The LCD data write waveform.

Reading data from the LCD is done in the same way, but control line R/W
has to be high. When we send a high to the LCD, it will reset and wait for
instructions. Typical instructions sent to LCD display after a reset are: turning on a
display, turning on a cursor and writing characters from left to right. When the
LCD is initialized, it is ready to continue receiving data or instructions. If it
receives a character, it will write it on the display and move the cursor one space to
the right. The Cursor marks the next location where a character will be written.
When we want to write a string of characters, first we need to set up the starting
address, and then send one character at a time. Characters that can be shown on
the display are stored in data display (DD) RAM. The size of DDRAM is 80 bytes.

The LCD display also possesses 64 bytes of Character-Generator (CG) RAM. This
memory is used for characters defined by the user. Data in CG RAM is represented
as an 8-bit character bit-map. Each character takes up 8 bytes of CG RAM, so the
total number of characters, which the user can define is eight. In order to read in
the character bit-map to the LCD display, we must first set the CG RAM address to
24

starting point (usually 0), and then write data to the display. The definition of a
'special' character is given in the picture

Before we access DD RAM after defining a special character, the program


must set the DD RAM address. Writing and reading data from any LCD memory is
done from the last address which was set up using set-address instruction. Once
the address of DD RAM is set, a new written character will be displayed at the
appropriate place on the screen. Until now we discussed the operation of writing
and reading to an LCD as if it were an ordinary memory. But this is not so. The
LCD controller needs 40 to 120 microseconds (uS) for writing and reading. Other
operations can take up to 5 mS. During that time, the microcontroller cannot access
the LCD, so a program needs to know when the LCD is busy. We can solve this in
two ways.
25

LCD Control Commands:


26

0x33,0x32 – Initialize LCD in 4 bit mode.

0x80 – First row First character address.

0xc0 – Second row First character address.


27

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Data
Lines Used:

RS: PD2 (P3^2)

LCD_EN: PD3 (P3^3)

D4-D7: PD4 – PD7. (P3^4 – P3^7)

Example Code:

#include<reg51.h>
sbit rs = P3^2;
sbit en = P3^3;
sbit d7 = P3^7;
sbit d6 = P3^6;
sbit d5 = P3^5;
sbit d4 = P3^4;
unsigned char a[16] = {" TCE "};
unsigned char b[16]= {" EEE "};
unsigned char i;
void delay(int x)
{
int k,l;
for(k = x;k > 0;k--)
for(l = 0;l < x;l++);
}
void data_disp(unsigned char data_out) // LCD take 21ms of execution time.
{
d4 = data_out & 0x01;
d5 = (data_out & 0x02) >> 1;
d6 = (data_out & 0x04) >> 2;
d7 = (data_out & 0x08) >> 3;

}
28

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

void cmd_single(unsigned char cmds)


{
rs = 0;
data_disp((cmds & 0xf0)>>4);
en = 1;
delay(5);
en = 0;
delay(20);
data_disp((cmds & 0x0f));
en = 1;
delay(5);
en = 0;
}
void cmd_write()
{
int i;
unsigned char a[7]={0x33,0x32,0x28,0x01,0x06,0x0c,0x80};
for(i=0;i<7;i++)
{
cmd_single(a[i]);
delay(20);
}
}
void data_single(unsigned char da)
{
rs = 1;
data_disp((da & 0xf0)>>4);
en = 1;
delay(5);
en = 0;
delay(20);
data_disp((da & 0x0f));
en = 1;
delay(5);
en = 0;
}
void main()
{
cmd_write();
while(1)
{
cmd_single(0x80);
for(i=0;i<15;i++)
{
data_single(a[i]);
}
cmd_single(0xc0);
for(i=0;i<16;i++)
{
data_single(b[i]);
}
}
}

OUTPUT: ‘TCE’ AND ‘EEE’ will be displayed in the centre of first and second row of LCD.
29

4x4 Matrix Keypad interface:

Matrix keypads are the most widely used input/output devices in


microcontrollers such as the AVR and a basic understanding of them is essential. At
the lowest level, keypads are organized in a matrix of rows and columns. the cpu
accesses both rows and columns through ports; therefore, with one 8-bit ports, an 4x4
matrix of keys can be connected to a microcontroller. When a key is pressed, a row and
a column make a contact; otherwise, there is no connection between rows and
columns. in PC keyboards, a single microcontroller takes care of hardware and
software interfacing of the keyboard. In such systems, it is the function of programs
stored in the flash of the microcontroller to scan the keys continuously, identify which
one has been activated, and presented it to the motherboard.

Scanning and Identify the key:

In Figure below shows a 4x4 matrix key connected to PORTB. The rows are
connected to an output port and the columns are connected to an input port. If no
key has been pressed, reading the input port yields 1s for all columns since they all
are connected to high (VCC). If all the rows are grounded and a key is pressed, one
of the columns will have 0 since the key pressed provides the path to ground, and
identify the key pressed.

Data Lines Used:

SCAN Lines: PB0 – PB3 (P1^0 – P1^3)


Read Lines: PB4 – PB7 (P1^4 – P1^7)
Control Lines: PA4 & PA5. (P0^4 & P0^5)
30

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Example Code:

#include<REG51.h>
#define HIGH 1
#define LOW 0
sbit SCANLINE_EN = P0^4;
sbit READLINE_EN = P0^5;
sbit rs = P3^2;
sbit en = P3^3;
sbit d7 = P3^7;
sbit d6 = P3^6;
sbit d5 = P3^5;
sbit d4 = P3^4;
unsigned char LcdData[14]={"PRESSED KEY = "};
unsigned char LcdCommands[7]={0x33,0x32,0x28,0x01,0x06,0x0c,0x80};

Vi Microsystems Pvt. Ltd., [ 14 ]


31

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

void Delay_Function(int x);


void Bit_Conversion_Function(unsigned char data_out);
void Command_Write_Function(unsigned char cmd); void
Data_Write_Function(unsigned char dat);
void main()
{
int ReadVal, DispVal='-', i;
for(i=0;i<7;i++)
{
Command_Write_Function(LcdCommands[i]);
Delay_Function(20);
}
for(i=0;i<14;i++)
{
Data_Write_Function(LcdData[i]);
Delay_Function(20);
}

while(HIGH)
{
P1 = 0x0E;
SCANLINE_EN=1;
SCANLINE_EN=0;
READLINE_EN=0;
ReadVal = (P1 & 0xF0);
READLINE_EN = 1;
if(ReadVal == 0x70)
DispVal=0x33; //printf("\n\r You Pressed Key:
3"); if(ReadVal == 0xb0)
DispVal=0x32; //printf("\n\r You Pressed Key:
2"); if(ReadVal == 0xd0)
DispVal=0x31; //printf("\n\r You Pressed Key:
1"); if(ReadVal == 0xe0)
DispVal=0x30;
//printf("
\n\r You Pressed Key: 0");
P1 = 0x07;
SCANLINE_EN = 1;
SCANLINE_EN = 0;
READLINE_EN = 0;
ReadVal = (P1 & 0xF0);
READLINE_EN = 1;
if(ReadVal == 0x70)
DispVal=0x46; //printf("\n\r You Pressed Key:
F"); if(ReadVal == 0xb0)
DispVal=0x45; //printf("\n\r You Pressed Key:
E"); if(ReadVal == 0xd0)
DispVal=0x44; //printf("\n\r You Pressed Key:
D"); if(ReadVal == 0xe0)
DispVal=0x43; //printf("\n\r You Pressed Key: C");

P1 = 0x0d;
SCANLINE_EN = 1;
SCANLINE_EN = 0;
READLINE_EN = 0;

Vi Microsystems Pvt. Ltd., [ 15 ]


32

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

ReadVal = (P1 & 0xF0);


READLINE_EN = 1;
if(ReadVal == 0x70)
DispVal=0x37; //printf("\n\r You Pressed Key:
7"); if(ReadVal == 0xb0)
DispVal=0x36; //printf("\n\r You Pressed Key:
6"); if(ReadVal == 0xd0)
DispVal=0x35; //printf("\n\r You Pressed Key:
5"); if(ReadVal == 0xE0)
DispVal=0x34; //printf("\n\r You Pressed Key: 4");

P1 = 0x0b;
SCANLINE_EN = 1;
SCANLINE_EN = 0;
READLINE_EN = 0;
ReadVal = (P1 & 0xF0);
READLINE_EN = 1;
if(ReadVal == 0x70)
DispVal=0x42; //printf("\n\r You Pressed Key:
B"); if(ReadVal == 0xb0)
DispVal=0x41; //printf("\n\r You Pressed Key:
A"); if(ReadVal == 0xd0)
DispVal=0x39; //printf("\n\r You Pressed Key:
9"); if(ReadVal == 0xe0)
DispVal=0x38; //printf("\n\r You Pressed Key: 8");

Command_Write_Function(0x8E);
Data_Write_Function(DispVal);
}
}

void Delay_Function(int x)
{
int k,l;
for(k = x;k > 0;k--)
for(l = 0;l < x;l++);
}

void Bit_Conversion_Function(unsigned char data_out) // LCD take 21ms of


execution time.
{
d4 = data_out & 0x01;
d5 = (data_out & 0x02) >> 1;
d6 = (data_out & 0x04) >> 2;
d7 = (data_out & 0x08) >> 3;
}
void Command_Write_Function(unsigned char cmd)
{
rs = 0;
Bit_Conversion_Function((cmd & 0xf0)>>4);
en = 1;
Delay_Function(5);
en = 0;
Delay_Function(10);

Vi Microsystems Pvt. Ltd., [ 16 ]


33

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Bit_Conversion_Function((cmd & 0x0f));


en = 1;
Delay_Function(5);
en = 0;
}

void Data_Write_Function(unsigned char dat)


{
rs = 1;
Bit_Conversion_Function((dat & 0xf0)>>4);
en = 1;
Delay_Function(5);
en = 0;
Delay_Function(10);
Bit_Conversion_Function((dat & 0x0f));
en = 1;
Delay_Function(5);
en = 0;
}

OUTPUT:

The assigned value of the pressed key will be displayed in LCD


34

7 - Segment Interface:

We can display a multi-digit number by connecting additional displays.


Even though LCD displays are more comfortable to work with, 7-segment displays
are still standard in the industry. This is due to their temperature robustness,
visibility and wide viewing angle. Segments are marked with non-capital letters: a,
b, c, d, e, f, g and dp, where dp is the decimal point. The 8 LEDs inside each display
can be arranged with a common cathode or common anode.

With a common cathode display, the common cathode must be connected to


the 0V rail and the LEDs are turned on with a logic one. Common anode displays
must have the common anode connected to the +5V rail. The segments are turned
on with a logic zero. The size of a display is measured in millimeters, the height of
the digit itself (not the housing, but the digit!). Displays are available with a digit
height of 7,10, 13.5, 20, or 25 millimeters. They come in different colors, including:
red, orange, and green. The simplest way to drive a display is via a display driver.

These are available for up to 4 displays. Alternatively displays can be driven by


a microcontroller and if more than one display is required, the method of driving them
is called "multiplexing." The main difference between the two methods is the number
of "drive lines." A special driver may need only a single "clock" line and the driver chip
will access all the segments and increment the display.

If a single display is to be driven from a microcontroller, 7 lines will be needed


plus one for the decimal point. For each additional display, only one extra line is
needed. To produce a 4, 5 or 6 digit display, all the 7-segment displays are connected
in parallel. The common line (the common-cathode line) is taken out separately and
this line is taken low for a short period of time to turn on the display.

Each display is turned on at a rate above 100 times per second, and it will appear
that all the displays are turned on at the same time.

As each display is turned on, the appropriate information must be delivered


to it so that it will give the correct reading. Up to 6 displays can be accessed like
this without the brightness of each display being affected. Each display is turned
on very hard for one-sixth the time and the POV (persistence of vision) of our eye
thinks the display is turned on the whole time. All the timing signals for the
display are produced by the program, the advantage of a microcontroller driving
the display is flexibility. The display can be configured as an up-counter, down-
counter, and can produce a number of messages using letters of the alphabet that
can be readily displayed.
35

Here we using PCF8574 IC Remote 8-bit I/O expander for I2C-busfor 7-segment interface.
Because ATMEGA32 has only 32IO lines. For that purpose we use I2c based IO expander
for this interface.

The device consists of an 8-bit quasi-bidirectional port and an I2C-bus interface. The
PCF8574 has a low current consumption and includes latched outputs with high
current drive capability for directly driving LEDs. It also possesses an interrupt line
(INT) which can be connected to the interrupt logic of the microcontroller. By sending
an interrupt signal on this line, the remote I/O can inform the microcontroller if there
is incoming data on its ports without having to communicate via the I2C-bus. This
means that the PCF8574 can remain a simple slave device.
36

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

Port Lines Used:

SCL: PC0 (P2^0)


SDA: PC1 (P2^1)

Example:
#include<REG51.h>

#define HIGH 1
#define LOW 0
sbit SCL = P2^0;
sbit SDA = P2^1;
bit ack;
unsigned char LookUp[10] =
{0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x3F};
unsigned char Address[4] = {0x40, 0x42, 0x44, 0x48};
void I2c_Start_Function();
void I2c_Stop_Function();
void I2c_Write_Function(int WriteData);
char I2c_Read_Function();
void Delay_Function(int DelayLength);
void main()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<10;j++)
{
I2c_Start_Function();
I2c_Write_Function(Address[i]);
37

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

I2c_Write_Function(LookUp[j]);
I2c_Stop_Function();
Delay_Function(250);
}
Delay_Function(250);
}
while(HIGH);
}
void I2c_Start_Function()
{
SDA = HIGH;
SCL = HIGH;
SDA = LOW;
SCL = LOW;
}

void I2c_Stop_Function()
{
int retry;
retry = 9;
SDA = HIGH;
while (retry--)
if (!SDA)
{
SCL = HIGH;
SCL = LOW;
}
}
void I2c_Write_Function(int WriteData)
{
unsigned char index;
for(index = 0x80; index != 0; index >>= 1)
{
if (WriteData & index)
SDA = HIGH;
else
SDA = LOW;
SCL = HIGH;
SCL = LOW;
}
SDA = HIGH;

SCL = HIGH;
ack = SDA;
SCL = LOW;
//return(ack == 0);

char I2c_Read_Function()
38

UNIVERSAL EMBEDDED TRAINER (VUET-REV0)

{
unsigned char X;
unsigned char index;
SDA = 1;
X = LOW;
for(index = 0x80; index != 0; index >>= 1)
{
SCL = 1;
if (SCL)
SCL = 0; X |= index;
}
SDA = ack; // ACK (0) or NACK (1) bit
SCL = HIGH;
SCL = LOW;
return(X);
}

void Delay_Function(int DelayLength)


{
int i,j;
for(i=0;i<DelayLength;i++)
for(j=0;j<i;j++);
}

OUTPUT:
Each 7 segment LED will be glowing from numbers 0- 9.

SAMPLE TASKS:

Obtain the following sequence of illumination


(i) The LEDs in the first row glow for some time.
(ii) Then LEDs in the second row glow for some time
(iii) The Odd LEDs in the first row glow for some time
(iv) The even LEDs in the second row glow for some time
(v) The events from (i) to (iv) repeats

 Display the name of departing and arriving junctions of a train alternatively.

 Display the train number and name in a running fashion

 If first key is pressed all LEDs in the first row should glow from left to right in running
fashion and if the second key is pressed, all LEDs in the second row should glow from
right to left in running fashion.

 Four lights have to be started at the same time by pressing a switch

 If a key is pressed, The odd LEDs in the first row should glow, After a delay, the even
LEDs in the second row should glow. Then all LEDs should glow and the process
repeats. If another key is pressed, process is stopped.

 Control the pattern of “dancing” lights with different keys

 Display “tce” if one key is pressed and “EEE’ in seven segment LEDs if second key is
pressed.
39

 Display “COOL” in 4 seven segment LEDs

MODULE - II
PROJECT - 1: INTERFACING MULTIPLE PERIPHERAL DEVICES WITH 8051 FOR AN
APPLICATION

SAMPLE PROJECTS:

 Four lights in a room are controlled by a single switch. (Pressing the switch once will
turn on the lights, again pressing will turn off the lights) (SIMPLE PROJECT)

 In a room, it is required to switch on three different devices. These devices are


operated by different switches. (SIMPLE PROJECT)

 Control a device by two switches, one for switching on and other for switching off.
In a chemical industry, three different products are manufactured. When a key
corresponding to the product is pressed, product number should be displayed in 7-
segment LED. (SIMPLE PROJECT)

 In a chemical industry, three different processes such as filling, heating and


mixing
are carried out. When a key corresponding to the process is pressed, the process name
should be displayed in LCD. (SIMPLE PROJECT)

 In a packaging industry, a counting device is required that increments every time


when an enter key is pressed and the counter is reset by pressing a reset key.
(WORTHY PROJECT)

 Get the marks of a student and display the average mark. (WORTHY PROJECT)

 Create a password checking system which displays “wrong” if wrong password is


pressed and displays “right” if correct password is given. The size of password is two
digits (WORTHY PROJECT)

 Design a simple single digit calculator (WORTHY PROJECT)

 Obtain the 4- bit BINARY sequence of illumination in LED arrays and


correspondingly display the hexa number in seven segment LED. (SIMPLE
PROJECT)

 Four devices have to be started sequentially after particular time by pressing the same
switch. (SIMPLE PROJECT)

 Design a decorative light sequence for a family function with selection key. (SIMPLE
PROJECT)

 In an industry, it is required to pack 25 products in a single package. It is also required


to count the number of packages made in a given time. It is required to display both
details. (SIMPLE PROJECT)

 In a Cool drinks factory, bottle filling process takes place as follows. The bottles are
placed with a gap in a conveyer belt. Some time is taken to fill the bottle. Simulate
suitable control to move the conveyer belt which is driven by motor. (SIMPLE
40

PROJECT)

 In a university, four different grades of marks are given as follows. S= 10; A=8; B=6;
C=0. The grades for six subjects are given as input. For a particular student, get the
information of grades and put the total out of 60 and display the name and total
marks. (WORTHY PROJECT)

 Design a stop watch using appropriate device (WORTHY PROJECT)

 Simulate the process of washing machine. If first key is pressed, machine is on.
Second key set the timer value. Third key starts the countdown timer. After time
elapsed,
machine turned off. (WORTHY PROJECT)

 Create a educational system which displays certain information if particular key is


pressed (SIMPLE PROJECT)

 Design a system to display the number of cars inside parking lot. If first key is
pressed, it represents one car entering into the lot. If second key is pressed, it
represents one car exiting. (WORTHY PROJECT)

 Simulate the process of oven/ induction stove/ Washing machine etc.( WORTHY
PROJECT)

MODULE - III

Analog to Digital Converter:

The A/D converter present on AVR ATMEGA32 variants is a 10-bit


successive approximation converter with a conversion time of 13 μs - 260 μsor just
shy of 15 kSPS. The A/D converter has either 8 multiplexed inputs depending on
the variant. The programming interface for the A/D converter is shown below.

Since everything in the microcontroller world is represented with "0's" and


"1's", how do we cater for a signal that is 0.5 or 0.77? Most of the world outside a
computer consists of analogue signals. Apart from speech and music, there are
many quantities that need to be fed into a computer. Humidity, temperature, air
pressure, colour, turbidity, and methane levels, are just a few. The answer is to take
a number of digital lines and combine them so they can "read" an analogue value.
An analogue value is any value between 0 and 1. You can also call it a "fractional
value." All the above quantities must now be converted to a value between 0 and 1
so they can be fed into a computer. This is the broad concept. It becomes a little
more complex in application.
41

If we take 8 lines and arrange than so they accept binary values, the total
count will be 256 (this is obtained by a count to 255 plus the value 0). If we connect
these 8 lines into a "black box," they will be called output lines and so we must
provide a single input line. With this arrangement we can detect up to 255
increments between "0" and "1." This black box is called a CONVERTER and since
we are converting from Analogue to Digital, the converter is called an A-to-D
converter or ADC. AD converters can be classified according to different
parameters. The most important parameters are precision and mode of data
transfer.

As to precision, the range is: 8-bit, 10-bit, 12-bit, 14-bit, 16-bit. Since 12-bit
conversion is an industrial standard, the example we have provided below was
done with a 12-bit ADC. The other important parameter is the way data is
transferred to a microcontroller. It can be parallel or serial. Parallel transmission is
faster. However, these converters are usually more expensive. Serial transmission
is slower, but in terms of cost and fewer input lines to a microcontroller, it is the
favourite for many applications. Analogue signals can sometimes go above the
allowed input limit of an ADC. This may damage the converter. To protect the
input, two diodes are connected as shown in the diagram. This will protect from
voltages above 5V and below 0V.

The ATmega32 features a 10-bit successive approximation ADC. The ADC is


connected to an 8-channel Analog Multiplexer which allows 8 single-ended voltage
inputs constructed from the pins of Port A. The single-ended voltage inputs refer
to 0V (GND). The device also supports 16 differential voltage input combinations.
Two of the differential inputs (ADC1, ADC0 and ADC3, ADC2) are equipped with
a programmable gain stage, providing amplification steps of 0 dB (1x), 20 dB (10x),
or 46 dB (200x) on the differential input voltage before the A/D conversion. Seven
differential analog input channels share a common negative terminal (ADC1),
while any other ADC input can be selected as the positive input terminal. If 1x or
10x gain is used, 8-bit resolution can be expected. If 200x gain is used, 7-bit
resolution can be expected.

The ADC contains a Sample and Hold circuit which ensures that the input
voltage to the ADC is held at a constant level during conversion. A block diagram
of the ADC is shown in Figure. The ADC has a separate analog supply voltage pin,
AVCC. AVCC must not differ more than ±0.3V from VCC. Internal reference
42

voltages of nominally 2.56V or AVCC are provided On-chip. The voltage reference
may be externally decoupled at the AREF pin by a capacitor for better noise
performance.

Port Lines Used:

ADC Input: PA6 or External EAN0 (P0^6)

Example Code:

#include<REG51.h>
#include<stdio.h>
#define HIGH 1
#define LOW 0
sbit SCL = P2^0;
sbit SDA = P2^1;
bit ack;
void Uart_Transmit_Function(char ch);
void Uart_Initialize_Function();
void I2c_Start_Function();
void I2c_Stop_Function();
void I2c_Write_Function(int WriteData);
char I2c_Read_Function();
void Delay_Function(int DelayLength);
void main()
{
unsigned int I2cReadData;
Uart_Initialize_Function();

I2c_Start_Function();
I2c_Write_Function(0x9C);
I2c_Write_Function(0x00);
I2c_Stop_Function();
Delay_Function(100);
43

while(HIGH)
{
I2c_Start_Function();
I2c_Write_Function(0x9D);
I2cReadData = I2c_Read_Function();
I2c_Stop_Function();
printf("\n\r The ADC Value is %d",
I2cReadData); Delay_Function(50);
}

void Uart_Initialize_Function()
{
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0x00;
TCON = 0x40;
SCON = 0x52;
SBUF = ' ';
}
void Uart_Transmit_Function(char ch)
{
while((SCON&0X02)!=0X02);
SCON = (SCON&0XFD);
SBUF = ch;
}
void I2c_Start_Function()
{
SDA = HIGH;
SCL = HIGH;
SDA = LOW;
SCL = LOW;
}

void I2c_Stop_Function()
{
int retry;
retry = 9;
SDA = HIGH;
while (retry--)
if (!SDA)
{
SCL = HIGH;
SCL = LOW;
}
}
void I2c_Write_Function(int WriteData)
{
unsigned char index;
44

for(index = 0x80; index != 0; index >>= 1)


{
if (WriteData & index)
SDA = HIGH;
else
SDA = LOW;
SCL = HIGH;
SCL = LOW;
}
SDA = HIGH;

SCL = HIGH;
ack = SDA;
SCL = LOW;
//return(ack == 0);

char I2c_Read_Function()
{
unsigned char X;
unsigned char index;
SDA = 1;
X = LOW;
for(index = 0x80; index != 0; index >>= 1)
{
SCL = HIGH;
if (SDA)
SCL = LOW; X |= index;
}
SDA = ack; // ACK (0) or NACK (1) bit
SCL = HIGH;
SCL = LOW;
return(X);
}
void Delay_Function(int DelayLength)
{
int i,j;
for(i=0;i<DelayLength;i++)
for(j=0;j<i;j++);
}

Digital to Analog Converter:

To generate a staircase waveform and display in CRO.

#include<REG51.h>
#include<stdio.h>
#define HIGH 1
#define LOW 0
sbit SCL = P2^0;
sbit SDA = P2^1;
bit ack;
45

void I2c_Start_Function();
void I2c_Stop_Function();
void I2c_Write_Function(int WriteData);
void Delay_Function(int DelayLength);
void main()
{
int i;
while(HIGH)
{

I2c_Start_Function();
I2c_Write_Function(0x9C);
I2c_Write_Function(0x40);
I2c_Write_Function(0x00);
Delay_Function(100);
I2c_Write_Function(0x40);
Delay_Function(100);
I2c_Write_Function(0x80);
Delay_Function(100);

for(i=0x80;i<=0xff;i++)
{

I2c_Write_Function(i);

Delay_Function(5);

}
for(i=0xff;i>0x80;i--)
{

I2c_Write_Function(i);

Delay_Function(5);

I2c_Write_Function(0x80);
Delay_Function(100);
I2c_Write_Function(0x40);
Delay_Function(100);
I2c_Write_Function(0x00);
Delay_Function(100);
I2c_Stop_Function();

}
}
46

void I2c_Start_Function()
{
SDA = HIGH;
SCL = HIGH;
SDA = LOW;
SCL = LOW;
}

void I2c_Stop_Function()
{
int retry;
retry = 9;
SDA = HIGH;
while (retry--)
if (!SDA)
{
SCL = HIGH;
SCL = LOW;
}
}

void I2c_Write_Function(int WriteData)


{
unsigned char index;

for(index = 0x80; index != 0; index >>= 1)


{
if (WriteData & index)
SDA = HIGH;
else
SDA = LOW;
SCL = HIGH;
SCL = LOW;
}
SDA = HIGH;

SCL = HIGH;
ack = SDA;
SCL = LOW;
//return(ack == 0);

SAMPLE TASKS:
 Display the given waveform in CRO using DAC interface.
 create a code for alert of voltage level exceeding a particular value .

Reference: https://www.youtube.com/watch?v=N8IlGfClDEo
47

MODULE - IV
Assembly Language Programming Using Keil:
1.ADDITION OF TWO 8 BIT NUMBERS:

To add two data present in different locations.

ORG 0000H
MOV A,#05H
MOV R1,#04H
ADD A,R1
MOV DPTR,#3000H
MOVX @DPTR,A
AGAIN : SJMP AGAIN
END

2.8 BIT MULTIPLICATION:

To multiply two data stored in memory location and store the result in external memory.

ORG 0000H
MOV DPTR,#4201H
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
MUL AB
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
HALT:SJMP HALT
END

3. 8 BIT DIVISION:

To divide two data stored in memory location and store the result in external memory.

ORG 0000H
MOV DPTR,#4201H
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
DIV AB
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
HALT:SJMP HALT
END
48

4. EXCHANGING THE LOCATION OF TWO NUMBERS:

To exchange two numbers present in accumulator and register and store the result in external memory
location 9000H.

ORG 0000H
MOV A,#05H
MOV R0,#06H
XCH A,R0
MOV DPTR,#9000H
MOVX @DPTR,A
INC DPTR
MOV A,R0
MOVX @DPTR,A
RET
END

5. BIGGEST NUMBER:

To find the biggest number by using decrement,jumping operators and store the result in external
memory location

ORG 0000H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
MOV R1,A
DEC R0
LOOP:
INC DPTR
MOVX A,@DPTR
MOV R2,A
SUBB A,R1
JC LEVEL
MOV A,R2
MOV R1,A
LEVEL:
DJNZ R0,LOOP
MOV A,R1
MOV DPTR,#9100H
MOVX @DPTR,A
HERE:SJMP HERE
END
49

6. SMALLEST NUMBER:

To determine the smallest number using conditional instructions and store the result in external
memory location 9001H.

ORG 0000H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
MOV R1,A
DEC R0
LOOP:
INC DPTR
MOVX A,@DPTR
MOV R2,A
SUBB A,R1
JNC LEVEL
MOV A,R2
MOV R1,A
LEVEL:
DJNZ R0,LOOP
MOV A,R1
MOV DPTR,#9100H
MOVX @DPTR,A
HERE:SJMP HERE
END

7. ASCENDING ORDER:

To sort the given datas in ascending order using registers,accumulator and external memory location

ORG 0000H
MOV R0,#05
DEC R0
LOOP1:MOV DPTR,#9000
MOV A,R0
MOV R1,A
LOOP2:MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
SUBB A,R2
JNC LOOP3
MOVX A,@DPTR
XCH A,R2
MOVX @DPTR,A
DEC 82
MOV A,R2
MOVX @DPTR,A
INC DPTR
LOOP3:R1,LOOP2
DJNZ R0,LOOP1
50

HALT:SJMP HALT
END

8. DESCENDING ORDER:

Sorting of given datas in descending order and store the result in external memory locations.

ORG 0000H
MOV R0,#0A
DEC R0
LOOP1:MOV DPTR #9000H
MOV A,R0
MOV R1,A
LOOP2:MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
SUBB A,R2
JC LOOP3
MOVX A,@DPTR
XCH A,R2
MOVX @DPTR,A
DEC 82
MOV A,R2
MOVX @DPTR,A
INC DPTR
LOOP3:DJNZ R1,LOOP2
DJNZ R0,LOOP1
HERE:SJMP HERE
END

9. BCD TO HEXA CONVERSION:

To convert decimal value stored in register RO to hexa value and store the result in register R1

ORG 0000H
MOV R0,#99d
MOV A,R0
ANL A,#0F0H
SWAP A
MOV B,#0AH
MUL AB
MOV R1,A
MOV A,R0
ANL A,#0FH
ADD A,R1
MOV R1,A
HERE:SJMP HERE
END
51

10. HEXA TO BCD CONVERSION:

To convert hexa value stored in external memory to decimal value.

ORG 0000H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV B,#64H
DIV AB
MOV R0,A
MOV A,B
MOV B,#0AH
DIV AB
SWAP A
ADD A,B
INC DPTR
MOVX @DPTR,A
MOV A,R0
INC DPTR
MOVX @DPTR,A
HERE:SJMP HERE
END
52

Creating Delays using Timer:


Write 8051 ALP to generate square wave with delay of 500us.
NOTE: Delay time=(2^16 – required count)*1us=500us

PROGRAM:
ORG 0000H
CLR TF0
MOV TMOD,#01H
L1: MOV TLO,#0C H
MOV THO.#0FE H
SET B TRO
L2:JNB TFO ,L1;
CPL P1.0
CLR TRO
CLR TFO
JMP L2
53

Stepper Motor Interface:

Stepper motors operate differently from normal DC motors, which simply spin
when voltage is applied to their terminals. Stepper motors, on the other hand,
effectively have multiple "toothed" electromagnets arranged around a central metal
gear, as shown at right. To make the motor shaft turn, first one electromagnet is given
power, which makes the gear's teeth magnetically attracted to the electromagnet's
teeth. When the gear's teeth are thus aligned to the first electromagnet, they are slightly
offset from the next electromagnet. So when the next electromagnet is turned on and
the first is turned off, the gear rotates slightly to align with the next one, and from
there the process is repeated. Each of those slight rotations is called a "step." In that
way, the motor can be turned a precise angle. There are two basic arrangements for the
electromagnetic coils: bipolar and unipolar.

Theory:

A step motor can be viewed as a DC motor with the number of poles (on both
rotor and stator) increased, taking care that they have no common denominator.
Additionally, soft magnetic material with many teeth on the rotor and stator cheaply
multiplies the number of poles (reluctance motor). Like an AC synchronous motor,
sinusoidal current, allowing a stepless operation, ideally drives it but this puts some
burden on the controller. When using an 8- bit digital controller, 256 micro steps per
step are possible. As a digital-toanalog converter produces unwanted Ohmic heat in
the controller, pulsewidth modulation is used instead to regulate the mean current.
Simpler models switch voltage only for doing a step, thus needing an extra current
limiter: for every step, they switch a single cable to the motor. Bipolar controllers can
switch between supply. voltage, ground, and unconnected. Unipolar controllers can
only connect or disconnect a cable, because the voltage is already hard wired.
54

Unipolar controllers need center-tapped windings. It is possible to drive Unipolar


stepper motors with bipolar drivers. The idea is to connect the output pins of the driver
to 4 transistors. The transistor must be grounded at the emitter and the driver pin must
be connected to the base. Collector is connected to the coil wire of the motor.

The torque they produce rates stepper motors. Synchronous electric motors
using soft magnetic materials (having a core) have the ability to provide position-
holding torque (called detent torque, and sometimes included in the specifications)
while not driven electrically. To achieve full rated torque, the coils in a stepper
motor must reach their full rated current during each step. The voltage rating (if
there is one) is almost meaningless. The motors also suffer from EMF, which means
that once the coil is turned off it starts to generate current because the motor is still
rotating. Their needs to be an explicit way to handle this extra current in a circuit
otherwise it can cause damage and affect performance of the motor.

Port Used:

Data Lines: PC2 – PC5. (P2^2 – P2^5)


55

Example Code:
#include<REG51.h>

void Delay_Function(int x);

void main(void)
{
while(1)
{
P2 = 0x24;
Delay_Function(20);
P2 = 0x14;
Delay_Function(20);
P2 = 0x18;
Delay_Function(20);
P2 = 0x28;
Delay_Function(20);
}
}

void Delay_Function(int x)
{
int k,l;
for(k = x;k > 0;k--)
for(l = 0;l < x;l++);
}
}

SAMPLE TASK:

 Generate delays using ALP.


 Rotate the stepper motor in particular direction by adjusting the step angle.

MODEL QUESTIONS
Interface 8051 with suitable devices and develop an embedded C program for the given
task:
1. If one key is pressed LED first array should blink. If another key is pressed, LED second
array should blink.

2. If one key is pressed LCD displays “CALL Incoming”. If another key is pressed LCD
displays “CALL Outgoing”.

3. Display the following sequence in four seven segment LEDs


1234

4. Display the following sequence in four seven segment LEDs


COOL

5. Generate the following waveforms

5V

2.5v
56

6. Generate triangle waveform and staircase waveform

7. Find the digital equivalent for the analog voltage levels 1v, 2.5v, and 4v

8. Count 00 to 99 in 2 seven segment LEDs

9. Rotate the stepper motor 180 clockwise and immediately 180 anticlockwise and stop the
motor. Assume step angle = 6°

10. Display “tce” if one key is pressed and “EEE’ in seven segment LEDs if second key is
pressed.

11. If a key is pressed, The odd LEDs in the first row should glow, After a delay, the even
LEDs in the second row should glow. Then all LEDs should glow and the process
repeats. If another key is pressed, process is stopped.

12. Display the train number and name in a running fashion

13. If first key is pressed all LEDs in the first row should glow from left to right in running
fashion and if the second key is pressed, all LEDs in the second row should glow from
right to left in running fashion.

14. Obtain the following sequence of illumination


5v
2.5v

15. Obtain the 4- bit BINARY sequence of illumination in LED arrays and correspondingly
display the hexa number in seven segment LED.

16. Blinking of first four LEDS in the two Led arrays; Use timer to produce delay.

17. Assembly language programs for expression evaluation, Data transfer, Sorting, Finding
biggest/smallest data, Binary to BCD and vice versa, finding number of odd and even
numbers in an array.

VIVA QUESTIONS:
Students should able to explain each and every line of the code they have written.

HARDWARE:
1. Which ports are used?
2. List the various hardware connected.
3. Explain the interfacing of hardware with 8051.
4. How a particular hardware is addressed / programmed / controlled by 8051?
5. Explain the architecture of chips interfaced. ( 74LS273, PCF8574, LTS543, PCF8591, 74LS244 )
6. Explain the construction and working principle of Stepper motor
7. Explain the construction and working principle of DC motor
57

8. Explain the Speed control of stepper motor/DC motor using 8051


9. Explain the bit patterns of SFRs associated with Timers, Ports, Interrupts and Serial communication of
8051.
10. Explain the operation and pin details of LCD.
11. List the LCD commands and its functions.
12. Explain I2C and UART concepts.
13. State the algorithm of the code written.
14. State the applications of interrupt, timer and serial communication in 8051.
15. How to assign a port as input or output port?
16.Concept of timers and Baudrate.

SOFTWARE:
1. What is the change in output if some particular part of the code is changed?
2. To get a particular output, how the sample code may be modified?
3. Explain the setting of bit patterns in SFRs.
4. How the array values are generated and what is the impact on changing the string or hexa values
initialized in an array?

You might also like