Embedded Lab Manual 8051 New
Embedded Lab Manual 8051 New
For 8051
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.
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
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
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
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
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.
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.
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.
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.
Here we go!
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.
Output Window
From Project menu, select Close project. The screen should look something like this.
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.
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.
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.
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.
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.
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.
Description:
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.
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
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.
Click on “Copy C Code”, corresponding code will be copied. Click on Ok. Paste the code in the
program.
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.
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 */
}
#include <8051.h>
/* Other includes */
/* function prototypes */
void func1(char ch1) ;
/* function definition */
void func1(char ch1)
{
/* Program structure */
}
void main ()
{
/* Calling Initialization routines */
while (1)
{
/* Call functions to be executed all time */
}
}
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
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.
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.
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.
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
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.
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). 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.
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.
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.
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.
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
PIN 1 PIN 1
PIN 1
Port 2
Port 0
PIN 1
PIN 1
Port 3
Port 1
PIN 1
Reset
PSCON: Power
Supply Connector
Pin 1
INT 0 INT 1
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.
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
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:
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.
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:
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
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.
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-
10 P2.3 DB3
11 P2.4 DB4
12 P2.5 DB5
13 P2.6 DB6
14 P2.7 DB7
SMCON: Stepper
Motor Connector
26 Pin FRC1
Connector
26 Pin FRC2
Connector
Connections:
The pin connections of ADC are as follows-
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:
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
26 Pin FRC1
Connector
DC Motor
X2 X1
RLY1
X3
RLY1
Connections:
X2 connector:
X2 Connector Port Pin
1 to 6 Not connected
7 RLY1
8 RLY2
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)
Battery Backup
for RTC X1
SPICON_RTC I2C-EEPROM: AT24C512
PORT 1
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
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
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
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.
Source Code:
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.
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.
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.
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board
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 */
}
}
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0
Source Code:
#include <Intel\8051.h>
void main ()
{
g_byOperand1 = 27 ; // Initialize variable with a number
g_byOperand2 = 9 ; // Initialize variable with a number
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board
J1
Port 2
Port 3 Switches /
Keys
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
}
}
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.
Block Diagram:
FRC 2 FRC2
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) ;
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.
Block Diagram:
Port 2 Port 0
Port 3 Port 1
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 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 */
}
}
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.
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0
Source Code:
#include <Intel\8051.h>
void main ()
{
/* Logically AND the data 35H and 0FH and place the result on Port 0 */
/* Logically OR the data 04H and 64H and place the result on Port 1 */
P1 = 0x04 | 0x64;
P2 = ~ 0x55;
/* Shift right (three times) data 9AH and place the result on Port 1 */
P3 = 0x9A >> 3;
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board WELCOME LCD
FRC 2 FRC2
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
asm nop
EN = 0;
}
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");
}
}
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.
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
Rx = P3.0, Tx = P3.1
The connection to the other serial port are: Rx --> Tx, Tx --> Rx, Gnd --> Gnd
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!”.
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
void main ()
{
while(1)
{
P0 = PHASEA ;
delay_ms(210) ;
P0 = PHASEB ;
delay_ms(210) ;
P0 = PHASEC ;
delay_ms(210) ;
P0 = PHASED ;
delay_ms(210) ;
}
}
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.
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.
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
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
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)
{
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.
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.
Block Diagram:
Test
Points
FRC2 FRC2
Port 3
Oscilloscop
e
Source Code:
#include <Intel\8052.h>
#include <standard.h>
#define DATAPORT P2
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.
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.
Block Diagram:
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
}
}
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.
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.
Block Diagram:
7SEG4*4KBD Interface
Module
Source Code:
#include <Intel\8051.h>
#include <standard.h>
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
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).
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.
Block Diagram:
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.
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.
Block Diagram:
Mini51-PE / 8051
Evaluation board SDIO8 / LED – Key
SDIO8 / LED – Key Board
Board Port 2 Port 0
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.
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
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.
Block Diagram:
Mini51-PE / 8051
Count Freq: 012 LCD
Evaluation board
FRC 2 FRC2
Port 3
Source Code:
#include <Intel\8051.h>
#include "lcd.h"
#include <standard.h>
#include <stdio.h>
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
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.
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.
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
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.
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.
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.
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.