Você está na página 1de 44

RELAY AND BUZZER

AIM:
To write the embedded c program for relay and buzzer and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

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


#include <stdio.h>
#define buzzer 0x00000400 // Pin10
#define relay 0x00000200 // Pin9
#define switch 0x00000100 // Pin8
int main (void)
{
IO0DIR = 0x0000FE00; // pin8 is low. this is used as input switch
IO0PIN = 0x00000000;
while (1)
{
if (IO0PIN & switch) //both are same, condition will be satisfied
{
IO0SET = buzzer;
IO0CLR = relay;
}
else
{
IO0CLR = buzzer;
IO0SET = relay;

1
}
}
}

RESULT:
Thus the program was executed and the result was verified.

2
STEPPER MOTOR

AIM:
To write the embedded c program for stepper motor and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

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


#include <stdio.h>
void delay (void)
{
int cntr1 = 2000000,i; // 100000 /* Delay function */
for (i = 0; i < cntr1; i++);
}
int main (void)
{
IO0DIR = 0x0000FF00;
IO0PIN= 0x00000000;
while(1)
{
IO0SET = 0x00000800;
delay();
IO0CLR = 0x00000800;
delay();

IO0SET = 0x00000400;
delay();

3
IO0CLR = 0x00000400;
delay();

IO0SET = 0x00000200;
delay();
IO0CLR = 0x00000200;
delay();

IO0SET = 0x00000100;
delay();
IO0CLR = 0x00000100;
delay();

}
}
RESULT:
Thus the program was executed and the result was verified.

4
LCD DISPLAY

AIM:
To write the embedded c program for LCD display and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

#include <stdio.h> /* standard I/O .h-file */


#include <LPC21xx.H> /* LPC21xx definitions */
void lcdcommand(void);
void lcddatawrt(void);
void lcd_amber(void);
void delay(void);
void delay1(void);
void lcd_initialization(void);
unsigned int n,i,j;
int main (void)
{
IODIR0 = 0x000FFF00; /*P0.8 to P0.18 DEFINED AS OUTPUT PINS*/
lcd_initialization();
delay();
while (1)
{
delay1(); /* Loop forever */
lcd_amber();
}

5
}
void delay(void)
{
for(i=0;i<=100;i++)
for(j=0;j<=1000;j++);
}
void delay1(void)
{
int i;
char k;
for(k=0;k<=100;k++)
{
for(i=0;i<=1000;i++) ; //400000
}
}
void lcdcommand(void)
{
IODIR0=0X000FFF00; /* P0.8 to P0.18 defined as Outputs */
IOPIN0 = n;
IOCLR0=0x00010000; /* RS(P0.16)=0 */
IOCLR0=0x00020000; /* R/W(P0.17)=0 */
IOSET0=0x00040000; /* EN(P0.18)=1 */
delay();
IOCLR0=0x00040000; /* EN(P0.18)=0 */
}
void lcddatawrt (void)
{
IODIR0=0X000FFF00; /* P0.8 to P0.18 defined as Outputs */
IOPIN0 = n;
IOSET0=0x00010000; /* RS(P0.16)=1 */
IOCLR0=0x00020000; /* R/W(P0.17)=0 */
IOSET0=0x00040000; /* EN(P0.18)=1 */
delay();
IOCLR0=0x00040000; /* EN(P0.18)=0 */
}
void lcd_initialization(void)
{
n=0x00003800; //initialize LCD 2 LINES 5x7 MATRIX
lcdcommand();
n=0x00000E00; //LCD COMMAND FOR CURSUR ON
lcdcommand();
n=0x00000100; //clear lcd
lcdcommand();
}
void lcd_amber(void)
{
n=0x00008000; // force cursur to begining of first line
lcdcommand();
n=0x00004100; /*A*/
lcddatawrt();
delay();

6
n=0x00005200; /*R*/
lcddatawrt();
delay();
n=0x00004D00; /*M*/
lcddatawrt();
delay();
n=0x00004200; /*B*/
lcddatawrt();
delay();
n=0x00004F00; /*O*/
lcddatawrt();
delay();
n=0x00004100; /*A*/
lcddatawrt();
delay();
n=0x00005200; /*R*/
lcddatawrt();
delay();
n=0x00004400; /*D*/
lcddatawrt();
delay();
}

RESULT:

Thus the program was executed and the result was verified.

7
DIGITAL INPUT - OUTPUT
AIM:
To write the embedded c program for digital input and output and to execute using
ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

#include <stdio.h> /* standard I/O .h-file */


#include <LPC21xx.H> /* LPC21xx definitions */
#define in0 0x00010000//16 //16 to 23
#define in1 0x00020000//17
#define in2 0x00040000//18
#define in3 0x00080000//19
#define in4 0x00100000//20
#define in5 0x00200000//21
#define in6 0x00400000//22
#define in7 0x00800000//23
#define out0 0x00000100 //08
#define out1 0x00000200 //09
#define out2 0x00000400 //10
#define out3 0x00000800 //11
#define out4 0x00001000 //12
#define out5 0x00002000 //13
#define out6 0x00004000 //14
#define out7 0x00008000 //15

int main (void)

8
{
{
IO0DIR = 0X0000FF00;
IO0PIN = 0X00000000;
while(1)
{
//SW0
if((IO0PIN & (in7)))
{
IO0SET = out7;
}
else IO0CLR = out7;

//SW1
if((IO0PIN & (in6)))
{
IO0SET =out6;
}
else IO0CLR = out6;
//SW2
if((IO0PIN & (in5)))
{
IO0SET = out5;
}
else IO0CLR = out5;
//SW3
if((IO0PIN & (in4)))
{
IO0SET = out4;
}
else IO0CLR = out4;
//SW4
if((IO0PIN & (in3)))
{
IO0SET = out3;
}
else IO0CLR = out3;
//SW5
if((IO0PIN & (in2)))
{
IO0SET =out2;

}
else IO0CLR = out2;

//SW6
if((IO0PIN & (in1)))
{
IO0SET =out1;
}
else IO0CLR =out1;

9
//SW7

if((IO0PIN & (in0)))


{
IO0SET = out0;
}
else IO0CLR = out0;
}
}
}

RESULT:
Thus the program was executed and the result was verified.

10
4x4 MATRIX KEYPAD:

AIM:
To write the embedded c program for 4x4 matrix keypad and to execute using
ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

#include <stdio.h> /* standard I/O .h-file */


#include <LPC21xx.H> /* LPC21xx definitions */
#define col0 0x00080000 //P 0.19
#define col1 0x00040000 //P 0.18
#define col2 0x00020000 //P 0.17
#define col3 0x00010000 //P 0.16
#define row0 0x00800000 //P 0.23
#define row1 0x00400000 //P 0.22
#define row2 0x00200000 //P 0.21
#define row3 0x00100000 //P 0.20 //LED's -->P 0.8 to P0.15
void delay1(void);
void delay2(void);
void delay3(void);
unsigned int n,i,j;
int main (void)
{
int j=0;
IODIR0 = 0x000FFF00;
IO0PIN = 0x00000000;

11
IO0CLR = 0x000FFF00;
while (1)
{
if (j ==0)
{
IO0SET = 0x00010000;
if((IO0PIN & row0))
{
IO0SET = 0x00000000;
}
else IO0CLR = 0x00000000;
}
if (j ==1)
{
IO0SET = 0x00020000;
if((IO0PIN & row0))
{
IO0SET = 0x00000100;
}
else IO0CLR = 0x00000100;
}
if (j ==2)
{
IO0SET = 0x00040000;
if((IO0PIN & row0))
{
IO0SET = 0x00000200;
}
else IO0CLR = 0x00000200;
}
if (j ==3)
{
IO0SET = 0x00080000;

if((IO0PIN & row0))


{
IO0SET = 0x00000300;
}
else IO0CLR = 0x00000300;
}
if (j ==4)
{
IO0SET = 0x00010000;
if((IO0PIN & row1))
{
IO0SET = 0x00000400;
}
else IO0CLR =0x00000400;
}
if (j ==5)
{

12
IO0SET = 0x00020000;
if((IO0PIN & row1))
{
IO0SET = 0x00000500;
}
else IO0CLR = 0x00000500;
}
if (j ==6)
{
IO0SET = 0x00040000;
if((IO0PIN & row1))
{
IO0SET = 0x00000600;
}
else IO0CLR = 0x00000600;
}
if (j ==7)
{
IO0SET = 0x00080000;
if((IO0PIN & row1))
{
IO0SET =0x00000700;
}
else IO0CLR = 0x00000700;
}
if (j ==8)
{
IO0SET = 0x00010000;
if((IO0PIN & row2))
{
IO0SET =0x00000800;
}
else IO0CLR = 0x00000800;
}
if (j ==9)
{
IO0SET = 0x00020000;
if((IO0PIN & row2))
{
IO0SET = 0x00000900;
}
else IO0CLR = 0x00000900;
}
if (j ==10)
{
IO0SET = 0x00040000;
if((IO0PIN & row2))
{
IO0SET =0x00000A00;
}
else IO0CLR = 0x00000A00;

13
}
if (j ==11)
{
IO0SET = 0x00080000;
if((IO0PIN & row2))
{
IO0SET = 0x00000B00;
}
else IO0CLR = 0x00000B00;
}
if (j ==12)
{
IO0SET = 0x00010000;
if((IO0PIN & row3))
{
IO0SET = 0x00000C00;
}
else IO0CLR =0x00000C00;
}
if (j ==13)
{
IO0SET = 0x00020000;
if((IO0PIN & row3))
{
IO0SET = 0x00000D00;
}
else IO0CLR = 0x00000D00;
}
if (j ==14)
{
IO0SET = 0x00040000;
if((IO0PIN & row3))
{
IO0SET = 0x00000E00;
}
else IO0CLR = 0x00000E00;
}
if (j ==15)
{
IO0SET = 0x00080000;
if((IO0PIN & row3))
{
IO0SET = 0x00000F00;
}
else IO0CLR = 0x00000F00;

}
delay3();
IO0CLR=0x000F0F00;
j++;
if(j>15)

14
{
j = 0;
}
}
}
void delay1(void)
{
int one;
for(one=0;one<=6227000;one++);
}
void delay2(void)
{
int one;
for(one=0;one<=62270;one++);
}
void delay3(void)
{
int one;
for(one=0;one<=922;one++);
}

RESULT:
Thus the program was executed and the result was verified.

15
SEVEN SEGMENT LED
AIM:
To write the embedded c program for seven segment LED and to execute using
ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

SINGLE DIGIT:
#include <stdio.h> /* standard I/O .h-file */
#include <LPC21xx.H> /* LPC21xx definitions */
void delay3(void);
int main (void)
{
IODIR0 = 0x00FFFF00;
IO0CLR = 0x00FFFF00;
while (1)
{
IO0CLR = 0x00FFFF00;
IO0SET = 0x00010000;
IO0SET = 0x0000E500; //1
} }

MULTI DIGIT:
#include <stdio.h> /* standard I/O .h-file */
#include <LPC21xx.H> /* LPC21xx definitions */
void delay3(void);
int main (void)

16
{
int repeat=0;
IODIR0 = 0x00FFFF00;
IO0CLR = 0x00FFFF00;
while (1)
{
for(repeat=0;repeat<=1000;repeat++)
{
{
//FIRST DIGIT DATA
IO0CLR = 0x00FFFF00;
delay3();
IO0SET = 0x00010000;
IO0SET = 0x0000FF00; //1+
delay3();
IO0CLR = 0x00FFFF00;
}
{
//SECOND DIGIT DATA
IO0CLR = 0x00FFFF00;
delay3();
IO0SET = 0x00020000;
IO0SET = 0x0000FF00; //8
delay3();
IO0CLR = 0x00FFFF00;
}
} }
}
//DELAY UNIT
void delay3(void)
{
int one;
for(one=0;one<=10;one++);
}

RESULT:
Thus the program was executed and the result was verified.

17
ANALOG TO DIGITAL CONVERTER
AIM:
To write the embedded c program for Analog to Digital Converter and to execute
using ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

#include"LPC214x.h"
#define ADC_DONE 0x80000000
void delay();
void ADCread(unsigned char);
void ADC_init()
{
AD0CR = ( 0x001 << 2 ) | // SEL=1, select channel 0, 1 to 4 on ADC0
(15000000/(1000000-1)<<8) | // CLKDIV = Fpclk / 1000000 - 1
( 0 << 16 ) | // BURST=0,no BURST, software controlled
( 0 << 17 ) | // CLKS = 0, 11 clocks/10 bits
( 1 << 21 ) | // PDN = 1, normal operation
( 0 << 22 ) | // TEST1:0 = 00
( 0 << 24 ) | // START = 0 A/D conversion stops
( 0 << 27 ); /* EDGE=0(CAP/MAT singal falling,trigger A/D conversion) */
}

void ADCread(unsigned char channelNum )


{

18
int ADCresult;
unsigned long ADC0IntDone = 0;
/* Clear all SEL bits */
AD0CR &= 0xFFFFFF00;
AD0CR |= (1 << 24)| (1 << channelNum );
while(ADC0IntDone==0) //wait till cnvrsn done
{
if ( AD0DR2 & ADC_DONE )
{
break;
}
}
AD0CR &= 0xF8FFFFFF;
ADCresult=(AD0DR2>>6)&0x3ff;//cnvrsn data holds AD0DR[6] to AD0DR[15]
}
void delay()
{ int i;
for(i=0;i<=10000;i++);
}
int main(void)
{
int k;
while(1){
PINSEL0=0x00000000;
PINSEL1=0x05000000; //ADC0.2 CHANNEL SELECT
IODIR0=0X0003FF00;
ADC_init();
ADCread(0x02);
IOCLR0=0X0003FF00;
k=AD0DR2;
k<<=2;
IOPIN0=k & 0x0003FF00;
delay();
}
}

RESULT:
Thus the program was executed and the result was verified.

19
FLASH LEDS

AIM:
To write the embedded c program for Flashing LEDs and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

BLINKY.C:
#include <RTL.h>
#include <LPC214x.H> /* LPC214x definitions */
OS_TID t_phaseA; /* assigned task id of task: phase_a */
OS_TID t_clock; /* assigned task id of task: clock */
#define IOSET IOSET0
#define IOCLR IOCLR0
#define IODIR IODIR0
#define LEDS_ON IOCLR
#define LEDS_OFF IOSET
#define LED_A (1 << 8)
#define LED_CLK (1 << 12)

void signal_func (OS_TID task) {


os_evt_set (0x0100, t_clock); /* send event signal to clock task */
os_dly_wait (15); /* delay 50 clock ticks */
os_evt_set (0x0100, t_clock);/* send event signal to clock task */
os_dly_wait (15); /* delay 50 clock ticks */
os_evt_set (0x0001, task); /* send event to task 'task' */
os_dly_wait (15); /* delay 50 clock ticks */

20
}
__task void phaseA (void) {
for (;;) {
os_evt_wait_and (0x0001, 0xffff);/*wait foraneventflag 0x0001*/
LEDS_ON = LED_CLK;
signal_func (t_phaseA); /* call common signal function */
os_dly_wait (8);
LEDS_OFF = LED_A;
}
}
__task void clock (void) {
for (;;) {
os_evt_wait_and (0x0100, 0xffff); /* wait for an event flag 0x0100*/
LEDS_ON = LED_CLK;
os_dly_wait (8); /* delay 8 clock ticks */
LEDS_OFF = LED_CLK;
}
}
__task void init (void) {
IODIR = LED_A |LED_CLK;
LEDS_OFF = LED_A | LED_CLK;
t_phaseA = os_tsk_create (phaseA, 0);/* start task phaseA */
t_clock = os_tsk_create (clock, 0); /* start task clock */
os_dly_wait (8);
os_evt_set (0x0001, t_phaseA); /* send signal event to task phaseA */
os_dly_wait (8);
os_tsk_delete_self ();
}
int main (void) {
while(1)
{
os_sys_init (init); /* Initialize RTX and start */
}
}

TIMER DELAY:

AIM:
To write the embedded c program for timer delay and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.

21
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

TIME DELAY.C:
#include <LPC21xx.H> /* LPC21xx definitions */
#include "Timer.h"
#include <stdio.h>
void wait (void) /* wait function */
{
unsigned long i;
i = timeval;
while ((i + 12) != timeval); /* wait 100ms */
}
int main (void)
{
unsigned int j;

IODIR0 = 0xFFFFFFFF;
init_timer();

while (1) /* Loop forever */


{ /*forward glowing or left shift of LED*/
for (j = 0x00000100; j < 0x00000800; j <<= 1)
{
IOSET0 =j;
wait (); /* call wait function */
IOCLR0 =j;
}
/*Reverse glowing or right shift of LED*/

for (j = 0x00000800; j > 0x00000100; j >>=1 )


{
IOSET0 = j;
wait (); /* call wait function */
IOCLR0 = j;
}

22
}}

TIME.C:
#include <LPC21XX.H> // LPC21XX Peripheral Registers
#include "Timer.h"
long volatile timeval;
/* Timer Counter 0 Interrupt executes each 10ms @ 60 MHz CPU Clock */
__irq void tc0 (void) {
timeval++;
T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
}
void init_timer (void) {
T0MR0 = 149999; // 10mSec = 150.000-1 counts
T0MCR = 3; // Interrupt and Reset on MR0
T0TCR = 1; // Timer0 Enable
VICVectAddr0 = (unsigned long)tc0; // set interrupt vector in 0
VICVectCntl0 = 0x20 | 4; // use it for Timer 0 Interrupt
VICIntEnable = 0x00000010; // Enable Timer0 Interrupt
}

RESULT:
Thus the program was executed and the result was verified.

23
INTERRUPT
AIM:
To write the embedded c program for interrupt and to execute using ARM
Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

EXTERNAL.C:
#include"LPC214x.h"
#include "extint.h"
#include"irq.c"
#include"type.h"
void delay(void);
int count1 (void);
int n,a;
int count=0x00010000;
unsigned int repeat,i,k ;
int main (void)
{
IODIR0=0xFFFFBF00; //p1
IOPIN0=0x00000000;
while(1)
{
init_VIC();
EINTInit();
for(repeat=0x00000100;repeat<0x00003000;repeat<<=1)
{
IOSET0 = repeat;

24
delay();
IOCLR0 = repeat;
delay();
}
}
}

DWORD EINTInit(void)
{
IOCLR0=0x00000000; //p1
PINSEL0=0x20000000;
PINSEL1=0x00000000;
EXTINT=EINT1;
EXTMODE=EINT1_EDGE;
EXTPOLAR=0;
if ( install_irq( EINT1_INT, (void *)EINT1_Handler ) == FALSE )
{
return (FALSE);
}
return( TRUE );
}
void EINT1_Handler(void) __irq
{
IOCLR1=0x00000000;
EXTINT = EINT1;
EXTMODE=EINT1_EDGE;
EXTPOLAR=0;
{
if ((IOPIN0 & (EINT0_INT)))
{
count1();
delay();
delay();
}
}
VICVectAddr = 0;
}
int count1()
{
PINSEL0=0x05000000;
IOCLR0 =repeat;
IOPIN0=count;
delay();
IOCLR0=count;
count=count+0x00010000;
return count;
}
void delay()
{
for(k=0;k<100;k++)
{

25
for(i=0;i<1000;i++);
}}

IRQ.C:
#include "LPC214x.h" /* LPC23XX Peripheral Registers*/
#include "type.h"
#include "irq.h"
void DefaultVICHandler (void) __irq
{
VICVectAddr = 0; /* Acknowledge Interrupt */
while ( 1 );
}

void init_VIC(void)
{
DWORD i = 0;
DWORD *vect_addr, *vect_cntl; /* initialize VIC*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;/*setallthevectorandvectorcontrolregisterto 0 */
for ( i = 0; i < VIC_SIZE; i++ )
{
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
*vect_addr = 0;
*vect_cntl = 0;
} /* Install the default VIC handler here */
VICDefVectAddr = (DWORD)DefaultVICHandler;
return;
}

DWORD install_irq( DWORD IntNumber, void *HandlerAddr )


{
DWORD i;
DWORD *vect_addr;
DWORD *vect_cntl;

VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */

for ( i = 0; i < VIC_SIZE; i++ )


{
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
if ( *vect_addr == (DWORD)NULL )
{
*vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */
*vect_cntl = (DWORD)(IRQ_SLOT_EN | IntNumber);
break;
}
}
if ( i == VIC_SIZE )

26
{
return( FALSE ); /* fatal error, can't find empty vector slot */
}
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
return( TRUE );
}

DWORD uninstall_irq( DWORD IntNumber )


{
DWORD i;
DWORD *vect_addr;
DWORD *vect_cntl;
VICIntEnClr = 1 << IntNumber;/* Disable Interrupt */
for ( i = 0; i < VIC_SIZE; i++ )
{
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
if ( (*vect_cntl & ~IRQ_SLOT_EN ) == IntNumber )
{
*vect_addr = (DWORD)NULL;/*cleartheVICentry in the VIC table */
*vect_cntl &= ~IRQ_SLOT_EN;/* disable SLOT_EN bit */
break;
}
}
if ( i == VIC_SIZE )
{
return( FALSE );/* fatal error, can't find interrupt number
in vector slot */
}
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
return( TRUE );
}

RESULT:
Thus the program was executed and the result was verified.

27
TRANMISSION FROM PC TO KIT USING SERIAL PORT
AIM:
To write the embedded c program for serial transmission and to execute using
ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

MYSERIAL.C:
#include <stdio.h> /* prototype declarations for I/O functions */
#include <LPC21xx.H> /* LPC21xx definitions */
int main (void)
{ /* execution starts here */
int a,b; /* initialize the serial interface */
while(1)
{
PINSEL0= 0x00000000;
IODIR0 = 0xFFF0FFFF;
IOPIN0 = 0x00000000;
a = IOPIN0;
b = a /65536;
b = b-3072;
PINSEL0= 0x00050000; /* Enable RxD1 and TxD1*/
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit*/
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock*/
U1LCR = 0x03; /* DLAB = 0 */
{
printf ("\n%d\n",b); /* the 'printf' function call */

28
}
} /* Replace the dots (...) with your own code. */
}

RESULT:
Thus the program was executed and the result was verified.

29
PULSE WIDTH MODULATION

AIM:
To write the embedded c program for PWM and to execute using ARM Processor
kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

PROGRAM:

PWM TEST.C:
#include "LPC214x.h" /* LPC21xx definitions */
#include "type.h"
#include "irq.h"
#include "timer.h"
#include "pwm.h"
extern DWORD timer_counter;
extern DWORD match_counter;
int main (void)
{
DWORD cycle = PWM_CYCLE, offset = 0;
init_VIC();
if ( PWM_Init( 0 ) != TRUE )
{
while( 1 ); /* fatal error */
}
PWM_Set( cycle, offset ); //1200, 0
PWM_Start();
while ( 1 )
{

30
if ( match_counter != 0 )
{
match_counter = 0;
if( offset <= PWM_CYCLE )
offset += PWM_OFFSET;
else
offset = 0;
PWM_Set( cycle, offset );
}
}
PWM_Stop() ;
return 0;
}

PWM.C:
#include "LPC214x.H" /* LPC21xx definitions */
#include "type.h"
#include "irq.h"
#include "timer.h"
#include "pwm.h"

DWORD match_counter;
void PWMHandler (void) __irq
{
DWORD regVal;
regVal = PWMIR;
IENABLE; /* handles nested interrupt */
if ( regVal & MR0_INT )
{
match_counter++;
}
PWMIR |= regVal; /* clear interrupt flag on match 0 */
IDISABLE;
VICVectAddr = 0; /* Acknowledge Interrupt */
}
DWORD PWM_Init( DWORD cycle )
{
match_counter = 0;
PINSEL0 = 0x000A800A; /* set GPIOs for all PWMs */
PINSEL1 = 0x00000400;
PWMTCR = TCR_RESET; /* Counter Reset */
PWMPR = 0x00; /* count frequency:Fpclk */
PWMMCR = PWMMR0I | PWMMR0R; /*interrupt on PWMMR0, reset on PWMMR0, reset
TC if PWM0 matches */
PWMMR0 = cycle; /* set PWM cycle */
PWMMR1 = cycle * 5/6;
PWMMR2 = cycle * 2/3;
PWMMR3 = cycle * 1/2;
PWMMR4 = cycle * 1/3;
PWMMR5 = cycle * 1/6; /* all PWM latch enabled */

31
PWMLER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN |
LER6_EN;
if ( install_irq( PWM0_INT, (void *)PWMHandler ) == FALSE )
{
return (FALSE);
}
return (TRUE);
}
void PWM_Set ( DWORD cycle, DWORD offset )
{
PWMMR0 = 100; //cycle; /* set PWM cycle */ //1200
PWMMR1 = 41; //cycle * 5/6 + offset; //1200
PWMMR2 = 78;// cycle * 2/3 + offset; //800
PWMMR3 = 53;// cycle * 1/2 + offset; //800
PWMMR4 = 27;//cycle * 1/3 + offset; //400
PWMMR5 = 65;//cycle * 1/6 + offset; //400
PWMLER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN |
LER6_EN;
return;
}
void PWM_Start( void )
{ /* All single edge, all enable */
PWMPCR = PWMENA1 | PWMENA2 | PWMENA3 | PWMENA4 | PWMENA5 |
PWMENA6;
PWMTCR = TCR_CNT_EN | TCR_PWM_EN;/* counter enable, PWM enable */
return;
}
void PWM_Stop( void )
{
PWMPCR = 0;
PWMTCR = 0x00; /* Stop all PWMs */
return;
}

IRQ.C:
#include "LPC214x.h" /* LPC23XX Peripheral Registers */
#include "type.h"
#include "irq.h"

void DefaultVICHandler (void) __irq


{
VICVectAddr = 0; /* Acknowledge Interrupt */
while ( 1 );
}

void init_VIC(void)
{
DWORD i = 0;
DWORD *vect_addr, *vect_cntl; /* initialize VIC*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;

32
VICIntSelect = 0;/*setallthevectorandvectorcontrol register to 0 */
for ( i = 0; i < VIC_SIZE; i++ )
{
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
*vect_addr = 0;
*vect_cntl = 0;
} /* Install the default VIC handler here */
VICDefVectAddr = (DWORD)DefaultVICHandler;
return;
}

DWORD install_irq( DWORD IntNumber, void *HandlerAddr )


{
DWORD i;
DWORD *vect_addr;
DWORD *vect_cntl;

VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */


for ( i = 0; i < VIC_SIZE; i++ )
{ /* find first un-assigned VIC address for the handler */
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
if ( *vect_addr == (DWORD)NULL )
{
*vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */
*vect_cntl = (DWORD)(IRQ_SLOT_EN | IntNumber);
break;
}
}
if ( i == VIC_SIZE )
{
return( FALSE );/* fatal error, can't find empty vector slot */
}
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
return( TRUE );
}

DWORD uninstall_irq( DWORD IntNumber )


{
DWORD i;
DWORD *vect_addr;
DWORD *vect_cntl;
VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
for ( i = 0; i < VIC_SIZE; i++ )
{ /* find first un-assigned VIC address for the handler */
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4);
if ( (*vect_cntl & ~IRQ_SLOT_EN ) == IntNumber )
{
*vect_addr = (DWORD)NULL;/*clearthe VIC entry in the VIC table*/

33
*vect_cntl &= ~IRQ_SLOT_EN; /* disable SLOT_EN bit */
break;
}
}
if ( i == VIC_SIZE )
{
return( FALSE );/* fatal error, can't find interrupt number
in vector slot */
}
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
return( TRUE );
}

RESULT:
Thus the program was executed and the result was verified.

34
I2C SERIAL EEPROM
AIM:
To write the embedded c program for I2C Serial EEPROM and to execute using
ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.

#include <lpc214x.H>
#include <stdio.h>
#define scl 0x00000100
#define sda 0x00000200
void randomwrite(unsigned int,unsigned int,unsigned int,unsigned int);
void randomread(unsigned int,unsigned int,unsigned int);
void delay(void);
void start(void);
void delay1(void);
void stop(void);
void i2cinit(void);
unsigned int getbyte(void);
void putbyte(unsigned int);
void showdata(unsigned int);
unsigned int Buffer =0;
int j,bt[8];
int main(void)
{
unsigned int z,da;
int result;

35
for (j = 0;j<=7;j++)
{
bt[j] = 0;
}

IODIR0 = 0xFFFFFFFF;
i2cinit();
da= 0xAA;
randomwrite(0xA0,0x01,0x01,da);
stop();
showdata(da);
delay();
delay1();
IOCLR0 = 0xFFFFF000;
delay();
randomread(0xA0,0x00,0x01);
delay();
}
void showdata(unsigned int x)
{
x<<=16;
IOSET0 = x;
}

void i2cinit()
{
int i;
IOSET0 = sda;
delay();
IOCLR0 = scl;
for(i=0;i<3;i++)
{
stop();
}
}
void start()
{
IOSET0 =scl;
delay();
IOSET0 =sda;
delay();
IOCLR0=sda;
delay();
IOCLR0=scl;
delay();

36
IOSET0 =sda;
}
void stop()
{
IOCLR0= sda;
delay();
IOSET0= scl;
delay();
IOSET0=sda;
}
void putbyte(unsigned int BUFFER)
{
int n, bt[8],check=0x00000000;

for ( n = 0;n<=7;n++) //GETTING BITS


{
if((BUFFER&1)==0) bt[0]=0;else bt[0]=1;
if((BUFFER&2)==0) bt[1]=0;else bt[1]=1;
if((BUFFER&4)==0) bt[2]=0;else bt[2]=1;
if((BUFFER&8)==0) bt[3]=0;else bt[3]=1;
if((BUFFER&16)==0) bt[4]=0;else bt[4]=1;
if((BUFFER&32)==0) bt[5]=0;else bt[5]=1;
if((BUFFER&64)==0) bt[6]=0;else bt[6]=1;
if((BUFFER&128)==0) bt[7]=0;else bt[7]=1;
}
for (n = 7;n>=0;n--) //ASSIGNING TO SDA
{
check = 0x00000000|bt[n];
if (check ==0x00000000)
{
IOCLR0 = 0x00000200;
}
if (check ==0x00000001)
{
IOSET0 = 0x00000200;
}
IOSET0=scl;
delay();
IOCLR0=scl;
delay();
}
IOSET0 =sda;
delay();
}
giveack()
{

37
IOCLR0=sda;
delay();
IOSET0 = scl;
delay();
IOCLR0 =scl;
delay();
IOSET0 =sda;
delay();
}
getack()
{
IOSET0 =sda;
delay();
IOSET0=scl;
while((IOPIN0&0x00000200));
IOCLR0 = scl;
delay();
}

void randomwrite(unsigned int device_address,unsigned int start_address,unsigned int


number_bytes,unsigned int da)
{
int x;
device_address = (device_address & 0xFE);
start();
putbyte(device_address);
getack();
putbyte(start_address);
getack();
for(x = 0; x<number_bytes;x++)
{
putbyte(da);
getack();
}
stop();
}

void randomread(unsigned int device_address,unsigned int start_address,unsigned int


number_bytes)
{
int x;
device_address = device_address & (0xFE);
start();
putbyte(device_address);
getack();
putbyte(start_address);

38
getack();
start();
device_address = 0xA1;
//device_address | (0x01);
putbyte(device_address);
getack();
for (x = 0;x<number_bytes;x++)
{
Buffer = getbyte();
giveack();
}
stop();
}
unsigned int getbyte()
{
unsigned int rdata;
int n,test;
IODIR0 =0xFFFFFFFF;
for ( n =7;n>=0;n--)
{
IOSET0 = scl; //1

if((sda & IOPIN0)==0)


{
bt[n] = 0;
}
else
{
bt[n] = 1;
}
delay();
delay1();
IOCLR0 =scl; //0
//delay();
}
rdata = (128*bt[7] + 64*bt[6] + 32*bt[5]+16*bt[4] + 8*bt[3] + 4*bt[2]+2*bt[1] +
1*bt[0]);
rdata<<=16;
IOSET0 = rdata;
IODIR0 =0xFFFFFFFF;
IOSET0 = sda;
delay();
rdata >>=16;
return rdata;
}

39
void delay()
{
int x,y;
for (x=0;x<=100;x++)
{
for(y=0;y<=1000;y++)
{
}
}
}

void delay1()
{
int x,y;

for (x<0;x<=100;x++)
{
for(y=0;y<=5000;y++)
{
}
}
}

RESULT:
Thus the program was executed and the result was verified.

40
I2C 7 SEGMENT

AIM:
To write the embedded c program for I2C and to execute using ARM Processor kit

REQIREMENTS:
Software used: keil software uvision-3
Hardware used: ARM kit, 15 pin FRC cable

PROCEDURE:
Step1: open keil uvision4 short cut in the desktop.
Step2: open project - > New project, save the project with no extension.
Step3: click NXP then disclose + symbol, then select LPC2148, then click ok.
Step4: next it will ask for startup code click no.
Step5: now the project is created, in project window disclose + of target1, the source
group will open.
Step6: open a new file and save the file with extension .c.
Step7: write the keil c program and save the file.
Step8: right click the source group, click the add files to the group source group , add
the saved c file program.
Step9: right click target1, click the option for target1, click output and click the create hex
file.
Step10: click flash magic short cut in desktop.
Step11: load elevator program and then implement.
#include <lpc214x.H>
#include <stdio.h>
#define scl 0x00000100
#define sda 0x00000200
//sbit control=P3^2;
void randomwrite(unsigned int,unsigned int,unsigned int,unsigned int);
void randomread(unsigned int,unsigned int,unsigned int);
void delay(void);
void start();
void delay1();
void stop();
void i2cinit();
void putbyte(unsigned int);
unsigned int mydata[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int main(void)
{
unsigned int z,da;
IODIR0 = 0xFFFFFFFF;
z=9;
i2cinit();
da = mydata[z];
randomwrite(0x40,0x00,0x01,da);
delay1();
}

41
void i2cinit()
{
IOSET0 = sda;
delay();
IOCLR0 = scl;
{
stop();
}
}
void start()
{
IOSET0 =scl;
delay();
IOSET0 =sda;
delay();
IOCLR0=sda;
delay();
IOCLR0=scl;
delay();
IOSET0 =sda;
}
void stop()
{
IOCLR0= sda;
delay();
IOSET0= scl;
delay();
IOSET0=sda;
}
void putbyte(unsigned int BUFFER)
{
int n, bt[8],check=0x00000000;

for ( n = 0;n<=7;n++)
{
if((BUFFER&1)==0) bt[0]=0;else bt[0]=1;
if((BUFFER&2)==0) bt[1]=0;else bt[1]=1;
if((BUFFER&4)==0) bt[2]=0;else bt[2]=1;
if((BUFFER&8)==0) bt[3]=0;else bt[3]=1;
if((BUFFER&16)==0) bt[4]=0;else bt[4]=1;
if((BUFFER&32)==0) bt[5]=0;else bt[5]=1;
if((BUFFER&64)==0) bt[6]=0;else bt[6]=1;
if((BUFFER&128)==0) bt[7]=0;else bt[7]=1;
}

for (n = 7;n>=0;n--)
{
check = 0x00000000|bt[n];
if (check ==0x00000000)

42
{
IOCLR0 = 0x00000200;
}
if (check ==0x00000001)
{
IOSET0 = 0x00000200;
}
IOSET0=scl;
delay();
IOCLR0=scl;
delay();
}
IOSET0 =sda;
delay();
}

giveack()
{
IOCLR0=sda;
delay();
IOSET0 = scl;
delay();
IOCLR0 =scl;
delay();
IOSET0 =sda;
delay();
}
getack()
{
IOSET0 =sda;
delay();
IOSET0=scl;
while(IOPIN0&0x00000200);
IOCLR0 = scl;
delay();
}

void randomwrite(unsigned int device_address,unsigned int start_address,unsigned int


number_bytes,unsigned int da)
{
int x;
device_address = (device_address & 0xFE);
start();
putbyte(device_address);
getack();
putbyte(start_address);
getack();
for(x = 0; x<=number_bytes;x++)
{
putbyte(da);

43
getack();
}
stop();
}

void delay()
{
int x,y;

for (x=0;x<=1;x++)
{
for(y=0;y<=1;y++)
{
}
}
}
void delay1()
{
int x,y;

for (x<0;x<=1;x++)
{
for(y=0;y<=5;y++)
{
}}}

RESULT:
Thus the program was executed and the result was verified.

44

Você também pode gostar