Sunteți pe pagina 1din 63

Sri Balamurugan Polytechnic College

Thalayuthu, Palani 624 618

Embedded System Lab Manual


YEAR: III SEM: VI

Department of Electronics & Communication

Engineering

ARM 7 LPC 2148 Controller

Embedded C & ASM Programs


List of Experiments
S. No Name of the Experiments Page No
Led Interface
1
Switch Interface
Buzzer Interface
2 Relay Interface
Stepper Motor Interface
3 External Interrupt
4 Timer Program
5 Seven Segment Display
6 Pwm Signals
7 Displaying a Message in a 2 Line X16 Characters
Transmission From Kit & Reception From Pc Using
8
Serial Port
9 Program For 4x4 Matrix Keyboard Interface
Analog To Digital Converter
10
Thermister
11 Multi 7 Segment Display
Addition
Subtraction
12
Multiplication
Division
I2c Serial Eeprom
13
Displaying Two Different Messages In Lcd Display In
14
Two Lines
15 Blinking Two Leds
16 Transmission From kit And Reception From Pc Using
Serial Port
17 Graphics Lcd
Ex. No: 1 A) Led Interface

Aim:

To Write an Embedded C Program to interface the 8 bit Led with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED Switch Interface Card 1

Program:

#include <LPC214X.H> //LPC2148 HEADER


//DELAY PROGRAM
void delay(void)
{
unsigned int i;
i=0xffffff;
while(i--);
}
//MAIN PROG STARTS HERE
int main(void)
{
PINSEL2=0; // Port 1 is I/O
IODIR1=0XFF<<24; //Port Pins P1.24 to P1.31 as Output Pins
while(1)
{
IOSET1=0X55<<24; //P1.25,P1.27,P1.29 &P1.31 LEDs are Glow
delay();
IOCLR1=0X55<<24; //P1.25,P1.27,P1.29 &P1.31 LEDs are off
IOSET1=0XAA<<24; //P1.24,P1.26,P1.28 &P1.30 LEDs are Glow
delay();
IOCLR1=0XAA<<24; //P1.24,P1.26,P1.28 &P1.30 LEDs are off
}
}
LED Interface Diagram R9
P1.31
LED8
R10
P1.30

LED7
R11
P1.29
LED6
R12
P1.28

LED5
R13
P1.27
LED4

R14
P1.26
LED3
R15
P1.25

LED2

R16
P1.24
LED1

Flow Chart for LED Interface

z
Start

Configure the ports P1.24 to P1.31 as I/O & Assign


those ports as O/P port pins

Set LEDS 2,4,6,8 to Glow

Call Delay Subroutine

Clear LEDS 2,4,6,8 & Set LEDS 1,3,5,7

Call Delay Subroutine

Clear LEDS 1,3,5,7

Result:

Thus the Embedded C program to interface LED Interface with LPC2148 has been tested
successfully.
Ex. No: 1 A) Switch Interface

Aim:

To Write an Embedded C Program to interface the 8 bit Switch with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED - Switch Interface Card 1

Program:

#include<lpc214x.h>
/*void delay(void)
{
unsigned int i=0xffffff;
while(i--)
}
*/
unsigned int num;
int main(void)
{
PINSEL2=0X00;
IODIR1=0XFF00FFFF;
IOSET1=0XFF000000;
while(1)
{
num=IOPIN1&0X00FF0000;
num=num<<8;
IOCLR1=0XFF<<24;
IOSET1=num;
}
}
Switch Interface Diagram VCC

P1.16
R1 SW8
1 2

P1.17
R2 SW7
1 2

P1.20 P1.19 P1.18


R3 SW6
1 2

R5 SW5
1 2

R6 SW4
1 2

P1.21
R4 SW3
1 2

P1.22
R7 SW2
1 2

P1.23
R8 SW1
1 2

Flow Chart for Switch Interface

Start

Configure the ports P1.16 to P1.23 as I/O & Assign


these ports as O/P port pins

Read the pin value register to find which is pressed

Using that value set the corresponding LEDS to Glow

Result:

Thus the Embedded C program to interface Switch Interface with LPC2148 has been tested
successfully.
Ex. No: 2 A) Buzzer Interface

Aim:

To Write an Embedded C Program to interface the 8 bit Buzzer Interface with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
#define BUZ 1<<31 //BUZZER IS INTERFACED WITH P0.31
unsigned int del,del1,del2;
void delay(unsigned int i)

{
while(i--);
}
int main(void)

IODIR0=BUZ; //BUZZER PORT AS OUTPUT


IOSET0=BUZ; //SWITCH OFF BUZZER (PNP TRANSISTER)

while(1)

IOSET0=BUZ; //SWITCH OFF BUZZER


delay(0xfffff); //CALL DELAY
IOCLR0=BUZ; //SWITCH ON BUZZER
delay(0xfffff); //CALL DELAY

} //REPEAT
}
Buzzer Interface Diagram
+5V
LS1

2
BUZZER
R54
PNP BCE

BUZZER
Q9

P0.31

Flow Chart for Buzzer Interface

Start

Configure the ports P0.31 to as I/O through Pinsel 1 &


assign this as O/P port

Set the O/P port value high, now buzzer is in OFF state

Call Delay

Clear the off port now buzzer is in ON State

Call Delay

Result:

Thus the Embedded C program to interface Buzzer Interface with LPC2148 has been tested
successfully.
Ex. No: 2 B) Relay Interface

Aim:

To Write an Embedded C Program to interface the 8 bit Relay Interface with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
//ASSIGN P0.30 IS RELAY INTERFACE PIN
#define relay 1<<30

// DELAY SUBROUTINE
//----------------------------------
void DELAY(void)
{
unsigned int i;
i=0xffffff;
while(i--);
}
//----------------------------------
//----------------------------------
//MAIN PROGRAM STARTS HERE
int main(void)
{
IODIR0=1<<30;
while(1) //INFINITE LOOP
{
IOSET0=1<<30; //SWITCH OFF RELAY
DELAY(); //CALL DELAY
IOCLR0=1<<30; //SWITCH ON RELAY
DELAY(); //CALL DELAY
} //REPEAT
}
Relay Interface Diagram

+5V

NC +5V +3V
5

R30
3
COM
4

D15
1
NO

R28

R27
2
LED
RELAY

1
TR1 2 P0.30

OPTO ISOLATOR-A

3
Flow Chart for Relay Interface

Start

Configure the port P0.30 as I/O & assign that port as


O/P port

Set the O/P value as High, Now relay circuit is not


Energized

Call Delay

Clear the O/P port value now the relay is Energized

Result:

Thus the Embedded C program to interface Relay Interface with LPC2148 has been tested
successfully.
Ex. No: 2 C) Stepper Motor Interface

Aim:

To Write an Embedded C Program to interface the Stepper Motor Interface with LPC 2148
Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 Stepper Motor Interface Card 1

Program:

#include <LPC214X.H>
unsigned char tim,tim1_0,tim1;
unsigned int yy;
void delay(void)
{
unsigned int j;
for(j=0;j<0x7fff;j++)
{
;
}
}
void del(void)
{
unsigned int j;
for(j=0;j<0x7ffFff;j++)
{
;
}
}
//THIS FUNCTION SHIFT THE INITIALSED VARIABLE 255 TIMES LEFT IN
INTERVALS
//tim is initialised with 33h
void reverse(void)
{
unsigned int n;
n=0xff;
do (P.T.O)
{
tim1_0= (tim & 0x1)<<1 | (tim & 2)<<1 | (tim & 4)<<1 | (tim & 8)>>3; //SHIFT LEFT
tim=tim1_0;
IOCLR1 |=0XF<<16; //CLEAR PREVIOUS
DATA INPORT1
IOSET1 |=tim<<16; //LOAD SHIFTED
VALUE IN TO PORT1
delay();
delay();
}while(n--!=0);
}
//THIS FUNCTION SHIFT THE INITIALSED VARIABLE 255 TIMES right IN INTERVALS
//tim is initialised with 33h
void forward(void)
{
unsigned int n;
n=0xff;
tim1_0=0;
do
{
tim1_0= (tim & 0x8)>>1 | (tim & 4)>>1 | (tim & 2)>>1 | (tim & 1)<<3; //shift right
tim=tim1_0;
IOCLR1 |=0XF<<16; //clear previous value in port1
IOSET1 |=tim<<16; //load new value
delay();
delay();
}while(n--!=0); //wait until 255 count
}
int main(void)
{
IODIR1=0XF<<16; //configure stepper moto port as output
tim=0X33; //load initial value in tim
while(1)
{
reverse(); //call reverse
del();
//pause
forward(); //call forward
del();
//pause
}
}
Stepper Motor Interface Diagram
+5V

+5V +5V

R32

R31
R23
R19
A C

D16

D17
P1.19 1 2 TR5 P1.17 5 6 TR3
R18 R22
7407 7407

TIP33
TIP4
R6 R6 T I P 42 2 T IP3
TIP4 TIP2

1
D3

R17
D9 +5V
D4
D10 1

STEPPER
2
D5 3
D11 4
5
6

+5V

+5V +5V

R35

R36
R25
R21
B D
P1.18 3 4 P1.16 9 8 TR2
TR4

D19

D18
R20 R24
7407
7407

R26
R6

TIP23
TIP1
TIP3 TIP1 T IP1 2 2 T IP2

D12

1
D6

R37
D7 D13

D8 D14

Flow Chart for Stepper Motor Interface

Start

Configure the port P0.30 as I/O & assign that port as


O/P port

Initially all O/P port values are High, So no winding


are energized

O/P ports 16 & 17 are cleared & port 8 & 9 are high

Result:

Thus the Embedded C program to interface Stepper Motor Interface with LPC2148 has been
tested successfully.
Ex. No: 3 External Interrupt

Aim:

To Write an Embedded C Program to interface the External Interrupt with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED Interface Card 1

Program:

#include <LPC214X.H>
#include "lcd.h"
unsigned char ll;
#define EINT1 0XC0 //pnisel value for eint1
//unsigned char ascii[]="0123456789ABCDEF";
unsigned int count,temp;
unsigned char dig0,dig1,dig2,dig3,dig4;
void del(void)
{
unsigned int i;
for(i=0;i<0xfffff;i++)
{
;
}
}
//external interrupt ISR
void isr(void) __irq
{
del(); //CALL DELAY
EXTINT =0x2; //CLEAR EINT1 INTERRUPT FLAG
count++; //UPDATE COUNT VALUE
VICVectAddr=0XFF; //MODIFY VECT ADDR REGISTER VALUE
}
//HEX TO BCD
void hex_bcd(long long a)
{
if(a>9)
{
dig4=a/10000; //REATIN QUOTIENT
temp=(a%10000); //REMINDER
dig3=temp/1000;
temp=(temp%1000);
dig2=temp/100;
temp=(temp%100);
dig1=temp/10;
dig0=temp%10;
}
else
{
dig4=dig3=dig2=dig1=0; //ALL DIGIT BUT DIG0 IS 0
dig0=a;
}
}
int main(void)
{
LCD_SETUP(); //CALL LCD SETUP
DISP(0," LPC2148 "); //DISPLAY MESSAGE IN ROW 0
DISP(1, "EINT2:"); //DISPLAY EINT1 AT ROW2
count=0; //INITIALIZE COUNT
PINSEL0 |=EINT1; //CONFIGURE P0.3 AS EINT1
EXTMODE=0x2; //EINT1 EDGE SENSITIVE
EXTPOLAR =0x0; //FOLLING ENGE
VICIntSelect =0<<15; //SELECT EINT1 AS IRQ TYPE
VICIntEnable =1<<15; //ENABLE EINT1
VICVectAddr0 =(unsigned long) isr; //LOAD ISR ADDRESS TO SLOT0 REG
VICVectCntl0 =0x20 | 15; //ENABLE SLOT0 INT
while(1)
{
hex_bcd(count); //CONVER COUNT IN TO BCD
CMD_WRITE(0XC6); //SELECT ROW0 6TH CHR
DATA_WRITE(ascii[dig4]); //DISLAY MSD
DATA_WRITE(ascii[dig3]);
DATA_WRITE(ascii[dig2]);
DATA_WRITE(ascii[dig1]);
DATA_WRITE(ascii[dig0]); //DISPLAY LSD
delay(); //WAIT

} //REPEAT
}
Stepper External Interrupt Diagram

VCC

R41
EINT

P0.3/EINT 1 2

Flow Chart for External Interrupt

Start

Configure port 2 as I/O port assigns these pins as O/P


pins. Initialize count to Zero

Configure P 0.3 as EINT 1 as IRQ type, Enable EINT

Enable slot 0, update count value frequency interrupt

Output:

It will count the External applied pulse & Display in the LED interface Board

Result:

Thus the Embedded C program to interface External Interrupt with LPC2148 has been tested
successfully.
Ex. No: 4 Timer Counter

Aim:

To Write an Embedded C Program to interface the Timer Program with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED - Switch Interface Card 1

Program:

#include <LPC214X.H>
//#include "lcd.h"
unsigned char
seg[]={0x40,0xf9,0xa4,0xb0,0x19,0x12,0x2,0xf8,00,0x10,0x8,0x3,0x46,0x21,0x6,0xe};
unsigned int COUNT,ch,temp;
unsigned char dig0,dig1,dig2,dig3,dig4;
void timer(void) __irq
{
unsigned char tmtcnt=0;
T0IR=1;
VICVectAddr=0xff;
Timer_Loop:

if(tmtcnt++ !=0x5)
goto Timer_Loop;
COUNT++;
if(COUNT<=9)
{
IOCLR0=0XFF<<4;
IOSET0=seg[COUNT&0xf]<<4;
}
else
{
COUNT=0;
}
}
// void hex_bcd(long long a)
//{
//if(a>9)
//{
//dig4=a/10000; //REATIN QUOTIENT
//temp=(a%10000); //REMINDER
//dig3=temp/1000;
//temp=(temp%1000);
//dig2=temp/100;
//temp=(temp%100);
//dig1=temp/10;
//dig0=temp%10;
//}
//else
//{
// dig4=dig3=dig2=dig1=0; //ALL DIGIT BUT DIG0 IS 0
// dig0=a;
//}
//}
void timer_init(void)
{
VPBDIV=0X1;
T0MR0=(5000000000/83);
T0MCR=0X3;
VICIntSelect =0<<4; //SELECT EINT1 AS IRQ TYPE
VICIntEnable =1<<4; //ENABLE EINT1
VICVectAddr0 =(unsigned long) timer; //LOAD ISR ADDRESS TO SLOT0 REG

VICVectCntl0 =0x20 | 4; //ENABLE SLOT0 INT


T0TCR=1;
}
int main(void)
{
//LCD_SETUP();
//DISP(0," TIMER INTERRUPT ");
//DISP(1," COUNT=");
IODIR0=0XFF<<4;
timer_init();
COUNT=0;
while(1)
{
//hex_bcd(COUNT); //CONVER COUNT IN TO BCD
//CMD_WRITE(0XC8); //SELECT ROW0 6TH CHR
//DATA_WRITE(ascii[dig4]); //DISLAY MSD
//DATA_WRITE(ascii[dig3]);
//DATA_WRITE(ascii[dig2]);
//DATA_WRITE(ascii[dig1]);
//DATA_WRITE(ascii[dig0]); //DISPLAY LSD
//delay(); ;
}
}
Flow Chart for Timer Counter

Start

Initialize count to zero and configure port 1 as I/O


assign as O/P ports

Select timer Interrupt as IRQ & it is enabled then


enable slot 0 Interrupt

Counter is incremented for every second

Output:

It will count the peripheral clock & display the digital value in LED Switch interface Card

Result:

Thus the Embedded C program to interface Timer Counter with LPC2148 has been tested
successfully.
Ex. No: 5 7 Segment Display

Aim:

To Write an Embedded C Program to interface the 7 Segment Display with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
unsigned char seg[]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x67,0x77,0x7c,0x39,0x5e,0x79,0x71};
//unsigned char
seg[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98,0x88,0x83,0xC6,0xA1,0x86,0x8E};
unsigned char dig[]={0XFE,0XFD,0xfB,0xf7}; //digit select code
unsigned char m[]={0,1,2,3}; //DIGIT ARRAY DIGIT TO BE
DISPLAYED
#define dig_addr 0x78 //0x48 or 0x78
#define seg_addr 0x70
#define start 5 //START CONDITION OF I2C
#define stop 4 //STOP CONDITION
#define si 3 //SERIAL INTERRUPT FLAG
#define ack 2 //ACK BIT
unsigned char check,dg;
void delay(void)
{ unsigned int jk;
for(jk=0;jk<0x3fF;jk++)
{
;
}
}
void disp(unsigned char address,unsigned char dat)
{
switch(I2C0STAT) //READ I2C STATUS CODE
{
case 0x8: //IF IT IS=0X8 PROCEED, IF NOT GOTO NEXT
CASE
I2C0DAT=address; //LOAD ADDRESS OF SLAVE DEVICE
I2C0CONCLR=1<<start; //CLEAR START CONDITION
break; //BREAK
case 0x18: //IF STATUS CODE =0X18,PROCEED,IF NOT GOTO NEXT CASE
I2C0DAT=dat; //SEND DATA TO SLAVE
break; //BREAK
case 0x28: //IF STATUS CODE =0X28,PROCEED,IF NOT GOTO NEXT CASE
I2C0CONSET=0X10; //SEND STOP CONDITION
delay(); //WAIT
check=0x55;
break; //BREAK
default : //DEFAULT
break;
}
I2C0CONCLR=0X8; //CLEAR SERIAL INTERRUPT FLAG
}
void i2c_init(void)
{
PINSEL0=0X50; //CONFIGURE I2C PORT
I2C0CONCLR=0X6C; //CLEAR CONSET REGISTER
I2C0CONSET=0X40; //ENABLE I2C0 PORT
I2C0SCLH=16; //LOAD ONTIME OF SERIAL CLOCK
I2C0SCLL=14; //LOAD OFF TIME OF SERIAL CLOCK
}
/*************************
DESCRIPTION : SEND START CONDION TO I2C MODULE AND CALL DISP.WAIT UNTIL
SUCCESSFUL WRITE
*****************/
void ddisp(unsigned char address,unsigned char dat)
{
check=0xaa; //check id=0xaa
I2C0CONSET=0X60; //send start conditon
do
{
disp(address,dat); //call disp
}while(check==0xaa); //WAIT UNTIL SUCCESSFUL WRITE OF I2C VALUE
}
int main(void)
{
i2c_init(); //CALL I2C INIT
dg=0; //DIGIT SELECT VARIABLE=0
while(1)
{
ddisp(dig_addr,0xff); //CALL DDISP TO BLANK DISPLAY
delay(); //MUX DELAY
ddisp(seg_addr,~seg[m[dg]]); //CALL DDISP FOR SEGMENT VALUE (COMPLEMENT)LOAD
delay(); //MUX DELAY
ddisp(dig_addr,dig[dg]); //CALL DDISP ENABLE DIGIT
if(dg++>3) //IS ALL THE DIGITS REFRESHED?
{
dg=0; //IF YES DG=0;
}
}
}
Diagram for 7 segment Display

+3V +3V
P0.4 RA1 A1 B1

COM1
A B

A
B
F
P0.5 RB1

10
9
8
7
6
+3V +3V

SEVEN SEGMENT
RC1 C1 D1

a
b
f
cm
P0.6
C D
P0.7 RD1

SEVEN SEGMENT
+3V +3V
P0.8 RE1 E1 F1

dp
E F

e
d
3
c
P0.9 RF1

E 1
D 2
COM13
C 4
H 5
+3V
P0.10 RG1 G1

G
R5

Flow Chart for 7 Segment Display

Start

Configure port 1 as I/O & assign those pins as O/P


pins. Initialize K to zero

Switch OFF the LEDS send the K values to LEDS

Call Delay Subroutine

Increment K

Output:

It displays the value from 0 to F

Result:

Thus the Embedded C program to interface 7 Segment Display with LPC2148 has been tested
successfully.
Ex. No: 6 PWM Signals

Aim:

To Write an Embedded C Program to interface the PWM Signals with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
unsigned int op1,op2;
void delay(void)
{
unsigned int h;
h=0xf;
while(h--);
}
void delay1(void)
{
unsigned int h;
h=0xfffff;
while(h--);
}
int main(void)
{
PINSEL0=2<<0; //STEP 1 SELECT P0.0 AS PWM1
//STEP 2
PWMPC=0;
PWMPR=0;
//STEP 3 CONFIGURE PWMMR0
//STEP 4 LOAD PWM PERIOD TO PWMMR0 TO RESET ON MATCH & INT
PWMMCR=0X3;
#define PWM_PERIOD 1000000
PWMMR0=PWM_PERIOD;
//STEP 5 LOAD ONTIME =100 TO PWMR2
#define ON_TIME 5000
op1= ON_TIME;
PWMMR1=ON_TIME;
//STEP 6 LATCH PWMR0 VALUE AND PWMMR2 VALUE
PWMLER = 1<< 1; // | 1<<4;
//STEP 7 SELECT PWM1 IN SINGLE EDGE MODE AND ENABLE
PWMPCR =1<<9; //0<<4 | 1 <<12;
PWMTCR=0X9; //STEP 8 START PWMTC
op2=0; //STEP 9 STOP
while (1)
{
if(op2==0)
{
op1++;
}
if(op2==1)
{
op1--;
}
delay();
PWMMR1 = op1;
PWMLER = 1<<1;
if(op1>PWM_PERIOD)
{
op2=1;
delay1();
delay1();
delay1();
}
if(op1< ON_TIME)
{
op2=0;
delay1();
delay1();
delay1();
}
}
}
Flow Chart for PWM Signals

Start

Configure port 1 as I/O Load PWM reg 0 value with


PWM cycle rate

Load Match reg 1. Set match register with value 2 it


will reset on match

Enable PWM 1 Output

Output:

PWM LED will blink according to the PWM rate.

Result:

Thus the Embedded C program to interface PWM Signals with LPC2148 has been tested
successfully.
Ex. No: 7 Displaying a Message in a 2 Line X16 Characters LCD

Aim:

To Write an Embedded C Program to interface the Displaying a Message in a 2 Line X16


Characters LCD with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <lpc214x.h>
#include <string.h>
void delay(void) // delay routine
{
unsigned int i;
i = 0xfff:
While (i--);
}
void write(unsigned char data)
{
IOSET0 = data <<16; // data is shifted left by 16 bits for sending to data bits (P0.23 P0.16)
delay(); // delay is called
IOSET1 = 1 << 31 // enable bit is set to 1
delay(); // delay is called
IOCLR1 = 1 << 31; // enable bit is made to 0
delay(); // delay is called
IOCLR0 = data <<16; // data lines are cleared
}
void cmd_write(unsigned char data)
{
IOCLR1 = 1 << 30; // make RS as 0
IOCLR1 = 1 <<31; // make enable bit as 0
write(data); // write routine is called
}

void data_write(unsigned char data)


{
IOSET1 = 1 << 30; // make RS as 1
IOCLR1 = 1 <<31; // make enable bit as 0
write(data); // write routine is called

}
void lcd_init()
{
cmd_write(0x38); // 5/8 matrix and 8 bit data
cmd_write(0xe); // first byte of the initialization sequence
cmd_write(0x1); // clear the display
cmd_write(0x6); // the cursor moves right when a data is entered
}
void disp(unsigned char *msg) // display message routine, * denotes the address pointer of the msg array
{
unsigned int i,j;
J = strlen(msg); // function to find the length of the message
for (i = 0; i<j; i ++) // for the string length, for loop is repeated
{
data_write (msg[i]); // each character is written }
}
int main(void) // main program
{
PINSEL1 = 0 ; // P0.16 to P0.31 are I/O
IODIR0 = 0xff << 16; // P0.16 to P0.23 are output lines (data lines)
PINSEL2 = 0; // P1 is I/O
IODIR1 = 0x3 <<30; // make P1.30 and P1.31 as output lines
lcd_init(); // LCD initialization routine is called
delay(); // delay routine is called
cmd_write(0x80); // cursor is in I row and I column
P.T.O

disp ( Welcome to ); // message is displayed in first row


cmd_write (0xc0); // cursor is in II row and I column
disp ( Electronics Dept. ); // message is displayed in second row
while (1); // idling
}
Flow Chart for Displaying a Message in a 2 Line X16 Characters LCD

Start

Configure pins P0.16 to


P0.3 as I/O & ass those LCD Initialize Routine
pin as O/P Configure port
6 as I/O & ass P1.30 &
P1.31 as O/P
Write a Command for Initializing LCD

Call LCD Integer routine

Call Delay Routine


Send a Command to LCD to clear the
Display

Initialize the cursor in 1st Row Send a Command to make right when data
& in 1st Column is entered

Print the Message

Delay Routine
Move the cursor into 2nd Row
& 1st Row

Print the Message

Output:
LCD Display
Welcome to Electronics Dept
Result:

Thus the Embedded c Program to Displaying a Message in a 2 Line X16 Characters LCD with
LPC2148 has been tested successfully.
Ex. No: 8 Transmission from kit & Reception from PC using serial port

Aim:

To Write an Embedded C Program to interface the Transmission from kit & Reception from
PC using serial port with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <lpc214x.h>
#include <string.h> // header for string function
#define pclk 60000000; // using Phase Lock Loop, 12 MHz frequency is multiplied
// by 5 and 60 MHz is obtained as chip clock. 60 MHz is defined
unsigned int baud_value
unsigned char val;
void uart0_init(unsigned int baud_rate)//uart0_init routine; parameter baud_rate is to be passed
{ PINSEL0 = 0x5; // P0.0 and P0.1 are configured as TXD and RXD
U0LCR = 0x83; // Divisor Latch Access Bit (D7) should be 1
// for 8 bit data, no parity, stop bit 1, bit 0 and 1 should be 1
baud_value = (pclk/16/baud_rate);// baud_value is 16 bit no. It is obtained by this formula
U0DLM = baud_value/256; // Higher order byte of baud_value
U0DLL =baud_value%256; // Lower order byte of buad_value
U0LCR = 0x3; // after accessing the divisor, DLAB bit is to be made as 0
U0FCR = 0x07; // FIFO buffer register is enabled with reset
}
void feed(void) // routine to be written whenever PLL registers are modified
{ PLL0FEED = 0xaa; // feed sequence 1
PLL0FEED = 0x55; //feed sequence 2
}
void pll_init(void)
{ PLL0CFG = 0x04; //PLL0CFG MSEL value is 4 to get multiply by 5
feed(); // feed sequence routine is executed
PLL0CON = 0x01; // PLL Enable bit is set
feed(); // feed sequence routine is executed
while(! (PLL0STAT & 0x0400));// after writing in the registers, wait till PLL Lock
PLL0CON = 0x3; // thereafter, the PLL connect signal is given, 0 bit and 1 bit are 1
feed(); // feed sequence routine is executed
VPDIV = 0x1; // PCLK = CCLK = 60 MHz
}
unsigned char receive(void)
{ while(! (U0LSR & 0x01)); // 0th bit in Line Status Reg. receive data ready
return (U0RBR); // the data in Receive Buffer register is returned
}
void transmit (unsigned char ch)
{ while(! (U0LSR & 1<<5)); // 5th bit in Line Status Reg. transmit hold reg. empty
U0THR = ch; // when it is empty, new character to transmit is placed in the reg.
}
void transstring (unsigned char *msg)
{ unsigned int i,l;
l = strlen(msg); // length of the string
for (i = 0; i<l; i++);
{ while (! (U0LSR & 1 <<5));// each character is sent from the array and it is transmitted
U0THR = msg[i];
}
transmit(0xd); // carriage return character
transmit(0xa); // line feed character
}
int main(void)
{ pll_init(); // pll_init routine is executed
uart0_init(9600); // uart0_init routine is executed with 9600 as baud rate
do
{ val = receive(); //after initialization, it is waiting for the data to be received
if (val == 1) // if the data received from the keyboard is 1.
{ transstring(Welcome );// the content of this string is transmitted
}
if (val == 2) // if the received data is 2, then
{ transstring(Electronics Dept.);// the content of this string is transmitted
}
if (val = 3) // if the received data is 3, then
{ transstring(Good bye); // the content of this string is transmitted
}
} while (val ! = 3); // this do loop is repeated till the received data is not 3
while(1); // idling
}
Flow Chart for Displaying a Message in a 2 Line X16 Characters LCD

Start
LCD Initialize Routine
PLL Initialize routine
called
Configure the PLL to multiply by 5

UART 0 initialize routine called


Forward this value, Enable the PLL &
feed this value check the PLL

Connect the PLL signal as clock source &


feed this & set the PLL k frequency
60MHZ

UART 0 initialize routine

Configure P0.0 & P0.1 as TxD & RxD pins,


make DLAB bit to 1
Wait for the received value if received
value is 1 print Welcome 2 means
Electronics Department 3 means Configure the baud rate to using values
Good Bye & the loop is terminated UODLM UODLL by using the formula

Output:
1 Welcome
2 Electronics Department
3 Good bye (& come out of loop)

Result:
Thus the Embedded c Program to Transmission from kit & Reception from PC using serial
port with LPC2148 has been tested successfully.
Ex. No:9 Program for 4X4 Matrix Keyboard Interface

Aim:

To Write an Embedded C Program to interface the Program for 4X4 Matrix Keyboard
Interface with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
#define ROW0 1<<0 //ROW0 ASSIGNED WITH P0.0
#define ROW1 1<<1 //ROW1 ASSIGNED WITH P0.1
#define ROW2 1<<2 //ROW2 ASSIGNED WITH P0.2
#define ROW3 1<<3 //ROW3 ASSIGNED WITH P0.3
#define CLM0 1<<25 //CLM0 ASSIGNED WITH P0.25
#define CLM1 1<<12 //CLM1 ASSIGNED WITH P0.12
#define CLM2 1<<13 //CLM2 ASSIGNED WITH P0.13
#define CLM3 1<<15 //CLM3 ASSIGNED WITH P0.15
const clm0_lookup[]={0,0,0,0,0,0,0,0xC,0,0,0,0x8,0,4,0,0}; //COLUM0 KEY LOOKUP TABLE
const clm1_lookup[]={0,0,0,0,0,0,0,0xD,0,0,0,0x9,0,5,1,0}; //COLUM1 KEY LOOKUP TABLE
const clm3_lookup[]={0,0,0,0,0,0,0,0xF,0,0,0,0xB,0,7,3,0}; //COLUM2 KEY LOOKUP TABLE
const clm2_lookup[]={0,0,0,0,0,0,0,0xE,0,0,0,0xA,0,6,2,0}; //COLUM3 KEY LOOKUP TABLE
unsigned char seg[]={0x40,0xf9,0xa4,0xb0,0x19,0x12,0x2,0xf8,00,0x10,0x8,0x3,0x46,0x21,0x6,0xe};//SEGMENT
LOOKUP TABLE
#define buz 1<<31; //BUZZER PIN
unsigned char key_buf,temp,temp1; //8 BIT VARIABLES
void delay(void)
{
unsigned int i;
i=0xffffff;
while(i--);
}
unsigned char key_scan(unsigned int clm)
{
//clear previous value at colum port
IOCLR0=CLM0;
IOCLR0=CLM1;
IOCLR0=CLM2;
IOCLR0=CLM3;
//set all colum port pin
IOSET0=CLM0;
IOSET0=CLM1;
IOSET0=CLM2;
IOSET0=CLM3;
IOCLR0=clm; //clear the desired colum pin
if((temp=IOPIN0 & 0XF) !=0XF) //read port0 status in temp
{
key_buf=temp; //load status in to key_buf if any key deppressed
}
else
{
key_buf=0xff; //if no key deppressed load ff in to key_buf
}
return(key_buf); //return the key_buf
}
int main(void)
{
PINSEL0=0;
//configure all pin of port0 as gpio
IODIR0=0XFFFFFFF0 ; //configure p0.0 to p0.3 as input
IOSET0=1<<30; //switch off RELAY
IOSET0=0X7F<<4; //disable segments
IOSET0=1<<31; //SWITCH OFF BUZZER
while(1)
{
IOSET0=1<<31; //SWITCH OFF BUZZER
if((temp1=key_scan(CLM0)) !=0XFF) //IF COLUM0 SCAN VALUE IS NOT 0XFF ENTER
{
temp1=clm0_lookup[temp1]; // TEMP1= KEY NUMBER FROM LOOKUP
goto last; // SKIP OFF FROM SCANING
}
if((temp1=key_scan(CLM1)) !=0XFF)
{ //IF COLUM1 SCAN VALUE IS NOT 0XFF ENTER
temp1=clm1_lookup[temp1];
goto last; // SKIP OFF FROM SCANING
}
if((temp1=key_scan(CLM2)) !=0XFF) //IF COLUM2 SCAN VALUE IS NOT 0XFF ENTER
{
temp1=clm2_lookup[temp1];
goto last; // SKIP OFF FROM SCANING
}
if((temp1=key_scan(CLM3)) !=0XFF) //IF COLUM3 SCAN VALUE IS NOT 0XFF ENTER
{
temp1=clm3_lookup[temp1];
}
IOSET0=1<<31; //BUZZER OFF
last:
if(temp1!=0xff) //IF TEMP1=0XFF SKIP THI LOOP
{
IOCLR0=1<<31; //IF TEMP1 IS NOT =0XFF SWITCH ON BEEP
while((IOPIN0 & 0XF) !=0XF); //DEBOUNZE //IF THE SWITCH STILL PRESSED REMAIN HERE
IOCLR0=0XFF<<4; //CLEAR COLUM VALUE
IOSET0=seg[temp1 & 0xf]<<4; //DISPLAY DEPRESSED VALUE IN SEGMENT DISPLAY
IOSET0=1<<31; //SWITCH OFF BEEP

}
}
}
Flow Chart for Program for 4X4 Matrix Keyboard Interface

Start

Configure P0.0 to
P0.15 as I/P pins &
O/P pins

Check the Column

If any
key is
pressed

Check the Column 1 Clear the column value & Display the dipressed
value in the Display

If any key
is pressed

Check the Column 2

If any
key is
pressed If any
key is
pressed

Check the Column 3

Result:
Thus the Embedded c program to interface the 4X4 Matrix keyboard with LPC2148 has been
tested successfully.
Ex. No: 10 A) Analog to Digital Convertor

Aim:

To Write an Embedded C Program to interface the Analog to Digital Convertor with LPC
2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED Interface Card 1

Program:

#include <LPC214X.H>
#include "lcd.h"
#define AD0_2_PINSEL 1<<26 //AD0.2 PINSEL VALUE

#define clkdiv 0X4<<8 //CLOCK VALUE 4


#define burst 0<<16
//BURST=0
#define clks 0<<17 //NOT IN BURST
#define pdn 1<<21
//PDN=1
#define start 0<<24 //NO START
#define edge 0<<27 //NO HARDWARE
unsigned int adc_val2,val;
//unsigned char ascii[]="0123456789ABCDEF";
void delay(void);
void delay1(void)
{
unsigned int i;
for(i=0;i<0x2ffff;i++)
{
;
}
}
unsigned int hex_bcd(unsigned int hex)
{
unsigned int temp0;
unsigned char dig3,dig2,dig1,dig0;
dig3=hex/1000;
temp0=hex%1000;
dig2=temp0/100;
temp0=temp0%100;
dig1=temp0/10;
dig0=temp0%10;
temp0=0;
temp0=temp0 | dig3<<12 | dig2<<8 |dig1<<4 | dig0;
return(temp0);
}
void adc_scan(void)
{
AD0CR =(AD0CR & 0XFfff00) | 0x4; //SELECT AD0.2
ADGSR =1<<24; //0X01000000; /* Start A/D Conversion */
do {
val = AD0DR2; /* Read A/D Data Register */
} while ((val & 1<<31) == 0); /* Wait for end of A/D Conversion */
ADGSR &= ~1<<24; // 0x01000000; /* Stop A/D Conversion */
val = (val >> 6) & 0x03FF;
val=(val*322)/100; //VAL *3300 MV/1024 WHERE VREF=3.3V
CMD_WRITE(0X89); //STARTS WITH ROW0 CHR.10
DATA_WRITE(ascii[hex_bcd(val) >>12 & 0xf]); //1.CONVER HEX TO BCD 2.SHIFT 4TH
DIGIT TO RIGHTAND MASK
//3.CONVERT TO ADCII 4.DISPLAY ON LCD
DATA_WRITE('.'); //DISPLAY "."
DATA_WRITE(ascii[hex_bcd(val)>>8 & 0xf]); //1.CONVER HEX TO BCD 2.SHIFT 3RD
DIGIT TO RIGHTAND MASK
//3.CONVERT TO ADCII 4.DISPLAY ON LCD
DATA_WRITE(ascii[hex_bcd(val)>>4 & 0xf]); //3.CONVERT TO ADCII 4.DISPLAY ON LCD
DATA_WRITE(ascii[hex_bcd(val) & 0xf]);
//3.CONVERT TO ADCII 4.DISPLAY ON LCD
DATA_WRITE(' '); /SPACE
DATA_WRITE('V');
delay1(); //WAIT
}
int main(void)
{
PINSEL1=AD0_2_PINSEL; //CONFIGURE P0.29 AS AD0.2
AD0CR=clkdiv | burst | clks | pdn |start |edge; LCD_SETUP();
//CALL LCD SETUP
DISP(0,"AD0.2="); //LCD DISPLAY
DISP(1,"ADC EXPERIMENT ");
while(1)
{
adc_scan();
//CALL ADC
delay1();
//DELAY
}
}
Flow Chart for Analog to Digital Convertor

Start
Select AD0.2 & start the A to D
conversion through global start
Configure AD0.2 register
as I/P through
PINSEL & set 2nd
bit is 1 to move A
to D convert Move the data register value to Val
operational
Configure the port 1 pins as I/O
& assign those pins as O/P pins
through I/O dir and initialize
clear all the LEDS If 31st
pin is
1

ADC scan routine called

8 bit digital value is shifted to 6 bit


& send to LEDS
Delay routine called

Output:

Equivalent digital value for analog value will display in LED switch interface according to the
applied analog voltage.

Result:

Thus the Embedded C program to interface Analog to Digital converter with LPC2148 has
been tested successfully.
Ex. No: 10 B) Thermister

Aim:

To Write an Embedded C Program to interface the Thermister with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED - Switch Interface card 1

Program:

#define AD0_1_PINSEL 1<<24 //AD0.1 PINSEL VALUE

#define clkdiv 0X4<<8 //CLOCK VALUE 4


#define burst 0<<16
//BURST=0
#define clks 0<<17 //NOT IN BURST
#define pdn 1<<21
//PDN=1
#define start 0<<24 //NO START
#define edge 0<<27 //NO HARDWARE
unsigned int adc_val2,val;
#include <LPC214X.H>
#include "lcd.h"
unsigned int temp0;
unsigned char dig3,dig2,dig1,dig0;
unsigned int val,val1;
void delay(void);
void delay1(void)
{
unsigned int i;
for(i=0;i<0xffff;i++)
{
;
}
}
void adc_scan(void)
{
AD0CR =(AD0CR & 0XFfff00) | 0x2; //SELECT AD0.1
ADGSR =1<<24; //0X01000000; /* Start A/D Conversion */
do {
val1 = AD0DR1; /* Read A/D Data Register */
} while ((val1 & 1<<31) == 0); /* Wait for end of A/D
Conversion */
ADGSR &= ~1<<24; // 0x01000000; /* Stop A/D Conversion */
val1 = (val1 >> 6) & 0x03FF;
}

int main(void)
{
PINSEL1=AD0_1_PINSEL;
//CONFIGURE P0.28 AS AD0.1
AD0CR=clkdiv | burst | clks | pdn |start |edge; // CONFIGURE AD0.1 IN SOFTWARE MODE
LCD_SETUP(); //CALL LCD SETUP
DISP(0,"TEMP=");
while(1)
{
adc_scan(); //CALL ADC_SCAN
val1=(val1*322)/100; //RESOLUTION VREF/1024
dig3=val1/1000; //HEX TO BCD
temp0=val1%1000;
dig2=temp0/100;
temp0=temp0%100;
dig1=temp0/10;
dig0=temp0%10;
CMD_WRITE(0X8A); //DISPLAY FROM 10TH CHR OF ROW1
DATA_WRITE(ascii[dig3]);
DATA_WRITE(ascii[dig2]);

DATA_WRITE(ascii[dig1]);
DATA_WRITE('.');
DATA_WRITE(ascii[dig0]);
DATA_WRITE('C');
delay1();
}
}
Flow Chart for Thermister

Start
Select AD0.2 & start the A to D
conversion through global start
Configure AD0.2 register
as I/P through
PINSEL & set 2nd
bit is 1 to move A
to D convert Move the data register value to Val
operational
Configure the port 1 pins as I/O
& assign those pins as O/P pins
through I/O dir and initialize
clear all the LEDS If 31st
pin is
1

ADC scan routine called

10 bit digital value is shifted to 8 bit


& send to LEDS
Delay routine called

Output:

Equivalent digital value will be displayed in the LED Switch interface board according to the
received temperature & Thermister.

Result:

Thus the Embedded C program to interface Thermister with LPC2148 has been tested
successfully.
Ex. No: 11 Multi 7 Segment Display

Aim:

To Write an Embedded C Program to interface the Multi 7 Segment Display with LPC 2148
Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 Multi 7 Segment Interface Card 1

Program:

#define dig0 IOCLR1=0X1<<24;


#define dig1 IOCLR1=0X1<<25;
#define dig2 IOCLR1=0X1<<26;
#define dig3 IOCLR1=0X1<<27;
#define dig4 IOCLR1=0X1<<28;
#define dig5 IOCLR1=0X1<<29;
#define seg_dig(x) IOSET1=~seg[dat>>x & 0xf]<<16;
#include <LPC214X.H>
unsigned char
seg[]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x67,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char temp;
//digit multiplex delay
void delay(void)
{
unsigned int i;
i=0xfff;
while(i--);
}
//This program multiplexes the display
void disp(unsigned int dat)
{
IOCLR1=0XFFFF<<16; //erase segment data
IOSET1=0XFF<<24; //Disable all digits
switch(temp)
{
case 0:
//IOSET1=(~seg[dat & 0xf])<<16; //0th digit segment code goes to port
seg_dig(0)
dig0 //0th digit enabled
break;
case 1:
seg_dig(4) //First digit segment code goes to port
dig1 //First digit enabled
break;
case 2:
seg_dig(8) //2nd digit segment code goes to port
dig2 //2nd digit enabled
break;
case 3:
seg_dig(12) //Third digit segment code goes to port
dig3 //Third digit enabled
break;
case 4:
seg_dig(16) //Fourth digit segment code goes to port
dig4 //Fourth digit enabled
break;
case 5:
seg_dig(20) //Fifth digit segment code goes to port
dig5 //Fifth digit enabled
break;
default :
break;
}
}
int main(void)
{
unsigned int lim,lim1;
IODIR1=0XFFFF<<16; //p1.16 to p1.29 output port
IOSET1=0XFF<<24; // disable digit
temp=0; //digit count
lim=0x000; //display counter
lim1=0; //delay counter
while(1)
{
disp(lim); // pass display counter value to display
delay(); //wait
if(temp++>5) //update and check (is digit count greater than 5?)
{
temp=0; //if yes make digit count=0
}
if(lim1++>0xfff) //is delay count value >0xfff?
{
lim++; //if yes updatae display counter value
lim1=0; //make lim1=0
}
}
}
Flow Chart for Multi 7 Segment Display

Start

Format the variable assign P1.10 to P1.29 as


O/P port. Initialize the variables.

Pass display cov to display the values in dig 0 for a particular time delay
display the every incrementing values in digit zero

Increment the variable temp & check it is greater than 5

If Make temp = 0

Pass the display cov values to the sec dig. D is all the increment values in digit 1

Increment the digital conversion values to the digit 5

If Make temp = 0

Pass the display conversion values to the digit 2

Increment & check the temp value is greater than 5

If Make temp = 0

Go to next digit & soon

Output:

It will count the internal clock & display the value in 6 digit 7 segment display.

Result:

Thus the Embedded C program to interface Multi 7 Segment with LPC2148 has been tested
successfully.
Ex. No: 12 Assembly Language Program

Aim:

To Write an Embedded C Program to interface the Multi 7 Segment Display with LPC 2148
Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

5 LED - Switch Interface card 1

Program:

A) Addition
AREA PROGRAM,CODE,READONLY
ENTRY
INCLUDE LIB.H
export __main
EXPORT __use_two_region_memory
__use_two_region_memory
__main

LDR R0,=-0X4
ADD R0,R0,LSL#2
LDR R0,=0X12345678 ;OP1 HIGHER ORDER NUM
LDR R1,=0X87654321 ;OP1 LOWER ORDER NUM
LDR R2,=0X12345678 ;OP2 HIGHER ORDER NUM
LDR R3,=0X87654321 ;OP2 LOWER ORDER NUM
ADDS R5,R1,R3 ;ADD LOWER ORDER DIGIT AND STORE
IN R5
ADC R4,R0,R2 ;ADD HIGHER OREDR DIGIT AND STORE
IN R4
STOP
B STOP
END
B) Subtraction

AREA PROGRAM,CODE,READONLY
ENTRY
INCLUDE LIB.H
export __main
EXPORT __use_two_region_memory
__use_two_region_memory
__main

LDR R0,=0X56781234 ;OP1 HIGHER ORDER NUM


LDR R1,=0X12345678 ;OP1 LOWER ORDER NUM
LDR R2,=0X43218765 ;OP2 HIGHER ORDER NUM
LDR R3,=0X87654321 ;OP2 LOWER ORDER NUM
SUBS R5,R1,R3 ;Subtract LOWER ORDER DIGIT AND
STORE IN R5
SBC R4,R0,R2 ;Subtract HIGHER OREDR DIGIT AND
STORE IN R4
STOP
B STOP
END

C) Multiplication

AREA PROGRAM,CODE,READONLY
ENTRY
INCLUDE LIB.H
export __main
EXPORT __use_two_region_memory
__use_two_region_memory
__main

LDR R0,=0X56781234 ;OP1 HIGHER ORDER NUM


LDR R1,=0X12345678 ;OP1 LOWER ORDER NUM
LDR R2,=0X43218765 ;OP2 HIGHER ORDER NUM
LDR R3,=0X87654321 ;OP2 LOWER ORDER NUM
SUBS R5,R1,R3 ;Subtract LOWER ORDER DIGIT AND
STORE IN R5
SBC R4,R0,R2 ;Subtract HIGHER OREDR DIGIT AND
STORE IN R4
STOP
B STOP
END
D) DIVISION

AREA PROGRAM,CODE,READONLY
ENTRY
INCLUDE LIB.H
export __main
EXPORT __use_two_region_memory
__use_two_region_memory
__main

LDR R0,=0X7FFFFFFF ;OP1


LDR R1,=0XFE ;OP1 LOWER ORDER NUM
LDR R2,=0;

LOOP
SUBS R0,R0,R1
BMI NER0
ADD R2,R2,#1
B LOOP
NER0
ADD R0,R0,R1

STOP
B STOP
END

Result:

Thus the Assembly Language program for Addition, Subtraction, Multiplication & Division has
been tested successfully.
Ex. No: 13 I2C Serial EEPROM

Aim:

To Write an Embedded C Program to interface the I2C Serial EEPROM with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include <LPC214X.H>
#include "lcd.h"
void delay(void);
unsigned int temp;
unsigned char i,vh,var;
void epr_delay(void);
void i2c_init()
{
PINSEL0 |=0X30C00000;
I2C1CONCLR=0X6C; //CLEARING ALL FLAGS
I2C1CONSET=0X40; //ENABLE I2C
I2C1SCLH =16; //0XC;
I2C1SCLL=14; //0XD; //100KHZ
}
void def(void)
{
unsigned int i;
for(i=0;i<0xfffff;i++)
{
;
}
}
void epr_delay(void)
{
unsigned int jk;
for(jk=0;jk<0xfffF;jk++)
{
;
}
}
//THIS FUNCTION WRITES AN 8 BIT DATA TO A PARTICULR ADDRESS OF I2C EEPROM
void epr_write(unsigned char adrh,unsigned char adrl,unsigned char dat)
{
epr_delay();
I2C1CONSET=0X60; //send start conditon
epr_delay(); //wait
if((temp=I2C1STAT)==0x8)
{
I2C1DAT=0xa0; //write device address
I2C1CONCLR =0x28; //clear start,si
}
epr_delay();
if((temp=I2C1STAT)==0x18)
{
I2C1DAT=adrh; //write higher order address
I2C1CONCLR =0x8; //clear si
}
epr_delay();
if((temp=I2C1STAT)==0x28)
{
I2C1DAT=adrl; //write low byte address
I2C1CONCLR =0x8; //clear si

}
epr_delay();
if((temp=I2C1STAT)==0x28){
I2C1DAT=dat; //write data
I2C1CONCLR =0x8; //clear si
epr_delay();
}
I2C1CONSET =0x10; //send stop condition
I2C1CONCLR=0x8; //clear si
}
//THIS FUNCTIONAL CALL RETURNS AN 8BIT DATA ARTER READING A PARTICULAR ADDRESS OF
EEPROM
unsigned char epr_read(unsigned char adrh,unsigned char adrl)
{
epr_delay();
I2C1CONSET=0X60; //send start conditon
epr_delay();
if((temp=I2C1STAT)==0x8) //check return status code
{

I2C1DAT=0xa0; //send device address


I2C1CONCLR =0x28; //clear start,si
}
epr_delay();
if((temp=I2C1STAT)==0x18)
{

I2C1DAT=adrh; //write higher order address byte


I2C1CONCLR =0x8;
}
epr_delay();
if((temp=I2C1STAT)==0x28)
{
I2C1DAT=adrl; //write low order address byte
I2C1CONCLR =0x8;
}
epr_delay();
I2C1CONSET =0x70; //restart
I2C1CONCLR=0x8; //clear si
epr_delay();
if((temp=I2C1STAT)==0x8)
{
I2C1DAT=0xa1; //write read address
I2C1CONCLR =0x28;
}
epr_delay();
if((temp=I2C1STAT)==0x40) //sla+r send and ack received
{

I2C1CONSET=0X04; //aa set for ack to send


I2C1CONCLR =0x28;
}
epr_delay();
if((temp=I2C1STAT)==0x50) //data received ack sent
{
vh=I2C1DAT;
I2C1CONCLR=0xc; //de activate ack
}
epr_delay();
if((temp=I2C1STAT)==0x58) // data received nack sent
{
I2C1CONSET=0X10; //stop condition sent
I2C1CONCLR=0X8;
}
return(vh);
}

int main(void)
{
i2c_init(); //initialise i2c for 400khz
LCD_SETUP(); //INITIALISE LCD SET UP
def();
DISP(0x0,"Serial_eeprom");
DISP(0x1,"Count:");
while(1)
{
var =epr_read(0x0,0x11); //READ DATA FROM 0011 H OF SERIAL EEPROM
CMD_WRITE(0XC6); //START DISPLAY FROM ROW0 AT 6TH CHR
DATA_WRITE(ascii[var >> 4 & 0xf]); //DISPLAY MSD OF DATA
DATA_WRITE(ascii[var & 0xf]); //DISPLAY LSD OF DATA
def();
var++; //UPDATE DATA BY 1
epr_write(0x00,0x11,var); //WRITE AT 0011H
} //REPEAT
//return 0;
}
Flow Chart for I2C Serial EEPROM

Start
Negative acknowledgement send

I2C Initialization
function
Stop condition sent

Initialize LCD setup

Write data to EEPROM

Display Serial EEPROM


Display
Send start condition
Read data from serial EEPROM

Write device address


Send start condition

Write higher order address


Send device address

Write lower order address


Write higher order address byte

Write data
Write lower order address byte

Send stop condition


Write read address

Data received &


acknowledgements send

Output:
It will count the values if we switch off the kit then ON means it will resume the count.
Result:
Thus the Embedded C program to interface I2C Serial EEPROM with LPC2148 has been tested
successfully.
Ex. No: 14 Displaying two different messages in LCD display in two lines

Aim:

To Write an Embedded C Program to interface the Displaying two different messages in LCD
display in two lines with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include "includes.h"
#include "lcd.h"
#define TASKSTART_STK_SIZE 256
#define TASK_STK_SIZE 256 /* Size of each task's stacks (# of WORDs) */
#define N_TASKS 3 /* Number of identical tasks */
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
char TaskData[N_TASKS]; /* Parameters to pass to each task */
INT8U err;
unsigned int count=0x1234;
unsigned int count1=0x5678;
void TaskStart(void *dataa); /* Function prototypes of Startup task */
void TaskSecond(void *dataa); /* Function prototypes of tasks */
void TaskThird(void *dataa);
OS_EVENT *JK=NULL;
int main (void)
{
// VPBDIV=0;
//P1.16 TO P0.22 AS OUTPU
LCD_SETUP(); //ININIALIZE LCD IN 4BIT
MODE
delay();
DISP(0x0,"COUNT:");
DISP(0x1,"COUNT1:");
JK=OSSemCreate(1);
OSInit(); /* Initialize uC/OS-II*/
OSTaskCreate(TaskStart,
(void *)0,
(OS_STK *)&TaskStk[0][TASK_STK_SIZE - 1],10);
OSTaskCreate(TaskSecond,
(void *)0,
(OS_STK *)&TaskStk[1][TASK_STK_SIZE - 1],11);
OSTaskCreate(TaskThird,
(void *)0,
(OS_STK *)&TaskStk[2][TASK_STK_SIZE - 1],12);
OSStart(); /* Start multitasking */
//for(i = 0; i <= 0x100; i ++);
}
void TaskStart (void *dataa)
{
unsigned long i = 0;
BSP_Init();
for(;;)
{
OSSemPend(JK,0,&err);
for(i = 0; i <= 0x3FFFFF; i ++); //Delay between
switching OFF LEDs
//Get Semaphore
//Ceitical section starts
CMD_WRITE(0X88);
DATA_WRITE(ascii[(count>>12) & 0xf]); //Display MSD OF COUNT
DATA_WRITE(ascii[count >>8 & 0xf]); //Display 2ND DIGIT OF COUNT
DATA_WRITE(ascii[(count>>4) & 0xf]); //Display FIRST DIGIT OF COUNT
DATA_WRITE(ascii[count & 0xf]); //Display OTH
DIGIT OF COUNT

// //critical section ends here


OSSemPost(JK);
OSTimeDlyResume(11); //Kill
the delay of Second task
OSTimeDlyHMSM(0,0,0,50); //Delay
the task for 5ms
//OSTaskDel(OS_PRIO_SELF);

}
void TaskSecond (void * pvdata)
{
unsigned long i = 0;
unsigned char err;
for(;;)
{
OSSemPend(JK,0,&err);
for(i = 0; i <= 0x3FFFFF; i ++); //Delay between
switching OFF LEDs
//Get Semaphore
//Ceitical section starts
CMD_WRITE(0Xc8);
DATA_WRITE(ascii[(count1>>12) & 0xf]); //Display MSD OF COUNT
DATA_WRITE(ascii[count1 >>8 & 0xf]); //Display 2ND DIGIT OF COUNT
DATA_WRITE(ascii[(count1>>4) & 0xf]); //Display FIRST DIGIT OF COUNT
DATA_WRITE(ascii[count1 & 0xf]); //Display OTH DIGIT
OF COUNT
//critical section ends here
OSSemPost(JK);
OSTimeDlyResume(12); //Kill the delay of Third
task
OSTimeDlyHMSM(0,0,0,10);
//Assign 0xf0 to the LEDs
//Kill the delay of First task
}
}
void TaskThird(void * pvdata)
{
unsigned long i = 0;
char err;
for(;;)
{
OSSemPend(JK,0,&err);
for(i = 0; i <= 0x3FFFFF; i ++);
//OSTimeDly(10);
count++;
OSSemPost(JK);
OSTimeDlyResume(10); //Kill the delay of Third
task
//Kill the delay of First
task
}
}
Flow Chart for Displaying two different message in LCD display in two lines

Start

Initialize the core

Initialize the BSP

OS start create & OS


start

Run tasks with the


independent control

Display datas on Control the Collect the datas


LCD datas from from string
signal

Initialize the task


control

Stop
Output:
LCD Display
Count 1234
Count 1 5678
Result:
Thus the RTOS program to Displaying two different messages in LCD display in two lines has
been tested successfully.
Ex. No: 15 Blinking two LEDS

Aim:

To Write an Embedded C Program to interface the Blinking two LEDS with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include "includes.h"
#include "Step_lcd.h"
#define TASKSTART_STK_SIZE 256
#define TASK_STK_SIZE 256 /* Size of each task's stacks (# of WORDs) */
#define N_TASKS 3 /* Number of identical tasks */
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
char TaskData[N_TASKS]; /* Parameters to pass to each task */
INT8U err;
unsigned int count=0x1234;
unsigned int count1=0x5678;
void TaskStart(void *dataa); /* Function prototypes of Startup task */
void TaskSecond(void *dataa); /* Function prototypes of tasks */
void TaskThird(void *dataa);
OS_EVENT *JK=NULL;
int main (void)
{
IODIR0=0XFF<<8;
IOSET0=0XFF<<8;
JK=OSSemCreate(1);
OSInit(); /* Initialize uC/OS-II*/
OSTaskCreate(TaskStart,
(void *)0,
(OS_STK *)&TaskStk[0][TASK_STK_SIZE - 1],10);
OSTaskCreate(TaskSecond,
(void *)0,
(OS_STK *)&TaskStk[1][TASK_STK_SIZE - 1],11);
OSTaskCreate(TaskThird,
(void *)0,
(OS_STK *)&TaskStk[2][TASK_STK_SIZE - 1],12);
OSStart(); /* Start multitasking */
}
void TaskStart (void *dataa)
{
unsigned long i = 0;
BSP_Init();
for(i = 0; i <= 0x3FFF; i ++);
while(1)
{
OSTimeDlyHMSM(0,0,0,5); //5MS DELAY
IOSET0=1<<8;
//P0.8 OFF
OSTimeDlyHMSM(0,0,0,10);
IOCLR0=1<<8;
OSTimeDlyHMSM(0,0,0,5);

OSTimeDlyResume(11); //Kill the delay of Second task


OSTimeDlyHMSM(0,0,0,5); //Delay the task for 5ms

}
void TaskSecond (void * pvdata)
{
unsigned long i = 0;
unsigned char err;
// for(;;)
while(1)
{

IOSET0=1<<9;
OSTimeDlyHMSM(0,0,0,20);
IOCLR0=1<<9;
OSTimeDlyHMSM(0,0,0,20);
OSTimeDlyResume(12); //Kill the delay of Third task
OSTimeDlyHMSM(0,0,0,10); //Assign 0xf0 to the LEDs

//Kill the delay of First task


}
}
void TaskThird(void * pvdata)
{
unsigned long i = 0;
char err;
//for(;;)
while(1)
{
for(i = 0; i <= 0x3FFFFF; i ++);
count++;
OSTimeDlyResume(10); //Kill the delay of Third task
//OSTimeDlyHMSM(0,0,0,10); //Kill the delay of First task
}
}
Flow Chart for Blinking two LEDS

Start

Initialize OS - case

Configure BSP

OS start create & OS


start
Transfer layer
multitasking

Toggle LEDS
for delay xms

Toggle LEDS
Application Layer
for delay yms
multitasking
Collect the datas
from string

Stop
Output:
Two LEDS are blinking with three different tasks
Result:
Thus the RTOS program Blinking two LEDS with LPC2148 has been tested successfully.
Ex. No: 16 Transmission from KIT and reception from PC using serial

Aim:

To Write an Embedded C Program to interface the Transmission from KIT and reception
from PC using serial with LPC 2148 Kit.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include "includes.h"
#define TASKSTART_STK_SIZE 256
#define TASK_STK_SIZE 256 /* Size of each task's stacks (# of WORDs) */
#define N_TASKS 3 /* Number of identical tasks */
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
char TaskData[N_TASKS]; /* Parameters to pass to each task */
INT8U err;
void TaskStart(void *dataa); /* Function prototypes of Startup task */
void TaskSecond(void *dataa); /* Function prototypes of tasks */
void TaskThird(void *dataa);
OS_EVENT *JK=NULL;
#include <string.h>
#include<stdlib.h>
#include<stdio.h>
#define pclk 60000000
unsigned int baud_value;
//unsigned char msg[]="WELCOME TO NITTTR";
//unsigned char msg1[]="LITTLE ENDIAN";
//unsigned char msg2[]="BIG ENDIAN";
void UART0_INIT(unsigned int baud_rate)
{
PINSEL0 |=0x5;
U0LCR =0x83;
baud_value=(pclk/16)/baud_rate;
U0DLM =baud_value/256;
U0DLL=baud_value % 256;
U0LCR =0x3;
U0FCR =0x07;
}
void delay(void)
{
unsigned int i;
for(i=0;i<0xffffF;i++)
{
}
}
void feed()
{
PLL0FEED=0XAA;
PLL0FEED=0X55;
}
void PLL_INIT()
{
PLL0CFG =0X24; //MULT DEVIDER
feed();
PLL0CON=1; //ENABLE PLL
feed();
while(!(PLL0STAT & 0X0400));
PLL0CON=0X3;
feed();
MAMCR=0X2;
MAMTIM=0X4;
VPBDIV=0X1;
}
unsigned char rec(unsigned char num)
{
while(!(U0LSR & 0X01));
return(U0RBR);
}
void PUTC0(unsigned char ch)
{
while(!(U0LSR & 1<<5));
U0THR=ch;
}
void PUTS0(unsigned char *ms0)
{
unsigned int i,l;
l=strlen(ms0);
for(i=0;i<l;i++)
{
while(!(U0LSR & 0X20));
U0THR=ms0[i];
}
PUTC0(0xd);
PUTC0(0xa);
}
int main (void)
{
IODIR0=0X1<<16;
PLL_INIT();
UART0_INIT(9600);
JK=OSSemCreate(1);
OSInit(); /* Initialize uC/OS-II*/
OSTaskCreate(TaskStart,
(void *)0,
(OS_STK *)&TaskStk[0][TASK_STK_SIZE - 1],10);
OSTaskCreate(TaskSecond,
(void *)0,
(OS_STK *)&TaskStk[1][TASK_STK_SIZE - 1],11);
OSTaskCreate(TaskThird,
(void *)0,
(OS_STK *)&TaskStk[2][TASK_STK_SIZE - 1],12);
OSStart(); /* Start multitasking */
//for(i = 0; i <= 0x100; i ++);
}
void TaskStart (void *dataa)
{
unsigned long i = 0;
BSP_Init();
for(;;)
{
for(i = 0; i <= 0x3FFFFF; i ++); //Delay between switching OFF LEDs
PUTS0("WELCOME TO VASEE ELECTRONICS0\n");

OSTimeDlyResume(11); //Kill the delay of Second task


OSTimeDlyHMSM(0,0,5,5); //Delay the task for 5ms
}
}
void TaskSecond (void * pvdata)
{
unsigned long i = 0;
unsigned char err;
for(;;)
{
//Clear the LEDs
for(i = 0; i <= 0xFF000; i ++); //Delay between switching ON
LEDs
PUTS0("WELCOME TO VASEE ELECTRONICS1\n");
OSTimeDlyResume(12);
//Kill the delay of Third task
OSTimeDlyHMSM(0,0,1,1);
//Assign 0xf0 to the LEDs
//Kill the delay of First task
}
}
void TaskThird(void * pvdata)
{
unsigned long i = 0;
char err;
for(;;)
{
//OSTimeDlyHMSM(0,0,1,10);
PUTS0("WELCOME TO VASEE ELECTRONICS2\n");
//
OSTimeDlyResume(10); //Kill the delay of Third task
//Kill the delay of First task
}
}
Flow Chart for Transmission from KIT and reception from PC using serial

Start Initialize port for


UART0 & configure
Baud rate
Initialize OS - case

Configure BSP Initialize PLC memory


map, Boot Block

OS start create & OS


start
Transfer control
to kernel

Run independ Application Layer


task with priority multitasking

1st priority task 2nd priority task 3rd priority task

Do not terminate
task

Stop
Output:
Welcome to Vasee Electronics 0
Welcome to Vasee Electronics 1
Welcome to Vasee Electronics 2
Result:
Thus the RTOS program Transmission from KIT and reception from PC using serial port has been tested
successfully
Ex. No: 17 Graphics LCD

Aim:

To Write a program.

Apparatus Required:

S. No Description Quantity

1 LPC 2148 kit 1

2 Adapter 1

3 RS232 Cable 1

4 Personal Computer 1

Program:

#include "LPC214X.H"
// os _stk adc_task stk [1000];
// os_stk disp_task stk [1000];
//FUNCTION DEFINITION
Void_adc_task (void *p data);
{
For (;;)
{
Read_adc ();
Os time delay (10);
}
}
Void_disp_task (void * p data)
{
For (;;)
{
Disp();
Write_xy ();
Graph_plotting();
Os_time dly (10);
}
}
Void main (void);
{
Bsp_int plsaii ();
Bsp_init ();
Pinsel 2 = 0X0000 0000;
IO0 DIR1 = 0XFFF0 7FFF;
IO1 DIR1 = 0XFFFF FFFF;
Init lcd ();
Clear_display();
For (int i=0; i<0XFFFF; i++);
For (int i=0; i<0XFF; i++);
Clear_display ();
Arm_uart0_int ();
Os_int ();
Os task create (adc_task & adc, task stk (a a a),0);
Os task create (disp_task & disp_task stk (a a a),1);
Os start ();
}

Result:
Thus the program for Temperature from LM35 interface & plot the temperature as time graph using
Graphic LCD was executed & verified.

S-ar putea să vă placă și