Professional Documents
Culture Documents
com
Department Of
ELECTRONICS AND
COMMUNICATION ENGINEERING
Prepared By
S nagakishore Bhavanam
Asst.ProF, ECE Dept..,GNIT
UMARANI N
AssOC.Prof, ECE Dept..,GNIT
www.jntuworld.com
www.jntuworld.com
CERTIFICATE
ii
www.jntuworld.com
www.jntuworld.com
Lab Objective:
An embedded system is some combination of computer hardware and software, either fixed in
capability or programmable, that is specifically designed for a particular kind of application device.
Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending
machines, and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible
hosts of an embedded system. Embedded systems that are programmable are provided with a programming
interface, and embedded systems programming is a specialized occupation.
Since the embedded system is dedicated to specific tasks, design engineers can optimize it, reducing the size
and cost of the product, or increasing the reliability and performance. Some embedded systems are mass-
produced, benefiting from economies of scale.
iii
www.jntuworld.com
www.jntuworld.com
There are 66 systems installed in this Lab. Their configurations are as follows :
Software
1 All systems are configured in DUAL BOOT mode i.e, Students can boot from Windows XP or
Linux as per their lab requirement.
This is very useful for students because they are familiar with different Operating Systems
so that they can execute their programs in different programming environments.
2 Each student has a separate login for database access
Oracle 9i client version is installed in all systems. On the server, account for each student has been
created.
This is very useful because students can save their work ( scenarios, pl/sql programs, data
related projects ,etc) in their own accounts. Each student work is safe and secure from other
students.
3 Latest Technologies like DOT NET and J2EE are installed in some systems. Before
submitting their final project, they can start doing mini project from 2nd year onwards.
4 MASM ( Macro Assembler ) is installed in all the systems
Students can execute their assembly language programs using MASM. MASM is very useful
students because when they execute their programs they can see contents of Processor
Registers and how each instruction is being executed in the CPU.
1 Rational Rose Software is installed in some systems
Using this software, students can depict UML diagrams of their projects.
2 Software installed : C, C++, JDK1.5, MASM, OFFICE-XP, J2EE and DOT NET, Xilinx ISE,
Modelsim, Tanner EDA, Rational Rose.
3 Systems are provided for students in the 1:1 ratio.
4 Systems are assigned numbers and same system is allotted for students when they do the lab.
iv
www.jntuworld.com
www.jntuworld.com
LAB CODE
1. Students should report to the concerned labs as per time table schedule.
2. Students who turn up late to the labs will in no case be permited to do the program scheduled for the
day.
3. After completion of the program , certification of the concerned staff in-charge in the observation
book is necessary.
4. Students should bring a notebook of about 100 pages and should enter the reading/observations into
the notebook while performing the experiment.
5. The record of observations along with the detailed experimental procedure of the experiment
performed in the immediate last session should be submitted and certified by the staff ember in-
charge.
6. Not more than three students in a group are permitted to perform the experiment on a setup.
7. The group-wise division made in the beginning should be adhered to and no mix up student among
different groups will be permitted later.
8. The components required pertaining to the experiment should be collected from stores in-charge
after duly filling in the requisition form.
9. When the experiment is completed, students should disconnect the setup made by them, and should
return all the components/instruments taken for the purpose.
10. Any damage of the equipment or burn-out of components will be viewed seriously either by putting
penalty or by dismissing the total group of students from the lab for the semester/year.
11. Students should be present in the labs for the total scheduled duration.
12. Students are required to prepare thoroughly to perform the experiment before coming to Laboratory.
13. Procedure sheets/data sheets provided to the students groups should be maintained neatly and to be
returned after the experiment.
www.jntuworld.com
www.jntuworld.com
Embedded systems are designed to do some specific task, rather than be a general-purpose computer
for multiple tasks. Some also have real-time performance constraints that must be met, for reason such as
safety and usability; others may have low or no performance requirements,allowing the system hardware
to be simplified to reduce costs.
Embedded systems are not always separate devices. Most often they are physically built-in to the
devices they control.
The software written for embedded systems is often called firmware, and is stored in read-only
memory or Flash memory chips rather than a disk drive. It often runs with limited computer hardware
resources: small or no keyboard, screen, and little memory.
Embedded systems range from no user interface at all dedicated only to one task to full user
interfaces similar to desktop operating systems in devices such as PDAs. Simple embedded devices use
buttons, LEDs, and small character or digit only displays, often with a simple menu system.
vi
www.jntuworld.com
www.jntuworld.com
INDEX
Cycle -1:
TITLE PAGENO
Title Page i
Certificate ii
Lab objective iii
Introduction about lab iv
Lab Code v
Description about ES Concepts vi
Index cycle-1 vii
Index cycle-2 viii
1. INTRODUCTION 1
2. CREATING C APPLICATIONS FOR 8051: QUICK START 1
3. CREATING C APPLICATIONS FOR 8051: IN DETAIL 4
4. DOWNLOADING AND RUNNING USER PROGRAMS 24
Experiments
vii
www.jntuworld.com
www.jntuworld.com
INDEX
Cycle-2
TITLE PAGENO
1. INTRODUCTION 53
2. GETTING STARTED 53
3. HARDWARE DESCRIPTION 59
4. CONNECTOR DETAILS, JUMPER AND SWITCH SETTINGS 61
5. DOWNLOADING AND RUNNING USER PROGRAMS 69
6. JTAG CABLE FOR DEBUGGING 71
Experiments
7. BUZZER INTERFACE 74
8. RELAY INERFACE 76
9. STEPPER MOTOR CLOCK WISE 78
10. STEPPER MOTOR ANTI-CLOCK WISE 80
11. 4*4 MATRIX KEY INTERFACE 82
12. ADC 84
13. TEMPERATURE SENSOR 86
14. SEVEN SEGMENT LED DISPLAY 88
15. GRAPHIC LCD INTERFACE (128X64) 91
16. ELEVATOR 96
viii
www.jntuworld.com
www.jntuworld.com
Introduction
This is users manual for SC51 Trainer Kit based on 89V51RD2 (8051) micro-controller. This
trainer board is designed to perform lab practical and has a facility to download the user
programs into the on-chip flash memory of the micro-controller. It is strongly recommended to
read this manual carefully before you start using the SC51 board.
3. From Project menu, select New Project. The Open dialog 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.
4. 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
microcontroller. 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
microcontroller, 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.
5. In the same window, the Crystal frequency field is also displayed with default value as 12
MHz. If your target uses different crystal frequency, then you may change it. However, the
current version of Compiler / Assembler does not actually use this value.
6. 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
microcontroller) 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.
1
www.jntuworld.com
www.jntuworld.com
7. 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.
8. 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).
9. 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.
10. 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.
11. 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.
12. 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.
13. 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.
www.jntuworld.com
www.jntuworld.com
14. 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.
15. 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 its name. (Contents of PC cannot be modified).
16. 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.
17. 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.
18. 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.
www.jntuworld.com
www.jntuworld.com
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!
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.
www.jntuworld.com
www.jntuworld.com
From Project menu, select Close project. The screen should look something like this.
To create a new project, from Project menu, select New Project. The screen should look
something like this.
www.jntuworld.com
www.jntuworld.com
The Open dialog 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
microcontroller.
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 microcontroller, the
www.jntuworld.com
www.jntuworld.com
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
microcontroller) 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.
www.jntuworld.com
www.jntuworld.com
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
www.jntuworld.com
www.jntuworld.com
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.
www.jntuworld.com
www.jntuworld.com
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:
10
www.jntuworld.com
www.jntuworld.com
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.
11
www.jntuworld.com
www.jntuworld.com
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
12
www.jntuworld.com
www.jntuworld.com
Click on Copy C Code, corresponding code will be copied. Click on Ok. Paste the code in
the program.
13
www.jntuworld.com
www.jntuworld.com
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.
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 */
}
14
www.jntuworld.com
www.jntuworld.com
Typical C program
#include <8051.h>
/* Other includes */
/* Global variable declaration */
/* function prototypes */
15
www.jntuworld.com
www.jntuworld.com
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.
16
www.jntuworld.com
www.jntuworld.com
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.
17
www.jntuworld.com
www.jntuworld.com
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.
18
www.jntuworld.com
www.jntuworld.com
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
19
www.jntuworld.com
www.jntuworld.com
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.
20
www.jntuworld.com
www.jntuworld.com
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.
21
www.jntuworld.com
www.jntuworld.com
It is also possible to modify register / SFR contents by double clicking on its 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.
22
www.jntuworld.com
www.jntuworld.com
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.
23
www.jntuworld.com
www.jntuworld.com
Microcontroller P89V51RD2 includes on-chip flash for storing user program and non-
volatile data. Thisflash is In-System-Programmable (ISP). Therefore it is possible to download
user program into on-chipflash, through serial port connected to PC.
This section describes how to use the software Flash Magic to download program into
P89V51RD2.
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)
24
www.jntuworld.com
www.jntuworld.com
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
www.jntuworld.com
www.jntuworld.com
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.
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.
26
www.jntuworld.com
www.jntuworld.com
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
27
www.jntuworld.com
www.jntuworld.com
Experiment No: 1
Aim: Write a C language program for Microcontroller 8051 to display message GNIT
WELCOMES U On 16x2 LCD
Block diagram:
Source code:
#include <Intel\8051.h>
#include <standard.h>
BIT RS P3.2
BIT RW P3.1
BIT EN P3.0
#define DATAPORT P2
unsigned char g_byData = 0xff;
void lcd_cmd(unsigned char p_byCmd)
{
RS=0;
RW=0;
DATAPORT = p_byCmd;
EN=1;
28
www.jntuworld.com
www.jntuworld.com
asm nop
asm nop
EN=0;
}
void lcd_init()
{
lcd_cmd(0x38);
delay_ms(30);
lcd_cmd(0x38);
delay_ms(30);
lcd_cmd(0x38);
delay_ms(30);
lcd_cmd(0x08);
delay_ms(6);
lcd_cmd(0x0c);
delay_ms(6);
lcd_cmd(0x06);
delay_ms(6);
}
29
www.jntuworld.com
www.jntuworld.com
else
lcd_cmd(0x80);
delay_ms(250);
for (count = 0;count<16;count++)
{
if(ch=p_byDataArr[count])
{
lcd_dat(ch);
}
else
{
while(count<16)
{
lcd_dat(' ');
count++;
void main ()
{
lcd_init();
while(1)
{
display_row(0,"GNIT");
display_row(1,"WELCOMES U");
}
}
Connections:
Connect FRC cable between FRC2 connector on Mini51-PE board and FRC 2 connector
on LCD Interface Board.
Output:
www.jntuworld.com
www.jntuworld.com
Experiment No: 2
Block diagram:
Source code:
#include<intel\8051.h>
#include<standard.h>
#define PHASEA 0x09
#define PHASEB 0x0a
#define PHASEC 0x06
#define PHASED 0x05
void main()
{
while(1)
{
P0=PHASEA;
31
www.jntuworld.com
www.jntuworld.com
delay_ms(12);
P0=PHASEB;
delay_ms(12);
P0=PHASEC;
delay_ms(12);
P0=PSHASED;
delay_ms(12);
}
}
Connections:
Connect FRC cable between FRC 1 connector on Mini 51-PE board and FRC 1 connector on
stepper motor driver circuit.
Connect FRC cable between FRC 2 connector on Mini 51-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 , present on main power supply provided along with Mini51-PE
board.
Output:
32
www.jntuworld.com
www.jntuworld.com
Experiment No:3
Block diagram:
Source Code:
#include<intel\8051.h>
#include<standard.h>
#define PHASEA 0x09
#define PHASEB 0x0a
#define PHASEC 0x06
#define PHASED 0x05
void main()
{
while(1)
{
33
www.jntuworld.com
www.jntuworld.com
P0=PHASED;
delay_ms(12);
P0=PHASEC;
delay_ms(12);
P0=PHASEB;
delay_ms(12);
P0=PHASEA;
delay_ms(12);
}
}
Connections:
Connect FRC cable between FRC 1 connector on Mini 51-PE board and FRC 1 connector on
stepper motor driver circuit.
Connect FRC cable between FRC 2 connector on Mini 51-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 , present on main power supply provided along with Mini51-PE
board.
Output:
34
www.jntuworld.com
www.jntuworld.com
Experiment No: 4
Block diagram:
Source code:
#include <Intel\8051.h>
#include <standard.h>
#include <stdio.h>
www.jntuworld.com
www.jntuworld.com
BIT oe P0.0
unsigned char adc_data;
void initser()
{
TH1=0xfd;
TL1=0xfd;
PCON&=0x7f;
SCON=0x50;
TMOD=0x20;
TCON=0x40;
}
void main ()
{
P0=0Xff;
P1=0Xff;
P2=0Xff;
P3=0Xff;
ale=0;
oe=0;
start=0;
initser();
P2=0x02;
ale=1;
delay_ms(60);
ale=0;
while(1)
{
start=1;
delay_ms(60);
start=0;
while(!eoc)
{
}
oe=1;
asm nop
asm nop
asm nop
asm nop
asm nop
adc_data=P3;
oe=0;
36
www.jntuworld.com
www.jntuworld.com
printf("ADC=%bu(ox%bX)\n",adc_data,adc_data);
P1=~adc_data;
delay_ms(1000);
//get char();
}
}
Connections:
Connect FRC cable between FRC2 connector on Mini51-PE board and FRC 2 connector
on ADC Interface Board
Output:
Digital value of corresponding analog input can be seen on LEDs connected to Port 1 of
8051 microcontroller. If by varying the analog input with varying pot, the corresponding digital
value observed on the LEDs.
37
www.jntuworld.com
www.jntuworld.com
Experiment No: 5
Block diagram:
Source code:
#include <Intel\8051.h>
#include <standard.h>
unsigned char g_byData=0;
void main ()
{
while(1)
{
P1=g_byData;
delay_ms(500);
P1=~g_byData;
delay_ms(500);
}
38
www.jntuworld.com
www.jntuworld.com
Connections:
Connect one channel of oscilloscope to TP1 pin onDAC Interface Board and connect
TP2 pin On DAC Interface board to ground pin of oscilloscope.
Output:
39
www.jntuworld.com
www.jntuworld.com
Experiment No: 6
Aim: Write a c language program for the Microcontroller 8051 to generate staircase waveform
using the DAC . DAC is interfaced using Port 2.
Block diagram:
Source code:
#include <Intel\8051.h>
#include<standard.h>
#define DATAPORT P2
unsigned char g_byData;
void main ()
{
while(1)
{
40
www.jntuworld.com
www.jntuworld.com
for(g_byData=0;g_byData<256;g_byData++)
{
DATAPORT = g_byData;
asm nop
}
}
}
Connections :
Connect one channel of oscilloscope to TP1 pin onDAC Interface Board and connect TP2 pin On
DAC Interface board to ground pin of oscilloscope.
Output:
41
www.jntuworld.com
www.jntuworld.com
Experiment No: 7
Block diagram:
Source code:
#include <Intel\8052.h>
#include <standard.h>
unsigned int c,i=201;
void main ()
{
while(1)
{
for(c=0;c<=201;c++)
42
www.jntuworld.com
www.jntuworld.com
{
P2 = c;
delay_ms(1);
if(c == 201)
{
for(i=201;i>=0;i--)
{
P2 = i;
delay_ms(1);
c=0;
}
}
}
}
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.
Output:
43
www.jntuworld.com
www.jntuworld.com
Experiment No: 8
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:
Source code:
#include <Intel\8051.h>
void main ()
{
P1=0x55;
delay_ms(8000);
P1=0xAA;
while(1)
{
}
}
44
www.jntuworld.com
www.jntuworld.com
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.
Output:
45
www.jntuworld.com
www.jntuworld.com
Experiment No: 9
Block diagram:
Source code:
#include <Intel\8051.h>
#include <stdio.h>
#include <standard.h>
BIT R1 P2.0
BIT Y1 P2.1
BIT G1 P2.2
BIT R2 P2.3
BIT Y2 P2.4
BIT G2 P2.5
BIT R3 P2.6
BIT Y3 P2.7
BIT G3 P3.0
46
www.jntuworld.com
www.jntuworld.com
BIT R4 P3.1
BIT Y4 P3.2
BIT G4 P3.3
#define LED_OFF 1
#define LED_ON 0
void Road1Green()
{
G1= LED_ON;
Y1=LED_OFF;
R1=LED_OFF;
GPED1=LED_ON;
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
}
Void Road1Yellow()
{
G1= LED_OFF;
Y1=LED_ON;
R1=LED_OFF;
GPED1=LED_OFF;
47
www.jntuworld.com
www.jntuworld.com
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
}
void Road2Green()
{
G1= LED_OFF;
Y1=LED_OFF;
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_ON;
Y2=LED_OFF;
R2=LED_OFF;
GPED2=LED_ON;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
}
void Road2Yellow()
{
G1= LED_OFF;
Y1=LED_OFF;
48
www.jntuworld.com
www.jntuworld.com
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_OFF;
Y2=LED_ON;
R2=LED_OFF;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
void Road3Green()
{
G1= LED_OFF;
Y1=LED_OFF;
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_ON;
Y3=LED_OFF;
R3=LED_OFF;
GPED3=LED_ON;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
}
49
www.jntuworld.com
www.jntuworld.com
void Road3Yellow()
{
G1= LED_OFF;
Y1=LED_OFF;
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_ON;
R3=LED_OFF;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_OFF;
R4=LED_ON;
GPED4=LED_OFF;
}
void Road4Green()
{
G1= LED_OFF;
Y1=LED_OFF;
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_ON;
Y4=LED_OFF;
R4=LED_OFF;
GPED4=LED_ON;
}
50
www.jntuworld.com
www.jntuworld.com
void Road4Yellow()
{
G1= LED_OFF;
Y1=LED_OFF;
R1=LED_ON;
GPED1=LED_OFF;
G2= LED_OFF;
Y2=LED_OFF;
R2=LED_ON;
GPED2=LED_OFF;
G3= LED_OFF;
Y3=LED_OFF;
R3=LED_ON;
GPED3=LED_OFF;
G4= LED_OFF;
Y4=LED_ON;
R4=LED_OFF;
GPED4=LED_OFF;
}
void main ()
{
while(1)
{
Road1Green();
delay_ms(8000);
Road1Yellow();
delay_ms(8000);
Road2Green();
delay_ms(8000);
Road2Yellow();
delay_ms(8000);
Road3Green();
delay_ms(8000);
51
www.jntuworld.com
www.jntuworld.com
Road3Yellow();
delay_ms(8000);
Road4Green();
delay_ms(8000);
Road4Yellow();
delay_ms(8000);
}
}
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.
Output:
The functionality of traffic light signal has been observed successfully.
52
www.jntuworld.com
www.jntuworld.com
1. Introduction
This is users manual for STK-2148 Trainer Kit based on LPC2148 micro-controller. This
trainer board is designed to perform lab practical and has a facility to download the user
programs into the on-chip flash memory of the micro-controller. It is strongly recommended to
read this manual carefully before you start using the STK-2148 board.
Caution:
This board contains 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. If you want to touch any of the parts, make sure to discharge
yourself to earth. Parts damaged due to ESD are not covered under limited warranty.
2. Getting Started
2.1 SCARM Installation:
1. As a part of the SCARM software package, you should have received a CD. Please insert
it into the CD-ROM drive. Open SPJTools (CD drive), open the folder SCARM and run
the SETUP.EXE
2. If it shows any error then click on Ignore.
3. SCARM Setup window will open, click on NEXT.
4. Accept the software license agreement by clicking on YES.
5. Choose destination location where you want to install the SCARM and click on NEXT.
6. Click NEXT button and installation will start.
7. Click FINISH button to complete the Installation.
8. Now connect the SCARM SPJ Lock to USB port of the computer
9. A pop-up will show Found New Hardware
10. Found New Hardware Wizard window will be open. Select No, not this time option
and click on Next.
11. Now select Install from a list or specific location (Advanced) and click on Next.
12. Browse for the folder drv from C:\SCARM\drv and click on Next.
53
www.jntuworld.com
www.jntuworld.com
13. Now Hardware Installation window will open, click on Continue Anyway.
14. After completion of installation, a message will come the wizard has finished
installing the software for SPJ Lock, now click on Finish.
15. After this you can start using SCARM (Start > All Programs > SPJ-SCARM >
SIDE_ARM). However, we recommend going through this users manual before you
actually start using it. SCARM is C Compiler for ARM. It includes an IDE and other
tools like Debugger, Visual Code Generator (VCG) and Terminal Emulation Utility
(SPJTerm). This document describes steps to create ARM applications in C using the
SCARM.
About Project:
What is a project?
A project is a file in which SIDEARM stores all information related to an application. E.g. it
stores the name of C and/or Assembler source file, 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.
To create a new project, select Project / New Project from the menu.
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.
54
www.jntuworld.com
www.jntuworld.com
3. From Project menu, select New Project. The Open dialog 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.
4. The action in the previous step will display the Project Settings dialog window. This
dialog window has 3 different parts named Compiler Options, 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 ARM 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 Philips as the manufacturer and LPC2148 as the micro-controller.
5. Click on Linker Options to display that part of the dialog window. In this window,
you will see a list of 8 Memory Banks, with names such as Memory #1, Memory
#2 and so on. In your target hardware, there may be none or 1 or more number of
contiguous memory blocks connected to the ARM micro-controller. Check the
appropriate number of memory banks to reflect the targets memory blocks. For each
checked memory bank, specify memory start address (in Hexadecimal) and memory
block size (in decimal). Size maybe specified either in number of Kilobytes (KB) or
Megabytes (MB). Some of the memory blocks maybe read-only (e.g. flash or
conventional EPROM). Accordingly, you may check or uncheck the Read only box.
Based on this information about memory banks, the IDE will automatically create the
Linker Script. This auto-generated script is adequate for most users. However, if you
wish to use your own script file instead of this autogenerated script, you may check the
Use different linker script box and further click on the browse button (marked )
and select appropriate linker script file.
55
www.jntuworld.com
www.jntuworld.com
6. 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 assembly and C projects. To write program in assembly language remove PROG1.c.
To remove PROG1.c, click on it and then click Remove File button. Now the project
contains only startup.asm, click OK button to create this new project. IDE will be
opened and it will show startup.asm file. To write new assembly language program go to
File option and select New File. Write the assembly language program in this file.
For example:
.global main
.p2align 2
.text
main:
forever:
.end-main
7. To save this file go to File option and click on Save. Save this file at the same location
(C:\SPJ). Give the file name same as project name with .asm extension means
PROG1.asm and select All Files (*.*) in the Save as type option. Now to add this
PROG1.asm in the project go to Project Settings Source files. Click on Add File
button and select PROG1.asm. It will be added in the project. Click on OK button. 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.
56
www.jntuworld.com
www.jntuworld.com
8. From the Compile menu, select Build. This will invoke the assembler to assemble the
file PROG1.asm; and further (assuming no errors) invoke the linker to create the .hex
file. 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.
9. You may inspect contents of the folder where your project files reside. When there are
no errors and build has completed successfully and then you will see a filename with
same name as the project name and extension .HEX (in above example, PROG1.hex).
This is the file that you will need to use to program your micro-controller.
10. Start the SIDE_ARM program (i.e. the Integrated Development Environment) from
start\Programs\SPJ-SCARM.
11. From Project menu, select Close project (if any project is open).
12. From Project menu, select New Project. The Open dialog 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.
13. The action in the previous step will display the Project Settings dialog window. This
dialog window has 3 different parts named Compiler Options, 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 ARM 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
57
www.jntuworld.com
www.jntuworld.com
micro-controller is not known or if you cannot find it in the list, then you may simply
select Philips as the manufacturer and LPC2148 as the micro-controller.
14. Click on Linker Options to display that part of the dialog window. In this window,
you will see a list of 8 Memory Banks, with names such as Memory #1, Memory
#2 and so on. In your target hardware, there may be none or 1 or more number of
contiguous memory blocks connected to the ARM micro-controller. Check the
appropriate number of memory banks to reflect the targets memory blocks. For each
checked memory bank, specify memory start address (in Hexadecimal) and memory
block size (in decimal). Size maybe specified either in number of Kilobytes (KB) or
Megabytes (MB). Some of the memory blocks maybe read-only (e.g. flash or
conventional EPROM). Accordingly, you may check or uncheck the Read only box.
Based on this information about memory banks, the IDE will automatically create the
Linker Script. This auto-generated script is adequate for most users. However, if you
wish to use your own script file instead of this autogenerated script, you may check the
Use different linker script box and further click on the browse button (marked )
and select appropriate linker script file.
15. 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
neither create/overwrite it nor 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.
16. 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
58
www.jntuworld.com
www.jntuworld.com
that you may haveadded 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.
17. 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 file. 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.
18. You may inspect contents of the folder where your project files reside. When there are
no errors and build has completed successfully and then you will see a filename with
same name as the project name and extension .HEX (in above example, PROG1.HEX).
This is the file that you will need to use to program your micro-controller.
3. Hardware Description
3.1 STK-2148:
Unpacking:
STK-2148 board.
Serial communication cable (Straight 9-Pin).
Power adaptor with cable.
SPJETs CD-ROM.
The power adaptor works with 230Volts AC. It produces approximately 9 Volts DC, and the
STK-2148 uses onboard regulators to provide 5 Volts, 3.3 Volts and 1.8 Volts DC to all
components on the board.
59
www.jntuworld.com
www.jntuworld.com
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 one end of the
serial cable to UART0 of STK-2148 board and other end to PCs serial port.
Powering ON:
After connecting the serial communication cable as described above, you may insert the power
adaptor output jack into the on-board power socket. Plug the power adaptor into 230VAC mains
outlet and turn it on. The power-on indication Green LED will turn on.
Caution:
Please do not connect or disconnect the serial communication cable while the board is powered
ON. Doing so can damage the serial port of the STK-2148 board and/or PC.
60
www.jntuworld.com
www.jntuworld.com
Below figure shows the locations of different components on the STK-2148 board.
61
www.jntuworld.com
www.jntuworld.com
Below figure shows the locations of different switches on the STK-2148 board.
62
www.jntuworld.com
www.jntuworld.com
S1: Turn ON this switch to connect UART1 connector to UART1 lines (TxD1/P0.8 and
RxD1/P0.9) of LPC2148.
S2: Mode selection switch. The LPC21xx micro-controllers include on-chip flash for storing
user program and non-volatile data. The LPC2148 have 512KBytes flash. This flash is In-
System-Programmable (ISP). The LPC21xx micro-controllers have a built-in boot-load program.
Upon power-on, this bootload program takes control; it passes control to the user program if pin
P0.14 is HIGH and some other conditions are satisfied. Please refer to the LPC21xx data-sheet
for further details. On the STK-2148 board, the P0.14 pin is made available on this S3 switch.
Turn ON this switch to control the Mode (ISP mode or Run mode) by Flash Magic.
S3: Turn ON this switch to connect USB device connector to USB lines of LPC2148.
S5: Turn ON this switch to connect I2C peripherals (Seven Segments, RTC (DS1307) and
EEPROM (AT24C512)) to I2C lines (SCL0/P0.2 and SDA0/P0.3) of LPC2148.
S6.3: Turn ON this switch to connect switch SW25 to EINT0/P0.16 of LPC2148. P0.16 is
External Interrupt 0 pin of LPC2148.
S7: Turn ON this switch to connect SPI EEPROM (AT25256) to SPI lines (SCK0/P0.4,
MISO0/P0.5, MOSI0/P0.6 and CS/P0.7) of LPC2148.
S11: Turn ON this switch to connect Stepper Motor to P0.10, P0.11, P0.12 and P0.13 of
LPC2148.
S13.2: Turn ON this switch to enable 8 LEDs connected to P0.10 (D9), P0.11 (D10), P0.12
(D11), P0.13 (D12), P0.18 (D13), P0.19 (D14), P0.20 (D15) and P0.21 (D16) of LPC2148.
63
www.jntuworld.com
www.jntuworld.com
64
www.jntuworld.com
www.jntuworld.com
UART0:
This is a DB9 female connector, used for RS232 serial communication with the PC:
Pin 5 = Ground
UART1:
This is a DB9 female connector, used for RS232 serial communication with the PC:
Pin 5 = Ground
16x2 LCD:
This is a 16 pin, single line connector, designed for connection to standard, text LCD modules.
The pin/signal correspondence is designed to be matching with that required by such LCD
modules.
Pin 1 = GND
Pin 2 = +5V
Pin 3 = Vlcd
www.jntuworld.com
www.jntuworld.com
Pin 5 = GND
Pin 7 to 10 = No Connection/GND
Pin 15 = Backlighting
Pin 16 = GND
This is a 20 pin, single line connector, designed for connection to standard, 128x64 Monochrome
Graphics LCD modules. The pin/signal correspondence is designed to be matching with that
required by such LCD modules.
Pin 1 = GND
Pin 2 = +5V
Pin 3 = Vlcd
66
www.jntuworld.com
www.jntuworld.com
Pin 17 =
Pin 18 =
Pin 19 = +5V
Pin 20 = GND
JTAG Connector:
This standard 20 pin JTAG connector provides debugging support for the LPC21xx. This
connector is mounted on top side of the board as shown in figure1. JTAG cables like SJT-S or
SJT-U can be connected to this connector, while other end of the cable can be connected to PC
COM port or USB port, respectively.
Debugger software (like the debugger built into SCARM) allows JTAG based debugging. It is
also possible to use third party JTAG based emulators /debuggers.
67
www.jntuworld.com
www.jntuworld.com
J6: This is 26 pin dual line headers. It brings out I/O and most of the pins of the LPC21xx micro-
controller. Further, 5V and GND are also made available on these connectors. These connectors
are intended for use to connect external peripherals.
68
www.jntuworld.com
www.jntuworld.com
The LPC21xx micro-controllers include on-chip flash for storing user program and non-volatile
data. LPC2148 on STK-2148 have 512KBytes flash. This flash is In-System-Programmable
(ISP). Therefore it is possible to download user program into on-chip flash of LPC2148, through
serial port connected to PC. For doing so, a certain position of S2 switch is required. S2 Switch
should be continuously ON. This section describes how to use the software Flash Magic to
download program into LPC2148.
The CD you have received with this board contains SCARM, C Compiler for ARM. Install it.
After installation go to folder C:\SCARM\Utilities. This folder contains 5 zip files. Install Flash
Magic from FlashMagic3.71.zip. Extract the FlashMagic3.71.zip and then run FlashMagic.exe
from the extracted files. (If you have wrong version of Flash Magic already installed, then please
uninstall it first and then install new version).
5.2 Download and Run program using Flash Magic into LPC2148:
69
www.jntuworld.com
www.jntuworld.com
3. Do proper settings in Flash Magic (COM Port: COM1 (if other choose it), Baud
Rate: 38400, Device: LPC2148, Interface: None (ISP), Enable Erase blocks used
by Hex File, Browse the file which you want to download) and click on Start
button.
4. Flash Magic will download the program. Wait till Finished comes.
5. After downloading Flash Magic automatically resets the STK-2148 board and
program executes. You can see output according to the program.
6. If again you want to Reset the board then press RST switch on SM2148 board.
You can see output according to the program.
Note: Flash Magic can be used to download the program into other Philips Microcontrollers also.
See the list in Flash Magic itself.
70
www.jntuworld.com
www.jntuworld.com
6.2 Contents:
The JTAG cable draws power from the target board. Thus it does not require a separate power
source.
SJT-S: There is a DB9 female connector on one end of the dongle. This directly mates with the
PC COM port which has a DB9 male connector (or you can connect yellow color serial cable,
supplied with SJT-S or STK-2148 board, between DB9 female connector on one end of the
dongle and PC COM port which has a DB9 male connector). The other end of the dongle has
DB25 female connector. There is a DB25 male connector on one end of the cable. These DB25
female and DB25 male connectors are designed to mate with each other directly. The other end
of the cable has a 20-pin header. This should be connected to the JTAG connector of the target
board.
Caution:
The JTAG Cable must not be connected or dis-connected when power is applied to the target
board. Turn off power to the target board, connect the JTAG Cable and then you may turn on
power to the target board. Connecting the JTAG Cable with incorrect polarity / orientation may
permanently damage the STK- 2148 board and/or the JTAG Cable. It will also make the
warranty void for both the products.
71
www.jntuworld.com
www.jntuworld.com
When the JTAG Cable is correctly connected to PC as well as the target board, it serves as a link
between the JTAG port of target processor and the PC. This link is used by SPJ - SCARM
software Tools (e.g. Debugger for ARM microcontrollers). This software tool, Debugger will
work correctly only when the JTAG Cable is connected correctly.
For SJT-S:
There is a crude test to verify SJT-S JTAG Cable connection. You may please follow these steps:
1. Connect JTAG Cable between PC COM port and JTAG connector on STK-2148, as per
instructions in this manual.
2. Turn ON power to the target board.
3. On the PC, run SPJ Terminal software.
4. In the Port Settings, select appropriate COM port (to which the JTAG cable is
connected). Select 115200 baud, no parity, 8 bits per char, 1 stop bit and no flow control.
5. Open the COM Port connection.
6. Type character V in the terminal window. I.e. send the character V to the PC COM
port.
7. If the JTAG Cable connection is correct, it will send version of JTAG cable. As a result,
you will see that version appearing in the terminal window. This indicates that JTAG
Cable connection is ok.
8. If you dont see any character in the terminal window, probably the JTAG Cable is not
connected appropriately.
72
www.jntuworld.com
www.jntuworld.com
7. To stop program go to Run -> Stop. Now you can insert breakpoint and say Run.
8. You can use all the functions visible in Run option.
9. In variable watch window you can see only global variables.
10. If you have declared any global variables then find their addresses from .map file.
11. Insert these addresses in variable watch window and you can see global variables also.
73
www.jntuworld.com
www.jntuworld.com
Experiment No: 1
Block diagram:
Source code:
#include <Philips\LPC2148.h>
unsigned int delay
void main ( )
{
IO0DIR = 0x02000000 ;
while(1)
{
IO0SET = 0x02000000 ;
for(delay=0;delay<30000;delay++);
IO0CLR = 0x02000000 ;
for(delay=0;delay<30000;delay++);
}
74
www.jntuworld.com
www.jntuworld.com
Connections:
Output:
75
www.jntuworld.com
www.jntuworld.com
Experiment No: 2
Block diagram:
Source code:
#include <Philips\LPC2148.h>
unsigned int i;
void main ()
{
IO0DIR = 0x003C3C00 ;
IO0SET = 0x003C3C00 ;
while(1)
{
for(i=0;i<30000;i++)
{
}
IO0SET = 0x000C0000 ;
for(i=0;i<30000;i++)
76
www.jntuworld.com
www.jntuworld.com
{
}
IO0CLR = 0x000C0000 ;
}
}
Connections:
Keep S13.2 switch in ON position to see relay conditions (ON or OFF) on LEDs (D13 to
D14).Keep S12 switch in ON position. S12.1 is connected to RLY1 and S12.2 is connected to
RLY2.RLY1 and RLY2 are connected to P0.18 and P0.19 respectively through LEDs D13 and
D14.
Output:
Note: Keep S13.2 and S12 switches in OFF position, after execution of program.
77
www.jntuworld.com
www.jntuworld.com
Experiment No: 3
Block diagram:
Source code:
#include <Philips\LPC2148.h>
#define PHASEA 0x00002400
#define PHASEB 0x00001400
#define PHASEC 0x00001800
#define PHASED 0x00002800
unsigned int delay ;
void main ()
{
PINSEL0 = 0x00000000; PINSEL1 = 0x00000000 ;
IO0DIR = 0x003C3C00; IO0SET = 0x003C0000 ;
while(1)
{
78
www.jntuworld.com
www.jntuworld.com
IO0SET = PHASEB ;
IO0CLR = (~PHASEB) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
IO0SET = PHASEC ;
IO0CLR = (~PHASEC) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
IO0SET = PHASED ;
IO0CLR = (~PHASED) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
}
}
Connections:
Keep S13.2 switch in ON position to see stepper motor phases on LEDs (D9 to D12).
Keep S11 switch in ON position. Stepper Motor is connected to P0.10, P0.11, P0.12 and P0.13
through LEDs D9 to D12.
Output:
we observed that the stepper motor moving in a clockwise direction and corresponding
phase changes are observed on LEDs D9 to D12.
Note: Keep S13.2 and S11 switches in OFF position to save power, after execution of program.
79
www.jntuworld.com
www.jntuworld.com
Experiment No: 4
Block diagram:
Source code:
#include <Philips\LPC2148.h>
#define PHASEA 0x00002400
#define PHASEB 0x00001400
#define PHASEC 0x00001800
#define PHASED 0x00002800
unsigned int delay ;
void main ()
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
IO0DIR = 0x003C3C00;
IO0SET = 0x003C0000;
while(1)
80
www.jntuworld.com
www.jntuworld.com
{
// Move stepper motor in anticlockwise direction
IO0SET = PHASED ;
IO0CLR = (~PHASED) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
IO0SET = PHASEC ;
IO0CLR = (~PHASEC) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
IO0SET = PHASEB ;
IO0CLR = (~PHASEB) & 0x00003C00 ;
for(delay=0; delay<30000; delay++)
IO0SET = PHASEA ;
IO0CLR = (~PHASEA) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;
}
}
Connections:
Keep S13.2 switch in ON position to see stepper motor phases on LEDs (D9 to D12).
Keep S11 switch in ON position. Stepper Motor is connected to P0.10, P0.11, P0.12 and P0.13
through LEDs D9 to D12.
Output:
we observed that the stepper motor moving in a anti clock wise direction and
corresponding phase changes are observed on LEDs D9 to D12.
Note: Keep S13.2 and S11 switches in OFF position to save power, after execution of program.
81
www.jntuworld.com
www.jntuworld.com
Experiment No: 5
Block diagram:
Source code:
#include <Philips\LPC2148.h>
#include <stdio.h>
#include "KBD.h"
#include "lcd.h"
int i8ch ;
char szTemp[16] ;
while(1)
{
82
www.jntuworld.com
www.jntuworld.com
i8ch = KBD_rdkbd() ;
sprintf(szTemp,"KeyCode = %02X",i8ch);
DisplayRow(2,szTemp) ;
}
}
Connections:
16 Keys (SW9 to SW25) present in 4x4 Matrix Keypad region on STK-2148 are
connected to P1.16 to P1.23.
Output:
In this program after pressing any key from SW9 to SW24, its code is displayed on 16x2
Text LCD.
83
www.jntuworld.com
www.jntuworld.com
Experiment No: 6
Block diagram:
Source code:
#include <Philips\LPC2148.h>
#include <stdio.h>
#include "LCD.h"
char adcreading[16] ;
www.jntuworld.com
www.jntuworld.com
}
return((adcdata >> 6) & 0x3ff) ; // Return 10 bit result
}
int main (void)
{
unsigned int delay, adc;
ADC_Init() ;
LcdInit();
DisplayRow(1,"ADC Test");
while(1)
{
adc = ADC_GetAdcReading();
sprintf(adcreading,"ADC0 CH1= 0x%03X",adc);
DisplayRow(2,adcreading) ;
for(delay=0;delay<60000;delay++);
}
}
Connections:
To give analog input from Potentiometer R20 present in Analog Input region on STK-
2148 keep S4.1 in ON position. To give external analog input, keep S4.1 in OFF position and
connect external analog input to pin 1 of AIN_EXT connector. Analog input range is from 0 to
3.3V.
Output:
We observed that digital reading of the corresponding analog input on 16x2 Text LCD.
85
www.jntuworld.com
www.jntuworld.com
Experiment No: 7
Block diagram:
Source code:
#include <Philips\LPC2148.h>
#include <stdio.h>
char adcreading[16] ;
void ADC_Init (void)
{
PINSEL1 = 0x04000000 ;
}
unsigned int ADC_GetAdcReading ()
{
unsigned int adcdata;
ADCR = 0x01200304 ;
86
www.jntuworld.com
www.jntuworld.com
Connections:
To interface LM35 (present in Analog Input region on STK-2148) with AD0.2 keep S4.2
in ON position.
Output:
87
www.jntuworld.com
www.jntuworld.com
Experiment No: 8
Block diagram:
Source Code:
#include <Philips\LPC2138.h>
#include <Stdio.h>
#include "sevenseg.h"
I2C0CONCLR = 0x6C;
I2C0CONSET = 0x40;
I2C0SCLH = 60;
I2C0SCLL = 60;
}
88
www.jntuworld.com
www.jntuworld.com
void main(void)
{
I2C_Init();
while(1)
{
SevenSeg(DISPLAY_7, DISPLAY_2);
}
}
89
www.jntuworld.com
www.jntuworld.com
Connections:
Output:
90
www.jntuworld.com
www.jntuworld.com
Experiment No: 9
Block diagram:
SOURCE CODE:
#include <Philips\LPC2148.h>
#include <stdio.h>
#include "Type.h"
#include "Configuration.h"
#include "UART0.h"
#include "Utils.h"
#include "GLCDInit.H"
#include "GLCDUtils.H"
91
www.jntuworld.com
www.jntuworld.com
InitSystem();
MicroDelay(300000);
GlcdInit();
GoToXY(1,1);
ClrScr() ;
GoToXY(1,1);
GlcdPuts(" SPJ Embedded \nTechnologies Pvt.Ltd.");
GoToXY(10,21);
GlcdPuts("www.spjsystems.com");
MicroDelay(300000);// LCD Setup delay
ClrScr() ;
while(1)
{
MicroDelay(100);
for(x=1;x<=16;x++)
{
GoToXY(x,21);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
{
GoToXY(16,y);
GLCDPutPixel(1);
}
for(x=16;x<=32;x++)
{
GoToXY(x,37);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
92
www.jntuworld.com
www.jntuworld.com
{
GoToXY(32,y);
GLCDPutPixel(1);
}
for(x=32;x<=48;x++)
{
GoToXY(x,21);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
{
GoToXY(48,y);
GLCDPutPixel(1);
}
for(x=48;x<=64;x++)
{
GoToXY(x,37);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
{
GoToXY(64,y);
GLCDPutPixel(1);
}
for(x=64;x<=80;x++)
{
GoToXY(x,21);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
93
www.jntuworld.com
www.jntuworld.com
{
GoToXY(80,y);
GLCDPutPixel(1);
}
for(x=80;x<=96;x++)
{
GoToXY(x,37);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
{
GoToXY(96,y);
GLCDPutPixel(1);
}
for(x=96;x<=112;x++)
{
GoToXY(x,21);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
{
GoToXY(112,y);
GLCDPutPixel(1);
}
for(x=112;x<=128;x++)
{
GoToXY(x,37);
GLCDPutPixel(1);
}
for(y=21;y<=37;y++)
94
www.jntuworld.com
www.jntuworld.com
{
GoToXY(128,y);
GLCDPutPixel(1);
}
}
}
Connections:
Output:
It is observed that, message displayed on Graphics LCD. After message square wave
appeared on graphic lcd
Note: Keep S13.1 switch in OFF position to save power, after execution of program.
95
www.jntuworld.com
www.jntuworld.com
Experiment No: 10
Block diagram:
Source Code:
#include <Philips\LPC2148.h>
#include "Elevator.h"
96
www.jntuworld.com
www.jntuworld.com
97
www.jntuworld.com
www.jntuworld.com
code = LED_FLOOR3 ;
break;
}
}
98
www.jntuworld.com
www.jntuworld.com
GroundFloorOff() ;
FirstFloorOff() ;
SecondFloorOff() ;
break;
}
}
99
www.jntuworld.com
www.jntuworld.com
{
break;
}
}
g_bytempnum = num ;
}
Keep S13.1 switch in ON position to see the output on LEDs (D9 to D12).
Output:
The Moment of Elevator from one floor to another floor is observed on LEDs D9 to D12.
100
www.jntuworld.com