ES Lab Manual

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 117

Department Of

ELECTRONICS AND
COMMUNICATION ENGINEERING

EMBEDDED SYSTEMS LAB MANUAL


M.Tech (VLSI-ES) I Year II Semester

Prepared By
B.LAKSHMI
Asst.ProF, ECE Dept..,RKCE

RK COLLEGE OF ENGINEERING
KETHANAKONDA, IBRAHIMPATNAM,
VIJAYAWADA – 521 456(A. P.)

i
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
RK COLLEGE OF ENGINEERING,
(Approved by AICTE, Affiliated to J N T U, KAKINADA.)
Ibrahimpatnam, VIJAYAWADA

CERTIFICATE

This is to certify that Mr./Ms/Mrs _______________________________________ Roll


No___________________Year___________Semister_________Department __________________
Has successfully completed all the experiments in the subject_________________________
Prescribed by JNTUH during the academic year _____________.

Faculty Incharge Head of The Department

ii
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.

An embedded system is a special-purpose computer system designed to perform one or a few


dedicated functions, often with real-time computing constraints. It is usually embedded as part of a complete
device including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal
computer, can do many different tasks depending on programming. Embedded systems have become very
important today as they control many of the common devices we use.

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
INTRODUCTION ABOUT LAB

There are 66 systems installed in this Lab. Their configurations are as follows :

ARM -926WITH PERFECTRTOS&ARM-


CORTEX
Processor :
RAM : 512 MB
Hard Disk : 120 GB
Mouse : Optical Mouse
Network Interface card : Present

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
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 student’s groups should be maintained neatly and to be
returned after the experiment.

v
Description about ES Concepts:

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
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

5. LCD DISPLAY (16X2) 28


6. STEPPER MOTOR CLOCK WISE 31
7. STEPPER MOTOR ANTI-CLOCK WISE 33
8. ADC 35
9. DAC-SQUARE WAVE 38
10. DAC-STAIR CASE 40
11. DAC-TRIANGULAR 42
12. DATA ON PORT 44
13. TRAFFIC LIGHT CONTROL 46

Vii
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
RK COLLEGE OF ENGINEERING

Embedded Systems Lab Manual, M.Tech VLSI-ES

Introduction
This is user‟s 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.

Creating „C‟ applications for 8051: Quick Start


1. Start the SIDE51 program (i.e. the Integrated Development Environment)

2. From Project menu, select Close project.

3. From Project menu, select New Project. 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
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
actionand 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.

2
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 it‟s 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.

3
Creating „C‟ applications for 8051: In Detail

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

1 Starting the IDE (SIDE51):


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

4

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.

5


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

6
“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.

7

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

8
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.

9

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.

Here we write a program for serial communication.

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

Description:

2 Using the Visual Code Generator (VCG):



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


10




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


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

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

13


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.

3 Why use while (1) :


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

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

while (1)
{
}

If the application demands some actions to be performed all time then the while loop will be as
follows

while (1)
{
/* Action to be performed continuously */
}
14
Typical „C‟ program

#include <8051.h>
/* Other includes */
/* Global variable declaration
*/ /* function prototypes */

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

void func1(char ch1)


{
/* Program structure */
}
void main ()
{
/* Calling Initialization routines */
/* Call functions which are to be executed only once */
while (1)
{
/* Call functions to be executed all time */
}
}


From the Compile menu, select Build

15

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

 
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
4 Using the Simulator:


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.

18


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

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

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

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
VariablesWatch Window and selectAddfrom the pop-up menu. Select the desired variable(s) to
watchand 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

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
Downloading and Running User Programs

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.

Download program using Flash Magic into P89V51RD2:


Install Flash Magic from CD. After installation, open it.
In Flash Magic go to Options -> Advanced Options-> Hardware Config.
Disable “Use DTR and RTS to control RST and PSEN”. Click on OK.

To download program follow the steps as below:

1. Connect power supply.

2. Keep the board in switched off mode.

3. Connect the RS232 port (9-Pin D type Male connector) of Mini51-PE, to COM1 or COM2 of
a PC, using the serial communication cable (supplied with the board).

4. Start Flash Magic. You will get the screen as below (Flash magic version 3.42.179)

24
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
onthe flash of P89V51RD2.
DO NOT SELECT: Fill unused Flash, this will consume lot of time in
programming.DO NOT SELECT: Gen Block checksums.
DO NOT SELECT: Prog Clocks Bit

8. Click on Browse button.


25
9. Use the browse option to go to the required directory.

10. Click on the hex file you want to download to the target hardware.

11. Click on open button. Once you do this the file will be selected in the Flash Magic.

12. Click on the Start button. Following message will be displayed:

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.

26
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
RK COLLEGE OF ENGINEERNG
Embedded Systems Lab Manual, M.Tech VLSI-ES

Experiment No: 1

To develop and execute the program to interface 16x2 LCD display


to the Microcontroller 8051

Aim:Write a „C‟ language program for Microcontroller 8051 to display message


“GNITWELCOMES U” On 16x2 LCD

Equipment:SC51, PC, Mini51-PE, LCD Interface Board

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
asm nop
asm nop
EN=0;
}

void lcd_dat(unsigned char p_byData)


{
RS=1;
RW=0;
DATAPORT = p_byData;
EN=1;
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);
}

void display_row(unsigned char p_byRow, unsigned char p_byDataArr[16])


{
unsigned char count, ch;
if(p_byRow)
lcd_cmd (0xc0);

29
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:

GNIT WELCOMES U has been displayed on LCD.


30
Experiment No: 2

To develop and execute the program to interface stepper motor to


the Microcontroller 8051.
Aim:Write a „c‟language program for the Microcontroller 8051 to rotate stepper
motorcontinuously in clock-wise direction . Motor is interfaced through Port 0 of
Microcontroller 8051.

Equipment: SC51 , PC , Mini51-PE , stepper motor driver circuit , stepper motor.

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
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:

It is been observed that Stepper motor is rotating in clock wise direction.

32
Experiment No:3

To develop and execute the program to interface stepper motor to


the Microcontroller 8051.
Aim:Write a „c‟language program for the Microcontroller 8051 to rotate stepper
motorcontinuously in anticlock-wise direction . Motor is interfaced through Port 0 of
Microcontroller
8051.
Equipment:SC51 , PC , Mini51-PE , stepper motor driver circuit , stepper motor.

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
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:

It is been observed that Stepper motor is rotating in anti-clock wise direction.

34
Experiment No: 4

To develop and execute the program to interface ADC 0809 to


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.

Equipment:SC 51, PC , Mini51-PE , ADC Interface Board , SDI08.

Block diagram:

Source code:

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

BIT start P0.1


BIT ale P0.2
BIT eoc P0.4
35
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
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
Experiment No: 5

To develop and execute the program to interface DAC 0808 to the


Microcontroller 8051.DAC (SQUARE)

Aim:Write a „c‟ language program for the Microcontroller 8051 to generate square
waveformusing the DAC . DAC is interfaced using Port 2.

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

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
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:

The square waveform is observed on oscilloscope.

39
Experiment No: 6

To develop and execute the program to interface DAC 0808 to the


Microcontroller 8051.DAC (STAIRCASE)

Aim:Write a „c‟ language program for the Microcontroller 8051 to generate staircase
waveformusing the DAC . DAC is interfaced using Port 2.

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

Block diagram:

Source code:

#include <Intel\8051.h>
#include<standard.h>
#define DATAPORT P2
unsigned char g_byData;

void main ()
{
while(1)
{
40
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:

The staircase waveform is observed on oscilloscope.

41
Experiment No: 7

To develop and execute the program to interface DAC 0808 to the


Microcontroller 8051.DAC (TRIANGULAR)

Aim:Write a „c‟ language program for the Microcontroller 8051 to generate triangularwaveform
using the DAC . DAC is interfaced using Port2.

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

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
{
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:

The triangular waveform is observed on oscilloscope.

43
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.

Equipment:SC51 , PC , Mini51-PE , , CRO.

Block diagram:

Source code:

#include <Intel\8051.h>
void main ()
{

P1=0x55;
delay_ms(8000);
P1=0xAA;
while(1)
{
}
}

44
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 Data is ported out successfully and observed on connected LED‟s.

45
Experiment No: 9

To develop and execute the program to TRAFFIC LIGHT CONTROL


Aim:Write a „c‟ language program for the Microcontroller 8051 to traffic light control

Equipment:SC51, PC, Mini51-PE, CRO.

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
BIT R4 P3.1
BIT Y4 P3.2
BIT G4 P3.3

BIT GPED1 P3.4


BIT GPED2 P3.5
BIT GPED3 P3.6
BIT GPED4 P3.7

#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
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
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
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
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
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
1. Introduction
This is user‟s 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
13. Now Hardware Installation window will open, click on Continue Anyway.
14. After completion of installation, a message will come the wizard has finishedinstalling
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 user‟s manual before
youactually 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.

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.

2.2 Quick start to create assembly language applications:

1. Start the SIDE_ARM program (i.e. the Integrated Development Environment) from
start\Programs\SPJ-SCARM\SIDE_ARM.
2. From Project menu, select Close project (if any project is open).

54
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
“CompilerOptions” will be automatically displayed. If the target micro-controller (must
be amember 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 target‟s 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
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
forall 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:

-----------write program here -----------

forever:

-----------write program here -----------

b forever @ branch unconditionally to label

.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
thisPROG1.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
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.

2.3 Quick start to create „C‟ language applications:

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
“CompilerOptions” will be automatically displayed. If the target micro-controller (must
be amember 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
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 target‟s 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
isrequired 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
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:

You will find following items in the package:


 
 STK-2148 board.
 
 Serial communication cable (Straight 9-Pin).
 
 Power adaptor with cable.
 
SPJETs‟ CD-ROM.

Power Supply Requirements:

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
Connecting the system:

The serial communication cable supplied with the board should be used to connect the board to a
PC running Windows95/98/NT/ ME/2000/XP/Vista Operating System. Connect 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
4. Connector Details, Jumper and Switch Settings
4.1 STK-2148 Block Diagram:

Below figure shows the locations of different components on the STK-2148 board.

61
Below figure shows the locations of different switches on the STK-2148 board.

62
4.2 DIP Switches Details:

S1: Turn ON this switch to connect UART1 connector to UART1 lines (TxD1/P0.8
andRxD1/P0.9) of LPC2148.

S2: Mode selection switch. The LPC21xx micro-controllers include on-chip flash for storinguser
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.

S4.1: Turn ON this switch to connect POT (R20) to ADC0.1/P0.28 of LPC2148.

S4.2: Turn ON this switch to connect LM35 to ADC0.2/P0.29 of LPC2148.

S5: Turn ON this switch to connect I2C peripherals (Seven Segments, RTC (DS1307)
andEEPROM (AT24C512)) to I2C lines (SCL0/P0.2 and SDA0/P0.3) of LPC2148.

S6.1: Turn ON this switch to connect Buzzer to P0.25 of LPC2148.

S6.2: Turn ON this switch to connect DAC/TP7 to DACOut/P0.25 of LPC2148.

S6.3: Turn ON this switch to connect switch SW25 to EINT0/P0.16 of LPC2148. P0.16
isExternal 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
ofLPC2148.

S12.1: Turn ON this switch to connect Relay 1 to P0.18 of LPC2148.

S12.2: Turn ON this switch to connect Relay 2 to P0.19 of LPC2148.

S13.1: Turn ON this switch to enable 128x64 Graphics LCD.

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
4.3 Push-Button Switches Details

4.4 LEDs and Buzzer Details:

64
4.5 Connector Details:

UART0:

This is a DB9 female connector, used for RS232 serial communication with the PC:

Pin 2 = UART0 RS232 TxD (output of μC)

Pin 3 = UART0 RS232 RxD (input to μC)

Pin 4 = RS232 DTR

Pin 5 = Ground

Pin 7 = RS232 RTS

All other pins of J1/UART0 are unused.

UART1:

This is a DB9 female connector, used for RS232 serial communication with the PC:

Pin 2 = UART1 RS232 TxD (output of μC)

Pin 3 = UART1 RS232 RxD (input to μC)

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

Pin 4 = P1.25 (Used as RS of LCD)


65
Pin 5 = GND

Pin 6 = P1.24 (Used as EN of LCD)

Pin 7 to 10 = No Connection/GND

Pin 11 = P0.15 (Used as D4 of LCD)

Pin 12 = P0.17 (Used as D5 of LCD)

Pin 13 = P0.22 (Used as D6 of LCD)

Pin 14 = P0.30 (Used as D7 of LCD)

Pin 15 = Backlighting

Pin 16 = GND

128x64 Graphics LCD:

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

Pin 4 = P1.25 (Used as RS of GLCD)

Pin 5 = P0.15 (Used as RW of GLCD)

Pin 6 = P1.24 (Used as EN of GLCD)

Pin 7 = P0.10 (Used as D0 of GLCD)

Pin 8 = P0.11 (Used as D1 of GLCD)

66
Pin 9 = P0.12 (Used as D2 of GLCD)

Pin 10 = P0.13 (Used as D3 of GLCD)

Pin 11 = P0.18 (Used as D4 of GLCD)

Pin 12 = P0.19 (Used as D5 of GLCD)

Pin 13 = P0.20 (Used as D6 of GLCD)

Pin 14 = P0.21 (Used as D7 of GLCD)

Pin 15 = P0.22 (Used as CS1 of GLCD)

Pin 16 = P0.30 (Used as CS2 of GLCD)

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
orSJT-U can be connected to this connector, while other end of the cable can be connected to
PCCOM 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
The pin-out of JTAG Connector is given below:

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.

The pin/signal details of J6 are as below:

68
5. Downloading and Running User Programs

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
Switchshould be continuously ON. This section describes how to use the software Flash Magic
to
download program into LPC2148.

5.1 How to install Flash Magic:

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:
 
 After installation of Flash Magic, open it.

 High
In Flash Magic go to Options -> Advanced Options-> Communications. Check
 Speed Communications and keep Maximum Baud Rate as 19200. Click on OK.

Again in Flash Magic go to Options -> Advanced Options-> Hardware Config. “Use
 DTR and RTS to control RST and P0.14” option should be checked. Click on OK. (After
doing above mentioned settings, Flash Magic stores it means for the next time just verify
if these setting are proper or not. If they are proper then you can directly follow below

 mentioned procedure)
1. Connect the J2/UART0 connector of STK-2148 board to COM1 or COM2 of a
PC, using the serial communication cable (supplied with the board).
2. Keep S2 switch in ON position. (You can keep S2 switch continuously ON)
Switch ON power to the STK-2148.

69
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
6. JTAG Cable for Debugging
6.1 Type:

SJT-S: Serial JTAG Cable.

6.2 Contents:

The “JTAG Cable” consists of following parts:


 
 Dongle (a small box with connectors on both ends).
 
Cable.

The “dongle” consists of some electronic circuit for interfacing the JTAG port of target processor
to the host computer. The cable is a bunch of wires to connect the dongle with the JTAG port of
target.

6.3 Power Supply Requirements:

The JTAG cable draws power from the target board. Thus it does not require a separate power
source.

6.4 Connecting JTAG Cable:

SJT-S: There is a DB9 female connector on one end of the dongle. This directly mates with
thePC 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
6.5 Verifying correct cable connection:

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 don‟t see any character in the terminal window, probably the JTAG Cable is not
connected appropriately.

6.6 How to Debug Program:

1. Connect SJT-S as mentioned above.


2. Open project in SIDEARM. Rebuild it.
3. Download the same code in the target board.
4. In SIDEARM go to Tools -> Debugger.
5. In Debugger go to Run -> Click on “Not connected to target (click here to connect)”.
6. Device ID starting from 0x4........ will be displayed and program will run.

72
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
RK COLLEGE OF ENGINEERING
Embedded Systems Lab Manual, M.Tech VLSI-ES

Experiment No: 1

Write a C language program for Buzzer interface


Aim:Write a program for buzzer interface.

Equipments:SCARM, PC, STK-2148.

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
Connections:

Keep S6.1 switch in ON position.Buzzer is connected to P0.25.

Output:

It is observed that Buzzer is turn ON and OFF.

Note: Keep S6.1 switch in OFF position, after execution of program.

75
Experiment No: 2

Write a C language program for Relay interface


Aim:Write a program to interface 2 relays with LPC2148.

Equipments:SCARM, PC, STK-2148.

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
{
}
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:

It is observed that Relays become ON and OFF continuously.

Note: Keep S13.2 and S12 switches in OFF position, after execution of program.

77
Experiment No: 3

Write a C language program for stepper motor interface in clock


wise direction
Aim:Write a program to interface stepper motor interface in clock wise direction

Equipments:SCARM, PC, STK-2148 with Stepper Motor.

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
// Move stepper motor in clockwise direction
IO0SET = PHASEA ;
IO0CLR = (~PHASEA) & 0x00003C00 ;
for(delay=0; delay<30000; delay++) ;

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
Experiment No: 4

Write a C language program for stepper motor interface in anti


clock wise direction
Aim:Write a program to interface stepper motor interface in anti clock wise direction

Equipments:SCARM, PC, STK-2148 with Stepper Motor.

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
{
// 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
Experiment No: 5

Write a C language program for 4*4 Matrix Keypad Interface


Aim:Write a program to interface 4*4 matrix keypad

Equipments:SCARM, PC, STK-2148.

Block diagram:

Source code:

#include <Philips\LPC2148.h>
#include <stdio.h>
#include "KBD.h"
#include "lcd.h"
int i8ch ;
char szTemp[16] ;

void main (void)


{
cdInit(); DisplayRow(1,"Keypad
Test ");
DisplayRow(2,"Press Any Key ");

while(1)
{
82
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
Experiment No: 6

Write a C language program for on-chip Analog to Digital


Conversion.
Aim:Write a program for on-chip ADC (ADC 0, Channel 1, P0.28).

Equipments:SCARM, PC, STK-2148.

Block diagram:

Source code:

#include <Philips\LPC2148.h>
#include <stdio.h>
#include "LCD.h"
char adcreading[16] ;

void ADC_Init (void)


{
PINSEL1 = 0x01000000 ;
}
unsigned int ADC_GetAdcReading ()
{
unsigned int adcdata;
ADCR = 0x01200302 ;
while(!((adcdata = ADGDR) & 0x80000000)
{
84
}
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.

Note: Keep S4.1 switch in OFF position, after execution of program.

85
Experiment No: 7

Write a C language program for LM35 Temperature Sensor


Interface.
Aim:Write a program to interface of LM35 temperature sensor to on-chip ADC (ADC 0,Channel
2, P0.29).

Equipments:SCARM, PC, STK-2148.

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
while(!((adcdata = ADGDR) & 0x80000000))
{
}
return((adcdata >> 6) & 0x3ff) ; // Return 10 bit result
}
void main (void)
{
unsigned int adc, delay;
float Temp, Temperature;
LcdInit();
DisplayRow(1,"LM35 Test");
ADC_Init() ; while(1)
{
adc = ADC_GetAdcReading();
Temp = (adc * 3.3);
Temperature = (Temp / 1023) * 100;
sprintf(adcreading,"Temp =%0.03f",Temperature) ;
DisplayRow(2,adcreading) ;
for(delay=0;delay<60000;delay++);
}
}

Connections:

To interface LM35 (present in Analog Input region on STK-2148) with AD0.2 keep S4.2
in ON position.

Output:

We observed the temperature reading on 16x2 Text LCD.

Note: Keep S4.2 switch in OFF position, after execution of program

87
Experiment No: 8

Write a C language program for I2C based Seven Segment LED


Display Interface
Aim:Write a program to display numbers on 7 segment displays using I2C protocol.

Equipments:SCARM, PC, STK-2148.

Block diagram:

Source Code:

#include <Philips\LPC2138.h>
#include <Stdio.h>
#include "sevenseg.h"

void I2C_Init (void)


{
PCONP |= 0x00000080;
PINSEL0 |= 0x00000050 ;

I2C0CONCLR = 0x6C;
I2C0CONSET = 0x40;
I2C0SCLH = 60;
I2C0SCLL = 60;
}
88
void SevenSeg(unsigned char dis1, unsigned char dis2);
void SevenSeg(unsigned char dis1, unsigned char dis2);
{
unsigned int i;
I2C0CONSET = 0x20;
I2C0CONCLR = 0x2C;
I2C0DAT = I2CEXPANDER_ADDR;
for(i=0;i<300;i++);
I2C0CONCLR = 0x2C;
I2C0DAT = dis1 ;
for(i=0;i<300;i++);
clear all except I2EN
I2C0DAT = dis2 ;
for(i=0;i<300;i++);
I2C0CONCLR = 0x2C;
I2C0CONSET = 0x10;
for(i=0;i<300;i++);
I2C0CONCLR = 0x2C;
}

void main(void)
{
I2C_Init();
while(1)
{
SevenSeg(DISPLAY_7, DISPLAY_2);
}
}

89
Connections:

Keep S5 switch (present in I2C Peripherals region) in ON position.

Output:

We observed 7 and 2 numbers on Seven Segments.

Note: Keep S5 switch in OFF position, after execution of program

90
Experiment No: 9

Write a C language program for 128x64 Graphics LCD Interface.


Aim:Write a program to interface 128x64 Graphics LCD.

Equipments:SCARM, PC, STK-2148.

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"

int main (void)


{
unsigned int
x,y; InitUart0();
printf("GLCD Test Program \n");

91
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
{
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
{
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
{
GoToXY(128,y);
GLCDPutPixel(1);
}
}
}

Connections:

Keep S13.1 switch in ON position to enable Graphics LCD.

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
Experiment No: 10

Write a C language program for Elevator.


Aim:Write a program to interface Elevator.

Equipments:SCARM, PC, STK-2148.

Block diagram:

Source Code:

#include <Philips\LPC2148.h>
#include "Elevator.h"

unsigned char code, g_bytempnum = LED_FLOOR0;


unsigned long int RetCode;

void Delay250 (void);


void Delay250 (void)
{
int k ;
for(k = 0 ; k < 100 ; k ++)
{
}
}

96
void DelayMs (int n);
void DelayMs (int n)
{
int k ;
for(k = 0 ; k < n ; k ++)
{
Delay250() ;
Delay250() ;
Delay250() ;
}
}

void Keyhit (void);


void Keyhit (void)
{
IO1DIR &= ALL_INPUT ;
RetCode = IO1PIN & ALL_KEYS ;
switch(RetCode)
{

case (ALL_KEYS & (~INPUT0)) : code


= LED_FLOOR0 ;
break;
case (ALL_KEYS & (~INPUT1)) : code
= LED_FLOOR1 ;
break;
case (ALL_KEYS & (~INPUT2)) : code
= LED_FLOOR2 ;
break;
case (ALL_KEYS & (~INPUT3)) :

97
code = LED_FLOOR3 ;
break;
}
}

void FloorLedOnOff(unsigned char num);


void FloorLedOnOff(unsigned char num)
{
switch(num)
{
case LED_FLOOR0 :
GroundFloorOn() ;
FirstFloorOff() ;
SecondFloorOff()
; ThirdFloorOff() ;
break;
case LED_FLOOR1 :
FirstFloorOn() ;
GroundFloorOff();
SecondFloorOff()
; ThirdFloorOff() ;
break;
case LED_FLOOR2 :
SecondFloorOn() ;
GroundFloorOff() ;
FirstFloorOff() ;
ThirdFloorOff() ;
break;
case LED_FLOOR3 :
ThirdFloorOn();

98
GroundFloorOff() ;
FirstFloorOff() ;
SecondFloorOff() ;
break;
}
}

void Elevator (unsigned char num);


void Elevator (unsigned char num)
{

unsigned char tempnum;


tempnum = num;

while(tempnum > g_bytempnum)


{
g_bytempnum ++ ;
FloorLedOnOff(g_bytempnum );
DelayMs(600);
if(g_bytempnum > 4)
{
break;
}
}
while(tempnum < g_bytempnum)
{
g_bytempnum -- ;
FloorLedOnOff(g_bytempnum );
DelayMs(600);
if(g_bytempnum < 0)

99
{
break;
}
}
g_bytempnum = num ;
}

void main (void);


void main (void)
{
PINSEL0 = 0x00000005 ;
IO0DIR = FLOOR | 0x003C0000;
IO0SET = FLOOR | 0x003C0000;
FloorLedOnOff(LED_FLOOR0);
while (1)
{
Keyhit();
Elevator (code);
}
}
Connections:

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

You might also like