Sunteți pe pagina 1din 19

LIST OF EXPERIMENTS

Note: Minimum of 10 Experiments have to be conducted

1. Write a simple program to print “hello world”

2. Write a simple program to show a delay.

3. Write a loop application to copy values from P1 to P2

4. Write a c program for counting the no of times that a switch is pressed & released.

5. Illustrate the use of port header file (port M) using an interface consisting of a keypad and liquid

crystal display.

6. Write a program to create a portable hardward delay.

7. Write a c program to test loop time outs.

8. Write a c program to test hardware based timeout loops.

9. Develop a simple EOS showing traffic light sequencing.

10. Write a program to display elapsed time over RS-232 link.

11. Write a program to drive SEOS using Timer 0.

12. Develop software for milk pasteurization system.


1. Write a simple program to print “hello world”

#include <lpc214x.h>
#define rs 0x00010000
#define en 0x00020000

void delay_ms(unsigned int t)


{
unsigned int i;
for(;t>0;t--)
for(i=0;i<13000;i++);

void cmd(unsigned char x)


{
unsigned int y;
y = x<<18;
IOPIN1 = IOPIN1 & 0xFC00FFFF;
IOPIN1 = IOPIN1 | y;

IOCLR1|= rs;
IOSET1|= en;
delay_ms(10);
IOCLR1|= en;
delay_ms(10);
}

void lcd_disp(unsigned char x)


{
unsigned int y;
y = x<<18;
IOPIN1 = IOPIN1 & 0xFC00FFFF;
IOPIN1 = IOPIN1 | y;

IOSET1|= rs;
IOSET1|= en;
delay_ms(10);
IOCLR1|=en;
delay_ms(10);
}
void disp_str(unsigned char *x)
{
while(*x)
lcd_disp(*x++);
}
void lcdinit()
{
IODIR1=0x03FF0000;
cmd(0x38);
cmd(0x01);
cmd(0x06);
cmd(0x0c);
cmd(0x80);
}
int main()
{
IODIR0=0xffffffff;
lcdinit();
while(1)
{
cmd(0x80);
disp_str("hello world");
}
}
2. Write a simple program to show a delay.
#include <lpc214x.h>
#define led1 0x00000001 // declare led1 is p0.0
#define led2 0x00000002 // declare led2 is p0.1
unsigned char x;
void delay_ms(unsigned int t) // delay functiobn
{
unsigned int i;
for(;t>0;t--)
for(i=0;i<5000;i++); //

}
int main()
{
IODIR0=0x00000003; // declare p0.1 to p0.2 as output pis for leds

while(1) // continuous loop


{
IOSET0|=led1;
IOSET0|=led2;
delay_ms(1000); // upto 1 sec leds are on(1000= 1 sec, if u want 2 sec delay then 2000)
IOCLR0|=led1;
IOCLR0|=led2;
delay_ms(1000); // upto 1 sec leds are off

}
}
3. Write a loop application to copy values from P1 to P2
#include <lpc214x.h>

unsigned char x;

unsigned int y;

int main()

IODIR0=0x00000000; // declare p0 as input

IODIR0=0xffff0000; // declare p as output

while(1) // continuous loop

x='w'; // single char 'w' transfer to x variable

y = x<<16; // valur transfer from p0.16 pin to p0.23(8 bit dat)

IOPIN0 = IOPIN0 & 0x00000000; // first clear the all pins that's why we are using

and(&) opration with zeros

IOPIN0 = IOPIN0 | y; // value transfer to port 0

IOPIN1 = IOPIN1 & 0x00000000; // first clear the all pins that's why we are using and(&)

opration with zeros

IOPIN1 = IOPIN0 ; // value transfer to port 0 to port1

}
4. Write a c program for counting the no of times that a switch is pressed & released.
#include <lpc214x.h>
#define sw 1<<0 // p0.0 connected to switch
unsigned int pc,rc; //pc= pressed count , rc= released count variables
unsigned char x;
int main()
{
IODIR0=0x00000000; // declare p0 as input

while(1) // continuous loop


{
x=IOPIN0; // read input value from switch
x=x&0x00000001; // if input signal is high that signal & with 1 then output is '1' otherwise
'0'
if(x==0x00000001) // switch is pressed signal is high then enter this loop
{
while(x==0x00000001); // wait until switch is released
pc++; // increment the pressed count
}
else if(x==0x00000000)
{
while(x==0x00000000); // wait until switch is pressed
rc++; // increment the released count
}}
}
5. Illustrate the use of port header file (port M) using an interface consisting of a keypad and liquid
crystal display.

#include <LPC214X.H>
#include "lcd.h"
#include "keypad.h"

unsigned char arr[4];

int main()
{
IODIR0=0xfff000ff; // declare col as inputs and row as outputs
lcdinit();

while(1)
{
cmd(0x80); // lcd 1st row display address
disp_str("ENTER VALUES ");
cmd(0xc0); // lcd 2 nd row display address
for(i=0;i<4;i++) // ENTER 4 VALUES
{
arr[i]=get_key(); // read value from keypad and assign
to array
lcd_disp(arr[i]); // display value in array
}
}
}

#define C1 0x00020000 //p0.17v col 1


#define C2 0x00040000 //p0.18 col 2
#define C3 0x00080000 //p0.19 col 3
#define RowA 0x00100000 //p0.20
#define RowB 0x00200000 //p0.21
#define RowC 0x00400000 //p0.22
#define RowD 0x00800000 //p0.23

unsigned char key ,ch;


unsigned int i,j;

void dela(int x);

void Return(void) //Return to 0 location on LCD


{
cmd(0x02);
dela(1500);
}
char READ_SWITCHES(void)
{

IO0CLR|=RowA;IO0SET|=RowB;IO0SET|=RowC;IO0SET|=RowD; //Test Row A

if (!(IOPIN0&=C1)) { dela(100); while (!(IOPIN0&=C1)); return '1'; }


IO0CLR|=RowA;IO0SET|=RowB;IO0SET|=RowC;IO0SET|=RowD;
if (!(IOPIN0&=C2)) { dela(100); while (!(IOPIN0&=C2)); return '2'; }

IO0CLR|=RowA;IO0SET|=RowB;IO0SET|=RowC;IO0SET|=RowD;
if (!(IOPIN0&=C3)) { dela(100); while (!(IOPIN0&=C3)); return '3'; }

IO0CLR|=RowB;IO0SET|=RowA;IO0SET|=RowC;IO0SET|=RowD; //Test Row B

if (!(IOPIN0&=C1)) { dela(100); while (!(IOPIN0&=C1)); return '4'; }

IO0CLR|=RowB;IO0SET|=RowA;IO0SET|=RowC;IO0SET|=RowD;
if (!(IOPIN0&=C2)) { dela(100); while (!(IOPIN0&=C2)); return '5'; }

IO0CLR|=RowB;IO0SET|=RowA;IO0SET|=RowC;IO0SET|=RowD;
if (!(IOPIN0&=C3)) { dela(100); while (!(IOPIN0&=C3)); return '6'; }

IO0CLR|=RowC;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowD; //Test Row C

if (!(IOPIN0&=C1)) { dela(100); while (!(IOPIN0&=C1)); return '7'; }


IO0CLR|=RowC;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowD;
if (!(IOPIN0&=C2)) { dela(100); while (!(IOPIN0&=C2)); return '8'; }
IO0CLR|=RowC;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowD;
if (!(IOPIN0&=C3)) { dela(100); while (!(IOPIN0&=C3)); return '9'; }

IO0CLR|=RowD;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowC;//Test Row D

if (!(IOPIN0&=C1)) { dela(100); while (!(IOPIN0&=C1)); return '*'; }


IO0CLR|=RowD;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowC;
if (!(IOPIN0&=C2)) { dela(100); while (!(IOPIN0&=C2)); return '0'; }
IO0CLR|=RowD;IO0SET|=RowA;IO0SET|=RowB;IO0SET|=RowC;
if (!(IOPIN0&=C3)) { dela(100); while (!(IOPIN0&=C3)); return '#'; }

return 'n'; // Means no key has been pressed


}
char get_key(void) //get key from user
{
char key = 'n'; //assume no key pressed

while(key=='n') //wait untill a key is pressed


key = READ_SWITCHES(); //scan the keys again and again

return key; //when key pressed then return its value


}

void dela(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<200;j++); //null statement
}

#define rs 0x00010000
#define en 0x00020000

void delay_ms(unsigned int t)


{
unsigned int i;
for(;t>0;t--)
for(i=0;i<13000;i++);

void cmd(unsigned char x)


{
unsigned int y;
y = x<<18;
IOPIN1 = IOPIN1 & 0xFC00FFFF;
IOPIN1 = IOPIN1 | y;

IOCLR1|= rs;
IOSET1|= en;
delay_ms(10);
IOCLR1|= en;
delay_ms(10);
}

void lcd_disp(unsigned char x)


{
unsigned int y;
y = x<<18;
IOPIN1 = IOPIN1 & 0xFC00FFFF;
IOPIN1 = IOPIN1 | y;

IOSET1|= rs;
IOSET1|= en;
delay_ms(10);
IOCLR1|=en;
delay_ms(10);
}

void disp_str(unsigned char *x)


{
while(*x)
lcd_disp(*x++);
}

void lcdinit()
{
IODIR1=0x03FF0000;
cmd(0x38);
cmd(0x01);
cmd(0x06);
cmd(0x0c);
cmd(0x80);
}
6. Write a program to create a portable hardward delay.

#include <lpc214x.h>

#define PLOCK 0x00000400


#define PRESCALE 60000

void delayMS(unsigned int milliseconds);


void initClocks(void);
void initTimer0(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);

int main(void)
{
initClocks();
initTimer0();
IO0DIR = 0xFFFFFFFF;

while(1)
{
IO0SET = 0xFFFFFFFF;
delayMS(500); //0.5 Second(s) Delay
IO0CLR = 0xFFFFFFFF;
delayMS(500);
}

void initTimer0(void)
{

T0CTCR = 0x0;
T0PR = PRESCALE-1;

T0TCR = 0x02;
}

void delayMS(unsigned int milliseconds)


{
T0TCR = 0x02;

T0TCR = 0x01;
while(T0TC < milliseconds);

T0TCR = 0x00;
}

void initClocks(void)
{
setupPLL0();
feedSeq();
connectPLL0();
feedSeq();

VPBDIV = 0x01;

void setupPLL0(void)
{

PLL0CON = 0x01;
PLL0CFG = 0x24;

void feedSeq(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}

void connectPLL0(void)
{

while( !( PLL0STAT & PLOCK ));

PLL0CON = 0x03;
}
7. Write a c program to test loop time outs.

#include <lpc214x.h>
#define sw 1<<0

void testtime_out(unsigned int milliseconds);

unsigned char x;
int main(void)
{
IO0DIR = 0xFFFFFFFe;

while(1)
{
mn:
x=IOPIN0;
x=x&0x00000001;
if(sw==0x00000001)
{
IO0SET = 0xFFFFFFFF;
IO0CLR = 0xFFFFFFFF;
testtime_out(1500); //1.5 Second(s) time out loop
goto mn;
}
else if(sw==0x00000000)
{
IO0SET = 0xFFFFFFFF;
IO0CLR = 0xFFFFFFFF;
testtime_out(1500); //1.5 Second(s) time out loop
goto mn;
}

}}

void testtime_out(unsigned int milliseconds) // test time out loop


{
unsigned int j;
for(;milliseconds>0;milliseconds--)
for(j=0;j<5000;j++);
}
8. Write a c program to test hardware based timeout loops.

#include <lpc214x.h>

#define PLOCK 0x00000400


#define PRESCALE 60000
#define sw 0x00010000

void delayMS(unsigned int milliseconds);


void initClocks(void);
void initTimer0(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);
unsigned char timeout_loop=0,x;

int main(void)
{
initClocks();
initTimer0();
IO0DIR = 0xFFFeFFFF;

while(1)
{
mn:
x= IOPIN0;
x=x&0x00010000;
if(x==0x00010000)
{
do
{
x= IOPIN0;
x=x&0x00010000;
IO0SET = 0xFFFFFFFF;
delayMS(1000); // 1 Second(s) Delay
IO0CLR = 0xFFFFFFFF;
} while(x==0x00010000&&T0TCR!=0X00);
goto mn;
}
else if(x==0x00000000)
{
do
{
IO0SET = 0xFFFF0000;
delayMS(1000); // 1 Second(s) Delay
IO0CLR = 0x0000FFFF;
}while(x==0x00000000&&T0TCR!=0X00);
goto mn;
}

}
}

void initTimer0(void)
{

T0CTCR = 0x0;
T0PR = PRESCALE-1;

T0TCR = 0x02;
}

void delayMS(unsigned int milliseconds)


{
T0TCR = 0x02;
T0TCR = 0x01;

while(T0TC < milliseconds);


T0TCR = 0x00;
timeout_loop++;
}

void initClocks(void)
{
setupPLL0();
feedSeq();
connectPLL0();
feedSeq();

VPBDIV = 0x01;

void setupPLL0(void)
{

PLL0CON = 0x01;
PLL0CFG = 0x24;
}

void feedSeq(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}

void connectPLL0(void)
{

while( !( PLL0STAT & PLOCK ));

PLL0CON = 0x03;
}
10. Write a program to display elapsed time over RS-232 link.

#include <lpc214x.h>

#define PLOCK 0x00000400


#define PRESCALE 60000
#define sw 0x00010000

void uart0_init(void);
void uart0_tx(unsigned char);
void str_uart0(unsigned char *x);
void delayMS(unsigned int milliseconds);
void initClocks(void);
void initTimer0(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);
unsigned char timeout_loop=0,x;

int main(void)
{
uart0_init();
initClocks();
initTimer0();
IO0DIR = 0xFFFeFFFF;

while(1)
{
mn:
x= IOPIN0;
x=x&0x00010000;
if(x==0x00010000)
{
do
{
str_uart0("event 1 is start and time is counting");
x= IOPIN0;
x=x&0x00010000;
IO0SET = 0xFFFFFFFF;
delayMS(1000); // 1 Second(s) Delay
IO0CLR = 0xFFFFFFFF;
} while(x==0x00010000&&T0TCR!=0X00);
str_uart0("time is 1 sec for event 1is completed , event 1 is lights all are on");
goto mn;
}
else if(x==0x00000000)
{
do
{
str_uart0("event 2 is start and time is counting");
IO0SET = 0xFFFF0000;
delayMS(2000); // 1 Second(s) Delay
IO0CLR = 0x0000FFFF;
}while(x==0x00000000&&T0TCR!=0X00);
str_uart0("time is 2 sec for event 1is completed , event 2 is some lights are on remaining are off
");
goto mn;
}

}
}

void initTimer0(void)
{

T0CTCR = 0x0;
T0PR = PRESCALE-1;

T0TCR = 0x02;
}

void delayMS(unsigned int milliseconds)


{
T0TCR = 0x02;
T0TCR = 0x01;

while(T0TC < milliseconds);


T0TCR = 0x00;
timeout_loop++;
}

void initClocks(void)
{
setupPLL0();
feedSeq();
connectPLL0();
feedSeq();
VPBDIV = 0x01;

void setupPLL0(void)
{

PLL0CON = 0x01;
PLL0CFG = 0x24;

void feedSeq(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}

void connectPLL0(void)
{

while( !( PLL0STAT & PLOCK ));

PLL0CON = 0x03;
}
void uart0_init(void)
{
PINSEL0 |=0x00000005;
U0LCR=0x83;
U0DLL=98;
U0DLM=0;
U0LCR=0x03;
}
void tx_uart0(unsigned char x)
{
U0THR=x;
while(!(U0LSR&=0x20));
}

void str_uart0(unsigned char *x)


{
while(*x)
tx_uart0(*x++);
}

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