Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
380 views108 pages

EC8711-Embedded Lab Manual

Uploaded by

parantn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
380 views108 pages

EC8711-Embedded Lab Manual

Uploaded by

parantn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 108

SRM VALLIAMMAI ENGINEERING COLLEGE

(An Autonomous Institution)


SRM Nagar, Kattankulathur – 603 203

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

LABORATORY MANUAL

Regulation – 2017

EC8711 - EMBEDDED LABORATORY

Academic Year 2020-2021

IV YEAR VII SEMESTER


Prepared by

Dr. N. Subhashini, Assistant Professor (Selection Grade)


Mr. C. Saravanakumar, Assistant Professor (Selection Grade)
Ms. K. Arthi, Assistant Professor (Ordinary Grade)
SRM VALLIAMMAI ENGINEERING COLLEGE
(An Autonomous Institution)
SRM Nagar, Kattankulathur – 603 203

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

VISION OF THE INSTITUTE

Educate to excel in social transformation

MISSION OF THE INSTITUTE

• To contribute to the development of human resources in the form of professional engineers and
managers of international excellence and competence with high motivation and dynamism, who besides
serving as ideal citizen of our country will contribute substantially to the economic development and
advancement in their chosen areas of specialization.
• To build the institution with international repute in education in several areas at several levels with
specific emphasis to promote higher education and research through strong institute- indus tr y
interaction and consultancy.

VISION OF THE DEPARTMENT

To excel in the field of electronics and communication engineering and to develop highly competent
technocrats with global intellectual qualities.

MISSION OF THE DEPARTMENT


M1: To educate the students with the state of art technologies to compete internationally, able to produce
creative solutions to the society`s needs, conscious to the universal moral values, adherent to the
professional ethical code
M2: To encourage the sudents for professional and software development career
M3: To equip the students with strong foundations to enable them for continuing education and research.
SRM VALLIAMMAI ENGINEERING COLLEGE
(An Autonomous Institution)
SRM Nagar, Kattankulathur – 603 203
PROGRAM OUTCOMES

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineer ing
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to provide
valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern enginee r ing
and IT tools including prediction and modeling to complex engineering activities with an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineer ing
practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineer ing
community and with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent
and life-long learning in the broadest context of technological change.

PROGRAM SPECIFIC OUTCOME(PSOs)

PSO1: Ability to apply the acquired knowledge of basic skills, mathematical foundations, principles of
electronics, modeling and design of electronics based systems in solving engineering Problems.
PSO2: Ability to understand and analyze the interdisciplinary problems for developing innovative sustained
solutions with environmental concerns.
PSO3: Ability to update knowledge continuously in the tools like MATLAB, NS2, XILINIX and
technologies like VLSI, Embedded, Wireless Communications to meet the industry requirements.
PSO4: Ability to manage effectively as part of a team with professional behavior and ethics.
SYLLABUS

EC8711 Embedded Lab LTPC


0042
Course Objective:
The student should be made to:
 Learn the working of ARM processor
 Understand the Building Blocks of Embedded Systems
 Learn the concept of memory map and memory interface
 Write programs to interface memory, I/Os with processor
 Study the interrupt performance

List of Experiments:
1. Study of ARM evaluation system
2. Interfacing ADC and DAC.
3. Interfacing LED and PWM.
4. Interfacing real time clock and serial port.
5. Interfacing keyboard and LCD.
6. Interfacing EPROM and interrupt.
7. Mailbox.
8. Interrupt performance characteristics of ARM and FPGA.
9. Flashing of LEDS.
10. Interfacing stepper motor and temperature sensor.
11. Implementing zigbee protocol with ARM.

Course Outcome:
At the end of the course, the student should be able to:
 Write programs in ARM for a specific Application
 Interface memory, A/D and D/A convertors with ARM system
 Analyze the performance of interrupt
 Write program for interfacing keyboard, display, motor and sensor.
 Formulate a mini project using embedded system

TOTAL: 60 PERIODS
LIST OF EXPERIMENTS

Expt. Title of the Experiment Page


No. No.

1 Study of ARM evaluation system 1

2 Interfacing ADC and DAC. 7

3 Interfacing LED and PWM. 15

4 Interfacing real time clock and serial port. 18

5 Interfacing keyboard and LCD. 24

6 Interfacing EPROM and interrupt. 35

7 Mailbox. 43

8 Interrupt performance characteristics of ARM and FPGA. 58

9 Flashing of LEDS. 69

10 Interfacing stepper motor and temperature sensor. 71

11 Implementing zigbee protocol with ARM. 78

Topic Beyond The Syllabus

12 Simulation using Proteus Software.- An Introduction 84

Simulation of calculator using 8051 microcontroller in Proteus


13 software 95
1

1. Study of ARM evaluation system

Aim
To learn about the evolution, core features, general characteristics and applications of ARM
processors.

Pre Lab Questions


1. What is an embedded system?
2. Mention the difference between microprocessor and microcontroller.
3. Enumerate the terms object oriented and object based language
4. Define Pipelining.
5. List the basic units of Microprocessor

Theory

The LPC2148 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with real-
time emulation and embedded trace support, that combines the microcontroller with embedded
high speed flash memory ranging from
32 kB to 512 kB. A 128-bit wide memory interface and unique accelerator architecture enable 32-
bit code execution at the maximum clock rate. For critical code size applications, the alternative
16- bit Thumb mode reduces code by more than 30 % with minimal performance penalty.

Due to their tiny size and low power consumption, LPC2148 are ideal for applicatio ns
where miniaturization is a key requirement, such as access control and point- of-sale. A blend of
serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple UARTS,
SPI, SSP to I2Cs and on-chip SRAM of 8 kB up to 40 kB, make these devices very well suited
for communication gateways and protocol converters, soft modems, voice recognition and low
end imaging, providing both large buffer size and high processing power. Various 32-bit timers,
single or dual 10-bit ADC(s), 10-bit DAC, PWM channels and 45 fast GPIO lines with up to nine
edge or level sensitive external interrupt pins make these microcontrollers particularly suitable for
industrial control and medical systems.
2

LPC2148 specification

Features:
16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

8 to 40 KB of on-chip static RAM and 32 to 512kB of on-chip flash Program memory.

128 bit wide interface/accelerator enables high speed 60 MHz operation.

In-System/In-Application Programming (ISP/IAP)via on-chip boot- loader software. Single

flash sector or full chip erase in 400ms and programming of 256 bytes in 1 ms.

Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the on-

chip Real Monitor software and high speed tracing of instructio n execution.

USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM. In addition, the

LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA.

One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a

o total of 6/14 analog inputs, with conversion times as low as 2.44μs per channel.

Single 10-bit D/A converter provide variable analog output.

Two 32-bit timers/external event counters (with four capture and four compare channels

each), PWM unit (six outputs) and watchdog.

Low power real-time clock with independent power and dedicated 32 kHz Clock input.

Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 kbit/s), SPI

and SSP with buffering and variable data length capabilities.

Vectored interrupt controller with configurable priorities and vector addresses.


3

Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.

Up to nine edge or level sensitive external interrupt pins available.

60 MHz maximum CPU clock available from programmable on-chip PLLwith settling time of

100 μs.

On-chip integrated oscillator operates with an external crystal in range from 1MHz to 30 MHz and
with an external oscillator up to 50MHz.

Power saving modes include Idle and Power-down.

Individual enable/disable of peripheral functions as well as peripheral clock scaling for additiona l
power optimization.

Processor wake-up from Power-down mode via external interrupt, USB, Brown-Out Detect

(BOD) or Real-Time Clock (RTC).

Single power supply chip with Power-On Reset (POR) and BOD circuits:

- CPU operating voltage range of 3.0 V to 3.6 V (3.3 V ± 10 %) with 5V tolerant

I/O pads.
4

Pin Configuration:

For further studies about LPC2148 specification refer NXP’s website to download LPC2148

user manual.
5

APPENDIX-II: CONNECTORS & CONNECTION DETAILS


Type Label Description
26 Pin FRC CON1 For GPIO
20 Pin FRC CON2 For JTAG
DB9 CON3 UART0
DB9 CON4 UART1
3 Pin RMC CON5 PWM output
6 Pin RMC CON6 ADC input
3 Pin RMC CON7 DAC output from OPAMP
3 Pin RMC CON8 Temperature sensor input
16 Pin RMC CON9 LCD Display
Power jack C10 Power input
PS2 CON11 Keyboard interface

Connections Details for 26 pin FRC:

Connection Details for LCD(16 pin RMC):


6

Connection Details for JTAG(20 pin FRC):

Post Lab Questions


1. What is the difference between embedded systems and the system in which rtos is running?
2. Discuss about semaphore.
3. What are the instructions used to access the memory in ARM?
4. Mention the characteristics of RISK Instruction.
5. Define Interrupt.

Result
The evolution, core features, general characteristics and the applications of ARM processors has
been studied and is evaluated.
7

2. INTERFACING ADC & DAC


Aim
To develop a C-Language program for reading an on-chip ADC, convert into decimal
and to display it in PC and to generate a square wave depending on this ADC reading. The ADC
input is connected to any analog sensor/ on board potentiometer.

Pre Lab Questions


1. List the types of ADC and DAC
2. Define resolution.
3. Summarize the features of Conversion time in ADC.
4, What is the function of Sample-and-hold circuits in analog-to digital converters?
5. Why are internal ADCs preferred over external ADCs?

Apparatus & Software Required

1. LPC2148 Development board.

2. K e il µV isi on5 software.

3. Flash Magic.

4. USB cable.

5. CRO .

Theory

The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic clocking
for the A/D converters is provided by the VPB clock. A programmable divider is included in
each converter, to scale this clock to the 4.5 MHz (max) clock needed by the successive
approximation process. A fully accurate conversion requires 11 of these clocks. The ADC cell
can measure the voltage on any of the ADC input signals.

ARM Board has one potentiometer for working with A/D Converter. Potentiometer outputs are
in the range of 0V to 3.3V. Switch select in right position for reading the Potentiometer value
by ADC.
8

Procedure

1. Follow the steps to create a New project


2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
9

MAIN ADC TEST

/*************************************************************************** *********/
/* This is a test program to ADC in the ARM LPC2148 development board */
/************************************************************************************/

#include <LPC214x.H> /* LPC214x definitions */


#include "ADC_Driver.c" /* contains prototypes of driver functions*/ #include
"lcd.c"
#include <stdio.h>

int main (void)


{
unsigned int adc_val;
unsigned int temp;
unsigned char buf[4] = {0,0,0,0};
ADCInit();
lcdinit();
//wait();
clrscr(10);
printstr("ADC Test",0,0); wait();
while (1) /* Loop forever */
{
adc_val = ADC_ReadChannel();
temp = (unsigned int)((3*adc_val*100)/1024);
sprintf(buf,"%d",temp);
printstr(buf,0,1);

/***************************************************************************/
LCD.C
/************************************************************************************/

#include <LPC214x.h>

#define RS 0x00000400 /* P0.10 */


#define CE 0x00001800 /* P1.11 */
void clrscr(char ch); void
lcdinit(void); void
lcdcmd(char); void
lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1 void printstr(unsigned char
*,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);

#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
10

void wait (void)


{ /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

}
void printstr(unsigned char *str, char x, char y)
{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);

}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

void lcddat(char cmd)


11

{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait ();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}

void clrscr(char ch)


{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}

void split_numbers(unsigned int number)


{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}

void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcome to ", 0, 0);
printstr(" SMMICRRO ", 0, 1);
}
12

/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
ADC_ DRIVER.C
/**************************************************************/

#include <LPC214x.H> /* LPC214x definitions */

Void ADCInit (void)


{
PINSEL1 |= 0x04000000; /*For Channel AD0.2 is P0.29*/
IODIR0 |= ~(0x04000000);
AD0CR |= 0x00200204; /*0x04 selects AD0.2 to mux output, 0x20 makes ADC in
operational*/
AD0GDR; /*A read on AD0GDR clears the DONE bit*/
}

void ADC_StartConversion(void)
{
AD0CR |= (1<<24);
}
void ADC_StopConversion(void)
{
AD0CR &= (~ (1<<24));
}

unsigned int ADC_ReadChannel(void)


{
// unsigned int i; unsigned long
ADC_Val, t;
ADC_StartConversion();
while((AD0DR2&0x80000000)==0); /*wait until ADC conversion completes*/
if(AD0STAT & 0x00000400)
{
//printstr("OVR",0,1);
return(0);
}
t = AD0DR2;
ADC_Val = ((t>>6) & 0x000003FF);//(AD0DR2 & 0x000003FF); //((AD0CR>>6) & 0x000003FF);
//ADC_StopConversion();
return(ADC_Val);

ADC PROGRAM PORT DETAILS


ARM DETAILS
P0.29 ADC0.2
PO.10 RS LCD PIN
P1.11 CE LCD PIN
13

DAC PROGRAM

/**************************************************************/ DAC.C
/**************************************************************/
This is a test program to DAC in the ARM LPC2148 development board
/**************************************************************/

#include<LPC214X.H>

void wait_long (void)


{ /* wait function */
int d;
for (d = 0; d < 1000000; d++); /* only to delay */
}

int main()
{
wait_long();
wait_long();
IODIR0 = 0X00000FFF;
IODIR1 = 0XFFFF0000;
IOSET0 = 0XFFFFFFFF;
IOCLR1 = 0XFFFF0000;
PINSEL1 |= 0x00080000; //Enable pin 0.25 as DAC
DACR = 0X00017FC0; // 000 = 0V (min),7FC = 1.6V,7FF = 3.3V(max)
While (1);
}

DAC PROGRAM PORT DETAILS


ARM DETAILS
P0.25 DAC ENABLE PIN
14

Post Lab Questions


1. What are the ADC operating modes in LPC2148?
2. What is the function of A/D Status Register
3. Which pin provides a voltage reference level for the D/A converter?
4. What is Burst conversion mode?
5. What is settling time?

Result :
The C-Language program for reading an on-chip ADC, convert into decimal and to display
it in PC was written & output is verified with the ADC input is connected to on board
potentiometer

The DAC, convert digital data into analog signal & output is verified with the DAC input and
the square wave has been generated to display it in CRO.
15

3. INTERFACING LED & PWM

Aim
To write a C program for Sw itch & L ED to activate LED’s and generate a PWM and to vary
the duty cycle .

Pre Lab Questions


1. What happens if the junction temperature of LED is increased?
2. Mention the principle of PWM.
3. What are the materials used to make LED?
4. What are the types of seven segment display.
5. Differentiate LED from LCD.

Apparatus & Software Required

1. LPC2148 Development board.


2. Keil µV isi on5 software.
3. Flash Magic.
4. USB cable.
5. CRO .

Theory
The PWM is based on the standard timer block and inherits all of its features, although only the
PWM function is pinned out on the LPC2148. The timer is designed to count cycles of the
peripheral clock (PCLK) and optionally generate interrupts or perform other actions when
specified timer values occur, based on seven match registers. The PWM function is also based
on match register events.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
16

/*************** *** *** *** *** *** *** *** *** *** ** * *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
SWITCH AND LED PROGRAM
/************************************************************************************/
/* Description: This program gets DIP switch inputs and switches ON corresponding LED
*/
/* P1.16 to P1.31 are output switch */

/**************** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** /

#include<LPC214x.H>

int main()
{

IO1DIR = 0xFFFF0000; // P1.16 TO P1.31 OUTPUT PIN

while(1)
{
IOCLR1 = 0xFFFF0000; // output pin cleared for enable the led
}
}

SWITCH AND LED PORT DETAILS


ARM DETAILS
P1.16 S&L ENABLE PIN
P1.17 S&L ENABLE PIN
P1.18 S&L ENABLE PIN
P1.19 S&L ENABLE PIN
P1.20 S&L ENABLE PIN
P1.21 S&L ENABLE PIN
P1.22 S&L ENABLE PIN
P1.23 S&L ENABLE PIN
P1.24 S&L ENABLE PIN
P1.25 S&L ENABLE PIN
P1.26 S&L ENABLE PIN
P1.27 S&L ENABLE PIN
P1.28 S&L ENABLE PIN
P1.29 S&L ENABLE PIN
P1.30 S&L ENABLE PIN
P1.31 S&L ENABLE PIN
17

/****************************************************************************/
PWM.C
/****************************************************************************/
/* Place lcd.c file into following directories C:\Keil\ARM\INC\Philips.*/
/* This program is used to Generate the PWM, Frequency and Duty cycle can be changed*/
*****************************************************************************/

#include<LPC214x.H>

int main(voi d
{

PINSEL1 |= 0x00000400; //Enable pin0.7 as PWM2


PWMPR = 0x00000100; //Load prescaler (to vary the frequency can modify here)

PWMPCR = 0x00002000; //PWM channel single edge control, output enabled


PWMMCR = 0x00000003; //On match with timer reset the counter

/* PWMR0 AND PWMR5 Both Value can change the duty cyle ex : PWMR0 = 10 AND PWMR5 = 2*/
PWMMR0 = 0x00000010; //set cycle rate to sixteen ticks
PWMMR5 = 0x00000008; //set rising edge of PWM2 to 2 ticks

PWMLER = 0x00000021; //enable shadow latch for match 0 - 2


PWMTCR = 0x00000002; //Reset counter and prescaler
PWMTCR = 0x00000009; //enable counter and PWM, release counter from reset
while(1) // main loop
{
}
}
PWM PROGRAM PORT DETAIL
ARM DETAILS
P0.7 PWM2

Post Lab Questions


1. How do the variations in an average value get affected by PWM period?
2. Name the common formats available for LED display
3. Why are the pulse width modulated outputs required in most of the applications?
4. How do you determine the duty cycle of the waveform ?
5. What is the function of GPIO?

Result
The C code is generated for Switch & LED and output is verified in LED’s by Switches
The C code is generated for PWM and to vary the duty cycle and verified in CRO output.
18

4. INTERFACING REAL TIME CLOCK PROGRAM


AND SERIAL PORT

Aim
To develop a C-Language program for reading the RTC, convert into decimal and to display
it.

Pre Lab Questions


1. How would you define real time clock?
2. List the applications of real time clock.
3. What is the baud rate of serial port ?
4. Compare serial communication and parallel communication.
5. Enumerate the different modes of communication.

Apparatus & Software Required

1. LPC2148 Development board.

2. K e il µV isi on5 software.

3. Flash Magic.

4. USB cable.

5. RS232 Serial cable.

Theory
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on,
and optionally when it is off. It uses little power in Power-down mode. On the LPC2141/2/4/6/8,
the RTC can be clocked by a separate 32.768 KHz oscillator, or by a programmable prescale
divider based on the VPB clock. Also, the RTC is powered by its own power supply pin, VBAT,
which can be connected to a battery or to the same 3.3 V supply used by the rest of the
device.
19

Serial Communication

Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time. The
advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port
needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would if
there were 8 wires. Serial ports lower cable costs and make cables smaller.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
20

/**************************************************************/
RTC.C
/**************************************************************/
/* Place lcd.c file into following directories C:\Keil\ARM\INC\Philips.******/
/* This program is used to interface the RTC.You can change the date and time*/
/* If you want. This Program can both Read and write data into RTC.RTC has a*/
/* Battery backup for continuous Running. ************************************/
/*
pclk = 30,000,000 Hz
PREINT = (int)(pclk/32768)-1
PREFRAC = pclk - ((PREINT+1 ) x 32768)
*/
#include<LPC214X.H>
#include<lcd.c>
int main()
{
unsigned int hrs,min,sec;
wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
printstr("SM MICRRO SYSTEM",0,0 );
printstr(" ARM DEV KIT ",0,1);

VPBDIV = 0x00000002; // VPB bus clock is one half of the processor clock(cclk)

PREINT = 0x00000392; // Set RTC prescaler for 30MHz Pclk


// PREINT = (int) (30,000,000/32768(RTC
crystal))-1 = 914
PREFRAC = 0x00004380;
CIIR = 0x00000001; // Enable seconds counter interrupt
CCR = 0x00000001; // Start the RTC
YEAR = 2009; // Year
MONTH = 11; // Month
DOM = 25; // Day of month
DOY = 0; // Day of year
DOW = 0; // Day of week
HOUR = 18; // Hours
MIN = 30; // Minutes
SEC = 30;
printstr(" ",0,1);
while(1)
{
gotoxy(0,1);
hrs = HOUR;
min = MIN;
sec = SEC;
split_numbers(hrs);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(min);
lcddat(tens+0x30);
21

lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);
lcddat(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
}
}

RTC PROGRAM PORT DETAILS

PORT INBUILT
22

SERIAL PORT PROGRAM

/**************************************************************/
/* Uart0 Initialization */

/* This is a test program to send and receive data via uart0 in the ARM LPC2148 */
development board itself
/************************************************************************************
#include <LPC214x.H> /* LPC214x definitions */
#include "uart0.h" /* contains prototypes of driver functions*/

int main (void)


{
unsigned char *s1;
initserial(); /* uart0 initialization */
send_string( "*** *** *** *** *** *** *** *** *** *** *** *** *** *** **");
send_string(" SM Micrro System ");
send_string(" Tambaram ");
send_string(" Chennai ");
send_string( "*** *** *** *** *** *** *** *** *** *** *** *** *** *** **");
send_string("");send_string("");
send_string("This program Echos the string entered by user."); send_string("So,type
some strings and press ENTER key");

while (1) /* Loop forever */


{
s1 = receive_string();
send_string(s1);
}

}
/************************************************************************************/
SERIAL PORT PROGRAM

/****************************************************************************/
/* Uart1 Initialization */
/***************************************** ***********************************/
#include<lpc214x.h>
#include<stdio.h>
#include<stdlib.h>

#include "uart1_driver.c"

int main()
{
unsigned char *a;
//unsigned char *w;
a=malloc(sizeof(100));

inituart1();
sendstrin g1( "A BC D E FG H IJK L M N O P Q RST U V W X Y Z ");
sendstrin g1( "A BC D E FG H IJK L M N O P Q RST U V W X Y Z ");
23

sendstring1("AB CDE F G HIJ KL M NO P Q RST U VW X YZ") ;


sendstring1("AB CDE F G HIJ KL M NO P Q RST U VW X YZ") ;
sendstring1("AB CDE F G HIJ KL M NO P Q RST U VW X YZ") ;
/*sendstring1(" * ");
sendstring1(" * * ");
sendstring1(" * * * "); s
endstring1(" **** ");
sendstring1(" * * * * * ");
sendstring1(" SM MICRRO ");
sendstring1(" * * * * * ");
sendstring1(" **** ");
sendstring1(" * * * ");
sendstring1(" * * ");
sendstring1(" * "); */

while(1)
{
receivestring1(a);
sendstring1(a);

}
}

SERIAL PROGRAM PORT

DETAILS UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1

Post Lab Questions


1. What is I2C and how does it work?
2. Summarize the features of I2C in LPC2148 ARM7 microcontroller.
3. Through which port the date and time is displayed in RTC?
4. What is a serial port?
5. List the registers used to transfer data in serial port.

Result
The C-Language program for reading RTC and displaying it in LCD was written & output is
verified with running the RTC from a default/specified time.
24

5. INTERFACING KEYBOARD AND LCD

MATRIX KEYBOARD PROGRAM

Aim
To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD
module. The display should come in the desired line and column.

Pre Lab Questions


1. Mention the function of pull up resistor?
2. Outline the keyboard matrix.
3. Summarize the working principal of LCD.
4. What kind of interrupt is generated if a key has to be operated in an interrupt mode?
5. How many rows and columns are present in a 16 x 2 alphanumeric LCD?

Apparatus & Software Required

1. LPC2148 Development board.

2. K e il µV isi on5 software.

3. Flash Magic.

4. USB cable.
.

Theory

The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to
connect only one key or switch with an I/O line. If the number of keys in the system exceeds the
more I/O lines are required. To reduce the number of I/O lines the keys are connected in the
matrix circuit. Keyboards use a matrix with the rows and columns made up of wires. Each key
acts like a switch. When a key is pressed a column wire makes contact with row wire and
completes a circuit.For example 16 keys arranged in a matrix circuit uses only 8 I/O lines.
25

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
26

/******************************************************* ***********/

MAIN.C
/***********************************************************************************/
/* Description: This program gets input from Matrix key board and displays
corresponding */
/* Key value in 7segment display. Hence this program demonstrates both
*/ 7 segment display as well as Matrix key board. */
/* P1.16 to P1.23 are inputs from matrix key board,*/
/* P1.24 to P1.31 are outputs to 7 segment display
*/
/*************************************************************************************
****/
/* ------- matrix key board description----------
*/
/* -- -- -- --
*/
/* row1 --| c |-- --| d |-- --| e |-- --| F |-- (SW1,SW2,SW3,SW4)
*/
/* -- -- -- --
*/
/* -- -- -- --
*/
/* row2 --| 8 |-- --| 9 |-- --| A |-- --| b |-- (SW5,SW6,SW7,SW8)
*/
/* -- -- -- --
*/
/* -- -- -- --
*/
/* row3 --| 4 |-- --| 5 |-- --| 6 |-- --| 7 |-- (SW9,SW10,SW11,SW12)
*/
/* -- -- -- --
*/
/* -- -- -- --
*/
/* row4 --| 0 |-- --| 1 |-- --| 2 |-- --| 3 |-- (SW13,SW14,SW15,SW16)
*/
/* -- -- -- --*/
/******************************************************************************/
#include <LPC214x.h>
#include "mat_7seg.h"
int main()
{
unsigned int key, last_key, Disp_key;
init_Matrix_7seg(); // Initialize matrix keyboard and 7segment dispaly
clearall_7seg(); // clear 7 segment display
last_key = 0; // Initialize this variable to zero
while(1)
{
key = catch_key(); // scan for a valid key press
if(key != 0) // zero means no key is pressed
{
if(key != last_key) // check whether the same key is pressed again(assume this as STEP1)
{
27

Disp_key = key; // valid new key is stored in another variable


last_key = key; // this variable's value is used for STEP1
}
}
//Display_Number(Disp_key); /*this function is used to display number in decimal
format*/
Alpha_Dispay(4,Disp_key); /*this function is used to display number in hex format
(single digit only)*/
}

/****************************************************************************/
MATRIX SEVEN SEGMENT DRIVER.C
/**************************************************************/

#include <LPC214x.h>
#include "defs.h"
/*******************************Global
variable s*** *** *** *** *** *** *** *** *** *** *** *** *** *** **/
unsigned int thousands,hundreds,tens,ones;
/*************************************************************************************
******/

void init_Matrix_7seg(void)
{
IODIR1 |= 0xff0f0000; // set 7seg LEDs as output ports and matrix's MSB as
inputs and LSB as outputs
IODIR0 |= S7SEG_ENB; // set P0.19 to P0.22 as outputs to drive 7seg enable
pins
IOPIN0 |= S7SEG_ENB; // since we are using active low 7 seg display, the
enable signals
// should be initially set to HIGH.
}

/*************************************************************************************
*******/
unsigned long scan_row(unsigned int row_num)
{
//unsigned int row,i;
unsigned long val;

IOSET1 = ROW_MASK; //clear the previous scan row output ie make all row ops high
switch(row_num)
{
case 1: IOCLR1 = ROW1;break; // make P1.16 low
case 2: IOCLR1 = ROW2;break; // make P1.17 low
case 3: IOCLR1 = ROW3;break; // make P1.18 low
case 4: IOCLR1 = ROW4;break; // make P1.19 low
//default: row = ERR;
}
// for(i=0;i<=65000;i++);
val = IOPIN1; // read the matrix inputs
val = ((val >> 20) & 0x0000000F)^0x0000000F; // shift the colum value so that it comes to LSB
// XORing is done to take 1's
complement of shifted value.
//
return(val);
}
28

unsigned int catch_key(void)


{
unsigned long v; v =
scan_row(1);
switch(v)
{
case 1: return(13);
case 2: return(14);
case 4: return(15);
case 8: return(16);
}
v = scan_row(2);
switch(v)
{
case 1: return(9);
case 2: return(10);
case 4: return(11);
case 8: return(12);
}
v = scan_row(3);
switch(v)
{
case 1: return(5);
case 2: return(6);
case 4: return(7);
case 8: return(8);
}
v = scan_row(4);
switch(v)
{
case 1: return(1);
case 2: return(2);
case 4: return(3);
case 8: return(4); default:
return(0);
}
}
/*************************************************************************************
*****/
void clearall_7seg(void)
{
IOPIN1 &= ~S7SEG_LED; // make all the 7seg led pins to LOW IOPIN0 |=
S7SEG_ENB // Disable all the 7 seg display
}
/*************************************************************************************
****/
void clearDigit_7seg(int digit_num)
{
IOPIN0 |= S7SEG_ENB; // clear enables first
switch(digit_num)
{
case 1: {
IOPIN0 = ~DIGI1_ENB; // now enable only the digit1
break;
}
case 2: {
IOPIN0 = ~DIGI2_ENB; // now enable only the digit2
break;
}
case 3: {
IOPIN0 = ~DIGI3_ENB; // now enable only the digit3
29

break;
}
case 4: {
IOPIN0 = ~DIGI4_ENB; // now enable only the digit4 break;
}
}
IOPIN1 &= ~S7SEG_LED; // make all the 7seg LED pins LOW
}
/*************************************************************************************
*****/
void Digit_Dispay(int digit_num, unsigned int value)
{
clearDigit_7seg(digit_num);
switch(value)
{
case 0: IOPIN1 |= ZERO;break;
case 1: IOPIN1 |= ONE; break;
case 2: IOPIN1 |= TWO; break;
case 3: IOPIN1 |= THREE; break;
case 4: IOPIN1 |= FOUR; break;
case 5: IOPIN1 |= FIVE; break;
case 6: IOPIN1 |= SIX; break;
case 7: IOPIN1 |= SEVEN; break;
case 8: IOPIN1 |= EIGHT; break;
case 9: IOPIN1 |= NINE; break;
}
}
/*************************************************************************************
*****/
void Alpha_Dispay(int digit_num, unsigned int value)
{
clearDigit_7seg(digit_num);
switch(value)
{
case 1: IOPIN1 |= ZERO;break;
case 2: IOPIN1 |= ONE; break;
case 3: IOPIN1 |= TWO; break;
case 4: IOPIN1 |= THREE; break;
case 5: IOPIN1 |= FOUR; break;
case 6: IOPIN1 |= FIVE; break;
case 7: IOPIN1 |= SIX; break;
case 8: IOPIN1 |= SEVEN; break;
case 9: IOPIN1 |= EIGHT; break;
case 10: IOPIN1 |= NINE; break; case
11: IOPIN1 |= AAA; break; case 12:
IOPIN1 |= bbb; break; case 13: IOPIN1 |=
ccc; break; case 14: IOPIN1 |= ddd; break;
case 15: IOPIN1 |= eee; break; case 16:
IOPIN1 |= fff; break;
}
}
/****************************************** *******************************************
******/
void split_numbers(unsigned int number)
{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
30

ones = number ;
}
/*************************************************************************************
******/
void Display_Number(unsigned int num)
{
unsigned int i;
if(num <= 9999)
{
clearall_7seg();
split_numbers((unsigned int)num);
Digit_Dispay(4, ones);
for(i=0;i<10000; i++);
Digit_Dispay(3, tens);
for(i=0;i<10000; i++);
Digit_Dispay(2, hundreds);
for(i=0;i<10000; i++);
Digit_Dispay(1, thousands);
for(i=0;i<10000; i++);
}

MATRIX SEVEN SEGMENT PROGRAM PORT DETAIL

ARM DETAILS
P0.19 SEGMENT ENABLE PIN
P0.21 SEGMENT ENABLE PIN
P0.22 SEGMENT ENABLE PIN
P1.16 KEY BOARD INPUT
P1.17 KEY BOARD INPUT
P1.18 KEY BOARD INPUT
P1.19 KEY BOARD INPUT
P1.20 KEY BOARD INPUT
P1.21 KEY BOARD INPUT
P1.22 KEY BOARD INPUT
P1.23 KEY BOARD INPUT
P1.24 OUTPUT SEGMENT
P1.25 OUTPUT SEGMENT
P1.26 OUTPUT SEGMENT
P1.27 OUTPUT SEGMENT
P1.28 OUTPUT SEGMENT
P1.29 OUTPUT SEGMENT
P1.30 OUTPUT SEGMENT
31

LCD PROGRAM

/**************************************************************/
LCD.h
/**************************************************************/

void clrscr(char ch);


void lcdinit(void);
void lcdcmd(char);
void lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(char *,char,char); //string, column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);
void Wait_Msg(void);
void Welcome_Msg(void);

/**************************************************************/
LCD.c
/**************************************************************/
#include <LPC214x.h>

#define RS 0x00000400 /* P0.10 */


#define CE 0x00001800 /* P1.11 */

void clrscr(char ch); void


lcdinit(void); void
lcdcmd(char); void
lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1 void printstr(char
*,char,char); //string, column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);

#define SET 1
#define OFF 0

unsigned int thousands,hundreds,tens,ones;

void wait (void) { /* wait function */ int


d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit()
{
IODIR0 |= 0x0000FFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
32

lcdcmd(0x0f); wait();
}

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

void printstr(char *str, char x, char y)


{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);

}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

void lcddat(char cmd)


{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
33

IOCLR0 = 0X00000FFF;
}

void clrscr(char ch)


{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}

void split_numbers(unsigned int number)


{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}

void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" PLEASE WAIT ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" WELCOME TO ", 0, 0);
printstr("SM MICRRO SYSTEM", 0, 1);
}
34

/************************************************************* **********/
LCD main.c
/******************************************************************************************/

/* This is a test program to display strings in LCD module in the ARM LPC2148 Development board itself */
/*********************************************************************************** ********** */
#include <LPC214x.H> /* LPC214x definitions */
#include "lcd.h" /* includes lcd driver funtions*/

int main (void)


{
lcdinit(); /*Initialize lcd*/
Wait_Msg(); /*Display message - "Please Wait"*/ Welcome_Msg();
/*Display message - "Welcome to SM MICRRO"*/

while(1) /*Loop Forever*/


{

LCD PROGRAM PORT DETAILS


ARM Details
PO.10 RS LCD PIN
P1.11 CE LCD PIN

Post Lab Questions


1. Outline the operations involved when the key in a 4 x 4 keyboard matrix is being pressed.
2. List the registers used to store the keyboard, display modes and other operations
programmed by CPU.
3. What is switch bouncing ? How to prevent it using de-bounce circuit?
4. How to adjust the contrast of the LCD?
5. Which command of an LCD is used to shift the entire display to the right?

Result

The C-Language program for displaying the Key pressed in the Keyboard is displayed
in the seven segment display and LCD module and the output was verified on the LCD on the
desires line and column/address.
35

6. INTERFACING EPROM AND INTERRUPT

Aim

To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt

Pre Lab Questions


1. What is an edge triggering ?
2. Mention the advantages and disadvantages of level triggering pulse.
3. Differentiate EPROM and ROM.
4. List the different types of Memory devices.
5. Which interrupt is said to be non maskable interrupt , Why?

Apparatus & Software Required

1. LPC2148 Development board.


2. Keil µV isi on5 software.
3. Flash Magic.
4. USB cable.

Theory
Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,
telecommunication, medical, industrial and PC related markets. Primarily used to store personal
preference data and configuration/setup data, Serial EEPROM’s are the most flexible type of
nonvolatile memory utilized today. Compared to other NVM solutions, Serial EEPROM devices
offer a lower pin count, smaller packages, lower voltages, as well as lower power consumption.
36

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.

EPROM PROGRAM
/******************************************************************************/
I2C.C
/**************************************************************************/

/* This Program For I2C Interface */


#include<LPC214x.H>
#include "lcd.c"

void InitI2C(void);
void SendI2CAddress(unsigned char Addr_S); void
WriteI2C(unsigned char Data);
void StopI2C(void); void
StartI2C(void);

#define STA 0x20


#define SIC 0x08
#define SI 0x08
#define STO 0x10
#define STAC 0x20
#define AA 0x04

void InitI2C(void)
{
I2C0CONCLR = 0xFF;
PINSEL0 |= 0x50; // Set pinouts as scl and sda
I2C0SCLL =19; //speed at 100Khz for a VPB Clock Divider = 4 at 12 MHz
I2C0SCLH =19;
I2C0CONSET = 0x40; //Active Master Mode on I2C bus
}

void SendI2CAddress(unsigned char Addr_S)


{
while(I2C0STAT!=0x08); // Wait for start to be completed
I2C0DAT = Addr_S; // Charge slave Address
I2C0CONCLR = SIC | STAC; // Clear i2c interrupt bit to send the data
while(!( I2C0CONSET & SI)) ; // wait till status available
}

unsigned char ReadI2C(void)


{
unsigned char r;
37

I2C0CONCLR = SIC;
I2C0CONSET = 0x04; // clear SIC;
while(!(I2C0CONSET & 0x8)); // wait till status available
r=I2C0STAT;
wait(); // check for error
if (r == 0x50){ // look for "Data byte has been received; ACK has been returned"
lcdcmd(0x01);
printstr("Read Sucess",0,0);
}

return I2C0DAT;
}

void WriteI2C(unsigned char Data)


{
unsigned char r;
I2C0DAT = Data; // Charge Data
I2C0CONCLR = 0x8; // SIC; Clear i2c interrupt bit to send the data
while(!(I2C0CONSET & 0x8)); // wait till status available
r=I2C0STAT;
if (r == 0x28)
{ // look for "Data byte in S1DAT has been transmitted; ACK has been received"
lcdcmd(0x01);
printstr("Write Sucess",0,0);
}
}
void StopI2C(void)
{
I2C0CONCLR = SIC;
I2C0CONSET = STO;
while((I2C0CONSET&STO)); // wait for Stopped bus I2C
}

void StartI2C(void)
{
I2C0CONCLR = 0xFF; // clear I2C - included if User forgot to "StopI2C()"
// else this function would hang.
I2C0CONSET = 0x40; // Active Master Mode on I2C bus
I2C0CONSET = 0x00000020; // Start condition
}
int main()
{

unsigned char r;

wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
printstr("SM MICRRO SYSTEM",0,0);
printstr(" ARM DEV KIT ",0,1);
InitI2C();
StartI2C();
SendI2CAddress(0xa0); // EEPROM device address
WriteI2C(0); // Set the control port value
WriteI2C('B');
38

StopI2C();
wait();
wait();
StartI2C();
SendI2CAddress(0xa0); // EEPROM device address
WriteI2C(0); // Set the control port value
StopI2C();
StartI2C();
SendI2CAddress(0xa1); // Start the read
r=ReadI2C(); // read the result
StopI2C();
gotoxy(0,1);
split_numbers(r);
lcddat(0x30+hundreds);
lcddat(0x30+tens);
lcddat(0x30+ones); while(1);

}
/*******************************************************************************************/
LCD.C
/*******************************************************************************************/

#define RS 0x00000400 /* P0.10 */


#define CE 0x00001800 /* P1.11 */
void clrscr(char ch); void
lcdinit(void); void
lcdcmd(char); void
lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);
#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
void wait (void) { /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit()
{
IODIR0 = 0xFFFFFFFF;
IOCLR0 = 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
39

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

}
void printstr(char *str, char x, char y)
{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);

}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

void lcddat(char cmd)


{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
40

if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}

void split_numbers(unsigned int number)


{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}

EPROM (I2C) PROGRAM PORT SETAILS


ARM DETAILS
PO.10 RS LCD PIN
P1.11 CE LCD PIN
P0.11 SCL
P0.14 SDA
41

INTERRUPT BUZZER PROGRAM


/***************************************************************************/
Ext Driver.C
/***********************************************************************/

#include <LPC214x.h>
void init_VIC(void)
{
/* initialize VIC*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
}

void ExtInt_ISR(void) irq


{
//EXTINT = (1<<2); /* clear EINT2 flag by writing HIGH to coresponding bit*/
//IOCLR0 = 0x40000000; /* Trigger the relay*/
IOCLR1 = 0x400f0000; /* P1.18 Trigger the relay*/
//IOPIN1 = 0x00000000;
EXTINT = (1<<2);
VICVectAddr = 0; /* Acknowledge Interrupt */
}
void init_Interrupt(void)
{
PINSEL0 = 0x80000000; // select P0.15 for EINT2
VICIntEnable = (1 << 16); // External interrupt 2 (EINT2)
VICVectCntl0 = (1<<5)|(16); // set the VIC control reg for EINT2
VICVectAddr0 = (unsigned long)ExtInt_ISR;
EXTMODE &= ~(1<<2); // set VIC for egdse sensitive for EINT2
// EXTPOLAR = ~(1<<2); // set VIC for falling edge sensitive for EINT2
}
void init_ports(void)
{
IODIR0 = 0x40000 0 00;
IODIR1 = 0x400f0 0 00;
IOPIN1 = 0xff010 0 00;
IOSET0 = 0x40000000;
IOSET1 = 0x400f0000;

}
/*void wait_for_turnoffRelay(void)
{
int val;
val = IOPIN1; // read the ports for key board input while((~(val>>20))
!= 0); // wait until 1st key in the matrix keyboard
is pressed
IOCLR0 = 0x00010000; // switch off the relay
}*/
42

/***********************************************************************************/
XINTR _RELAY.C
/**********************************************************************************/
#include <LPC214x.h>
#include "ext.h"
int main()
{
init_VIC();
init_Interrupt();
init_ports();
while(1)
{
//wait_for_turnoffRelay();
}
}

INTERRUPT BUZZER PROGRAM


ARM DETAILS
P1.18 TRIGGER THE RELAY
P0.15 EINT2

Post Lab Questions


1. What will be the initial values in all the cells of an EPROM ?
2. What are the contents of the IE register, when the interrupt of the memory location 0x00 is caused?
3. Why normally LJMP instructions are the topmost lines of the ISR?
4. Enumerate the features of nested interrupt.
5. Illustrate the Master Slave mode.

Result
The C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.
43

7. MAIL BOX

Aim
To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.

Pre Lab Questions


1. How does mailbox works in RTOS?
2. What is Semaphore?
3. Differentiate mailbox and queue.
4. List the synchronous and asynchronous modes are there in serial port?
5. Interpret the inter process communication

Apparatus & Software Required

1. LPC2148 Development board.

2. K e il µV isi on5 software.

3. Flash Magic.

4. USB cable.
.

Theory
Real-time and embedded systems operate in constrained environments in which computer
memory and processing power are limited. They often need to provide their services within strict
time deadlines to their users and to the surrounding world. It is these memory, speed and timing
constraints that dictate the use of real-time operating systems in embedded software.

The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer" that hides
from application software the hardware details of the processor (or set of processors) upon
which the application software will run.

In providing this "abstraction layer" the RTOS kernel supplies five main categories of basic
services to application software
44

The most basic category of kernel services is Task Management. This set of services allows
application software developers to design their software as a number of separate "chunks" of
software -- each handling a distinct topic, a distinct goal, and perhaps its own real-time deadline.
Each separate "chunk" of software is called a "task." The main RTOS service in this category is
the scheduling of tasks as the embedded system is in operation.

The second category of kernel services is Intertask Communication and Synchronization. These
services make it possible for tasks to pass information from one to another, without danger of
that information ever being damaged. They also make it possible for tasks to coordinate, so that
they can productively cooperate with one another. Without the help of these RTOS services,
tasks might well communicate corrupted information or otherwise interfere with each
other.Since many embedded systems have stringent timing requirements, most RTOS kernels
also provide some basic Timer services, such as task delays and time-outs.

Many (but not all) RTOS kernels provide Dynamic Memory Allocation services. This category
of services allows tasks to "borrow" chunks of RAM memory for temporary use in applicatio n
software. Often these chunks of memory are then passed from task to task, as a means of quickly
communicating large amounts of data between tasks. Some very small RTOS kernels that are
intended for tightly memory-limited environments, do not offer Dynamic memory allocation.
45

Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of services.
These services, if available, provide a uniform framework for organizing and accessing the
many hardware device drivers that are typical of an embedded system.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
46

/****************************************************************************/
MAILBOX.C
/****************************************************************************/
#include <string.h>
#include <stdio.h>
#include <RTL.h>
#include <LPC214x.H> /* LPC214x definitions */
#include "config.h"
#include "uart.h" #include
"lcd.h"

OS_TID tsk1; /* assigned identification for task 1 */


OS_TID tsk2; /* assigned identification for task 2 */

typedef struct { /* Message object structure */


char msgBuf[MBOX_MSG_ BUF_SIZE];
} T_MEAS;

os_mbx_declare (MsgBox,MAILBOX_MEM ORY_POOL_CNT); /* Declare an RTX mailbox*/


_declare_box (mpool,sizeof(T_MEAS),MAILBOX_M EMORY_POOL_ CNT);/* Dynamic memory pool*/
task void send_task (void);
task void rec_task (void);
void main_menu()
{
send_string( U SE_ U A R T,"\n\r\n\n** *** *** *** *** *** *** *** **** *** *** *** *** *** **" );
send_string(USE_UART,"\n\r SM Micrro System, Tambaram, Chennai ");
send_string(USE_UART,"\n\r MailBox Message Simulation ");
send_string(USE_UART,"\n\r MAIN MENU");
send_string(USE_UART,"\n\r********************************************");
send_string(USE_UART,"\n\n\r");
send_string(USE_UART,"\n\rThis program simulates MailBox IPC mechanism.");
send_string(USE_UART,"\n\rPlease Follow Below Commands"); send_string(USE_UART," \n\r - Type any
string and press enter to send"); send_string(USE_UART," \n\r the string
using mailbox. "); send_string(USE_UART,"\n\r - Press SPACE Key to
check available Mailbox Count"); send_string(USE_UART,"\n\r - Press ESC Key to reset
the input string"); send_string(USE_UART,"\n\n\r");
}
/*
* Task 1: RTX Kernel starts this task with os_sys_init (send_task)
* */
task void send_task (void)
{
T_MEAS *mptr;
static unsigned char sInputBuf[MBOX_MSG_BUF_SIZE]; int
cnt=0;
char sSndTskBuf[30]; char
ch;
int MsgFree = 0;

tsk1 = os_tsk_self (); /* get own task identification number */


#ifndef DISABLE_RECV_TASK
tsk2 = os_tsk_create (rec_task, 0); /* start task 2 */
#endif /* DISABLE_RECV_TASK */
os_mbx_init (MsgBox, sizeof(MsgBox));/* initialize the mailbox */
os_dly_wait (5); /* Startup delay for MCB21xx */
lcdinit();
47

clrscr(10);
printstr(" MailBox ",0,0);
printstr(" Simulation ",0,1);

#ifndef DISABLE_RECV_TASK
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
memset (mptr->msgBuf,'\0',M BOX_MSG_ BUF_SIZE);
memcpy ( mptr->msgBuf, STD_MSG1, sizeof(STD_MSG1) );
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
os_dly_wait (100);

mptr = _alloc_box (mpool);


memset (mptr->msgBuf,'\0',MBOX_MSG_ BUF_SIZE);
memcpy ( mptr->msgBuf, STD_MSG2, sizeof(STD_MSG2) );
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_tsk_pass (); /* Cooperative multitasking */
os_dly_wait (100);

mptr = _alloc_box (mpool);


memset (mptr->msgBuf,'\0',MBOX_MSG_ BUF_SIZE);
memcpy ( mptr->msgBuf, STD_MSG3, sizeof(STD_MSG3) );
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_dly_wait (100);
#endif /* DISABLE_RECV_TASK */
memset (sInputBuf,'\0',MBOX_MSG_ BUF_SIZE);
cnt = 0;
main_menu();
while(1)
{
ch = receive(USE_UART);
if(ch == CARRIAGE_ RET && cnt > 0)
{
send_string(USE_UART,"\n\n\n\r************SENDING MAILBOX USER MESSAGE***************");
MsgFree = os_mbx_check (MsgBox); if
(MsgFree != 0)
{
mptr = _alloc_box (mpool);
memset (mptr->msgBuf,'\0',MBOX_MSG_ BUF_SIZE);

memcpy ( mptr->msgBuf, sInputBuf, strlen((const char *)sInputBuf) );

*/ sprintf (sSndTskBuf, “\n\ros_mbx_send by Task ID:%d ", tsk1);

send_string(USE_UART,sSndTskBuf);
send_string(USE_UART,"\n\n\r");
} os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. os_dly_wait
else
{ (100);
} memset (sInputBuf,'\0',MBOX_MSG_ BUF_SIZE); cnt
#ifdef = 0;
DISABLE_RECV_TASK

send_string(USE_UART,"\n\rMailbox is FULL");
main_menu();
48

#endif /* DISABLE_RECV_TASK */
}
else if ( KEY_SPACE == ch)
{
MsgFree = os_mbx_check (MsgBox); if
(MsgFree == 0)
{
send_string(USE_UART,"\n\rMailbox is FULL. ...................... ");
}
else
{
sprintf (sSndTskBuf, "\n\rMailBox Free Count : %d ", MsgFree);
send_string(USE_UART,sSndTskBuf);
send_string(USE_UART,"\n\n\r");
}
os_dly_wait (100);
main_menu();

}
else if ( KEY_ESC == ch)
{
cnt = 0;
memset (sInputBuf,'\0',MBOX_MSG_ BUF_SIZE);
send_string(USE_UART,"\n\rClearing Buffer
Please Wait...............");
os_dly_wait (100);
main_menu();
}
else if('\0' != ch)
{

sInputBuf[cnt++] = ch;

cnt %= MBOX_MSG_BUF_SIZE;
if(ch == CARRIAGE_ RET && cnt ==1) //empty string
{
cnt = 0;
}
else
{
putcharr (USE_UART,ch);
}

}
}

// os_tsk_delete_self (); /* We are done here, delete this task */


}

#ifndef DISABLE_RECV_TASK
/*
* Task 2: RTX Kernel starts this task with os_tsk_create (rec_task, 0)
* */
task void rec_task (void)
{
T_MEAS *rptr;
static char sRxTskBuf[MBOX_MSG_BUF_SIZE];

for (;;)
{
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait for the message */
send_string(USE_UART,"\n\n\n\r************MAILBOX MESSAGE
RECEIVED***************");
49

sprintf (sRxTskBuf, "\n\rec_task by Task ID: %d ", tsk2); send_string(USE_UART,sRxTskBuf);

memset (sRxTskBuf,'\0',M BOX_MSG_BUF_SIZE);


memcpy ( sRxTskBuf, rptr->msgBuf, strlen(rptr->msgBuf) ); send_string(USE_UART,"\n\n\rReceived Mbox: ");
send_string(USE_UART,sRxTskBuf);

send_string(USE_UART,"\n\r***************************************************");
_free_box (mpool, rptr); /* free memory allocated for message */
main_menu();
}
}
#endif /* DISABLE_RECV_TASK */

/*
* Main: Initialize and start RTX Kernel
* */
int main (void)
{
initserial(USE_UART); /* uart0 initialization */

_init_box (mpool, sizeof(mpool), /* initialize the 'mpool' memory for */


sizeof(T_MEAS)); /* the membox dynamic allocation */
os_sys_init (send_task); /* initialize and start task 1 */
}

/*
* end of file
* */

/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ** * *** *** **/
RTX _CONFIG.C
/*************************************************************/
/*
* RL-ARM - RTX
*
* Name: RTX_CONFIG.C
* Purpose: Configuration of RTX Kernel for NXP LPC21xx
* Rev.: V4.20
*
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2011 KEIL - An ARM Company. All rights reserved.
* */

#include <RTL.h>
#include <LPC21xx.H> /* LPC21xx definitions */

/*
* RTX User configuration part BEGIN
* */

//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------


//
// <h>Task Configuration
// =====================
//
50

// <o>Number of concurrent running tasks <0-250>


// <i> Define max. number of tasks that will run at the same time.
// <i> Default: 6
#ifndef OS_TASKCNT
#define OS_TASKCNT 6
#endif

// <o>Number of tasks with user-provided stack <0-250>


// <i> Define the number of tasks that will use a bigger stack.
// <i> The memory space for the stack is provided by the user.
// <i> Default: 0
#ifndef OS_PRIVCNT
#define OS_PRIVCNT 0
#endif
// <o>Task stack size [bytes] <20-4096:8><#/4>
// <i> Set the stack size for tasks which is assigned by the system.
// <i> Default: 200
#ifndef OS_STKSIZE
#define OS_STKSIZE 50
#endif

// <q>Check for the stack overflow


// ===============================
// <i> Include the stack checking code for a stack overflow.
// <i> Note that additional code reduces the RTX performance. #ifndef
OS_STKCHECK
#define OS_STKCHECK 1
#endif

// </h>
// <h>Tick Timer Configuration
// =============================
// <o>Hardware timer <0=> Timer 0 <1=> Timer 1
// <i> Define the on-chip timer used as a time-base for RTX.
// <i> Default: Timer 0
#ifndef OS_TIMER
#define OS_TIMER 1
#endif

// <o>Timer clock value [Hz] <1-1000000000>


// <i> Set the timer clock value for selected timer.
// <i> Default: 15000000 (15MHz at 60MHz CCLK and VPBDIV = 4)
#ifndef OS_CLOCK
#define OS_CLOCK 15000000
#endif

// <o>Timer tick value [us] <1-1000000>


// <i> Set the timer tick value for selected timer.
// <i> Default: 10000 (10ms)
#ifndef OS_TICK
#define OS_TICK 10000
#endif

// </h>

// <h>System Configuration
// =======================
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task switching. #ifndef
OS_ROBIN
#define OS_ROBIN 1
51

#endif

// <o>Round-Robin Timeout [ticks] <1-1000>


// <i> Define how long a task will execute before a task switch.
// <i> Default: 5
#ifndef OS_ROBINTOUT
#define OS_ROBINTOUT 5
#endif

// </e>

// <o>Number of user timers <0-250>


// <i> Define max. number of user timers that will run at the same time.
// <i> Default: 0 (User timers disabled)
#ifndef OS_TIMERCNT
#define OS_TIMERCNT 0
#endif

// <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries


// <12=> 12 entries <16=> 16 entries
// <24=> 24 entries <32=> 32 entries
// <48=> 48 entries <64=> 64 entries
// <96=> 96 entries
// <i> ISR functions store requests to this buffer,
// <i> when they are called from the IRQ handler.
// <i> Default: 16 entries #ifndef
OS_FIFOSZ
#define OS_FIFOSZ 16
#endif

// </h>
//------------- <<< end of configuration section >>> -----------------------

// Standard library system mutexes


// ===============================
// Define max. number system mutexes that are used to protect
// the arm standard runtime library. For microlib they are not used. #ifndef
OS_MUTEXCNT
#define OS_MUTEXCNT 8
#endif

/*
* RTX User configuration part END
* */

#if (OS_TIMER == 0) /* Timer 0 */


#define OS_TID_ 4 /* Timer ID */
#define TIMx(reg) T0##reg
#elif (OS_TIMER == 1) /* Timer 1 */
#define OS_TID_ 5 /* Timer ID */
#define TIMx(reg) T1##reg
#else
#error OS_TIMER invalid
#endif

#define OS_TIM_ (1 << OS_TID_) /* Interrupt Mask */


#define OS_TRV ((U32)(((double)OS_ CLOCK*(double)OS_TICK)/ 1E6) -1) #define
OS_TVAL TIMx(TC) /* Timer Value */
#define OS_TOVF (TIMx(IR) & 1) /* Overflow Flag */
#define OS_TFIRQ() VICSoftInt = OS_TIM_; /* Force Interrupt */ #define
OS_TIACK() TIMx(IR) = 1; /* Interrupt Ack */ \
52

VICSoftIntClr = OS_TIM_; \
VICVectAddr = 0;
#define OS_TINIT() TIMx(MR0) = OS_TRV; /* Initialization */ \
TIMx(MCR) = 3; \
TIMx(TCR) = 1; \
VICDefVectAddr = (U32)os_def_interrupt; \
VICVectAddr15 = (U32)os_clock_interrupt; \
VICVectCntl15 = 0x20 | OS_TID_;
#define OS_IACK() VICVectAddr = 0; /* Interrupt Ack */

#define OS_LOCK() VICIntEnClr = OS_TIM_; /* Task Lock */


#define OS_UNLOCK VICIntEnable = OS_TIM_; /* Task Unlock */
()

/* WARNING: Using IDLE mode might cause you troubles while debugging. */ #define _idle_()
PCON = 1;

/*
* Global Functions
* */

/* os_idle_demon */
task void os_idle_demon (void) {
/* The idle demon is a system task, running when no other task is ready */
/* to run. The 'os_xxx' function calls are not allowed from this task. */

for (;;) {
/* HERE: include optional user code to be executed when no task runs.*/
}
}

/* os_tmr_call */

void os_tmr_call (U16 info) {


/* This function is called when the user timer has expired. Parameter */
/* 'info' holds the value, defined when the timer was created. */

/* HERE: include optional user code to be executed on timeout. */


}

/* os_error */

void os_error (U32 err_code) {


/* This function is called when a runtime error is detected. Parameter */
/* 'err_code' holds the runtime error code (defined in RTL.H). */

/* HERE: include optional code to be executed on runtime error. */ for (;;);


}
/*
* RTX Configuration Functions
* */

static void os_def_interrupt (void) irq {


/* Default Interrupt Function: may be called when timer ISR is disabled */ OS_IACK();
}
53

#include <RTX_lib.c>

/*
* end of file
* *

/***************************************************************************/
LCD.C
/**************************************************************/

#include <LPC214x.H> /* LPC214x definitions */


#define RS 0x00000400 /* P0.10 */
#define CE 0x00001000 /* P1.11 */

#define SET 1
#define OFF 0

void lcdcmd(char cmd); void


lcddat(char cmd);
void printstr(unsigned char *str, char x, char y);

void wait (void) { /* wait function */ int


d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit(void)
{
IODIR0 |= 0x000014f0;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

void printstr(unsigned char *str, char x, char y)


{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);

}
54

void lcdcmd(char cmd)


{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 |= LCDDAT;
IOCLR0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable lcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 |= LCDDAT;
IOCLR0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable lcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;

void lcddat(char cmd)


{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 |= LCDDAT;
IOSET0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable lcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 |= LCDDAT;
IOSET0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable lcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
}

void clrscr(char ch)


{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}
55

/************************************************************/
UART.C
/*************************************************************/

/* This file contains driver functions to send and receive data via uart0 in the */
/* ARM LPC2148 development board itself */
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/ #include
<LPC214x.H>
#include "config.h"
#define TEMT (1<<6)

void initserial(unsigned char uart)


{
if(0 == uart)
{
PINSEL0 = 0x00000005; /* Make pins 19 and 21 to function as TXD0 and RXD0 for
UART0*/
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0FDR = 0x00000010; /* DIVADDVA L = 0; MULVAL = 1 */
U0DLL = 98; /* 9600 Baud Rate @ 15MHz VPB Clock; = 97.65=98
*/
U0LCR = 0x03; /* DLAB = 0 */
U0IER = 0x01; /* Enable reciever data available interrupt*/
}
else
{
PINSEL0 = 0x00050000; /* Make pins 19 and 21 to function as TXD0 and
RXD0 for UART0*/
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1FDR = 0x00000010; /* DIVADDVA L = 0; MULVAL = 1 */
U1DLL = 98; /* 9600 Baud Rate @ 15MHz VPB Clock; = 97.65=98
*/
U1LCR = 0x03; /* DLAB = 0 */
U1IER = 0x01; /* Enable reciever data available interrupt*/

}
}
void putcharr (unsigned char uart, unsigned char ch) /* Writes character to Serial
Port*/
{
if(0 == uart)
{
while (!(U0LSR & TEMT)); U0THR
= ch;
}
else
{
while (!(U1LSR & TEMT)); U1THR
= ch;
}
}

unsigned char getcharr (unsigned char uart) /* Reads character from Serial
Port*/
{
if(0 == uart)
{
while (!(U0LSR & 0x01));
return (U0RBR);
56

}
else
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
}

char receive(unsigned char uart) /*function for receiving data from sensor (reads byte by byte & returns value if
exist, else #) */
{
if(0 == uart)
{
if (U0LSR & 0x01) /* If U0LSR 1st bit contains valid data, then return value of U0RBR*/
{
return (U0RBR);
}
return '\0'; /* If other than 0 to 9 data is recieved return
#*/
}
else
{
if (U1LSR & 0x01) /* If U0LSR 1st bit contains valid data, then return
value of U0RBR*/
{
return (U1RBR);
}

return '\0'; /* If other than 0 to 9 data is recieved return


#*/

}
}

void send_string(unsigned char uart,char* cpr) /* Writes string to serial port */


{
while(*cpr != '\0')
{
putcharr (uart,*cpr); cpr++;
}
}

unsigned char* receive_string(unsigned char uart) /* Reads string to serial


port */
{
static unsigned char c[30]; unsigned
char i=0;
c[i] = getcharr(uart); while(c[i] !=
CARRIAGE_ RET)
{
i++;
c[i] = getcharr(uart);

}
c[i] = '\0';
return(c);
}
57

CONFIG.H
/**************************************************************/
#define MAILBOX_M EMORY_POOL_ CNT 16
#define MBOX_MSG_ BUF_SIZE 100
#define USE_UART 0
/****************************************************************/
/* Enable below macro to disable the the recv task to check mailbox full */
//#define DISABLE_RECV_TASK
/****************************************************************/
#define STD_MSG1 "MailBox Test Message 1" #define
STD_MSG2 "MailBox Test Message 2" #define STD_MSG3
"MailBox Test Message 3"
#define LINE_FEED 0x0A #define
CARRIAGE_ RET 0x0D #define
KEY_SPACE 0x20 #define
KEY_ESC 0x1B

MAIL PROGRAM PROGRAM PORT

DETAILS UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
LCD PORT DETAILS
ARM DETAILS
PO.10 RS LCD PIN
P1.11 CE LCD PIN

Post Lab Questions


1. Mention the operations that can be performed on a mailbox.
2. When does the mailbox will get deleted?
3. Illustrate the operation of reading operation from a mailbox.
4. How to configure the mailbox?
5. What is branch prediction?

Result

The C-Language program to create a mailbox and to understand the about the RTOS functio ns
is developed and is verified.
58

8. Interrupt Performance Characteristics of ARM and FPGA

Aim
To study about the Interrupt performance characteristics between ARM and FPGA.

Pre Lab Questions


1. Define interrupts.
2. What is FPGA?
3. Difference between ARM and FPGA.
4. What are PROS and CONS for ARM?
5. What is interrupt pipelining?

Apparatus & Software Required


1. LPC2148 Development board.
2. K e il µV isi on5 software.
3. Flash Magic.
4. USB cable.
5. Xilinx FPGA Spartan 6
6. Xilinx ISE Design suite
7. JTAG Cable
8. FRC Cable

Theory
UART implementation FPGA & ARM7

Why we are doing this experiment?

An embedded system typically consists of both hardware and software. During the design phase
of an embedded system the system design Engineer has to choose the components of software and
hardware. In a system, implementing a specified logic or algorithm can be done exclusively using
software alone or hardware alone.
59

Implementing a logic or algorithm using only with software involves low cost but delivers only
low performance. Implementing the same logic or algorithm only with hardware involves high
performance but with low cost.

Hence, from the above graphical analysis it is clear that while designing an embedded system the
design engineer must choose a heterogeneous methodology which involves both hardware and
software. In this heterogeneous method the engineer has to decide which part of the logic to be
implemented in software and which other part to be implemented in software based on
performance. So from this experiment a student can learn how to design an embedded system based
on performance characteristics.

What is hardware software partitioning on performance characteristics?


Choosing the implementation method based on cost is called hardware software portioning on cost
characteristics. The design engineer must also consider the performance characteristics like speed,
power consumption and reliability while choosing the implementation methodology. Hence
deciding which part of our algorithm has to be implemented in software and which other part of
the algorithm has to be implemented as hardware based on performance characteristics is called
Hardware software partitioning on performance characteristics
60

Objective of the Experiment:


The aim of this experiment is to implement a UART serial communication algorithm as an
embedded system by which to learn hardware-software partitioning based on performance
characteristics.

Design of the system:


It is assumed that the reader knows about
i. UART communication protocol
ii. How microprocessor/microcontroller works
iii. What is FPGA and its use
iv. What is ASIC

Software UART Hardware UART


Advantages: Advantages:
i. Simple to implement i. Speed depends only on the FPGA’s
ii. Can be easily modified when clocking speed
need arises ii. The same design can be
manufactured several copies.
Hence it is
reliable
Disadvantages: Disadvantages:
i. Complexity of writing code increases i. Designing and writing code in HDL
when the design involves the needs good understanding of digital
operating system. circuit design and a HDL language.
ii. Speed depends on the Hence complex to implement.
microprocessor’s execution speed and ii. The hardware cannot be modified
other application code that club with when there is need to upgrade the
this UART algorithm implemented protocol if it is
iii. Since the software code implemented as ASIC.
depends on processor architecture,
porting the same code in other type of
processor needs modifying code again
and hence it is
not reliable

Hence, in this experiment we are going to follow the heterogeneous approach to implement the
UART algorithm. So it involves both software part and as well as hardware part.
61

Every protocol has two basic techniques,


i. Data driving logic and
ii. Data packing/ unpacking logic

Data driving logic:

This involves feeding and obtaining the actual data to be packed to the data packing/ unpacking
logic.

Data packing/unpacking logic:


This involves packing the data or unpacking the data and error checking as per the protocol
specification.

In this experiment, to design UART communication


a) Data driving logic is implemented in Software. The reason for choosing this logic to
be implemented in software is
i) The data is user dependent
ii) Initiating the data transfer is also user dependent
iii) Software design can easily be changed based on the user requirement
b) Data packing/unpacking logic is implemented in hardware. The reason for choosing
this logic to be implemented in hardware is
i. Since the protocol specification is fixed one and the packing/ unpacking logic
involves designing algorithm for the protocol alone
ii. Data packing/ unpacking speed is high
62

Pictorial representation:
To PC, for
flashing the
program
LPC2148 Development Kit TX memory

MA D
B
X
9
232

ARM7
LPC2148/246 RX
8
Data and
control Data driving
logic is
lines implemented in
software and
ARM 7
processor
executes it.
26 pin FRC connector

26 pin FRC connector


26 pin FRC cable

Xilinx FPGA Development


Data and
control
lines Xilinx FPGA
XC3S250E To PC, for
HyperTerminal
TX
display

MA D
Data B
X
packing/unpacking 9
232
fro ARTolld
logic is implemented
Th e insoftware
hardware and which drives the data RX m ppli river.
FPGA is used for it.
63

Software Part:
1. UART driver i.e. data driving logic is software part in this experiment.
2. This software is written using Embedded C language
3. Keil uVision4 IDE and keil arm compiler is used for compiling the C code.
4. Flash Magic tool has been used to download the program in to ARM7 micro controller.

Hardware part:

1. UART protocol i.e. packing/unpacking logic is hardware part in this experiment.


2. This hardware is designed using Verilog HDL program
3. The Modelsim IDE is used for simulation to test the functionality of the hardware designed using
Verilog HDL
4. Xilinx ISE is used to synthesize the design and to download the synthesized RTL file in to the
Xilinx FPGA XC3S250E.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
64

/******************************************************/
UART implementation FPGA & ARM7
ARM UART
/*********************************************************************/

#include <LPC214x.h>

void init_ios(void)
{
/*
P1.16 to P1.23 -- IN -- rx data
P1.24 to P1.31 -- OUT -- tx data
P0.15 -- OUT -- tx cmd
P0.16 -- IN -- tx done
P0.17 -- IN -- rx_rdy
*/
IODIR1 = 0xff000000; // tx data made as output IODIR0
= 0x00008000; // tx cmd made as output
IOCLR0 = 0xff008000; // Default both the outputs to Zero
}

void tx_char(unsigned char data)


{
char tx_done;
unsigned int i;
tx_done = ((IOPIN0>>16) & 0x00000001);
if(tx_done)
{
IOPIN1 &= ~0xff000000; // clr data port
IOPIN1 |= data<<24; // place data on port
for(i=0;i<1000;i++); // wait
IOSET0 = 1<<15; // enable tx command
for(i=0;i<9000;i++); // wait
IOCLR0 = 1<<15; // Disable tx command
while(!tx_done)
tx_done = ((IOPIN0>>16) & 0x00000001);
}

}
void tx_string(unsigned char* stringg)
{
while(*stringg != '\0')
{
tx_char(*stringg);
stringg++;
}
tx_char(0x0a);
tx_char(0x0d);
}

int main (void)


{
char i;
init_ios();
for(i=0;i<100;i++);
65

while (1)
{
tx_string("SM MICRRO SYSTEM");
}
}

/**************************************************************/
FPGA UART
/**************************************************************/

S/G Name Port in arm Data Direction in FPGA

tx_cmd -- P0.15 IN
tx_data[0] -- P1.24 IN
tx_data[1] -- P1.25 IN
tx_data[2] -- P1.26 IN
tx_data[3] -- P1.27 IN
tx_data[4] -- P1.28 IN
tx_data[5] -- P1.29 IN
tx_data[6] -- P1.30 IN
tx_data[7] -- P1.31 IN
tx_done -- P0.16 OUT

rx_data[0] -- P1.16 OUT


rx_data[1] -- P1.17 OUT
rx_data[2] -- P1.18 OUT
rx_data[3] -- P1.19 OUT
rx_data[4] -- P1.20 OUT
rx_data[5] -- P1.21 OUT
rx_data[6] -- P1.22 OUT
rx_data[7] -- P1.23 OUT
rx_rdy -- P0.17 OUT

Connector Details

P0.18 - P113 P1.24- P116 |


Po.17 - P59 P1.25- P66 |
P0.16 - P112 P1.26- P91 |
P0.15 - P92 P1.27- P93 |
P0.19 - P94 P1.28- P98 |
P0.20 - P97 P1.29- P106 |
P0.21 - P105 P1.30- P103 |
P0.23 - P104 P1.31- P96 |
+5v - GND - |
P1.16 - P135 P1.23- P134 |
P1.17 - P132 P1.22- P131 |
P1.18 - P130 P1.21- P117 |
P1.19 - P139 P1.20- P126 |

*/

module uart_top( clk,


rst,
tx,
66

rx,
lcd_rs,
lcd_en,
//lcd_rw,
lcd_dat,
tx_cmd_i,
tx_data_i,
tx_done_o,
rx_data_o,
rx_rdy_o
);

/*********** I/O Declecration**********/


input clk;
input rst;
input rx;
output tx;
input tx_cmd_i;
input [7:0]tx_data_i;
output lcd_rs;
output lcd_en;
//output lcd_rw;
output [3:0]lcd_dat; output
tx_done_o;
output [7:0]rx_data_o; output
rx_rdy_o;
/*
Local Wire and reg decleration for I/Os
*/
wire u_clk; wire
tx_done;
reg [7:0] dat = 8'h31;
//reg tx_cm;
//reg [15:0]c1;

wire [3:0]lcddata_in; wire


rx_rdy;

baud b1(
.sys_clk(clk),
.sys_rst_l(rst),
.baud_clk(u_clk)
);

u_xmit t1( .sys_clk(u_clk),


.sys_rst_l(rst),
.uart_xmitH(t x),
.xmitH(t x_cmd_i),
.xmit_dataH(tx_data_i),
.xmit_doneH(tx_done_o)
);

u_rec r1( .sys_rst_l(rst),


.sys_clk(u_clk),
.uart_dataH(rx),
.rec_dataH(lcddata_in),
.rec_readyH( rx_rdy)
);

lcd_dis lcd1( .clk(clk),


.rs(lcd_rs),
67

.en(lcd_en),
//.rw(lcd_rw),
.data(lcd_dat),
.wr_sig(rx_rdy),
.data_in(lcddata_in)
);
/*
always @(posedge u_clk or negedge rst) begin
if(~rst)
begin
c1 <= 16'd0;
end
else
begin
c1 <= c1 + 16'd1; if(c1 == 16'd1000)
tx_cm <= 1'b1; if(c1
== 16'd1010)
begin
tx_cm <= 1'b0; end

end end
*/

assign rx_data_o = lcddata_in; assign rx_rdy_o


= rx_rdy;

endmodule

/********************************************************************/
FPGA UCF FILE
/**************************************************************/

#PACE: Start of Constraints generated by PACE #PACE:

Start of PACE I/O Pin Assignments


NET "clk" LOC = "p80" ;
NET "lcd_dat[0]" LOC = "p2" ;
NET "lcd_dat[1]" LOC = "p3" ;
NET "lcd_dat[2]" LOC = "p4" ;
NET "lcd_dat[3]" LOC = "p5" ;
NET "lcd_en" LOC = "p16" ; NET
"lcd_rs" LOC = "p15" ; NET
"rst" LOC = "p6" ;
NET "rx" LOC = "p120" ;
NET "rx_data_o[0]" LOC = "p168" ; NET
"rx_data_o[1]" LOC = "p171" ; NET
"rx_data_o[2]" LOC = "p172" ; NET
"rx_data_o[3]" LOC = "p177" ; NET
"rx_data_o[4]" LOC = "p178" ; NET
"rx_data_o[5]" LOC = "p179" ; NET
"rx_data_o[6]" LOC = "p180" ; NET
"rx_data_o[7]" LOC = "p181" ;
68

NET "rx_rdy_o" LOC = "p200" ;


NET "tx" LOC = "p119" ;
NET "tx_cmd_i" LOC = "p197" ;
NET "tx_data_i[0]" LOC = "p185" ; NET
"tx_data_i[1]" LOC = "p186" ; NET
"tx_data_i[2]" LOC = "p187" ; NET
"tx_data_i[3]" LOC = "p189" ; NET
"tx_data_i[4]" LOC = "p190" ; NET
"tx_data_i[5]" LOC = "p192" ; NET
"tx_data_i[6]" LOC = "p193" ; NET
"tx_data_i[7]" LOC = "p196" ; NET
"tx_done_o" LOC = "p199" ;

#PACE: Start of PACE Area Constraints #PACE: Start of

PACE Prohibit Constraints #PACE: End of Constraints

generated by PACE

Post Lab Questions


1. What are basically ARM processors?
2. Compare RISC and CISC.
3. How to interface interrupts?
4. Explain the importance of using LPC2148 Development Board.
5. List out the applications of ARM.

Result

The C-Language program for Interrupt performance characteristics between ARM and FPGA
and its characteristics was studied.
69

9. Flashing of LEDS

Aim

To develop a ‘C’ program to make the LED blink (including delay routine). Upon change in the
delay program the speed should vary.

Pre Lab Questions


1. What is seven segment displays?
2. Where LEDs are used?
3. What are the different configurations of LED?
4. What is the use of flash magic software?
5. Differentiate LED from LCD.

Apparatus & Software Required

1. LPC2148 Development board.


2. K e il µV isi on5 software.
3. Flash Magic.
4. USB cable.

Theory

LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
electrons are able to recombine with holes and energy is released in the form of light. This effect
is called electroluminescence and the color of the light is determined by the energy gap of the
semiconductor.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
70

/* This is a test program to make the LEDs L2 and L3 Blink in the ARM LPC2148 */
development board itself
/************************************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
void wait (void) /* wait function */
{
int d;

for (d = 0; d < 1000000; d++); /* only to delay for LED flashes */


}

int main (void)


{

IODIR0 = 0x80002000; /* P0.13 and P0.31 defined as Outputs */

while (1) /* Loop forever */


{
IOCLR0 = 0x80002000; /*Active Low outputs makes the
LEDs ON*/
wait ();

IOSET0 = 0x80002000; /* High outputs makes the LEDs


OFF*
/
wait ();

FLASHING LED PROGRAM PORT DETAILS


ARM DETAILS
P0.13 LED PIN
P0.31 LED PIN

Post Lab Questions


1. What is the function of GPIO?
2. What are the Pins which are used to connect LEDs?
3. How to identify 'Polarity' of LED?
4. What is a use of Jumper?
5. Which port is used in ARM 7 processor kit?

Result
The C-Language program to make the LED blink was developed and output was verified. Upon
change in the delay program the speed variation was verified.
71

10. INTERFACING STEPPER MOTOR AND


TEMPERATURE SENSOR

Aim
To write C Programs for running stepper motor either in clock- wise or counter-clock- wise and
the direction of the rotation of the stepper motor depends on the variation in the temperature
sensor.

Pre Lab Questions

1. What is LM35?
2. List the devices used to sense temperature.
3. What is the purpose of a thermocouple?
4. What is signal conditioning?
5. What is the output voltage of a thermocouple?

Apparatus & Software Required

1. LPC2148 Development board.


2. K e il µV isi on5 software.
3. Flash Magic.
4. USB cable.
5. Stepper Motor.

Theory

Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central
metal gear. To make the motor shaft turn, first one electromagnet is given power, which makes
the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus
aligned to the first electromagnet, they are slightly offset from the next electromagnet.
72

So when the next electromagnet is turned on and the first will turn off, the gear rotates slightly
to align with the next one and from there the process is repeated. Each of those slight rotations is
called a "step." In that way, the motor can be turned to a précised angle. There are two basic
arrangements for the electromagnetic coils: bipolar and unipolar.

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.

STEPPER MOTOR PROGRAM

/* This is a test program to stepper motor interface in the ARM LPC2148 */


/* development board itself */
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/ #include
<LPC214x.H> /* LPC214x definitions */

#define step1 0x00010000 /* P1.16 */


#define step2 0x00020000 /* P1.17 */

void wait (void)


{ /* wait function */
int d;
for (d = 0; d < 10000; d++); /* only to delay for LED flashes */
}

call_stepper_forw()
{
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00040000;
// wait();
// wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00060000;
// wait();
// wait();
73

wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00070000;
// wait();
// wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00050000;
// wait();
// wait();
wait();
wait();
}

int main (void)


{
IODIR1 |= 0xFFFFFFFF; IOCLR1
|= 0X00FF0000;
wait();
while(1) /*Loop Forever*/
{
call_stepper_forw();
// wait();
// wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
}
}

STEPPER MOTOR PROGRAM PORT DETAILS


ARM DETAILS
P1.16 STEP 1
P1.17 STEP 2
74

TEMPERATURE SENSOR PROGRAM

/*************************************************************/
MAIN ADC TEST
/*************************************************************/
/* This is a test program to temperature sensor in the ARM LPC2148 development board*/
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/
#include <LPC214x.H> /* LPC214x definitions */
#include "ADC_Driver.c" /* contains prototypes of driver functions*/ #include
"lcd.c"
#include <stdio.h>

int main (void)


{
unsigned int adc_val;
unsigned int temp;
unsigned char buf[4] = {0,0,0,0};
ADCInit();
lcdinit();
//wait();
clrscr(10);
printstr("ADC Test",0,0); wait();
while (1) /* Loop forever */
{
adc_val = ADC_ReadChannel();
temp = (unsigned int)((3*adc_val*100)/1024);
sprintf(buf,"%d",temp);
printstr(buf,0,1);

}
}

/************************************************************************************/
LCD.C
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/

#include <LPC214x.h>

#define RS 0x00000400 /* P0.10 */


#define CE 0x00001800 /* P1.11 */

void clrscr(char ch); void


lcdinit(void); void
lcdcmd(char); void
lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(unsigned char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);

#define SET 1
#define OFF 0
75

unsigned int thousands,hundreds,tens,ones;

void wait (void) { /* wait function */


int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

void printstr(unsigned char *str, char x, char y)


{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);

}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}

void lcddat(char cmd)


76

{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}

void clrscr(char ch)


{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}

void split_numbers(unsigned int number)


{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}

void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcome to ", 0, 0);
printstr(" SMMICRRO ", 0, 1);
}
77

ADC_ DRIVER.C
/**************************************************************/

#include <LPC214x.H> /* LPC214x definitions */


Void ADCInit (void)
{
PINSEL1 |= 0x04000000; /*For Channel AD0.2 is P0.29*/
IODIR0 |= ~(0x04000000);
AD0CR |= 0x00200204; /*0x04 selects AD0.2 to mux output, 0x20 makes ADC in operational*/
AD0GDR; /*A read on AD0GDR clears the DONE bit*/
}
void ADC_StartConversion(void)
{
AD0CR |= (1<<24);
}
void ADC_StopConversion(void)
{
AD0CR &= (~(1<<24));
}
unsigned int ADC_ReadChannel(void)
{
// unsigned int i; unsigned long
ADC_Val, t;
ADC_StartConversion();
while((AD0DR2&0x80000000)==0); /*wait until ADC conversion completes*/
if(AD0STAT & 0x00000400)
{
//printstr("OVR",0,1); return(0);
}
t = AD0DR2;
ADC_Val = ((t>>6) & 0x000003FF);//(AD0DR2 & 0x000003FF); //((AD0CR>>6) & 0x000003FF);
//ADC_StopConversion();
return(ADC_Val);
}.
TEMPERATURE SENSOR PROGRAM PORT DETAILS
ARM DETAILS
P0.29 ADC0.2
PO.10 RS LCD PIN
P1.11 CE LCD PIN

Post Lab Questions


1. Why LM35 is used to Measure Temperature?
2. Compare the difference between LM 34 and LM 35 sensors?
3. What is the operating temperature range in LM35?
4. How many pins are available in LM35?
5. What is the main function of analog pin in LPC 2148?

Result
The C-Language program for running stepper motor either in clock-wise or counter-clock- wise
Depending on the temperature is developed in the sensor LM35 and the output is verified in LCD.
78

11. Implementing zigbee protocol with ARM

Aim

To write C Programs for Zigbee Protocol and verify the communication between Xbee Module
Transmitter and Receiver.

Pre Lab Questions


1. What are the applications of zigbee protocol?
2. Why Zigbee based is preferred for wireless communication?
3. What is the function of a scheduler?
4. What is the main function of voltage convertors in UART?
5. List the advantages of using Zigbee protocol.

Apparatus & Software Required

1. LPC2148 Development board.


2. K e il µV isi on5 software.
3. Flash Magic.
4. USB cable.
5. Zigb e e Mod ule Tx and Rx .
Theory

The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF Modules
were directed to operate within the ZigBee protocol. The modules provide reliable delivery of
data between remote devices. Zigbee is the communication protocol like wifi and Bluetooth. Xbee
is the module using Zigbee protocol

Some of its features are:

ZigBee is targeted at radio-frequency (RF) applications

Low data rate, long battery life, and secure networking

Transmission range is between 10 and 75 meters (33~246 feet)

The addressing space allows of extreme node density—


up to 18,450,000,000,000,000,000 devices (64 bit IEEE address)
79

Using local addressing, simple networks of more than 65,000 nodes can be configured,
with reduced address overhead
The radios use direct-sequence spread spectrum coding, which is managed by the digital
stream into the modulator.
To ensure reliable data transmission

Binary phase shift keying (BPSK) in the 868/915 MHz

Offset quadrature phase shift keying (O-QPSK) at 2.4 GHz

Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
80

/****************************************************************************/
ARM TRANSMITTER
PROGRAM LCD.C
/****************************************************************************/

#include <LPC214x.h>
#include "lcd.h"
#define RS 0x00000400 /* P0.10 */
#define CE 0x00001800 /* P1.11 */

/*void clrscr(char ch); void


lcdinit(void); void
lcdcmd(char);
void lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1 void printstr(char
*,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);*/

#define SET 1
#define OFF 0

unsigned int thousands,hundreds,tens,ones; void wait

(void)
{ /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}

void gotoxy(char x, char y)


{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);

void printstr(char *str, char x, char y)


{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
81

lcddat(str[i]);

}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100);
//enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

}
void lcddat(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;

LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble


IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
82

void split_numbers(unsigned int number)


{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}

void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcome to ", 0, 0);
printstr(" SM MICRRO ", 0, 1);
}

/***********************************************************************************/
LCD.h
/***********************************************************************************/

void clrscr(char ch); void


lcdinit(void); void
lcdcmd(char); void
lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number); void
Wait_Msg(void);
void Welcome_Msg(void);

/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
UART_1.C
/**************************************************************/

#include <LPC214X.H>
#include "lcd.c"

#define TEMT 0X40

void uart_1(void); void


delay(void);
void putcharr (unsigned char ch); /* Writes character to Serial Port*/
void tx_string(char str);

int main(void)
{
uart_1();
lcdinit();
delay();
delay();
83

delay();
delay();
printstr("SM MICRRO SYSTEM",0,0);
while(1)
{
tx_string('C');

gotoxy(7,1);
lcddat('C');
delay();
delay();
delay();
delay();
while(1);
}
}

void uart_1(void)
{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1FDR = 0x00000010;
U1DLL = 98;
U1LCR = 0x03;
U1IER = 0x01;
}
void delay(void)
{
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}

void tx_string(char str)


{
putcharr(str);
}
void putcharr (unsigned char ch) /* Writes character to Serial Port*/
{
while (!(U1LSR & TEMT)); /* U1LSR --> Status register
*/
U1THR = ch;
}
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
ARM RECEIVER PROGRAM
/**************************************************************/
#include <LPC214X.H>
#include "lcd.c"
void uart_1(void); void
delay(void);
unsigned char getcharr (void); /* Reads character from Serial Port*/

int main(void)
{
char rx_data;
uart_1();
lcdinit();
printstr("SM MICRRO SYSTEM",0,0);
while(1)
{
84

rx_data = getcharr(); /* Reads character from Serial


Port*/
gotoxy(7,1);
lcddat(rx_data);
}
}

void uart_1(void) /* UART Installation */


{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1FDR = 0x00000010;
U1DLL = 98;
U1LCR = 0x03;
U1IER = 0x01;
}
void delay(void)
{
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
unsigned char getcharr (void) /* Reads character from Serial Port*/
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
Implementing zigbee protocol with ARM PROGRAMS PORT DETAIL
TRANSMITTER PROGRAM RECEIVER PROGRAM

ARM Details ARM Details


P0.8 TXD1 P0.8 TXD1
P0.9 RXD1 P0.9 RXD1
P0.10 RS LCD PIN P0.10 RS LCD PIN
P1.11 CE LCD PIN P1.11 CE LCD PIN

Post Lab Questions


1. How to verify the communication between Transmitter and Receiver?
2. Which module is using Zigbee protocol?
3. How many UART ports available in LPC2148?
4. Write the two modes of communication are used in a ZigBee network.
5. Mention the transmission range for Zigbee protocol.

Result
The C-Language program for Zigbee Protocol is written and the communication between
Xbee Module Transmitter and Receiver is verified.
84

12. SIMULATION USING PROTEUS


SOFTWARE –AN INTRODUCTION

Aim
To simulate a multivibrator using Proteus Software and
check its functionality by verifying its output with an simulated LED.

Pre Lab Questions


1. What is the need for a simulation tool?
2. What is Proteus Software?
3. List the feature of Proteus Software?
4. List some of the design tools in proteus software?
5. Give any 3 gadgets available in the proteus software?

Procedure
Step1:
Start All Programs Proteus xx Professional
ISIS xx Professional
85

Note:

Identify the components

The Menu Bar

The Toolbars

Command Toolbars
86
Mode Selector Toolbar

Orientation Toolbar

Simulation Toolbar

Construct the following multivibrator circuit using analog and digital components and
simulate it,
87
The Components needed are,

Resistors 4.7kΩ ,1kΩ 330Ω , 100k (variable resistor)


Capacitors 10uF ,0.01uF
IC NE555
LED
Power supply

Step 2:

Choose required components from the component library in


editing commands.
88

Then the component library window will appear

Step 3
Then choose the all require components and put into the main window.
89

1. Select “Analog ICs” in Category

2. Then select “555 ANALOG TIME/OSCILATOR”

3. Next click on OK

4. Finally component put into main window


90

Following the same procedure, place all the required components to main window
91

Step 4
Connect all the components as the above circuit diagram by using connecting lines. We can
get connecting lines by selecting ends of the components as shows in following figure.

Then complete the circuit using connecting lines as following figure…..


92

Step 5
Now make sure all the components correctly connected. Then go the simulation tool bar.

To start the simulation click on play button.


Then start the simulation if there are any errors the
simulation must be fail and give error messages.
93

Check the output by inspecting the status of the LED.

Post Lab Questions


1. What is mode selector tool bar
2. What is orientation tool bar
3. What is the need for simulation tool bar?
4. What is the frequency of the output obtained in simulation?
5. What is the name of the library under which 555IC is located?

Result
Thus the Multivibrator is simulated using Proteus Software and the output is
observed.
94
95

13. SIMULATION OF CALCULATOR USING 8051


MICROCONTROLLER IN PROTEUS
SOFTWARE

Aim
To simulate a simple calculator using 8051 microcontroller in Proteus Software.

Pre Lab Questions


1. List some of the microprocessor supported by proteus software
2. List the required arithmetic operations to be performed by the calculator?
3. Write down the features of 8051 microcontroller
4. What is the difference between microprocessor and microcontroller?
5. What is the size of the data bus in 8051 microcontroller?

Procedure

The calculator we are going to design is quite basic calculator, it will only perform 4 tasks, which
are as follows:
When you press the (+) button then it will add the two digits. For example, you want to
add 2 and 3 then you need to press 2 + 2 = these four buttons in sequence and when you
press the = button it will automatically will give you the sum.
When you press (-) button it will subtract the two digits like 3 – 2 = and it will give you
the result.
When you press (x) button it will multiply the two digits.
When you press the (/) button it will simply divide the two digits.
Whenever you press the (=) button, it will give you the output
depending on the function you used before and if you press (=) in the start then it will give
“Wrong Input”.
Finally, there’s (ON/C) button on the Calculator, when you press this it will simply reset the
code and will clear the LCD.
So, that’s how this calculator is gonna work. Moreover, it will always reset when you try to
calculate new value.
As its a simple calculator, so its only limited to 1 digit, means it will only apply the operation
on single digit input like 2+3 but it won’t work on more than 1 digit like 12 + 13.
After that, we will do the coding part for calculator with 8051 Microcontroller.
So, now let’s get started with Proteus Simulation.
96

Proteus Simulation
The Proteus Simulation of this Calculator with 8051 Microcontroller and is shown in
below figure:

Programming Code

1 while(1)
2 {
3 //get numb1
4 key = get_key();
5 writecmd(0x01); //clear display
6 writedata(key); //Echo the key pressed to LCD
7 num1 = get_num(key); //Get int number from char value, it checks for
8
9 wrong input as well
10 if(num1!=Error) //if correct input then proceed, num1==Error
11 means wrong input
12 {
13 //get function
14 key = get_key();
15 writedata(key); //Echo the key pressed to LCD
16 func = get_func(key); //it checks for wrong func 17
18 if(func!='e') //if correct input then proceed,
19 func=='e' means wrong input 20
{
21 //get numb2
22 key = get_key();
23 writedata(key); //Echo the key pressed to LCD
24 num2 = get_num(key); //Get int number from char
25 value, it checks for wrong input as well 26
27 if(num2!=Error) //if correct input then
28 proceed, num2==Error means wrong input
97
{
29
//get equal sign key =
30
get_key();
31
writedata(key); //Echo the key pressed to LCD if(key ==
32
33
'=') //if = is pressed then
34
35 proceed
{
36
switch(func) //switch on function
37
{
38
case '+': disp_num(num1+num2); break; case '-':
39
disp_num(num1-num2); break; case 'x':
40
disp_num(num1*num2); break; case '/':
41
disp_num(num1/num2); break;
42
}
43
}
44
else //key other then =
45

46 here means error wrong input 47 {


48
if(key == 'C') //if clear screen is
49 pressed then clear screen and reset
writecmd(0x01); //Clear Screen DispError(0);
else
//Display wrong
input error
}
}
}
}
}

As you can see in the above function, first check for the first key press.
When you pressed the first key on keypad then I get this key and converter it to integer.
After that I waited for the next key which must be some operation key like + – X or / otherwise
it will generate the error message.
After that code is waiting for the third key which should be some numerical digit and then
It converts it to integer again and if you entered some invalid key then it will generate the
error.
Finally waiting for the = sign. When you press the = sign it will automatically perform the
required operation which Iplaced in the switch case loop.
It will calculate the value and then print out the result and on next key press it will first clear
the screen and then get the value and will continue.
Below is the detailed code for the project with comments

1 #include<reg51.h>
2 #include<string.h> 3
4 //Define Macros
5 #define Error 13 // Any value other than 0 to 9 is good here 6
7 //Function declarations
8 void cct_init(void);
9 void delay(int);
10 void lcdinit(void);
98
11 void writecmd(int);
12 void writedata(char);
13 void writeline(char[]);
14 void ReturnHome(void);
15 char READ_SWITCHES(void);
16 char get_key(void);
17 int get_num(char);
18 char get_func(char);
19 void DispError(int);
20 void disp_num(int);
21 void WebsiteLogo();
22 22
23 /
24 //Pin description
25 /*
26 P2 is data bus
27 P3.7 is RS
28 P3.6 is E
29 P1.0 to P1.3 are keypad row outputs
30 P1.4 to P1.7 are keypad column inputs 31
*/
32 //********************
33 // Define Pins
34 //********************
35 sbit RowA = P1^0; //RowA
36 sbit RowB = P1^1; //RowB
37 sbit RowC = P1^2; //RowC
38 sbit RowD = P1^3; //RowD
39
40 sbit C1 = P1^4; //Column1
41 sbit C2 = P1^5; //Column2
42 sbit C3 = P1^6; //Column3
43 sbit C4 = P1^7; //Column4
44
45 sbit E = P3^6; //E pin for LCD
46 sbit RS = P3^7; //RS pin for LCD
47
48 // ***********************************************************
49 // Main program
50 //
51 int main(void)
52 {
53 char key; //key char for keeping record of pressed
54 key
55 int num1 = 0; //First number
56 char func = '+'; //Function to be performed among two
57 numbers
58 int num2 = 0; //Second number 59
60 cct_init(); //Make input and output pins as required
61 lcdinit(); //Initilize LCD
62 WebsiteLogo();
63 while(1)
64 {
65 WebsiteLogo();
66 //get numb1
67 key = get_key();
68 writecmd(0x01); //clear display
69 WebsiteLogo();
70 writedata(key); //Echo the key pressed to LCD
71 num1 = get_num(key); //Get int number from char value, it checks
72 for wrong input as well 73
74 if(num1!=Error) //if correct input then proceed, num1==Error
75 means wrong input 76
{
77 //get function
78 key = get_key();
79 writedata(key); //Echo the key pressed to LCD
80 func = get_func(key); //it checks for wrong func 81
99
82 if(func!='e') //if correct input then proceed,
83 func=='e' means wrong input
84 {
85 //get numb2
86 key = get_key();
87 writedata(key); //Echo the key pressed to LCD
88 num2 = get_num(key); //Get int number from char
89 value, it checks for wrong input as well
90
91 if(num2!=Error) //if correct input then
92 proceed, num2==Error means wrong input
93 {
94 //get equal sign
95 key = get_key();
96 writedata(key); //Echo the key pressed to
97 LCD
98
99 if(key == '=') //if = is pressed then
100 proceed
101 {
102 switch(func) //switch on function
103 {
104 case '+': disp_num(num1+num2); break;
105 case '-': disp_num(num1-num2); break;
106 case 'x': disp_num(num1*num2); break;
107 case '/': disp_num(num1/num2); break;
108 }
109 }
110 else //key other then =
111 here means error wrong input
112 {
113 if(key == 'C') //if clear screen is
114 pressed then clear screen and reset
115 {
116 writecmd(0x01); //Clear Screen
117 WebsiteLogo();
118 }
119 else
120 {
121 DispError(0); //Display wrong
122 input error
123 WebsiteLogo();
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131
132 void WebsiteLogo()
133 {
134 writecmd(0x95);
135 writedata('w'); //write
136 writedata('w'); //write
137 writedata('w'); //write
138 writedata('.'); //write
139 writedata('T'); //write
140 writedata('h'); //write
141 writedata('e'); //write
142 writedata('E'); //write
143 writedata('n'); //write
144 writedata('g'); //write
145 writedata('i'); //write
146 writedata('n'); //write
147 writedata('e'); //write
148 writedata('e'); //write
149 writedata('r'); //write
150 writedata('i'); //write
151 writedata('n'); //write
152 writedata('g'); //write
100
153
154 writecmd(0xd8);
155
156 writedata('P'); //write
157 writedata('r'); //write
158 writedata('o'); //write
159 writedata('j'); //write
160 writedata('e'); //write
161 writedata('c'); //write
162 writedata('t'); //write
163 writedata('s'); //write
164 writedata('.'); //write
165 writedata('c'); //write
166 writedata('o'); //write
167 writedata('m'); //write
168 writecmd(0x80);
169 }
170
171 void cct_init(void)
172 {
173 P0 = 0x00; //not used
174 P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
175 P2 = 0x00; //used as data port for LCD
176 P3 = 0x00; //used for RS and E
177 }
178
179 void delay(int a)
180 {
181 int i;
182 for(i=0;i<a;i++); //null statement
183 }
184
185 void writedata(char t)
186 {
187 RS = 1; // This is data
188 P2 = t; //Data transfer
189 E = 1; // => E = 1
190 delay(150);
191 E = 0; // => E = 0
192 delay(150);
193 }
194
195
196 void writecmd(int z)
197 {
198 RS = 0; // This is command
199 P2 = z; //Data transfer
200 E = 1; // => E = 1
201 delay(150);
202 E = 0; // => E = 0
203 delay(150);
204 }
205
206 void lcdinit(void)
207 {
208 ///////////// Reset process from datasheet /////////
209 delay(15000);
210 writecmd(0x30);
211 delay(4500);
212 writecmd(0x30);
213 delay(300);
214 writecmd(0x30);
215 delay(650);
216 /////////////////////////////////////////////////////
217 writecmd(0x38); //function set
218 writecmd(0x0c); //display on,cursor off,blink off
219 writecmd(0x01); //clear display
220 writecmd(0x06); //entry mode, set increment
221 }
222 void ReturnHome(void) /* Return to 0 cursor location */
101

223
224 {
225 writecmd(0x02);
226 delay(1500);
227 WebsiteLogo();
228 }
229
230 void writeline(char Line[])
231 {
232 int i;
233 for(i=0;i<strlen(Line);i++)
234 {
235 writedata(Line[i]); /* Write Character */
236 }
237
238 ReturnHome(); /* Return to 0 cursor position */
239 }
240
241 char READ_SWITCHES(void )
242 {
243 RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A
244
245 if (C1 == 0) { delay(10000); while (C1==0); return '7'; }
246 if (C2 == 0) { delay(10000); while (C2==0); return '8'; }
247 if (C3 == 0) { delay(10000); while (C3==0); return '9'; }
248 if (C4 == 0) { delay(10000); while (C4==0); return '/'; }
249
250 RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B
251 if (C1 == 0) { delay(10000); while (C1==0); return '4'; }
252 if (C2 == 0) { delay(10000); while (C2==0); return '5'; }
253 if (C3 == 0) { delay(10000); while (C3==0); return '6'; }
254 if (C4 == 0) { delay(10000); while (C4==0); return 'x'; }
255
256
257 RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C
258
259 if (C1 == 0) { delay(10000); while (C1==0); return '1'; }
260 if (C2 == 0) { delay(10000); while (C2==0); return '2'; }
261 if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
262 if (C4 == 0) { delay(10000); while (C4==0); return '-'; }
263
264 RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D
265
266 if (C1 == 0) { delay(10000); while (C1==0); return 'C'; }
267 if (C2 == 0) { delay(10000); while (C2==0); return '0'; }
268 if (C3 == 0) { delay(10000); while (C3==0); return '='; }
269 if (C4 == 0) { delay(10000); while (C4==0); return '+'; }
270
271 return 'n'; // Means no key has been pressed
272 }
273
274 char get_key(void) //get key from user
275 {
276 char key = 'n'; //assume no key pressed 277
278 while(key=='n') //wait untill a key is pressed
279 key = READ_SWITCHES(); //scan the keys again and again 280
281 return key; //when key pressed then return its value
282 }
283
284 int get_num(char ch) //convert char into int
285 {
286 switch(ch)
287 {
288 case '0': return 0; break;
289 case '1': return 1; break;
290 case '2': return 2; break;
291 case '3': return 3; break;
292 case '4': return 4; break;
293 case '5': return 5; break;
294 case '6': return 6; break;
102

Post Lab Questions


1. What is the need for LCD in the project?
2. What is the need for ADC in the Project?
3. What are the arithmetic operations done in the simulation?
4. What is the need for RESET button in the project?
5. What is the operating frequency of the microcontroller?

Result

Thus the calculator was simulated using 8051microcontroller in Proteus Software.

You might also like