0% found this document useful (0 votes)
148 views

Embedded Lab Manual 8051 New

ar

Uploaded by

Mack Mast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views

Embedded Lab Manual 8051 New

ar

Uploaded by

Mack Mast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 102

Embedded Lab Manual

For 8051

SPJ Embedded Technologies Pvt. Ltd.


Survey No. 124/12 A, Mulik Baug, Near MIT College,
Off Paud Road, Kothrud.
Pune – 411038 (INDIA)
Tel. +91-20-27293002
Fax. +91-20-27293003
http://www.spjsystems.com
Embedded Lab Manual

DISCLAIMER
Embedded Lab Manual for 8051 and other documentation:
This manual and the accompanying documentation such as schematic diagrams – in soft or hard form -
contains descriptions of copyrighted products, which are not explicitly indicated as such. The absence of the
trademark symbol does not infer that a Product is not protected.
Additionally, registered patents and trademarks are similarly not expressly indicated in these documents.
The information in these documents has been carefully checked and is believed to be entirely reliable.
However, SPJ Embedded Technologies Pvt. Ltd. (henceforth “Company”) assumes no responsibility for
any inaccuracies. The Company, neither gives any guarantee nor accepts any liability whatsoever for
consequential damages resulting from the use of these documents or associated product. The Company
reserves the right to alter the information contained herein without prior notification and accepts no
responsibility for any damages that might result. Additionally, The Company offers no guarantee nor accepts
any liability for damages arising from the improper usage or improper installation of the hardware or
software. The Company further reserves the right to alter the layout and/or design of the hardware without
prior notification and accepts no liability for doing so.

SPJ Embedded Technologies Pvt. Ltd.


Survey No. 124/12 A, Mulik Baug, Near MIT College,
Off Paud Road, Kothrud.
Pune – 411038 (INDIA)
INDIA
Phone : +91 (20) 27293002
Fax : +91 (20) 27293003
Email : [email protected]
Web Site: http://www.spjsystems.com

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 2 of 102


Embedded Lab Manual

Table of Contents
1. Introduction.......................................................................................................................................6

2. Getting Started...................................................................................................................................7
2.1 SC51 Installation:..........................................................................................................................7
2.2 Creating 8051 Assembly Language applications:..........................................................................8
2.3 Creating ‘C’ applications for 8051: Quick Start............................................................................9
2.4 Creating ‘C’ applications for 8051: In Detail..............................................................................11
2.4.1 Starting the IDE (SIDE51):...................................................................................................11
2.4.2 Using the Visual Code Generator (VCG):.............................................................................19
2.4.3 Why use while(1) :................................................................................................................25
2.4.4 Using the Simulator:..............................................................................................................30

3. Hardware Description.....................................................................................................................40
3.1 Mini51-PE:..................................................................................................................................40
3.2 Connector Details of Mini51-PE:................................................................................................41

4. Downloading and Running User Programs....................................................................................43

5. Accessories.......................................................................................................................................46
5.1 LED & Switches Interface Board (SDIO8): ................................................................................46
5.2 Seven Segment Interface Board (7SEG-4x4KBD): ......................................................................47
5.3 LCD Interface Board (LCD-KBD):..............................................................................................49
5.4 Stepper Motor Driver Circuit (STP51):.......................................................................................50
5.5 ADC Interface Board (SADC08/09):............................................................................................51
5.6 DAC Interface Board (SDAC08):................................................................................................53
5.7 Traffic Light Control Simulation (TCS51): .................................................................................53
5.8 Relay Interface Board (SRL2): ....................................................................................................54
5.9 I2C & SPI Interface Board (SSI):................................................................................................55
5.10 DC Motor & Thumbwheel Switch Interface Board (STWS-DCM):.............................................56

6. Assembly Language Practicals........................................................................................................58


Assignment 1: Write a program to copy a block of 10 bytes of data from RAM locations starting at
15h to RAM locations starting at 25h................................................................................................58
Assignment 2: Write a Program to find the frequency of square wave generated on pin P1.0...........59

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 3 of 102


Embedded Lab Manual

Assignment 3: Write a Program to generate a square wave of 50 Hz frequency on pin P1.2 using
interrupt for timer..............................................................................................................................60
Assignment 4: Write a Program to connect INT 1 pin to a switch that is normally high whenever it
goes low LED should turn ON which is connected to P3.2 & LED is normally OFF. LED should be
ON as long as switch is pressed.........................................................................................................61

7. C Language Practicals.....................................................................................................................62
Experiment 1: To develop and execute the program to output data on the port lines of the
Microcontroller 8051........................................................................................................................62
Experiment 2: To develop and execute the program for arithmetic operation for the Microcontroller
8051..................................................................................................................................................64
Experiment 3: To develop and execute the program for demonstrating input and output operations
using keyboard interface for the Microcontroller 8051......................................................................66
Experiment 4: To develop and execute the program to interface 7 segments LED display to the
Microcontroller 8051........................................................................................................................68
Experiment 5: To develop and execute the program to generate square wave on port lines of Port 1 of
the Microcontroller 8051...................................................................................................................70
Experiment 6: To develop and execute the program for demonstrating logical operations performed
by the Microcontroller 8051..............................................................................................................72
Experiment 7: To develop and execute the program to interface 16X2 LCD display to the
Microcontroller 8051........................................................................................................................74
Experiment 8: To develop and execute the program to demonstrate serial communication, using RS-
232C standard, for the Microcontroller 8051....................................................................................78
Experiment 9: To develop and execute the program to interface stepper motor to the Microcontroller
8051..................................................................................................................................................80
Experiment 10: To develop and execute the program to interface ADC 0809 to the Microcontroller
8051..................................................................................................................................................82
Experiment 11: To develop and execute the program to interface DAC 0808 to the Microcontroller
8051..................................................................................................................................................85
Experiment 12: To develop and execute the program to interface relays to the Microcontroller 8051.
..........................................................................................................................................................87
Experiment 13: To develop and execute the program to interface 4*4 matrix keyboard to the
Microcontroller 8051........................................................................................................................89
Experiment 14: Write a program to interface DC Motor to Microcontroller 8051.............................93
Experiment 15: To develop and execute the program to output the result of addition of contents of
registers R0 and R1 on all four ports for the Microcontroller 8051...................................................94
Experiment 16: Assume 1 Hz. Frequency pulse is connected to I/P P3.4 Write a Program to display
count on LCD....................................................................................................................................96
Experiment 17: To develop and execute the program for I2C based ADC.........................................98

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 4 of 102


Embedded Lab Manual

Experiment 18: To develop and execute the program for I2C based DAC.........................................99
Experiment 19: To develop and execute the program for I2C based EEPROM................................100
Experiment 20: To develop and execute the program for I2C based RTC........................................101
Experiment 21: To develop and execute the program for SPI based RTC........................................102

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 5 of 102


Embedded Lab Manual

1. Introduction
This is user’s manual for Embedded Lab for 8051 Microcontroller. Development tools for this lab
include

a. SC51,
b. Mini51-PE,
c. Accessories

‘SC51’ is ‘C’ compiler for 8051 microcontroller. Using SC51 you can write 8051 applications in C,
Assembly or have mix programming of Assembly and C. It also includes Simulator to debug your
software without the target hardware.

Mini51-PE is a general purpose Evaluation Board. This board has a facility to download HEX file into
the on-chip flash, without the need of removing the chip from the socket. These boards are offered using
different variants of 8051 micro-controller families. Thus, introducing the students to various derivatives
of 8051.

Different accessories can be interfaced with Mini51-PE board viz.SDIO8, 7SEG-4x4KBD, LCD-KBD,
STP51, SADC08/09, SDAC08, TCS51, SRL2 etc.

CAUTION: These boards contain components that are sensitive to Electro-Static Discharge (ESD).
The board must be handled carefully, so as not to subject it to ESD. As far as possible, do not touch any
conducting part on the board – including any component or connector pins – as this may damage parts of
the board permanently. While handling the board, hold it only by it’s edges. If you must touch any of the
parts, make sure to discharge yourself to earth. Parts damaged due to ESD are not covered by the limited
warranty.

WARRANTY: It’s 1 year against manufacturing defects only.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 6 of 102


Embedded Lab Manual

2. Getting Started
2.1 SC51 Installation:
1. As a part of the SC51 software package, you should have received a CDROM. Please insert it
into the CD-ROM drive. Open SPJTools (CD drive), open folder SC51 and run the
SETUP.EXE
2. If any error comes then click Ignore.
3. SC51 Setup window will open, click NEXT.
4. Click YES to accept the software license agreement.
5. Choose destination location where you want to install the SC51 and click NEXT.
6. Click NEXT and installation will start.
7. Click FINISH to complete the Installation.
8. Now connect the SC51 SPJ Lock to USB port of the computer.
9. A pop-up will show “Found New Hardware”
10. Found New Hardware Wizard window will open. Select No, not this time option and click
Next.
11. Now select Install from a list or specific location (Advanced) and click Next.
12. Browse for the folder drv from C:\SC51\drv and click Next.
13. Now Hardware Installation window will open, click Continue Anyway.
14. After completion of installation, a message will come The wizard has finished installing the
software for SPJ Lock, now click Finish.
15. After this you can start using SC51 (Start > All Programs > SPJ Systems’ SC51 > SIDE51).

About “Project”:
What is a project?
A project is a file in which SIDE51 stores all information related to an application. E.g. it stores the
name(s) of ‘C’ and/or Assembler source file(s), memory size to be used and other options for compiler,
assembler and linker.
Opening a project:
To open an existing project file, select Project / Open Project from the menu.
Creating a new project:
To create a new project, select Project / New Project from the menu.
Changing project settings:
To change the project settings (such as adding or removing ‘C’ and/or Assembler source file(s),
changing memory settings etc.), select Project / Settings from the menu.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 7 of 102


Embedded Lab Manual

2.2 Creating 8051 Assembly Language applications:


1. Start the SIDE51 program (i.e. the Integrated Development Environment)
2. If any project is shown open in the editor, then From Project menu, select Close project.
3. From Project menu, select New Project.
4. Select Type of Project as Only Assembly Language. Click OK.
5. The New Project window will be displayed. Select the desired path where you wish to save this
program (for example, C:\SPJ). CAUTION: The pathname must not contain space or other
special characters such as tab, comma, semicolon etc. Then in the “File name” field, type the
name of the project (do not give any extension, by default it will take .P51 as extension). Then click
on the “Open” button.
6. The action in the previous step will display the “Project Settings” dialog window. This dialog
window has 3 different tabs named “Compiler Options”, “Assembler / Linker Options”, and
“Source Files”. Any of these 3 tabs can be displayed by clicking on the corresponding name near
the top of this dialog window. Currently, the “Compiler Options” will be automatically
displayed.
7. In this “Compiler Options” window you can see Manufacturer as Intel, Microcontroller as 8052
and Crystal Frequency as 12MHz. Click on OK. (You may select the appropriate Manufacturer
from the list; and then select the appropriate part number of the Microcontroller from the list. If
your target board uses different crystal frequency, then you may change it.)
8. Now you can see “Source Files” window. In this window, under ASM Files title you can see
.asm file of the name you have given to the project. IDE has automatically created this empty
file. You have to write your program in this file. Click on OK.
9. In the Editor window you can see blank .asm file. Write your program in this file.
10. After finishing the program, to generate its hex file select: From the Compile menu, select Build.
This will invoke the assembler to assemble the .asm file; and further (assuming no errors) invoke
the linker to create the .HEX and other files. If there are any errors or warnings during the
process of assembling or linking, then those will be displayed in the output window (below the
editor window). If there are errors, then you may correct those by making appropriate changes to
the program; select Save from File menu to save the changes and then again select Build from
Compile menu. Repeat this until there are no errors.
11. Now we are ready to simulate this program. To do so, simply select Simulator from the Tools
menu. Simulator for 8051 is an independent program and it will be launched by this action and
the current project (TEST1) will be automatically opened. The Simulator will automatically
display 5 windows (clockwise, from left-top corner): Program window, Serial window, Internal
RAM watch window, SFR watch window, and Symbols watch window. As the names indicate,
these windows display the corresponding information. So, the same program that you typed will
be visible in the Program window.
12. To single step through the program, you may select Single Step from the Run menu (pressing
F7 key is also equivalent). When you do so, the program window will indicate that one
instruction has been executed and the next instruction will be highlighted. You may repeat the
same to single step through the entire program.
13. While single stepping through the program, the contents of general purpose registers (R0-R7) as
well SFRs will be displayed in the SFR Watch Window. The register / SFR contents can be seen
changing as effect of each executed instruction. It is also possible to modify register / SFR
contents (except PC) by double clicking on it’s name.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 8 of 102


Embedded Lab Manual

14. Similarly, it is possible to observe contents of internal RAM while single stepping through the
program. To do so, right click in the Internal RAM Watch Window and then select Add from the
pop-up menu. Then enter the starting address of the 16-byte block of Internal RAM that you
wish to observe (e.g. 30) and press “OK” button. Upon doing so, the entered memory address
followed by contents of 16 consecutive locations will be displayed. It is also possible to modify
the contents of Internal RAM by double clicking on the address in this Internal RAM Watch
Window.
15. Similarly, it is possible to observe contents of external RAM while single stepping through the
program. To do so, it is necessary to first make the “External RAM Watch Window” visible. To
do so, select External RAM Watch from View menu. Then, the remaining procedure is similar to
that followed for Internal RAM Watch Window.
16. When you are through with debugging, select Exit from File menu to close the Simulator. Then
(if necessary) you may edit the program, build it again and start the simulator to debug again.
Please note, only one instance of Simulator program should be started at any time. It is
recommended to close the Simulator while making any changes to the program.

2.3 Creating ‘C’ applications for 8051: Quick Start


1. Start the SIDE51 program (i.e. the Integrated Development Environment)
2. From Project menu, select Close project.
3. From Project menu, select New Project.
4. Select Type of Project as C and Assembly Language. Click OK.
5. The New Project window will be displayed. Select the desired path where you wish to create this
new project. (For example, C:\SPJ). CAUTION: the path and filename must not contain space or
other special characters such as tab, comma, semicolon etc. In the “File name” field, type the
name of the project, without any extension. For example, you may type “PROG1”. Then click on
the “Open” button.
6. The action in the previous step will display the “Project Settings” dialog window. This dialog
window has 3 different tabs named “Compiler Options”, “Assembler / Linker Options”, and
“Source Files”. Any of these 3 tabs can be displayed by clicking on the corresponding name near
the top of this dialog window. Currently, the “Compiler Options” will be automatically
displayed.
7. In this “Compiler Options” window you can see Manufacturer as Intel, Microcontroller as 8052
and Crystal Frequency as 12MHz. Click on OK. (You may select the appropriate Manufacturer
from the list; and then select the appropriate part number of the Microcontroller from the list. If
your target board uses different crystal frequency, then you may change it.)
8. Now you can see “Source Files” window.. This window will indicate that IDE has automatically
added 2 files in this new project: PROG1.C and STARTUP.ASM. The STARTUP.ASM file is
automatically created by the IDE and is required for all C projects. Similarly, the IDE has
automatically created an empty C file (PROG1.C). If the file PROG1.C already exists in the
same path, then IDE would not create it or modify it; but it will anyway add it to the project
automatically. If you wish to add more files in this project, then click on the “Add file” button,
select the desired filename and then click on “Open” button. Now the Project Settings dialog will
indicate that selected file has been added into the project. When all necessary files have been
added to the project, click “OK” button to create this new project.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 9 of 102


Embedded Lab Manual

9. The PROG1.C file created by the IDE will be an empty file containing only the frame of “main”
function. You may write the desired program statements in this file (or other files that you may
have added to the project). When done, select Save from File menu. If you have modified more
than one source files, then select Save All from File menu.
10. From the Compile menu, select Build. This will invoke the Compiler to compile the file
PROG1.C; and further (assuming no errors) invoke the linker to create the .HEX and other files.
If there are any errors or warnings during the process of compiling, assembling or linking, then
those will be displayed in the output window (below the editor window). If there are errors, then
you may correct those by making appropriate changes to the program; select Save from File
menu to save the changes and then again select Build from Compile menu. Repeat this until
there are no errors.
11. Now we are ready to simulate this program. To do so, simply select Simulator from the Tools
menu. Simulator for 8051 is an independent program and it will be launched by this action and
the current project (PROG1) will be automatically opened. The Simulator will automatically
display 5 windows (clockwise, from left-top corner): Program window, Serial window, Internal
RAM watch window, SFR watch window, and Symbols watch window. As the names indicate,
these windows display the corresponding information. So, the same program that you typed
(PROG1.C) will be visible in the Program window.
12. To single step through the program, you may select Single Step from the Run menu. Pressing
F7 key is also equivalent to selecting Single Step from the Run menu. When you do so, the
program window will indicate that one C statement has been executed and the next statement
will be highlighted. You may repeat the same to single step through the entire program.
13. While single stepping through the program, the contents of general purpose registers (R0-R7) as
well SFRs will be displayed in the SFR Watch Window. The register /SFR contents can be seen
changing as effect of each executed instruction. It is also possible to modify register / SFR
contents by double clicking on it’s name. (Contents of PC cannot be modified).
14. Similarly, it is possible to observe values of variables. To do so, right click in the Variables
Watch Window and select Add from the pop-up menu. Select the desired variable(s) to watch
and click “OK” button. This will display the names and values of the selected variables in the
variables watch window. It is also possible to modify a variable value by double-clicking on its
name.
15. The Serial window displays the activity related to 8051 serial port. i.e. any character transmitted
to the serial port is displayed in this window. Similarly, it is possible to simulate receiving
characters. To do so, simply click inside the Serial window and type any character(s) that you
wish to simulate as received.
16. When you are through with debugging, select Exit from File menu to close the Simulator. Then
(if necessary) you may edit the program, build it again and start the simulator to debug again.
Please note, only one instance of Simulator program should be started at any time. It is
recommended to close the Simulator while making any changes to the program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 10 of 102


Embedded Lab Manual

2.4 Creating ‘C’ applications for 8051: In Detail


Want a quick start? Read this section sitting in front of your Computer. Please follow the instructions in
the given example. By the time you finish with the example, you will have acquired enough knowledge
about the features of this software. That will enable you to actually start using the software for your
applications.

Here we go!

2.4.1 Starting the IDE (SIDE51):

 Click on START button and select Programs / SPJ Systems’ SC51 / SIDE51. The screen should
look something like this. There are 3 different windows viz. Editor window, Workspace window
and Output window as shown below.

Workspace Window Editor Window

Output Window

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 11 of 102


Embedded Lab Manual

 From Project menu, select Close project. The screen should look something like this.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 12 of 102


Embedded Lab Manual

17. To create a new project, from Project menu, select New Project. The screen should look
something like this. Select Type of Project as C and Assembly Language. Click OK.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 13 of 102


Embedded Lab Manual

 The New Project window will be displayed. Select the desired path where you wish to create this
new project. (For example, C:\SPJ). CAUTION: the path and filename must not contain space or
other special characters such as tab, comma, semicolon etc. In the “File name” field, type the
name of the project, without any extension. For example, you may type “PROG1”. Then click on
the “Open” button.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 14 of 102


Embedded Lab Manual

 The action in the previous step will display the “Project Settings” dialog window. This dialog
window has 3 different parts named “Compiler Options”, “Assembler /Linker Options”, and
“Source Files”. Any of these 3 parts can be displayed by clicking on the corresponding name
near the top of this dialog window. Currently, the “Compiler Options” will be automatically
displayed. If the target micro-controller (must be a member of 8051 family) is known, you may
select the appropriate Manufacturer from the list; and then select the appropriate micro-controller
from the device list. If the target micro-controller is not known or if you cannot find it in the list,
then you may simply select “Intel” as the manufacturer and “8051” or “8052” as the micro-
controller. Note that when you select “8051” as the micro-controller, the “Internal RAM (Bytes)”
selection automatically changes to 128. Similarly, when you select “8052” as the micro-
controller, the “Internal RAM (Bytes)” selection automatically changes to 256. Select 8051 or
8052, depending on whether your target micro-controller has 128 or 256 bytes internal RAM,
respectively.

 In the same window, the “Crystal frequency” field is also displayed with default value as 12
MHz. If your target uses different crystal frequency (such as 11.0592 MHz), then you may
change it.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 15 of 102


Embedded Lab Manual

 Click on “Assembler / Linker Options” to display that part of the dialog window. Under
“Program Memory (Code Memory) map:” you may enter the start and end address of program
memory available in your target. This program memory maybe internal (inside the micro-
controller) or external. For example, if the target microcontroller is Atmel 89C52 without any
external memory, then you may enter start address as 0000 and end address as 1FFF.
 Similarly, enter start and end addresses of the XDATA (i.e. external data memory). This
XDATA memory maybe on-chip or off-chip. Only start and end addresses are important, but not
physical location.
 The Compiler / Assembler automatically produces Intel HEX format file (.HEX file). If you also
require the binary image file (.BIN file), then check the box labeled “Generate .BIN file (ROM
image)”.
 If you plan to use In-Circuit-Emulator (ICE) for debugging, then check the box labeled
“Generate Absolute OMF file”. This will create .AOM file, which is required by the ICE.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 16 of 102


Embedded Lab Manual

 Click on “Source Files” to display that part of the dialog window. This window will indicate that
IDE has automatically added 2 files in this new project: PROG1.C and STARTUP.ASM. The
STARTUP.ASM file is automatically created by the IDE and is required for all C projects.
Similarly, the IDE has automatically created an empty C file (PROG1.C). If the file PROG1.C
already exists in the same path, then IDE would not create it or modify it; but it will anyway add
it to the project automatically. If you wish to add more files in this project, then click on the
“Add file” button, select the desired filename and then click on “Open” button. Now the Project
Settings dialog will indicate that selected file has been added into the project. When all necessary
files have been added to the project, click “OK” button to create this new project.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 17 of 102


Embedded Lab Manual

 The PROG1.C file created by the IDE will be an empty file containing only the frame of “main”
function.

 Now you may write the desired program statements in this file (or other files that you may have
added to the project). When done, select Save from File menu. If you have modified more than
one source files, then select Save All from File menu.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 18 of 102


Embedded Lab Manual

Here we write a program for serial communication.

Aim: Write a C program to send “WELCOME” on serial port continuously.

Description:

2.4.2 Using the Visual Code Generator (VCG):

 To send data to serial port, first initialize serial port. To initialize serial port go to Visual Code
Generator menu. It will display 3 options (Initialize TMOD/TCON, Initialize Serial Port and
Interrupt Settings). Select Initialize Serial Port.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 19 of 102


Embedded Lab Manual

 Initialize Serial Port window will be displayed. Do proper settings to initialize serial port.
 Serial Port Mode: 1 : 8-Bit UART (Baud Rate: Variable)
 Enable REN (Receiver Enable)
 For Baud Rate Use: TIMER 1
 Desired Baud Rate: 9600
 Crystal Frequency: 11.0592 (Depending on Hardware)
 Click on Generate Code

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 20 of 102


Embedded Lab Manual

 Click on “Copy C Code”, corresponding code will be copied. Last Line is “Please also initialize
TMOD / TCON”. We have to initialize TMOD / TCON because we have used TIMER 1 for
Baud Rate Generation. Click on Ok. Paste the code in the program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 21 of 102


Embedded Lab Manual

 To initialize TMOD/TCON go to Visual Code Generator menu. Select Initialize TMOD/TCON.


Initialize TMOD/TCON window will be displayed. Do proper settings to initialize
TMOD/TCON.
 Enable TR1: Check to run Timer 1
 Timer 1 Mode: 2 – 8-Bit Auto Reload Mode
 Click on Generate Code

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 22 of 102


Embedded Lab Manual

 Click on “Copy C Code”, corresponding code will be copied. Click on Ok. Paste the code in the
program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 23 of 102


Embedded Lab Manual

 Serial port is our standard input output device. “printf” statement will send data (WELCOME)
to serial port and to continuously send data we will write “printf” statement in continuous loop
viz. while(1). “printf” is compilers’ library function. It is included in the library stdio.h, therefore
we have to include its prototype in the program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 24 of 102


Embedded Lab Manual

2.4.3 Why use while(1) :

8051 does not have any halt instruction. In embedded systems once the program is started, it should
never terminate. Only time it stops is when user switches it off. This concept has to be understood
very thoroughly. The while(1) loop helps the user to achieve this. while(1) means, while the
condition is true, in other words the while loop will execute all time. The only way to halt the system
is to switch it off.

If a task is to be performed only once, the user will have an empty while (1) loop as below
while (1)
{
}

If the application demands some actions to be performed all time then the while loop will be as
follows
while (1)
{
/* Action to be performed continuously */
}

Typical ‘C’ program

#include <8051.h>
/* Other includes */

/* Global variable declaration */

/* function prototypes */
void func1(char ch1) ;

/* function definition */
void func1(char ch1)
{
/* Program structure */
}
void main ()
{
/* Calling Initialization routines */

/* Call functions which are to be executed only once */

while (1)
{
/* Call functions to be executed all time */
}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 25 of 102


Embedded Lab Manual

 From the Compile menu, select Build.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 26 of 102


Embedded Lab Manual

 This will invoke the Compiler to compile the file PROG1.C; and further (assuming no errors)
invoke the linker to create the .HEX and other files. If there are any errors or warnings during
the process of compiling, assembling or linking, then those will be displayed in the output
window (below the editor window). If there are errors, then you may correct those by making
appropriate changes to the program; select Save from File menu to save the changes and then
again select Build from Compile menu. Repeat this until there are no errors. In which case
you will get the message in Build window as below

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 27 of 102


Embedded Lab Manual

 If there are any errors you will see the screen as below.
 In this program I have removed semicolon after printf statement and again rebuilded it, so it
is syntax error.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 28 of 102


Embedded Lab Manual

 Scroll up the Output window to locate the Error statement. On this statement, when you
double click, the editor will take you directly to the line creating the error.

 Rectify all such errors and warnings. Then again from compile option perform Build/ReBuild
all to generate hex file. And if there is no any error in the code then you will get the message
as in previous screen. And the output .hex file will have been generated in your working
directory.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 29 of 102


Embedded Lab Manual

2.4.4 Using the Simulator:

 Now we are ready to simulate this program. To do so, simply select Simulator from the
Tools menu.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 30 of 102


Embedded Lab Manual

 Simulator for 8051 is an independent program and it will be launched by this action and the
current project (PROG1) will be automatically opened. The Simulator will automatically
display 5 windows (clockwise, from left-top corner): Program window, Serial window,
Internal RAM watch window, SFR watch window, and Symbols watch window. As the
names indicate, these windows display the corresponding information. So, the same program
that you typed (PROG1.C) will be visible in the Program window.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 31 of 102


Embedded Lab Manual

 In Simulator you can Debug the program. Different options available in Run menu to debug
the program are:

 Insert Breakpoint
 Single Step
 Step Over
 Run
 Terminate Program
 CPU Reset

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 32 of 102


Embedded Lab Manual

 To single step through the program, you may select Single Step from the Run menu.
Pressing F7 key is also equivalent to selecting Single Step from the Run menu.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 33 of 102


Embedded Lab Manual

 When you do so, the program window will indicate that one C statement has been executed
and the next statement will be highlighted. You may repeat the same to single step through
the entire program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 34 of 102


Embedded Lab Manual

 While single stepping through the program, the contents of general purpose registers (R0-R7) as well
SFRs will be displayed in the SFR Watch Window. The register /SFR contents can be seen changing
as effect of each executed instruction.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 35 of 102


Embedded Lab Manual

 It is also possible to modify register / SFR contents by double clicking on it’s name. (Contents of PC
cannot be modified). Eg. To modify contents of Port 1 double click on P1 in SFR Watch Window.
Edit SFR P1 window will be displayed. You can Enter Hex Value or change Binary Representation
by clicking on the required bit.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 36 of 102


Embedded Lab Manual

 Similarly, it is possible to observe values of variables. To do so, right click in the Variables Watch
Window and select Add from the pop-up menu. Select the desired variable(s) to watch and click
“OK” button. This will display the names and values of the selected variables in the variables watch
window. It is also possible to modify a variable value by double-clicking on its name.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 37 of 102


Embedded Lab Manual

 The Serial I/O window displays the activity related to 8051 serial port. i.e. any character transmitted
to the serial port is displayed in this window. Similarly, it is possible to simulate receiving
characters. To do so, simply click inside the Serial window and type any character(s) that you wish
to simulate as received.
Now Single Step or Run the program from Run menu. We can see WELCOME message on Serial
I/O Window.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 38 of 102


Embedded Lab Manual

 When you are through with debugging, select Exit from File menu to close the Simulator. Then (if
necessary) you may edit the program, build it again and start the simulator to debug again. Please
note, only one instance of Simulator program should be started at any time. It is recommended to
close the Simulator while making any changes to the program.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 39 of 102


Embedded Lab Manual

3. Hardware Description
3.1 Mini51-PE:
Unpacking:
You will find following items in the package:
• Mini51-PE board
• Serial communication cable
• Power Supply with cable
• Lab Manual

26 Pin FRC1 26 Pin FRC2


Connector Connector

PIN 1 PIN 1

PIN 1
Port 2
Port 0
PIN 1

PIN 1
Port 3
Port 1
PIN 1
Reset

Serial Port / 9-Pin


D type Connector

PSCON: Power
Supply Connector

Pin 1
INT 0 INT 1

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 40 of 102


Embedded Lab Manual

Connecting the system:


The serial communication cable supplied with the board should be used to connect the board to a PC
running Windows95/98/NT/ME/2000/XP/Vista Operating System. Connect the PSCON connector on
Mini51-PE to the Power Supply with the supplied cable. The system is now ready to be turned ON.
Specifications:
The Mini51-PE board includes:
• Philips P89V51RD2 running at 11.0592 MHz.
• RS232 port (9 pin D type female connector) with serial communication cable.

3.2 Connector Details of Mini51-PE:


1) PSCON: Power Supply Connector in the sequence of +5, Gnd, +12, Gnd, -12, Gnd.
2) INT0, INT1: External Interrupt Generation keys.
3) Jumper J1-EA :
a) Right Short position – Internal memory access
b) Left Short position – External ROM access.

4) Port X (X is 0/1/2/3 means Port 0/Port 1/Port 2/Port 3):

Pin Number Pin Assignment


PIN 1 P X.0
PIN 2 P X.1
PIN 3 P X.2
PIN 4 P X.3
PIN 5 P X.4
PIN 6 P X.5
PIN 7 P X.6
PIN 8 P X.7
PIN 9 VCC
PIN 10 GND

5) FRC1: 26 pin FRC Connector, to connect peripheral cards.


FRC1 is used to connect:
a) SDAC08 (DAC Interface Board)
b) SEMEM (External Memory (RAM) Interface Board)
These are connected to this FRC1 connector via the FRC flat cable.
The pin connection details are as given below:

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 41 of 102


Embedded Lab Manual

Pin Number Pin Assignment Pin Number on Pin Assignment


on Connector Connector
PIN 1 P1.0 PIN 2 P1.1
PIN 3 P1.2 PIN 4 P1.3
PIN 5 P1.4 PIN 6 P1.5
PIN 7 P1.6 PIN 8 P1.7
PIN 9 EA PIN 10 ALE
PIN 11 PSEN PIN 12 NC
PIN 13 +12V PIN 14 +12V
PIN 15 GND PIN 16 GND
PIN 17 -12V PIN 18 -12V
PIN 19 GND PIN 20 GND
PIN 21 +5V PIN 22 +5V
PIN 23 GND PIN 24 GND
PIN 25 ADC CLK PIN 26 RST (Reset)

6) FRC2: 26 pin connector to connect Accessories. Following Accessories use FRC2 for connecting
the CPU card:
a) LCD-KBD (LCD Interface Board),
b) 7SEG-KBD (7 Segment Interface Board),
c) STP51 (Stepper Motor Driver Circuit),
d) SADC0809 (ADC Interface Board),
e) SDAC08 (DAC Interface Board)
f) SEMEM (External Memory (RAM) Interface Board)
These are connected to this FRC2 connector via the FRC flat cable.
The pin connection details are as given below:
Pin Number Pin Assignment Pin Number on Pin Assignment
on Connector Connector
PIN 1 P2.0 PIN 2 P2.1
PIN 3 P2.2 PIN 4 P2.3
PIN 5 P2.4 PIN 6 P2.5
PIN 7 P2.6 PIN 8 P2.7
PIN 9 P0.0 PIN 10 P0.1
PIN 11 P0.2 PIN 12 P0.3
PIN 13 P0.4 PIN 14 P0.5
PIN 15 P0.6 PIN 16 P0.7
PIN 17 P3.0 PIN 18 P3.1
PIN 19 P3.2 PIN 20 P3.3
PIN 21 P3.4 PIN 22 P3.5
PIN 23 P3.6 PIN 24 P3.7
PIN 25 +5V PIN 26 GND
Note: Pin 1 of FRC1 and FRC2 connector can be identified by triangle marked on the same connectors
or they are also shown in the Mini51-PE board image.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 42 of 102


Embedded Lab Manual

4. Downloading and Running User Programs


Microcontroller P89V51RD2 includes on-chip flash for storing user program and non-volatile data. This
flash is In-System-Programmable (ISP). Therefore it is possible to download user program into on-chip
flash, through serial port connected to PC.
This section describes how to use the software Flash Magic to download program into P89V51RD2.

Download program using Flash Magic into P89V51RD2:


Install Flash Magic from CD. After installation, open it.
In Flash Magic go to Options -> Advanced Options-> Hardware Config.
Disable “Use DTR and RTS to control RST and PSEN”. Click on OK.
To download program follow the steps as below:
1. Connect power supply.
2. Keep the board in switched off mode.
3. Connect the RS232 port (9-Pin D type Male connector) of Mini51-PE, to COM1 or COM2 of a
PC, using the serial communication cable (supplied with the board).
4. Start Flash Magic. You will get the screen as below (Flash magic version 3.42.179)

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 43 of 102


Embedded Lab Manual

5. Do proper settings in Flash Magic (COM Port: Suppose COM1, Baud Rate: 4800, Device:
89V51RD2, Interface: None (ISP), Enable Erase blocks used by Hex File).
6. Click on Verify After Programming. This option will verify that the program loaded in the flash
is same as the hex file selected. Thus if any corruption of data has occurred then it can be
detected.
7. IMPORTANT:
• DO NOT SELECT: Set Security Bit 1. This will block the further erase and write cycles on
the flash of P89V51RD2.
• DO NOT SELECT: Fill unused Flash, this will consume lot of time in programming.
• DO NOT SELECT: Gen Block checksums.
• DO NOT SELECT: Prog Clocks Bit

8. Click on Browse button.


9. Use the browse option to go to the required directory.
10. Click on the hex file you want to download to the target hardware.

11. Click on open button. Once you do this the file will be selected in the Flash Magic.
12. Click on the Start button. Following message will be displayed:

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 44 of 102


Embedded Lab Manual

13. At this point you should power ON the board. If the board is already powered ON, then you
should press the Reset Switch (RST KEY) on the board.
14. After the above, the above message will dis-appear and the programming will start.
15. Once the file is loaded it will be verified.
16. Finally you will get the message on the bottom of the Flash Magic Screen as Finished.

17. To Run the program, RESET the board or Power OFF and Power ON the board again.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 45 of 102


Embedded Lab Manual

5. Accessories
5.1 LED & Switches Interface Board (SDIO8):
Digital I/O simulation board with 8 LEDs and 8 switches.
All the LEDs are connected by common anode method. That means the positive leg of each LED is
connected to Vcc and negative leg to the port pins of the microcontroller. A logic 0 on the port pin will
make LED ON and logic 1 will make it OFF. Vcc and Gnd are marked on 10 pin connector of the board.
SDIO8 also having 8 on-board Switches. When pressed, the switches are grounded. When Idle, they are
pulled high (+5V).SDIO8 can be interfaced to all the ports (Port 0, Port 1, Port 2 and Port 3) on Mini51-
PE board.

LED1 KEY1

J1

LED8 KEY8

J1:

J1 Connector on SDIO8 Description


1 LED1/KEY1
2 LED2/KEY2
3 LED3/KEY3
4 LED4/KEY4
5 LED5/KEY5
6 LED6/KEY6
7 LED7/KEY7
8 LED8/KEY8
9 Vcc (+5V)
10 Ground

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 46 of 102


Embedded Lab Manual

5.2 Seven Segment Interface Board (7SEG-4x4KBD):


This is 7 Segment interface board, with 4 7Segment displays. 7 Segment is just 7 LEDs that have been
combined into one case to make a convenient device for displaying numbers and some letters. The 7
Segment used is a common anode version. That means the positive leg of each LED is connected to Vcc
and negative leg to the port pins of the microcontroller. At logic 0 LED in segment will become ON and
at logic 1 it will become OFF. By doing proper combination of logic 0s you can see numbers and some
letters on 7 segments.

Connections:
To select individual 7 segment displays:
 To select Display 1, make P3.7 = 0
 To select Display 2, make P3.6 = 0
 To select Display 3, make P3.5 = 0
 To select Display 4, make P3.4 = 0

Port 2 of 8051 microcontroller is connected to 7 segments of all the 4 displays.


a
----
f | g |b
----
e | |c
---- . dot
d

Segment Port Pin


a P2.5
b P2.4
c P2.2
d P2.1
e P2.0
f P2.6
g P2.7
dot P2.3

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 47 of 102


Embedded Lab Manual

This board also contains 16 keys arranged in a matrix form (4*4).

7 Segment LED
Display 1 Displays (4 Nos.)
through 8 parallel lines

Display 4
26 Pin FRC2
Connector

4*4 Matrix
Keyboard

In Matrix keyboard, as shown above we have scan line and return lines. On the scan lines the user has to
drive the data and on return lines receive the data. Matrix keyboard is connected to Port 0 of 8051
microcontroller. Pins P0.0 to P0.3 are scan lines and pins P0.4 to P0.7 are return lines.

The port pins by default are at logical high level. We want to detect a key press. When you press a key
the respective scan line is shorted to respective return line. And the status of the return line is to be read.
As by default all lines are high, so to identify the key pressed, we need to make that particular scan line
low, thus when we read the return line status, that particular line will be low and all others will be high.

So we force the scan line to level 0, one at a time. And read the status of the return lines. If we detect
any of the return lines as level 0, then we have detected a key pressed. We wait for the de-bouncing.
Then the scan code, the code we have sent on the scan line together with the return code, the value we
read from the return lines. This together, scan code + return code will identify a unique key.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 48 of 102


Embedded Lab Manual

5.3 LCD Interface Board (LCD-KBD):


16 char X 1 row, 16 char X 2 rows, 16 char X 4 rows LCD modules can be interfaced to Mini51-PE
board using LCD Interface board.
The LCD is interfaced in 8-bit mode and I/O mapped.
While writing a command to LCD make sure RS (register select) is 0, RW is 0 and afterwards write the
data and Enable LCD by taking it high and back to low.
While writing a data to LCD makes sure RS is 1, RW is 0, write the data and Enable LCD by taking it
high and back to low.

This board also contains 16 keys arranged in a matrix form (4*4). When any is pressed corresponding
lines goes to logic 0 otherwise they are at logic 1. Matrix keyboard is connected to Port 0 of 8051
microcontroller. Pins P0.0 to P0.3 are scan lines and pins P0.4 to P0.7 are return lines.

VRLCD: POT to
adjust LCD Contrast
16*2 LCD
Display

4*4 Matrix
26 Pin FRC2 Keyboard
Connector

LCD Connections:
The pin connections of LCD are as follows-

Pin Number of LCD Port Pin Description


1 Ground.
2 Vcc (+5V)
3 Power supply to control LCD contrast through pot
4 P3.2 RS
5 P3.1 RW
6 P3.0 E
7 P2.0 DB0
8 P2.1 DB1
9 P2.2 DB2

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 49 of 102


Embedded Lab Manual

10 P2.3 DB3
11 P2.4 DB4
12 P2.5 DB5
13 P2.6 DB6
14 P2.7 DB7

5.4 Stepper Motor Driver Circuit (STP51):


The Stepper Motor is a transducer that converts electrical pulse input into mechanical motion. The
stepper motor does not move continuously. The stepper motor moves in steps of fixed size.
The most common stepper motor has four stator windings that are paired with centre tapped common.
Such type of stepper motor is known as “four phases or uni-polar stepper motor”.
The power is applied in appropriate polarity to each stator winding. To apply the power, additional
motor driver switches are used along with Microcontroller 8051. These switches are operated in typical
sequence to rotate the motor.

SMCON: Stepper
Motor Connector
26 Pin FRC1
Connector

26 Pin FRC2
Connector

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 50 of 102


Embedded Lab Manual

 SM-CON: Stepper motor connector. The pin connections are as follows-

Pin Number Pin assignment


1 No connection.
2 Power Supply of Stepper Motor.
3 P0.0
4 P0.1
5 P0.2
6 P0.3
7 Power Supply of Stepper Motor.
8 Ground.

5.5 ADC Interface Board (SADC08/09):


The Analog to Digital Converter (ADC) is important device that interfaces a Microcontroller 8051 to the
analog world. The Successive Approximation type ADC is fast as compare to Dual Slope ADC. It
requires ‘N’ clock pulses for ‘N’ bit conversion. The smallest change in an analog input (VIN) that can be
detected by the ADC to get minimum one digit change at the digital output is the resolution of ADC.
The resolution of ADC is also defined by the number of output bits (8 bits 0\or 12 bits or 16 bits) and
reference voltage level of ADC.
Here we are using ADC0808/0809. The ADC0808/0809 allows us to monitor up to 8 different
transducers. It has 8-bit data output. The 8 analog input channels are multiplexed and selected by using
address pins A, B and C.

Steps to program the ADC0808/0809:

 Select an analog channel by providing bits to A, B and C channel select lines.


Eg. To select channel 1, give A=1, B=0 and C=0, and so on.
 Activate the ALE pin. It needs H-to-L pulse to latch in the address.
 Activate SC by H-to-L pulse to initiate conversion.
 Monitor EOC to see whether conversion is finished. L-to-H output indicates that the data is
converted and is ready to be picked up.
 Activate OE to read data out of the ADC chip. H-to-L pulse to OE pin will bring digital data out of
the ADC chip.

Connections:
The pin connections of ADC are as follows-

Port Pin Pin assignment for ADC


P2.0 A (channel select 0)
P2.1 B (channel select 1)
P2.2 C (channel select 2)
P0.1 START (start of conversion)
P0.2 ALE (address latch enable)

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 51 of 102


Embedded Lab Manual

P0.4 EOC (end of conversion)


P0.0 OE (output enable)
P3 Digital Output

I/P Connector
Differential Analog
Input POT

Socket to Connect
Temperature Sensor
26 Pin FRC2
LM35
Connector
Gain Adjusting
POT

ADCLK: Clock
Select (Left Short)

 I/P Connector: This is the 8 channel connector for giving input analog signals. IN0 & IN2 are
used internally for the temperature sensor LM35 & Liner POT respectively. IN3 to IN 7 are given
for user to give input analog signals. The connector details are as follows:

Pin 1 : IN 7 Pin 2 : Gnd


Pin 3 : IN 6 Pin 4 : Gnd
Pin 5 : IN 5 Pin 6 : Gnd
Pin 7 : IN 4 Pin 8 : Gnd
Pin 9 : IN 3 Pin 10 : Gnd

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 52 of 102


Embedded Lab Manual

5.6 DAC Interface Board (SDAC08):


Digital to analog converter is another device that also connects the microcontroller to the analog world.
Various types of DACs are used in practice. R-2R ladder DAC is very effective and popular. Similar to
ADC specifications, resolution of the DAC is determined by digital input bits. Most commonly output of
the DAC is in current form. External ‘I to V converter’ is often used along with DAC to get the voltage
output.
Here we are using DAC08. The digital inputs are converted to current and by connecting a resistor to
current pin; we convert the result to voltage. This voltage level can be monitored on an oscilloscope.

Connections:
8-bit digital input data is sent to DAC08 through Port 2 of 8051 microcontroller. P2.0 is LSB and P2.7 is
MSB.

26 Pin FRC1
Connector Ground (TP2)
Analog Output (TP1)

26 Pin FRC2
Connector

5.7 Traffic Light Control Simulation (TCS51):


Four-way road control, LEDs to indicate various status of Traffic light. Includes cable to connect to the
above boards. Includes application software for the simulation.
All the LEDs are connected by common anode method. That means the positive leg of each LED is
connected to Vcc and negative leg to the port pins of the microcontroller. At logic 0 LED will become
ON and at logic 1 it will become OFF.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 53 of 102


Embedded Lab Manual

26 Pin FRC1
Connector

5.8 Relay Interface Board (SRL2):


Relay board with 2 relays and DC Motor with LED indication for Relay status. Relay with 230VAC /5A
or 24VDC 10A ratings. NPN transistor BC547 is used to drive relay. At logic 1 relay will become ON
and at logic 0 it will become OFF.
SRL2 can be interfaced to all the ports (Port 0, Port 1, Port 2 and Port 3) on Mini51-PE board.

DC Motor

X2 X1
RLY1

X3
RLY1

Connections:
X2 connector:
X2 Connector Port Pin
1 to 6 Not connected
7 RLY1
8 RLY2

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 54 of 102


Embedded Lab Manual

9 +5 V
10 GND

X1 connector:
X2 Connector Port Pin
1 NC-1
2 COM-1
3 NO-1

X3 connector:
X2 Connector Port Pin
1 NC-2
2 COM-2
3 NO-2

Note: NC-x is Normally Close and NO-x is Normally Open terminal of Relay-x (RLY-1 or RLY-2)

5.9 I2C & SPI Interface Board (SSI):


This board is used to study I2C and SPI protocol. On this board I2C based ADC/DAC (PCF8591), RTC
(DS1307), EEPROM (AT24C512) is present. Also SPI based EEPROM (AT25256) and RTC (DS1305)
is present. To give analog input to ADC, POT (connected to AIN0 of PCF8591) and LM35 (connected
to AIN1 of PCF8591) is provided on-board. Remaining 2 channels of PCF8591 (AIN2 and AIN3) are
present on X1 and X3 connector. User can connect external analog input to these channels.

Battery Backup
for RTC X1
SPICON_RTC I2C-EEPROM: AT24C512

PORT 1

SPI-RTC: DS1305 I2C-ADC/DAC: PCF8591

Power ON LED X3
PR1, POT Connected to
AIN0 of PCF8591
I2C-CON
I2C-RTC:
SPI EEPROM: AT25256
DS1307

SPICON_EEPROM
LM35, Connected to
AIN1 of PCF8591

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 55 of 102


Embedded Lab Manual

X 1:
X1 Connector on SSI Description
1 Vcc (+5V)
2 AIN2 of PCF8591
3 Ground

X 3:
X3 Connector on SSI Description
1 Vcc (+5V)
2 AIN3 of PCF8591
3 Ground

PORT1 (Connector for I2C and SPI Interfaces):


Pin Port Pin Description for I2C Description for SPI
1 P1.0 NC NC
2 P1.1 NC NC
3 P1.2 NC NC
4 P1.3 NC CS (Chip Select for SPI EEPROM)
5 P1.4 NC CS (Chip Select for SPI RTC)
6 P1.5 NC MOSI
7 P1.6 SCL MISO
8 P1.7 SDA SCLK
9 Vcc (+5V) Vcc (+5V) Vcc (+5V)
10 GND GND GND

5.10 DC Motor & Thumbwheel Switch Interface Board (STWS-DCM):


This board contains DC Motor and Thumbwheel switch Interface. L293D IC is used to drive DC motor.
Thumbwheel switch gives BCD output.
You can interface DC Motor and Thumb Wheel Switch to Mini51-PE, through all the ports (Port 0, Port
1, Port 2 and Port 3) on Mini51-PE board.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 56 of 102


Embedded Lab Manual

PORT1 Connector
IC, L293D

DC Motor

Thumbwheel Switch

PORT0 Connector

PORT1(For DC Motor):
PORT1 Connector Description
on STWS-DCM
1 NC
2 NC
3 NC
4 NC
5 NC
6 NC
7 INPUT 1 to L293D
8 INPUT 2 to L293D
9 Vcc (+5V)
10 Ground

PORT0 (For Thumbwheel Switch):


PORT0 Connector Description
on STWS-DCM
1 1 (BCD)
2 2 (BCD)
3 4 (BCD)
4 8 (BCD)
5 NC
6 NC
7 NC
8 NC
9 Vcc (+5V)
10 Ground

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 57 of 102


Embedded Lab Manual

6. Assembly Language Practicals


Note: All the programs are available in the CD.

Assignment 1: Write a program to copy a block of 10 bytes of data from


RAM locations starting at 15h to RAM locations starting at 25h.
Equipments : SC51, PC.

Source Code:
MOV R0,#15H ;source pointer
MOV R1,#25H ;destination pointer
MOV R3,#10 ;counter
BACK: MOV A,@R0 ;get a byte from source
MOV @R1,A ;copy it to destination
INC R0 ;increment source pointer
INC R1 ;increment destination pointer
DJNZ R3, BACK ;keep doing it for all ten bytes
HERE: SJMP HERE ;continuous infinite loop

Procedure:
To Edit / Assemble/ Generate Hex file: Refer Section 2.2

Output:
You can see output of this program on Simulator. In the SIDE51 window from Tools menu open
Simulator. In Simulator you can see Internal RAM Watch Window. In Internal RAM Watch Window
double click on Right click here to add watch. Now you can see Modify Memory Contents window.
All the memory contents are 00. Change memory contents from 0015H to 001EH. Click Ok in Modify
Memory Contents window. Now right click on Right click here to add watch in Internal RAM
Watch Window. Click on Add. Type 25 in Memory Address (Hex) window and press Enter. You can
see values at the location starting from 25H in Internal RAM Watch Window.
From Run menu in Simulator click on Run option. You can see contents from 0015H to 001EH are
moved to 0025H to 002EH.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 58 of 102


Embedded Lab Manual

Assignment 2: Write a Program to find the frequency of square wave


generated on pin P1.0.
Equipments : SC51, PC, Mini51-PE, Oscilloscope.

Source Code:

MOV TMOD,#20H ; T1/mode 2/8 bit auto reload


MOV TH0,#5
SETB TCON.6 ; TR1
BACK: JNB TCON.7, BACK ; TF1
CPL P1.0
CLR TCON.7 ; clear TF1
SJMP BACK

Connections:
Connect one channel of Oscilloscope to P1.0 (Pin number 1 on Port1 connector).

Procedure:
To Edit / Assemble/ Generate Hex file: Refer Section 2.2
To download and run this program: Refer Chapter 4

Output:
You can see the square wave on oscilloscope. Measure its frequency.
Philips microcontrollers (P89C51RD2, P89V51RD2, P89C668, P89C669) works on double speed
therefore frequency is doubled.

For Mini51-PE (11.0592 MHz): frequency = 2 * 1.83597 KHz = 3.67KHz

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 59 of 102


Embedded Lab Manual

Assignment 3: Write a Program to generate a square wave of 50 Hz


frequency on pin P1.2 using interrupt for timer.
Equipments : SC51, PC, Mini51-PE, Oscilloscope.

Source Code:

ORG 0
LJMP MAIN
ORG 000BH ; ISR for Timer 0 Interrupt
CPL P1.2 ; Generate Square wave as make the pin high/low alternatively
MOV TL0,#00 ; Timer value = DC00H
MOV TH0,#0DCH
RETI

ORG 30H
MAIN:MOV TMOD, #00000001B ; Timer0, Mode 1
MOV TL0,#00 ; Timer value = DC00H
MOV TH0,#0DCH
MOV IE, #82H ; Enable Timer0 Interrupt
SETB TCON.4 ; TR0
HERE: SJMP HERE
END

Connections:
Connect one channel of Oscilloscope to P1.2 (Pin number 2 on Port1 connector).

Procedure:
To Edit / Assemble/ Generate Hex file: Refer Section 2.2
To download and run this program: Refer Chapter 4

Output:
You can see the square wave on oscilloscope.
Philips microcontrollers (P89C51RD2, P89V51RD2, P89C668, P89C669) works on double speed
therefore frequency is doubled.

For Mini51-PE (11.0592 MHz): frequency = 100Hz

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 60 of 102


Embedded Lab Manual

Assignment 4: Write a Program to connect INT 1 pin to a switch that is


normally high whenever it goes low LED should turn ON which is
connected to P3.2 & LED is normally OFF. LED should be ON as long as
switch is pressed.
Equipments : SC51, PC, Mini51-PE, SDIO8.
Source Code:
ORG 0000H
LJMP MAIN ; bypass interrupt vector table

; ISR for hardware interrupt INT1 to turn ON led


ORG 0013H ; INT1 ISR
CLR P3.2 ; turn ON led
MOV R3, #255
BACK: DJNZ R3, BACK ; keep led ON for a while
SETB P3.2 ; turn OFF led
RETI ; return from ISR

; main program for initialization


ORG 30H
MAIN:MOV IE, #084h ; enable external INT1
HERE: SJMP HERE ; stay here until get interrupted
END

Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to Port 3 on Mini51-
PE board.

Procedure:
To Edit / Assemble/ Generate Hex file: Refer Section 2.2
To download and run this program: Refer Chapter 4

Output:
KEY5 on SDIO8 is connected to INT1 and LED6 on SDIO8 is connected to P3.2. When KEY5 is
pressed LED6 will glow otherwise it will be OFF.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 61 of 102


Embedded Lab Manual

7. C Language Practicals
Note: All the programs are available in the CD.

Experiment 1: To develop and execute the program to output data on the port
lines of the Microcontroller 8051.
Aim: Write a ‘C’ language program to output constant data 55H on Port 1 of
Microcontroller 8051.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:

Mini51-PE / 8051
Evaluation board

Port 2 Port 0 LEDs


J1
Port 1
Port 3 Switches /
Keys

SDIO8 / LED-Key Board


Source Code:
#include <Intel\8051.h>

void main ()
{
/* Output constant data (0x55) to port P1. */
P1 = 0x55 ;

/*
In 8051 there is no halt instruction.
The user program should retain the control of the hardware from switch ON to switch OFF.
To achieve this we have to include the below loop which will do nothing but not terminate
the program.
*/
while(1)
{
/* "do nothing" infinite loop */
}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 62 of 102


Embedded Lab Manual

Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to Port 1 on Mini51-
PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see constant data 55H (0101 0101 in binary) on LEDs (on SDIO8 board) connected to Port 1 of
8051 microcontroller.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 63 of 102


Embedded Lab Manual

Experiment 2: To develop and execute the program for arithmetic operation


for the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to output the result of
a. Addition of two data elements on Port 0,
b. Subtraction of two data elements on Port 1,
c. Multiplication of two data elements on Port 2, and
d. Division (quotient) of two data elements on Port 3.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:

Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0

SDIO8 / LED – Key SDIO8 / LED – Key


Port 3 Port 1 Board
Board

Source Code:
#include <Intel\8051.h>

unsigned char g_bySum, g_byDifference, g_byProduct, g_byQuotient ;


unsigned char g_byOperand1, g_byOperand2 ;

/* Few of the rules followed to declare a variable


g = global variable
by = variable data type unsigned char (byte)
rest of the name is defining the functionality of the variable */

void main ()
{
g_byOperand1 = 27 ; // Initialize variable with a number
g_byOperand2 = 9 ; // Initialize variable with a number

g_bySum = g_byOperand1 + g_byOperand2 ;


P0 = g_bySum ; // output result to Port 0

g_byDifference = g_byOperand1 - g_byOperand2 ;


P1 = g_byDifference ; // output result to Port 1

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 64 of 102


Embedded Lab Manual

g_byProduct = g_byOperand1 * g_byOperand2 ;


P2 = g_byProduct ; // output result to Port 2

g_byQuotient = g_byOperand1 / g_byOperand2 ;


P3 = g_byQuotient ; // output result to Port 3

while(1)
{
// Do nothing loop...
}
}

Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to the respected Port
on Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the result of arithmetic operation on LEDs (on SDIO8 board) connected to the respected
Port of 8051 microcontroller.
 Result (24H) of first, addition operation can be seen on Port 0. Connect black end of 10 Pin
Cable to J1 connector on SDIO8 board and white end to Port 0 on Mini51-PE board.
 Result (12H) of second, subtraction operation can be seen on Port 1. Connect black end of 10 Pin
Cable to J1 connector on SDIO8 board and white end to Port 1 on Mini51-PE board.
 Result (F3H) of third, multiplication operation can be seen on Port 2. Connect black end of 10
Pin Cable to J1 connector on SDIO8 board and white end to Port 2 on Mini51-PE board.
 Result (03H) of fourth, division operation can be seen on Port 3. Connect black end of 10 Pin
Cable to J1 connector on SDIO8 board and white end to Port 3 on Mini51-PE board.

Note: For the below mentioned program see Experiment no.14


Aim: Write ‘C’ language program for Microcontroller 8051 to output the result of addition of contents
of register R0 and R1 on all four ports.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 65 of 102


Embedded Lab Manual

Experiment 3: To develop and execute the program for demonstrating input


and output operations using keyboard interface for the Microcontroller
8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to check the key
depression of the key on port line 2.7 and output the key status of key on port line 2.6 of
Microcontroller 8051.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:

Mini51-PE / 8051
Evaluation board

Port 1 Port 0 LEDs

J1
Port 2
Port 3 Switches /
Keys

SDIO8 / LED-Key Board


Source Code:
#include <Intel\8051.h>
BIT INPUT P2.7 /* Define P2.7 as input */
BIT OUTPUT P2.6 /* Define P2.6 as output */

bit g_bKeyIn ; // Define a variable of type bit

/* Few of the rules followed to declare a variable


g = global variable
b = variable data of type bit
Rest of the name is defining the functionality of the variable */

void main ()
{
INPUT = 1; /* Define Pin 2.7 as input */

/* Continuously Read the key and send its status to the output pin */

while(1)
{
g_bKeyIn = INPUT ; // Read the status of the input pin
OUTPUT = g_bKeyIn ; // Send the status read to the output pin

}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 66 of 102


Embedded Lab Manual

Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to the Port 2 on
Mini51-PE board.
KEY1 is connected to P2.7 (INPUT) and LED2 is connected to P2.6 (OUTPUT).

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
Status of KEY1 can be seen on LED2. If KEY1 is pressed then LED2 will become ON and if KEY is
released then LED2 will become OFF.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 67 of 102


Embedded Lab Manual

Experiment 4: To develop and execute the program to interface 7 segments


LED display to the Microcontroller 8051.
Aim: Write a ‘C’ language program to display string of characters “1234” on four- 7
segment LED displays. Displays are interfaced in multiplexed mode.

Equipments: SC51, PC, Mini51-PE, 7 Segment LED Interface Module.

Block Diagram:

Mini51-PE / 8051 7 Segments


Evaluation board

FRC 2 FRC2

7 Segment LED Interface


Source Code:
Module
#include <Intel\8051.h>
#include <standard.h>

/* P2 : Connected to 7 segements of all the displays


a
---- a = P2.5, b = P.2.4, c = P.2.2, d = P.2.1
f | g|b
---- e = P.2.0, f = P.2.6, g = P.2.7, dot = P2.3
e | |c
---- .
d */
/* Use #define to define names to ports, constants so that its easy to write the code and understand too.
Also if you need to make changes to these values, you will have to change the same at only one place.
*/

#define SELECTDISP P3 // define P3 as port to select the display


#define DATAPORT P2 /* define P2 as data port connected to the segments
as defined above */

#define SEL_DISP_1 0x7f // Select Display 1 and disable others, P3.7 = 0


#define SEL_DISP_2 0xbf // Select Display 2 and disable others, P3.6 = 0
#define SEL_DISP_3 0xdf // Select Display 3 and disable others, P3.5 = 0
#define SEL_DISP_4 0xef // Select Display 4 and disable others, P3.4 = 0
void main ()
{
SELECTDISP = 0x0f ; // Define port as output
// Also selects all Displays

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 68 of 102


Embedded Lab Manual

DATAPORT = 0x00 ; // Define port as output


// Also all segments of all displays will be ON
DATAPORT = 0xff ; // Make all displays off

delay_ms(10) ;

/* This is a library Function. To see help of this move the cursor on the function and press F1 and keep
it low for approx 10*1000 machine cycles. If target hardware freq is 12 MHz, this will generate
approximately 10 milli seconds delay */
/* Display the data in while loop, so that the data 1234 is continuously displayed. If we do not use this in
while loop the display will become blank once it is 1234disabled (since the displays do not have latched
data bus).*/

while (1)
{
SELECTDISP = SEL_DISP_1 ; // Select Display 1
DATAPORT = 0xeb ; // Show 1 on display 1 (Segment b and c ON)
delay_ms(5) ;

SELECTDISP = SEL_DISP_2 ; // Select Display 2


DATAPORT = 0x4C ; // Show 2 on display 2 (Segment a,b,g,d,e ON)
delay_ms(5) ;

SELECTDISP = SEL_DISP_3 ; // Select Display 3


DATAPORT = 0x49 ; // Show 2 on display 3 (Segment a,b,g,c,d ON)
delay_ms(5) ;

SELECTDISP = SEL_DISP_4 ; // Select Display 4


DATAPORT = 0x2b ; // Show 2 on display 4 (Segment f, g, c ON)
delay_ms(5) ;
}
}

Connections:
Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on 7 Segment
LED Interface Module.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see characters “1234” on four- 7 segment LED displays.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 69 of 102


Embedded Lab Manual

Experiment 5: To develop and execute the program to generate square wave


on port lines of Port 1 of the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to generate square wave of
frequency 1 KHz on all port lines of Port 1.Use hardware delay technique.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:

Mini51-PE / 8051 Oscilloscop


Evaluation board e

Port 2 Port 0

Port 3 Port 1

Source Code:
#include <Intel\8051.h>
#include <standard.h>

unsigned char g_byData = 0; /* Declare Variable */

void main ()
{
/* Following while loop is an infinite loop.
The action which you want to perform continuously, should be written in this loop. In this program we are
generating square wave on all port pins of Port 1, continuously. The frequency of the Square Wave is
approximately 1KHz */

while(1)
{
P1 = g_byData; /* Make all the port pins of Port 1 low */
delay_ms(500); /* This is a library Function. To see help of this, move the cursor on the
function and press F1 and keep it low for approx 500*1000 machine
cycles. If target hardware freq is 12 MHz, this will generate approximately
500 milli seconds delay */
P1 = ~g_byData; /* Make all the port pins of Port 1 high */
delay_ms(500); /* Keep them low for approx. 500ms */
}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 70 of 102


Embedded Lab Manual

Connections:
Connect one channel of Oscilloscope to any pin of Port 1.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the square wave of frequency 1 KHz on oscilloscope.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 71 of 102


Embedded Lab Manual

Experiment 6: To develop and execute the program for demonstrating logical


operations performed by the Microcontroller 8051.

Aim: Write a ‘C’ language program for Microcontroller 8051 to output result of
following logical operations to the port.
1. AND operation: 35H AND OFH: output to PORT 0,
2. OR operation: 04H OR 64H: output to PORT 1,
3. Complement operation: Complement of 55H : output to PORT2,
4. SHIFT RIGHT operation: SHIFT RIGHT 9A H three times: output to PORT 3.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:
Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0

SDIO8 / LED – Key SDIO8 / LED – Key


Port 3 Port 1 Board
Board

Source Code:
#include <Intel\8051.h>

void main ()
{
/* Logically AND the data 35H and 0FH and place the result on Port 0 */

P0 = 0x35 & 0x0F;

/* Logically OR the data 04H and 64H and place the result on Port 1 */

P1 = 0x04 | 0x64;

/* Logically COMPLIMENT the data 55H place the result on Port 0 */

P2 = ~ 0x55;

/* Shift right (three times) data 9AH and place the result on Port 1 */

P3 = 0x9A >> 3;

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 72 of 102


Embedded Lab Manual

while(1)
{
/* "do nothing" infinite loop */
}
}

Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to the respected Port
on Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the result of logical operation on LEDs (on SDIO8 board) connected to the respected Port
of 8051 microcontroller.
 Result (05H) of first, AND operation can be seen on Port 0. Connect black end of 10 Pin Cable
to J1 connector on SDIO8 board and white end to Port 0 on Mini51-PE board.
 Result (64H) of second, OR operation can be seen on Port 1. Connect black end of 10 Pin Cable
to J1 connector on SDIO8 board and white end to Port 1 on Mini51-PE board.
 Result (AAH) of third, Compliment operation can be seen on Port 2. Connect black end of 10
Pin Cable to J1 connector on SDIO8 board and white end to Port 2 on Mini51-PE board.
 Result (13H) of fourth, Shift right operation can be seen on Port 3. Connect black end of 10 Pin
Cable to J1 connector on SDIO8 board and white end to Port 3 on Mini51-PE board.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 73 of 102


Embedded Lab Manual

Experiment 7: To develop and execute the program to interface 16X2 LCD


display to the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to display message
“WELCOME” on 16 X 2 LCD display.

Equipments: SC51, PC, Mini51-PE, LCD Interface Board.

Block Diagram:

Mini51-PE / 8051
Evaluation board WELCOME LCD

FRC 2 FRC2

LCD Interface Board

Source Code:
#include <Intel\8051.h>
#include <standard.h>
BIT RS P3.2 // Register Select. 0 = Cmd , 1 = data
BIT RW P3.1 // Read/Write, 0 = write, 1 = read
BIT EN P3.0 // LCD Enable
#define DATAPORT P2 // Port P2 connected to data lines of the LCD
unsigned char g_byData = 0xff ; // Variable for data
void lcd_cmd (unsigned char p_byCmd)
{
// sends command to LCD
RS = 0; // select command register
RW = 0; // Make Read write in low
DATAPORT = p_byCmd ;
// Generate a pulse on EN Pin
EN = 1;
asm nop

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 74 of 102


Embedded Lab Manual

asm nop
EN = 0;
}

void lcd_dat (unsigned char p_byData)


{
// sends data to LCD
RS = 1;
RW = 0;
DATAPORT = p_byData ;
// Generate a pulse on EN Pin
EN = 1;
asm nop
asm nop
EN = 0;
}
void lcd_init ()
{
lcd_cmd(0x38) ; // 2 lines and 5x7 matrix
delay(250) ;
lcd_cmd(0x0c) ; // Display on, cursor off
delay(250) ;
lcd_cmd(0x01) ; // clear lcd
delay(250) ;
}
void display_row (unsigned char p_byRow, unsigned char p_byDataArr[16])
{
/* this function is written for 16 char X 2 line LCD row == 0 means first row row == 1 means
second row */
unsigned char count, ch ;
if(p_byRow) // if row is same as saying if row is non zero, in our
// case its row = 1
lcd_cmd(0xc0); // display on second line
else

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 75 of 102


Embedded Lab Manual

lcd_cmd(0x80); // display on first line

delay(250) ;
for(count=0;count<16;count++)
{
if(ch = p_byDataArr[count]) // equate p_byDataArr element to ch and
check if
{ // its value is non zero
lcd_dat(ch); // If not non zero send data to the lcd
delay(250) ;
}
else
{
while(count < 16)
{
lcd_dat(' ') ; // insert spaces until end of line
delay(250) ;
count ++ ;
}
}
}
}

void main ()
{
lcd_init ();
while (1)
{
display_row(0,"WELCOME");
}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 76 of 102


Embedded Lab Manual

Connections:
Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on LCD
Interface Board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
WELCOME will be displayed on LCD.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 77 of 102


Embedded Lab Manual

Experiment 8: To develop and execute the program to demonstrate serial


communication, using RS-232C standard, for the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to send message
“WELCOME” serially to the personal computer. Serial communication should be carried
out at baud rate of 9600 bps, 8-bit data, and 1 stop-bit.

Equipments: SC51, PC, Mini51-PE.

Block Diagram:

Mini51-PE / 8051
WELCOME
Evaluation board
WELCOME
Port 2 Port 0 9 Pin D type Male
Connector

Port 3 Port 1
Serial Cable
Computer
9 Pin D type Male
Connector

Source Code:
/*This program uses the on-chip serial port as the standard output device; and sends
"WELCOME \n" message to it*/

#include <Intel\8051.h>
#include <stdio.h>

void main ()
{
/* Initialize Serial Port
Code below is generated using:
Visual Code Generator (Initialize Serial Port)
It initializes serial port in
Mode 1: 9600 baud rate generated using Timer 1 @ 11.0592 MHz

Here we are using 3 pin serial connection: Rx, Tx, Gnd.

Rx = P3.0, Tx = P3.1

The connection to the other serial port are: Rx --> Tx, Tx --> Rx, Gnd --> Gnd

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 78 of 102


Embedded Lab Manual

The P89V51RD2 give TTL level for Rx and Tx. When we drive this through RS232 driver we get the
RS232 levels for these signals */

TH1 = 0xfd ;
TL1 = 0xfd ;
PCON &= 0x7f ;
SCON = 0x50 ;

/* Initialize TMOD/TCON
Code below is generated using:
Visual Code Generator (Initialize TMOD/TCON)
It puts Timer1 in 8 bit auto-reload mode and starts it
Timer1 is used for baud rate generation */

TMOD = 0x20 ;
TCON = 0x40 ;

/* Serial port is now initialized and ready to use. Following while loop is an infinite loop.
The action which you want to perform continuously, should be written in this loop.
In this program we are sending "WELCOME !" message on serial port, continuously. */

while(1)
{
printf("WELCOME !\n") ; // \n will generate a new line on the terminal
}
}

Connections:
Keep the Serial cable connected as it is.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see output on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings. Do proper
settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com
Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the board. Mini51-
PE board will continuously transmit the message "WELCOME!”.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 79 of 102


Embedded Lab Manual

Experiment 9: To develop and execute the program to interface stepper


motor to the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to rotate stepper motor
continuously in clockwise direction. Motor is interfaced through Port 0 of
Microcontroller 8051.

Equipments: SC51, PC, Mini51-PE, Stepper Motor Driver Circuit, Stepper Motor.

Block Diagram:
LEDs showing
Mini51-PE / 8051 Phase Output
Evaluation board
FRC1 FRC1 Stepper Motor

FRC2 FRC2

Stepper Motor Driver Circuit


Source Code:
#include <Intel\8051.h>
#include <standard.h>

#define PHASEA 0x09


#define PHASEB 0x0c
#define PHASEC 0x06
#define PHASED 0x03

void main ()
{
while(1)
{

P0 = PHASEA ;
delay_ms(210) ;

P0 = PHASEB ;
delay_ms(210) ;

P0 = PHASEC ;
delay_ms(210) ;

P0 = PHASED ;
delay_ms(210) ;

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 80 of 102


Embedded Lab Manual

}
}

Connections:
Connect FRC cable between FRC 1 connector on Mini51-PE board and FRC 1 connector on Stepper
Motor Driver Circuit.
Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on Stepper
Motor Driver Circuit.
Connect Stepper Motor to SM-CON connector on Stepper Motor Driver Circuit.
If stepper motor requires +5V or +12V external power supply then connect it to +5V or +12V supply
respectively (depending on colour combination of connector pins), present on main power supply
provided along with Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
Stepper motor will rotate in clockwise direction.

Note: In the similar way by reversing the phases only we can rotate the stepper motor in anticlockwise
direction. This program is included in the CD.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 81 of 102


Embedded Lab Manual

Experiment 10: To develop and execute the program to interface ADC 0809
to the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to read the digital output of
the ADC and output it on port 1 and on serial port.

Equipments: SC51, PC, Mini51-PE, ADC Interface Board, SDIO8.

Block Diagram:

Mini51-PE / 8051
Evaluation board ADC Interface Board

Port 2 Port 0
FRC2
FRC 2
Port 3 Port 1

POT to give
Analog Input
LEDs
J
1
Switches

SDIO8 / LED-Key Board

Source Code:
#include <Intel\8051.h>
#include <standard.h>

/*
8 LEDs are connected to port P1.
So data read from ADC should be sent to P1.
ADC channel selection pins = P2.2, P2.1, P2.0
ADC start of conversion pin = P0.1
ADC ALE pin = P0.2
ADC end of conversion pin = P0.4
ADC output enable pin = P0.0
ADC data = P3
*/
BIT start P0.1

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 82 of 102


Embedded Lab Manual

BIT ale P0.2


BIT eoc P0.4
BIT oe P0.0

unsigned char adc_data;

void initser()
{
TH1 = 0xfd ;
TL1 = 0xfd ;
PCON &= 0x7f ;
SCON = 0x50 ;
TMOD = 0x20 ;
TCON = 0x40 ;
}

void main ()
{
initser();
P2 = 0x02; /* select channel IN2 */
ale = 1; /* ale pin = high */
delay_ms(60);
/*
Following while loop is an infinite loop.
So ADC data of channel IN2 will be continuously read and sent to P1 and serial port.
Since it is connected to a POTentiometer, output will change when POT is moved.
*/
while(1)
{

start = 1; /* start of conversion pin = high */


delay_ms(60);

start = 0; /* start of conversion pin = low */


ale = 0; /* ale pin = low */

while(!eoc) /* monitor EOC pin. It will go high when conversion


completes */
{
/* wait until conversion completes. */
}
oe = 1; /* output enable pin = high */
asm nop
delay_ms(60);
adc_data = P3; /* conversion is complete. Now read ADC data. */

oe = 0; /* output enable pin = low */

printf("ADC = %bu\n",adc_data); /* now output that data to serial port */


P1 = ~adc_data; /* now output that data to LEDs connected to P1 */
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 83 of 102


Embedded Lab Manual

Connections:
Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on ADC
Interface Board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
Digital value of corresponding analog input can be seen on LEDs (on SDIO8 board) connected to Port 1
of 8051 microcontroller. If you vary the analog input by varying pot then corresponding digital value
can be seen on LEDs.
You can also see the digital value on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings.
Do proper settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity:
None, Com Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the
board.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 84 of 102


Embedded Lab Manual

Experiment 11: To develop and execute the program to interface DAC 0808
to the Microcontroller 8051.
Aim: Write a ‘C’ language program for Microcontroller 8051 to generate staircase
waveform using the DAC. DAC is interfaced using port 2.

Equipments: SC51, PC, Mini51-PE, DAC Interface Board, CRO.

Block Diagram:

Mini51-PE / 8051 FRC1 DAC Interface Board


Evaluation board

Port 2 Port 0 FRC1

Test
Points

FRC2 FRC2

Port 3

Oscilloscop
e

Source Code:
#include <Intel\8052.h>
#include <standard.h>
#define DATAPORT P2

unsigned char g_byData ;


void main ()
{
while(1)
{
/* when we give 0 as input to DAC it generates the 0 level and when we give 255 (0xff) to DAC it
generates 5V level As we increase the digital count from 0 to 255 (0xff) the voltage output will
gradually increase from 0 to 5V thus showing the staircase effect You can check the output on
the oscilloscope. Two points are provided on the DAC card, to connect the probe of oscilloscope
*/

for(g_byData=0; g_byData<256; g_byData++)


{
DATAPORT = g_byData ;

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 85 of 102


Embedded Lab Manual

delay_ms(1) ;
}
}
}

Connections:
Connect one channel of Oscilloscope to TP1 pin on DAC Interface board and connect TP2 pin on DAC
Interface Board to ground pin of oscilloscope.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see staircase waveform on oscilloscope.

Note: In the similar way we can see triangular and square waveform on oscilloscope. These programs
are also included in the CD.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 86 of 102


Embedded Lab Manual

Experiment 12: To develop and execute the program to interface relays to the
Microcontroller 8051.
Aim: Write a ‘C’ language program to interface relays to Port 1 of Microcontroller 8051.

Equipments: SC51, PC, Mini51-PE, SRL4.

Block Diagram:

Mini51-PE / 8051 SRL2 Relay DC


Evaluation board Motor Board
DC Motor

Port 2 Port 0
X2

Port 3
Relays

LEDs
Source Code:
#include <Intel\8051.h>
#include <standard.h>

void main ()
{
/* Following while loop is an infinite loop.
The action which you want to perform continuously should be written in this loop.
In this program relays will become ON and OFF after 500ms delay, continuously */

while(1)
{
P1 = 0x00; //all relays will become ON
delay_ms(500); //this function generates delay of 500ms
P1 = 0xff; //all relays will become OFF
delay_ms(500); //this function generates delay of 500ms

}
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 87 of 102


Embedded Lab Manual

Connections:
Connect 10-pin cable supplied to you along with SRL4 board as follows:
Connect black end of 10 Pin Cable to JP4 connector on SRL4 board and white end to Port 1 on Mini51-
PE board.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see Relays becoming ON and OFF continuously.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 88 of 102


Embedded Lab Manual

Experiment 13: To develop and execute the program to interface 4*4 matrix
keyboard to the Microcontroller 8051.
Aim: Write a ‘C’ language program to display keycode of 4*4 matrix keyboard on four-
7 segment LED displays.

Equipments: SC51, PC, Mini51-PE, 7SEG4*4KBD (7 Segment LED Interface Module).

Block Diagram:

Mini51-PE / 8051 7 Segments


Evaluation board
FRC2
4*4 Matrix
Keyboard
FRC 2

7SEG4*4KBD Interface
Module

Source Code:
#include <Intel\8051.h>
#include <standard.h>

unsigned char g_byScanCode = 0xfe ;


unsigned char g_byRetCode = 0x00 ;
unsigned char g_byTemp;
unsigned int g_bycode;

void main ()
{
/*
Pin0 - Pin3 - Scan Lines
Pin4 - Pin7 - Return Lines

*/
P3 = 0x00 ;
P2 = 0x00 ;
P0 = 0xff ;
while (1)
{
g_byTemp = P0 ; // Read P0
g_byTemp = g_byTemp | 0x0f ; // make all scan lines as 1
g_byTemp = g_byTemp & g_byScanCode ; // make the desired scan line as 0

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 89 of 102


Embedded Lab Manual

P0 = g_byTemp ; // make scan line as 0


g_byRetCode = P0 ; // read the port for return lines
if ((g_byRetCode & 0xf0) != 0xf0) // mask the scan lines and then compare the return
// lines
{ // key detected
if(g_byRetCode == 0xee)
{
P2 = 0x88;
}
else if(g_byRetCode == 0xed)
{
P2 = 0x2b;
}
else if(g_byRetCode == 0xeb)
{
P2 = 0x08;
}
else if(g_byRetCode == 0xe7)
{
P2 = 0x9c;
}
else if(g_byRetCode == 0xde)
{
P2 = 0xeb;
}
else if(g_byRetCode == 0xdd)
{
P2 = 0x19;
}
else if(g_byRetCode == 0xdb)
{
P2 = 0x09;
}
else if(g_byRetCode == 0xd7)
{
P2 = 0x68;
}
else if(g_byRetCode == 0xbb)
{
P2 = 0x48;
}
else if(g_byRetCode == 0xbe)
{
P2 = 0x4c;
}

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 90 of 102


Embedded Lab Manual

else if(g_byRetCode == 0xbd)


{
P2 = 0x18;
}
else if(g_byRetCode == 0xb7)
{
P2 = 0x0c;
}
else if(g_byRetCode == 0x77)
{
P2 = 0x1e;
}
else if(g_byRetCode == 0x7b)
{
P2 = 0x38;
}
else if(g_byRetCode == 0x7d)
{
P2 = 0xcb;
}
else if(g_byRetCode == 0x7e)
{
P2 = 0x49;
}

delay_ms(300) ; // for debounce


P0 = 0xff ; // make port lines as 1
}

g_byScanCode = ~g_byScanCode ; // invert the scan code


g_byScanCode <<= 1 ; // shift by 1
g_byScanCode = ~g_byScanCode ; // invert the scan code toget final scan code

if (g_byScanCode == 0xef)
g_byScanCode = 0xfe ;
}
}

Connections:
Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on
7SEG4*4KBD (7 Segment LED Interface Module).

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 91 of 102


Embedded Lab Manual

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
After pressing any key on 4*4 matrix keyboard, its keycode will be displayed on all 7 Segments.

Note: In the similar way we can show the keycode on LCD display. This program is also included in the
CD.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 92 of 102


Embedded Lab Manual

Experiment 14: Write a program to interface DC Motor to Microcontroller


8051.
Aim: Write a program to interface DC motor with Microcontroller 8051.
Equipments: SC51, PC, Mini51-PE, DC Motor Interface card (STWS-DCM).

Block Diagram:

Mini51-PE / 8051 STWS-DCM


DC Motor
Evaluation board Port 1

Port 2 Port 1

Port 0

Port 3

Thumb Wheel

Source Code:
#include <Intel\8051.h>

void main ()
{
while(1)
{
//P1 = 0x80;
P1 = 0x40;
}
}

Connections:
Connect 10 pin straight cable between Port 1 connector on Mini51-PE board and Port 1connector on
STWS-DCM (Thumb wheel and DC Motor Interface Module).

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the DC motor moving in a particular direction.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 93 of 102


Embedded Lab Manual

Experiment 15: To develop and execute the program to output the result of
addition of contents of registers R0 and R1 on all four ports for the
Microcontroller 8051.
Aim: Write ‘C’ language program for Microcontroller 8051 to output the result of
addition of contents of register R0 and R1 on all four ports.

Equipments: SC51, PC, Mini51-PE, SDIO8.

Block Diagram:

Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0

SDIO8 / LED – Key SDIO8 / LED – Key


Port 3 Port 1 Board
Board

Source Code:
#include <Intel\8051.h>

/*
While writing the program in C language, we can't directly access internal registers (like r0, r1 etc.) of
micrcontroller. To access these registers we have to use assembly language only. Therefore we will
insert assembly language statements directly into our C program using asm keyword.

The asm keyword:


This is an additional keyword, which allows you to insert assembly language statements directly into
your C program. This keyword when used must appear as the first word of a line. Everything
following this keyword - up to the end of line - is directly copied into the .ASM output file. Please note
that, no syntax checking is done by the compiler on this assembly language statement, it is done
later on by the assembler.
*/

void main ()
{
asm mov r0,#01 // move data 01H to register r0
asm mov r1,#02 // move data 02H to register r1
asm mov a,r0 // move data present in register r0 to accumulator
asm add a,r1 // add data present in register r1 with data present in accumulator
asm mov P0,a // output result to Port 0
asm mov P1,a // output result to Port 1
asm mov P2,a // output result to Port 2

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 94 of 102


Embedded Lab Manual

asm mov P3,a // output result to Port 3

while(1)
{
// Do nothing loop...
}

}
Connections:
Connect 10-pin cable supplied to you along with SDIO8 board as follows:
Connect black end of 10 Pin Cable to J1 connector on SDIO8 board and white end to the respected Port
on Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the result of addition of contents of register R0 and R1 on LEDs (on SDIO8 board)
connected to the any Port of 8051 microcontroller because to all the ports same data is sent.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 95 of 102


Embedded Lab Manual

Experiment 16: Assume 1 Hz. Frequency pulse is connected to I/P P3.4


Write a Program to display count on LCD.
Aim: Write a ‘C’ language program for Microcontroller 8051 to display count on LCD of
1 Hz frequency pulse connected to I/P P3.4.

Equipments: SC51, PC, Mini51-PE, LCD Interface Board, Frequency generator.

Block Diagram:

Mini51-PE / 8051
Count Freq: 012 LCD
Evaluation board

FRC 2 FRC2
Port 3

LCD Interface Board


Function 1 Hz freq. pulse
Generator connected to
P3.4 (Pin 5)

Source Code:
#include <Intel\8051.h>
#include "lcd.h"
#include <standard.h>
#include <stdio.h>

unsigned char count, sztemp;

void main ()
{
lcd_init();
TMOD = 0x06 ; //counter 0, mode 2, C/T = 1
TCON = 0x10 ;
TH0 = 0x00;
T0 = 1; //make T0 (P3.4) as input
while(1)
{
TR0 = 1; //start counter 0
if(!TF0) //check TF0
{
count = TL0; //get result/count from TL0

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 96 of 102


Embedded Lab Manual

sprintf(sztemp,"Count Freq: %03bu",count);


display_row(0,sztemp);
}
TR0 = 0; //stop counter 0
TF0 = 0; //clear TF0
}
}

Connections:
Connect 1 Hz frequency pulse to P3.4 (pin number 5 on Port 3 connector).

Connect FRC cable between FRC 2 connector on Mini51-PE board and FRC 2 connector on LCD
Interface Board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see the count on LCD.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 97 of 102


Embedded Lab Manual

Experiment 17: To develop and execute the program for I2C based ADC.

Aim: Write a ‘C’ language program to interface I2C based ADC with 8051 Microcontroller.
Equipments: SC51, PC, Mini51-PE, SSI (I2C and SPI Interface Board).
Block Diagram:

Mini51-PE / 8051
Evaluation board SSI
PORT 1

Source Code:
This program is available in the CD at:
Programs\CLanguage\I2C8051_ADC_POT

Connections:
To give analog input, PR1, POT is connected to AIN0 of ADC (PCF8591).
Connect 10-pin cable supplied to you along with SSI board as follows:
Connect one white end of 10 Pin Cable to PORT1 connector on SSI board and another white end to Port
1 on Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
You can see digital reading on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings. Do
proper settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None,
Com Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the board.
Digital reading will be displayed on SPJTerminal. If you vary the POT then corresponding change you
will see on SPJTerminal.

Note:
LM35 Temperature sensor is connected to AIN1 of ADC (PCF8591).
Its program is available in the CD at:
Programs\CLanguage\I2C8051_LM35
After downloading this program, you can see temperature reading on SPJTerminal.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 98 of 102


Embedded Lab Manual

Experiment 18: To develop and execute the program for I2C based DAC.

Aim: Write a ‘C’ language program to interface I2C based DAC with 8051 Microcontroller.
Equipments: SC51, PC, Mini51-PE, SSI (I2C and SPI Interface Board).
Block Diagram: GND

Mini51-PE / 8051 AOUT


Evaluation board SSI
PORT 1

Source Code:
This program is available in the CD at:
For Square Wave: Programs\CLanguage\I2C8051_DAC_Square
For Ramp Wave: Programs\CLanguage\I2C8051_DAC_Ramp

Connections:
Connect 10-pin cable supplied to you along with SSI board as follows:
Connect one white end of 10 Pin Cable to PORT1 connector on SSI board and another white end to Port
1 on Mini51-PE board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4

Output:
Connect Oscilloscope to AOUT and GND pin on SSI board. You can see corresponding waves on
oscilloscope.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 99 of 102


Embedded Lab Manual

Experiment 19: To develop and execute the program for I2C based
EEPROM.

Aim: Write a ‘C’ language program to interface I2C based EEPROM with 8051 Microcontroller.
Equipments: SC51, PC, Mini51-PE, SSI (I2C and SPI Interface Board).
Block Diagram:

Mini51-PE / 8051
Evaluation board SSI
PORT 1

Source Code:
This program is available in the CD at:
Programs\CLanguage\I2C8051_EEPROM
Connections:
Connect 10-pin cable supplied to you along with SSI board as follows:
Connect one white end of 10 Pin Cable to PORT1 connector on SSI board and another white end to Port
1 on Mini51-PE board.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4
Output:
In this program we write some data at a particular address in the EEPROM and then read the same
address. Read data you can see on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings.
Do proper settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity:
None, Com Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the
board.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 100 of 102


Embedded Lab Manual

Experiment 20: To develop and execute the program for I2C based RTC.
Aim: Write a ‘C’ language program to interface I2C based RTC with 8051 Microcontroller.
Equipments: SC51, PC, Mini51-PE, SSI (I2C and SPI Interface Board).
Block Diagram:

Mini51-PE / 8051
Evaluation board SSI
PORT 1

Source Code:
This program is available in the CD at:
Programs\CLanguage\I2C8051_RTC
Connections:
Connect 10-pin cable supplied to you along with SSI board as follows:
Connect one white end of 10 Pin Cable to PORT1 connector on SSI board and another white end to Port
1 on Mini51-PE board.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4
Output:
You can see date and Time on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings. Do
proper settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None,
Com Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the board.
To set RTC: Keep pressed Enter key from keyboard and press Reset key on Mini51-PE. Then on
SPJTerminal you will see message like “Enter date and time in dd mm yy hh mm ss format”, then enter
date and time in the same format and press Enter then Press Y to store these new settings.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 101 of 102


Embedded Lab Manual

Experiment 21: To develop and execute the program for SPI based RTC.
Aim: Write a ‘C’ language program to interface SPI based RTC with 8051 Microcontroller.
Equipments: SC51, PC, Mini51-PE, SSI (I2C and SPI Interface Board).
Block Diagram:

Mini51-PE / 8051
Evaluation board SSI
PORT 1

Source Code:
This program is available in the CD at:
Programs\CLanguage\SPI8051_RTC
Connections:
Connect 10-pin cable supplied to you along with SSI board as follows:
Connect one white end of 10 Pin Cable to PORT1 connector on SSI board and another white end to Port
1 on Mini51-PE board.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4
Output:
You can see date and Time on SPJTerminal. Therefore Open SPJTerminal. Go to Port -> Settings. Do
proper settings (Baud Rate: 9600 (if other choose it), Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None,
Com Port: Com 1 (if other choose it)). Click on OK. Go to Port -> Open. If required Reset the board.
To set RTC: Keep pressed Enter key from keyboard and press Reset key on Mini51-PE. Then on
SPJTerminal you will see message like “Enter date and time in day dd mm yy hh mm ss format”, then
enter day, date and time in the same format and press Enter then Press Y to store these new settings.

© SPJETPL All Rights Reserved. (www.spjembedded.com) Page 102 of 102

You might also like