Ec6711 Emb Lab PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 92

SHRI ANDAL ALAGAR COLLEGE OF

ENGINEERING
An ISO 9001:2000 Institution

No.6, G.S.T. Road, Mamandur-603 111.

EC6711 - EMBEDDED LABORATORY

Prepared by

Ms.M.Prabha, M.E, (PhD). MS.G.R.ASHA GANGA, M.E.


Assistant Professor Assistant Professor
Department of ECE Department of ECE
SAACE
Ex. No: STUDY OF ARM EVALUATION SYSTEM
Date:

AIM:
To study the ARM Evaluation processor LPC2148.

THEORY:
Introduction:
The LPC2141/2/4/6/8 microcontrollers are based on a 32/16 bit ARM7TDMI-S
CPU with real-time emulation and embedded trace support that combines the
microcontroller with embedded high speed flash memory ranging from 32 kB to
512 kB. A 128-bit wide memory interface and unique accelerator architecture
enable 32-bit code execution at the maximum clock rate. For critical code size
applications, the alternative 16-bit Thumb mode reduces code by more than 30 %
with minimal performance penalty.
Due to their tiny size and low power consumption, LPC2141/2/4/6/8 are ideal
for applications where miniaturization is a key requirement, such as access control
and point-of-sale. A blend of serial communications interfaces ranging from a
USB 2.0 Full Speed device, multiple UARTs, SPI, SSP to I2Cs, and on-chip
SRAM of 8 kB up to 40 kB, make these devices very well suited for
communication gateways and protocol converters, soft modems, voice recognition
and low end imaging, providing both large buffer size and high processing power.
Various 32-bit timers, single or dual 10-bit ADC(s), 10-bit DAC, PWM channels
and 45 fast GPIO lines with up to nine edge or level sensitive external interrupt
pins make these microcontrollers particularly suitable for industrial control and
medical systems.

2
SAACE

Block diagram

3
SAACE
Kit overview:

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

8 kB to 40 kB of on-chip static RAM and 32 kB to 512 kB of on-chip flash


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

In-System Programming/In-Application Programming (ISP/IAP) via on-


chip boot loader software. Single flash sector/full chip erase in 400 ms and
programming of 256 bytes in 1 ms.

USB 2.0 Full-speed compliant device controller with 2 kB of endpoint


RAM. In addition, the LPC2146/48 provides 8 kB of on-chip RAM
accessible to USB by DMA.
One or two (LPC2141/42 vs. LPC2144/46/48) 10-bit ADCs provide a total
of 6/14 analog inputs, with conversion times as low as 2.44 s per channel.

Single 10-bit DAC provides variable analog output (LPC2142/44/46/48


only).

4
SAACE

Two 32-bit timers/external event counters (with four capture and four
compare channels each), PWM unit (six outputs) and watchdog.

Low power Real-Time Clock (RTC) with independent power and 32 kHz
clock input. Multiple serial interfaces including two UARTs (16C550), two
Fast I2C-bus (400 Kbit/s), SPI and SSP with buffering and variable data
length capabilities.

Vectored Interrupt Controller (VIC) with configurable priorities and vector


addresses.

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


package.

Up to 21 external interrupt pins available.

60MHz maximum CPU clock available from programmable on-chip PLL


with settling time of 100s.

On-chip integrated oscillator operates with an external crystal from 1 MHz


to 25 MHz.

Power saving modes include idle and Power-down.

Individual enable/disable of peripheral functions as well as peripheral clock


scaling for additional power optimization.

Processor wake-up from Power-down mode via external interrupt or BOD.

Single power supply chip with POR and BOD circuits:

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


tolerant I/O pads.

5
SAACE
Pin diagram of LPC2148:

Applications:
Industrial control
Medical systems
Access control
Point-of-sale
Communication gateway
Embedded soft modem
General purpose applications

RESULT:
Thus the study of ARM Evaluation is completed.

6
SAACE
Ex. No: ADC INTERFACING
Date:

AIM:
To interface convert Analog signal in digital form using ADC in ARM
processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
Basic clocking for the A/D converters is provided by the VPB clock. A
programmable divider is included in each converter, to scale this clock to the 4.5
MHz (max) clock needed by the successive approximation process. A fully
accurate conversion requires 11 of these clocks.
In ARM2148 Kit, for testing on-board analog input, port lines P0.29 and
P0.30 connected through 10K potentiometer selected by jumpers. The signals
P0.29 and P0.30 can be used as general purpose pins if the analog inputs are not
used and in this case the analog voltages can easily be removed by removing the
two jumpers on JP4 and JP5.

PIN DETAILS: connect J27 & J28 using 10 pin FRC cable.

PIN
PORT
CONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46
(ADC) AD0.1 P0.28 uC PIN -> 13

7
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

8
SAACE
PROGRAM:
INTERFACING ADC

#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000

#define r1 (1<<24)
#define r2 (1<<25)
#define r3 (1<<26)
#define r4 (1<<27)

#define c1 (1<<28)
#define c2 (1<<29)
#define c3 (1<<30)
#define c4 (1<<31)

void lcd_cmd (unsigned char);


void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void ADC_Init(void);
unsigned int Read_ADC(void);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" ADC Example 1 "};
unsigned char msg1[]= {"~~~~~~~~~~~~~~~~"};

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++);
} }

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS;

9
SAACE
IOCLR0 |= RW;
LCD4_Convert(data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN; }

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}

void ADC_Init()
{
PINSEL1 |= 0x01000000;
AD0CR = 0x00200F02;
}
unsigned int Read_ADC()
{
unsigned int adc_data;
AD0CR |= 0x01000000;
//Delay(100000);
do
{
adc_data = AD0DR1;
}while(!(adc_data & 0x80000000));
//Wait untill the DONE bits Sets
AD0CR &= ~0x01000000;
//AD0CR &= 0xFE000000;

10
SAACE
adc_data = adc_data>>6;
adc_data = adc_data & 0x3FF;
return (adc_data);
}

int main(void)
{

unsigned int adc_data;


unsigned char ones,tens,hundreds,thousands;

PINSEL1 = 0;
IODIR0 = 0xFF << 16;
PINSEL0 = 0x00000000;
IODIR0 = 0Xffffffff;
PINSEL1 = 0x00000000;
IODIR1 = 0xf0000000;

lcd_initialize();
lcd_display();

ADC_Init();
delay(1000);

while(1)
{
lcd_data(keypad());

adc_data = Read_ADC();
ones = adc_data % 10;
adc_data = adc_data / 10;
tens = adc_data % 10;
adc_data = adc_data / 10;
hundreds = adc_data % 10;
adc_data = adc_data / 10;
thousands = adc_data % 10;

lcd_cmd(0xC0);
lcd_data(thousands | 0x30);
lcd_data(hundreds | 0x30);
lcd_data(tens | 0x30);
lcd_data(ones | 0x30);
delay(100000);
delay(100000);
delay(100000);
delay(100000);

}
}

11
SAACE
OUTPUT:

RESULT:
Thus the Conversion of Analog to Digital is performed and verified with
ARM processor successfully.

12
SAACE
Ex. No: DAC INTERFACING
Date:

AIM:
To interface and convert Digital to Analog using DAC in ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:

The DAC enables the LPC2148 to generate a variable analog output. The
maximum DAC output voltage is the VREF voltage.

PIN DETAILS:
VIN (+) - P0.25
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

13
SAACE
FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

14
SAACE
PROGRAM:
INTERFACING DAC
#include <LPC214x.h>
#define DAC_BIAS 0
void DacInit( void );
void DacOut( unsigned int val );
void _Delay45Us(void);

void delay(void)
{
int i;
for(i=0;i<100;i++)
_Delay45Us();
}

int main (void)


{
unsigned int i = 0;
DacInit();
IODIR1|=0xFFFF0000;
IOPIN1&=~(0xFFFF0000);
while (1)
{
for(i=0;i<1023;i++)
{
DacOut(i);
i=i+15;
}
for(;i>0;i--)
{
DacOut(i);
i=i-15;
}
}
}

void DacInit( void )


{
PINSEL1 |= 0x00080000;
}

void DacOut( unsigned int val )


{
DACR = (val << 6) | (DAC_BIAS<<16);
}

void _Delay45Us(void)
{
volatile unsigned int k;
for(k=0;k<409;k++)
{
__asm
{
nop;
}
}
}

15
SAACE
OUTPUT:

RESULT:
Thus the Conversion of Digital to Analog is performed and verified with
ARM processor successfully.

16
SAACE
Ex. No: LED INTERFACING
Date:

AIM:
To interface LED with ARM processor.
APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
DIP switch is a digital input section. This is used to give digital external input to
microcontroller.

A DIP switch is a manual electric switch that is packaged with others in a group in
a standard dual-in-line package (DIP). The term may refer to each individual
switch, or to the unit as a whole. This type of switch is designed to be used on a
printed circuit board along with other electronic components and is commonly
used to customize the behaviour of an electronic device for specific situations.DIP
switches are an alternative to jumper blocks. Their main advantages are that they
are quicker to change and there are no parts to lose.

PIN DETAILS: Connect J15 & J16 using 10 pin FRC cable.

SWITCH PORT PIN CONFIGURATION


Sw 1 P1.24 uC PIN -> 32
Sw 2 P1.25 uC PIN -> 28
Sw 3 P1.26 uC PIN -> 24
Sw 4 P1.27 uC PIN -> 64
Sw 5 P1.28 uC PIN -> 60
Sw 6 P1.29 uC PIN -> 56
Sw 7 P1.30 uC PIN -> 52
Sw 8 P1.31 uC PIN -> 20

17
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

18
SAACE
PROGRAM:
INTERFACING LED

#include<LPC214x.h>

void ARM_INIT()
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;

IO0DIR = 0X00000000;
IO1DIR = 0X00FF0000;
}

static void delay(void )


{
volatile int i,j;
for (i=0;i<0x3F;i++)
for (j=0;j<500;j++);
}

int main(void)
{
ARM_INIT();
while(1)
{

IO1CLR = 0X00FF0000;
IO1SET = (IO1PIN & 0xff000000) >> 0x08;
delay();
}
}

19
SAACE
OUTPUT:

RESULT:
Thus the interfacing of LED with ARM processor is done successfully.

20
SAACE
Ex. No: PWM INTERFACING
Date:

AIM:
To interface the Pulse Width Modulation with ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
Single edge controlled PWM outputs all go high at the beginning of each
cycle unless the output is a constant low. Double edge controlled PWM outputs
can have either edge occur at any position within a cycle. This allows for both
positive going and negative going pulses.

PIN DETAILS: Connect J17 & J19 using 10 pin FRC cable.

PORT PIN CONFIGURATION


PWM4_LED P0.8 uC PIN ->33
PWM6_LED P0.9 uC PIN ->34

PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.

21
SAACE
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

22
SAACE
PROGRAM:
INTERFACING PWM

#include <lpc214x.h>

#define PLOCK 0x00000400


void initPWM(void);
void initClocks(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);
int main(void)
{
initClocks();
initPWM();
while(1)
{ ; }
}

void initPWM(void)
{
PINSEL0 = ( 1<< 17) | ( 1<< 19);
PWMPR = 0x02;
PWMMCR = (1<<1);
PWMMR0 = 2000000;
PWMMR4 = 500000;
PWMMR6 = 1500000;
PWMLER = 0x51;
PWMPCR = 0x5000;
PWMTCR = (1<<1);
PWMTCR = (1<<0) | (1<<3);
}
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;
}

23
SAACE
OUTPUT:

RESULT:
Thus the Pulse Width Modulation is performed and verified with ARM
processor successfully.

24
SAACE
Ex. No: RTC INTERFACING
Date:

AIM:
To interface Real Time Clock with ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
Real-time clock (RTC) counts seconds, minutes, hours, day of the week, date
of the month, month, and year with leap-year. Full binary-coded decimal (BCD)
clock/calendar and 56-byte, battery-backed, nonvolatile (NV) RAM for data
storage. Two-wire serial interface are SDA, SCL. The clock operates in either the
24-hour or 12-hour format with AM/PM indicator.

PIN DETAILS: Connect J6 & J10 using 10 pin FRC cable.

PORT PIN CONFIGURATION


LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46

PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.

25
SAACE
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

26
SAACE
PROGRAM:
INTERFACING REAL TIME CLOCK

#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000

#define SS 0
#define MN 8
#define HH 16
#define DD 15
#define MM 8
#define YY 2014

void lcd_cmd (unsigned char);


void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);

void delay_ms(unsigned int count);


void delay_us(unsigned int count);

void init_RTC(void);
void set_RTC(void);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" Real time clock"};
unsigned char msg1[]= {" "};

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++) for(j=0;j<12000;j++);
}

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS; //0x1000; //RS
IOCLR0 |= RW; //0x2000; //RW
LCD4_Convert(data);

27
SAACE
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}

void init_RTC(void)
{
PCONP |= 0x00000200;
CCR = 0x00000002;
CIIR = 0x00000000;
AMR = 0x000000FF;
ILR = 0x00000003;
CCR = 0x00000011;
}
void set_RTC(void)
{
CCR = 0x00000002;
YEAR = YY;
MONTH = MM;
DOM = DD;
HOUR = HH;
MIN = MN;
SEC = SS;

28
SAACE
CCR = 0x00000011;
}

void number_lcd(int num)


{
lcd_data( (num / 10) + 0x30);
lcd_data( (num % 10) + 0x30);
}

void delay_us(unsigned int count)


{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<10;k++)
{
__asm
{
nop;
}
}
}
}
void delay_ms(unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop;
nop;
}
}
}
}

int main(void)
{
init_RTC();
PINSEL1 = 0;
IODIR0 = 0xFF << 16;
lcd_initialize();
lcd_display();
while(1)
{

// cmd_lcd(0xc4);
lcd_cmd(0xc4);

number_lcd(HOUR);
lcd_data(':');
number_lcd(MIN);
lcd_data(':');
number_lcd(SEC);
delay_ms(500);

29
SAACE
OUTPUT:

RESULT:
Thus the interfacing of Real Time Clock with ARM processor is performed
and displayed.

30
SAACE
Ex. No: SERIAL PORT
Date:

AIM:
To interface Serial port with ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Serial cable
7. Power card
THEORY:

PIN DETAILS: USART 0 interface pin details.

PORT PIN CONFIGURATION


RxD0 P0.1 uC PIN ->21
TxD0 P0.0 uC PIN ->19

31
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

32
SAACE
PROGRAM:
INTERFACING SERIAL PORT

#include <LPC21xx.H>
#define CR 0x0D
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;

int main(void)
{
char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";
VPBDIV = 0x02;
init_serial();
while(1)
{
while (*Ptr)
{
putchar(*Ptr++);
}
putchar(getchar());
}
}

void init_serial (void)


{
PINSEL0 = 0x00000005;
U0LCR = 0x00000083;
U0DLL = 0x000000C3;
U0LCR = 0x00000003;
}

int putchar (int ch)


{ if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR;
} while (!(U0LSR & 0x20));
return (U0THR = ch);
}

int getchar (void)


{
while (!(U0LSR & 0x01));
return (U0RBR);
}

33
SAACE
OUTPUT:

RESULT:
Thus the interfacing of serial port with ARM processor is performed and
displayed.

34
SAACE
Ex. No: KEYBOARD INTERFACING
Date:

AIM:
To interface keyboard with ARM processor
APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
Keypad is a set of buttons arranged in a block or "pad" which usually bear
digits, symbols and usually a complete set of alphabetical letters. If it mostly
contains numbers then it can also be called a numeric keypad. Here we are using
4 X 4 matrix keypad.

1`

35
SAACE
PIN DETAILS: connect J22 & J23 using 10 pin FRC cable.

PORT PINCONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uCPIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46
ROW1 P1.24 uC PIN -> 32
ROW1 P1.25 uC PIN -> 26
ROW1 P1.26 uC PIN -> 24
ROW1 P1.27 uC PIN -> 64
COLOUM1 P1.28 uC PIN -> 60
COLOUM2 P1.29 uC PIN -> 56
COLOUM3 P1.30 uC PIN -> 52
COLOUM4 P1.31 uC PIN -> 20

PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.

36
SAACE
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

37
SAACE
PROGRAM:
INTERFACING KEYBOARD

#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000

#define r1 (1<<24)
#define r2 (1<<25)
#define r3 (1<<26)
#define r4 (1<<27)

#define c1 (1<<28)
#define c2 (1<<29)
#define c3 (1<<30)
#define c4 (1<<31)

void lcd_cmd (unsigned char);


void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
unsigned char keypad (void);
void keypad_delay(void);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" ANY KEY PRESS "};
unsigned char msg1[]= {"~~~~~~~~~~~~~~~~"};

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++) for(j=0;j<12000;j++);
}

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS;
IOCLR0 |= RW;

38
SAACE
LCD4_Convert(data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}

int main(void)
{
PINSEL1 = 0;
IODIR0 = 0xFF << 16;

PINSEL0 = 0x00000000;
IODIR0 = 0Xffffffff;
PINSEL1 = 0x00000000;
IODIR1 = 0xf0000000;

lcd_initialize();
lcd_display();
while(1)
{
lcd_data(keypad());
}

39
SAACE
}

unsigned char keypad (void)


{
unsigned char key;
IOCLR1|=(c1|c2|c3|c4|r1|r2|r3|r4);
while(1)
{
IOCLR1|=c1;
IOSET1|=(c2|c3|c4); // first column = 1

if((IOPIN1&r1)==0)
{
key='3'; // key='7';
keypad_delay();
return key;
}
else if((IOPIN1&r2)==0)
{
key='7'; // key='8';
keypad_delay();
return key;
}
else if((IOPIN1&r3)==0)
{
key='B'; // key='9';
keypad_delay();
return key;
}
else if((IOPIN1&r4)==0)
{
key='F'; // key='/';
keypad_delay();
return key;
}

IOCLR1|=c2;
IOSET1|=(c1|c3|c4); //second column = 2

if((IOPIN1&r1)==0)
{
key='2'; //key='4';
keypad_delay();
return key;
}
else if((IOPIN1&r2)==0)
{
key='6'; // key='5';
keypad_delay();
return key;
}
else if((IOPIN1&r3)==0)
{
key='A'; //key='6';
keypad_delay();
return key;
}
else if((IOPIN1&r4)==0)
{
key='E'; //key='*';
keypad_delay();
return key;

40
SAACE
}

IOCLR1|=c3;
IOSET1|=(c1|c2|c4); //third column = 3

if((IOPIN1&r1)==0)
{
key='1';
keypad_delay();
return key;
}
else if((IOPIN1&r2)==0)
{
key='5'; // key='2';
keypad_delay();
return key;
}
else if((IOPIN1&r3)==0)
{
key='9'; // key='3';
keypad_delay();
return key;
}
else if((IOPIN1&r4)==0)
{
key='D'; // key='-';
keypad_delay();
return key;
}

IOCLR1 |= c4;
IOSET1|=(c1|c2|c3); //forth column = 4

if((IOPIN1&r1)==0)
{
lcd_cmd(0x01);
keypad_delay();

}
else if((IOPIN1&r2)==0)
{
key='4'; // key='0';
keypad_delay();
return key;
}
else if((IOPIN1&r3)==0)
{
key='8'; //key='=';
keypad_delay();
return key;
}
else if((IOPIN1&r4)==0)
{
key='C'; //key='+';
keypad_delay();
return key;
}
}
}

void keypad_delay(void)
{

41
SAACE
unsigned int t1,t2;
for(t1=0;t1<300;t1++)
for(t2=0;t2<1275;t2++);
}

OUTPUT:

RESULT:
Thus the keyboard interfacing with ARM processor is done and pressed key
is verified successfully.

42
SAACE

Ex. No: LCD INTERFACING


Date:

AIM:

To interface LCD with ARM processor and display the text.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:
The ARM214X Kit, have 2x16 characters LCD. 7 pins are needed to create 4-bit
interface; 4 data bits (P0.19 P0.22, D4-D7), address bit (RS-P0.16), read/write
bit (R/W-P0.17) and control signal (E-P0.18). The LCD controller is a standard
KS0070B or equivalent, which is a very well-known interface for smaller character
based LCDs. Figure below illustrate the LCD part of the design and which pins are
used for the interface. The LCD is powered from the 5V power supply enabled by
switch SW28.

PIN DETAILS: connect J6 & J10 using 10 pin FRC cable.

PORT PINCONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46

43
SAACE

PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (blinking led)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

44
SAACE
PROGRAM:
INTERFACING LCD

#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000

void lcd_cmd (unsigned char);


void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};
unsigned char msg[] = {" LPC 2148 SMART "};
unsigned char msg1[]= {" EMBEDDED LAB "};

int main(void)
{
PINSEL1 = 0;
IODIR0 = 0xFF << 16;
lcd_initialize();
lcd_display();
while(1);
}

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++) for(j=0;j<12000;j++);
}

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;

45
SAACE
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}

46
SAACE
OUTPUT:
=

RESULT:
Thus the interfacing LCD display with ARM processor is done and text is
displayed in LCD.

47
SAACE
Ex. No: EEPROM INTERFACING
Date:

AIM:
To write and read data from EEPROM interfaced with ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:

JUMPER DETAILS: connect J6 & J10 using 10 pin FRC cable.

PORT PIN
CONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46

48
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (blinking led)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

49
SAACE
PROGRAM:
INTERFACING EPROM

#include <lpc214x.h>

#define AT24c02_ADDr 0xA0


#define AT24c04_ADDr 0xAC

void lcd_initialize (void);


void lcd_out(unsigned char c);
void Lcd_Msg_Display(char row,char col,char size, char *ptr);
void Lcd_Digit_Display(char row,char size, int value);
void DisplayLCD2Digit(char LineNumber,char CharPosition,char Data);
void delay(unsigned int n);

void irq_iic(void)__irq;;
void InitializeIIC(void);
void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned
char count,unsigned char *data);
void WriteByte(int addr,unsigned char *data);
void ReadByte(int addr,unsigned char *data);
void delay2(void);
unsigned char *I2CData, I2Counter, I2CAddress, MemAddress, lock;

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++);
} }

void lcd_initialize()
{

lcd pin selection

PINSEL0 = 0x00000000;
IODIR0 = 0Xffffffff;
PINSEL1 = 0x00000000;
IODIR1 = 0xf0000000;

IOCLR0 |= 0x00010000;
IOCLR0 |= 0x00020000;
delay(10);
lcd_out(0x03);
delay(10);
lcd_out(0x03);
delay(5);
lcd_out(0x03);
lcd_out(0x02);
lcd_out(0x28);
lcd_out(0x08);
lcd_out(0x01);
lcd_out(0x06);

50
SAACE
lcd_out(0x0f);
lcd_out(0x0c);
}

void lcd_out(unsigned char c)


{
delay(1); // check delay y/n
if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;

delay(1);
IOSET0 |= 0x00040000;
delay(1);
IOCLR0 |= 0x00040000;

if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;

IOSET0 |= 0x00040000;
delay(1);
IOCLR0 |= 0x00040000;
}
cursor_position(char offset)
{

IOCLR0 |= 0x00010000;
if (offset >=16)
lcd_out((0x40+offset-16) | 0x80);
else lcd_out(offset | 0x80);
IOSET0 |= 0x00010000;
}

void Lcd_Msg_Display(char row,char col,char size, char *ptr)


{
unsigned char i;

cursor_position(row);

for (i=0;i<size;i++)
{
if ((row+i) == size)
{
IOCLR0 |= 0x00010000;
lcd_out(0x40 | 0x80);
IOSET0 |= 0x00010000;
}
lcd_out(*(ptr+i));
}
}

void Lcd_Digit_Display(char row,char size, int value)


{
unsigned char z = '0';
unsigned char i;
unsigned char s[16];

for(i=0;i<size;i++)
{

51
SAACE
s[size-1-i] = (value %10)+ z;
value = value /10;
}
cursor_position(row);
for(i=0;i<size;i++)
{
lcd_out (s[i]);
}
}

int main(void)
{
unsigned char Data=0, Address;
lcd_initialize();
InitializeIIC();

Lcd_Msg_Display(0,0,16, " EEPROM I2C-ch1 ");


Lcd_Msg_Display(16,0,16,"ADr: Data: ");

Data = 111;
Address = 100;
WriteByte(Address,&Data);
ReadByte(Address,&Data);

Lcd_Digit_Display(20,3,Address);
Lcd_Digit_Display(29,3,Data);

delay(200);
while(1)
{ ; }

void InitializeIIC(void)
{
lock = 0;
VICVectCntl0 = 0x00000029;
VICVectCntl0 = 0x20 | 19;
VICVectAddr0 = (unsigned long) irq_iic;
VICIntEnable = 0x00080000;
PINSEL0 |= 0x50;
PINSEL0 |= 0x30C00000;
I2C1SCLH = 0x104;
I2C1SCLL = 0x104;
}

void WriteByte(int addr,unsigned char *data)


{
I2CTransferByte(0xAc,addr,1,&data[0]);
I2CTransferByte(AT24c02_ADDr,addr,1,&data[0]);
0xA0 -> means 24c02

while(lock==1);
delay2();
}

void ReadByte(int addr,unsigned char *data)


{
I2CTransferByte(0xAc,addr,0,&data[0]);
I2CTransferByte(0xAd,addr,1,&data[0]);

52
SAACE
I2CTransferByte(AT24c02_ADDr,addr,0,&data[0]);
I2CTransferByte((AT24c02_ADDr+1),addr,1,&data[0]);
while(lock==1);
}

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned


char count,unsigned char *data )
{
while(lock == 1)
{ ; }
lock = 1;

I2CAddress = I2CAddr;
I2CData = data;
I2Counter = count;
MemAddress = MemAddr;
I2C1CONCLR = 0x000000FF;
I2C1CONSET = 0x00000040;
I2C1CONSET = 0x00000020;
}

void irq_iic(void)__irq //Iic_Srv(void)


{
switch (I2C1STAT)
{

case (0x08):
I2C1CONCLR = 0x20;
I2C1DAT = I2CAddress;
break;

case (0x18):
I2C1DAT = MemAddress;
break;

case (0x20):
I2C1DAT = I2CAddress;
break;

case (0x28):
if(I2Counter > 0)
{
I2Counter--;
I2C1DAT = *I2CData;
I2CData++;
}
else
{
I2C1CONSET = 0x10;
lock = 0;
}
break;

case (0x30) :
I2C1DAT = *I2CData;
break;

case (0x40) :
I2C1CONSET = 0x04;
break;

case (0x48) :

53
SAACE
I2C1CONSET = 0x20;
break;

case (0x50) :
if(--I2Counter>0)
{
*I2CData = I2C1DAT;
I2CData++;
}
else
{
*I2CData = I2C1DAT;
I2C1CONSET = 0x10;
lock = 0;
}
break;
case (0x58):
I2C1CONSET = 0x20;
break;

default :
break;
}

I2C1CONCLR = 0x08;
VICVectAddr = 0x00000000;
}

void delay2(void)
{
long int i; i=0xffff;
while(i)
{ i--; }
}

54
SAACE
OUTPUT:

RESULT:
Thus the writing and reading the data from EEPROM with ARM
processor is performed.

55
SAACE
Ex. No: INTERRUPT INTERFACING
Date:

AIM:
To implement interrupt in ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:
The Vectored Interrupt Controller (VIC) takes 32 interrupt request inputs
and programmable assigns them into 3categories, FIQ, vectored IRQ, and non-
vectored IRQ. The programmable assignment scheme means that priorities of
interrupts from the various peripherals can be dynamically assigned and adjusted.

PIN DETAILS: connect J35 & J36 using 10 pin FRC cable.

PORT PIN CONFIGURATION


LED EINT1 P0.25 uC PIN ->28
LED EINT2 P0.24 uC PIN ->32

External switch

PORT PIN CONFIGURATION


SW EINT1 P0.3 uC PIN ->26
SW EINT2 P0.7 uC PIN ->31

56
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (blinking led)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

57
SAACE
PROGRAM:
INTERFACING INTERRUPT

#include <LPC21xx.H>
#include "debug_tools.h"

void EXTINTVectoredIRQ (void)__irq;

int main (void)


{

IODIR0 = 0x00000C00;
IODIR1 = 0x03000000;
IOSET1 = 0x03000000;
PINSEL0 = 0x000000C0;

/*NOTE: VICVectCntl0
----------------------------------------------------------------------
VICVectCntl0 = 0x0000002F;

/*Note: Vector Address registers 0-15 (VICVectAddr0-15 - 0xFFFF F100-13C)


----------------------------------------------------------------------
VICVectAddr0 = (unsigned)EXTINTVectoredIRQ;

/*Note:
Interrupt Enable register (VICIntEnable - 0xFFFF F010)
----------------------------------------------------------------------

VICIntEnable = 0x00008000;

while(1)
{
IOSET1 = 0x01000000;
IOCLR1 |= 0x02000000;
}
}

void EXTINTVectoredIRQ (void) __irq


{

/*NOTE:
EINT1
-----------------------------------------------------------------

IOSET1 = 0x02000000;
IOCLR1 |= 0x01000000;

EXTINT = 0x00000002;
VICVectAddr = 0x00000000;
}

58
SAACE
OUTPUT:

RESULT:
Thus the implementation of interrupt is performed in ARM
processor.

59
SAACE
Ex. No: MAILBOX
Date:

AIM:
To implement the Mailbox in ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Serial cable
7. Power card

PIN DETAILS: USART 0 interface pin details.

PORT PIN CONFIGURATION


RxD0 P0.1 uC PIN ->21
TxD0 P0.0 uC PIN ->19

PROCEDURE:
KEIL:
Double click on Keil Vision4 icon.
Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

60
SAACE

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

61
SAACE
PROGRAM:
MAILBOX

#include <RTL.h>
#include <LPC21xx.H>
#include <stdio.h>

OS_TID tsk1;
OS_TID tsk2;

typedef struct
{
float voltage;

float current;

U32 counter;
}

T_MEAS;

os_mbx_declare (MsgBox,16);
_declare_box (mpool,sizeof(T_MEAS),16);

__task void send_task (void);


__task void rec_task (void);

void init_serial ()
{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1DLL = 97;
U1LCR = 0x03;
}

__task void send_task (void)


{
T_MEAS *mptr;

tsk1 = os_tsk_self ();


tsk2 = os_tsk_create (rec_task, 0);
os_mbx_init (MsgBox, sizeof(MsgBox));
os_dly_wait (5);

mptr = _alloc_box (mpool);


mptr->voltage = 223.72;
mptr->current = 17.54;
mptr->counter = 120786;
os_mbx_send (MsgBox, mptr, 0xffff);
IOSET1 = 0x10000;
os_dly_wait (100);

mptr = _alloc_box (mpool);

62
SAACE
mptr->voltage = 227.23;
mptr->current = 12.41;
mptr->counter = 170823;
os_mbx_send (MsgBox, mptr, 0xffff);
os_tsk_pass ();
IOSET1 = 0x20000;
os_dly_wait (100);

mptr = _alloc_box (mpool);


mptr->voltage = 229.44;
mptr->current = 11.89;
mptr->counter = 237178;
os_mbx_send (MsgBox, mptr, 0xffff);
IOSET1 = 0x40000;
os_dly_wait (100);

os_tsk_delete_self ();
}

__task void rec_task (void)


{
T_MEAS *rptr;

for (;;) {
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff);
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",rptr->counter);
_free_box (mpool, rptr);
}
}

int main (void)


{

IODIR1 = 0xFF0000;
init_serial ();
_init_box (mpool, sizeof(mpool),
sizeof(T_MEAS));
os_sys_init (send_task);
}

RESULT:
Thus the implementation of Mailbox by ARM processor is performed and
verified.

63
SAACE
Ex. No: INTERRUPT PERFORMANCE CHARACTERISTICS OF ARM
Date: AND FPGA

AIM:
To interrupt performance characteristics of ARM and FPGA.

APPARATUS REQUIRED:
1. PC
2. Xilinx ISE9.2i
3. FPGA Kit
4. Compiler-Keilk Vision4
5. Programmer-Flash Magic
6. LPC2148 (ARM7) development board
7. Interfacing cable
8. Power card

THEORY:
The Vectored Interrupt Controller (VIC) takes 32 interrupt request inputs
and programmable assigns them into 3categories, FIQ, vectored IRQ, and non-
vectored IRQ. The programmable assignment scheme means that priorities of
interrupts from the various peripherals can be dynamically assigned and adjusted.

PIN DETAILS: connect J35 & J36 using 10 pin FRC cable.

PORT PIN CONFIGURATION


LED EINT1 P0.25 uC PIN ->28
LED EINT2 P0.24 uC PIN ->32

External switch

PORT PIN CONFIGURATION


SW EINT1 P0.3 uC PIN ->26
SW EINT2 P0.7 uC PIN ->31

64
SAACE

PROCEDURE:
KEIL:
Double click on Keil Vision4 icon.
Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

XILINX:
Open Xilinx ISE and click on file menu for the file project.
Create the new source and click on verilog module.
Assign the input and output entities.
Save the project and click on synthesis and syntax and check for syntax.
Once the design is synthesized successfully, it is ready to implement on
FPGA.
Assign pin package for input and output entities.
In generate programming file click configure device and download the
program on FPGA. If the device is programmed properly, it will say
program succeed else program failed.

65
SAACE
PROGRAM:
INTERRUPT IN ARM
#include <LPC21xx.H>
#include "debug_tools.h"

void EXTINTVectoredIRQ (void)__irq;

int main (void)


{

IODIR0 = 0x00000C00;
IODIR1 = 0x03000000;
IOSET1 = 0x03000000;
PINSEL0 = 0x000000C0;

/*NOTE: VICVectCntl0
----------------------------------------------------------------------
VICVectCntl0 = 0x0000002F;

/*Note: Vector Address registers 0-15 (VICVectAddr0-15 - 0xFFFF F100-13C)


----------------------------------------------------------------------
VICVectAddr0 = (unsigned)EXTINTVectoredIRQ;

/*Note:
Interrupt Enable register (VICIntEnable - 0xFFFF F010)
----------------------------------------------------------------------

VICIntEnable = 0x00008000;

while(1)
{
IOSET1 = 0x01000000;
IOCLR1 |= 0x02000000;
}
}

void EXTINTVectoredIRQ (void) __irq


{

/*NOTE:
EINT1
-----------------------------------------------------------------
IOSET1 = 0x02000000;
IOCLR1 |= 0x01000000;

EXTINT = 0x00000002;
VICVectAddr = 0x00000000;
}

66
SAACE

INTERRUPT IN FPGA

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating


---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity SAS is
Port ( clk : in STD_LOGIC;
int : in STD_LOGIC;
ledout : out STD_LOGIC_VECTOR (3 downto 0);
intout : out STD_LOGIC);
end SAS;

architecture Behavioral of SAS is


signal cnt:std_logic_vector (7 downto 0):=x"00";

begin
process(clk)
begin
if rising_edge(clk)then
cnt<= cnt+1;
if int = '1' then
intout <= '1';
cnt <= cnt;
ledout <=x"0";
else
intout <= '0';
ledout <= cnt (7 downto 4);
end if;
end if;
end process;

end Behavioral;

FPGA

Assign Package Pin:

NET "clk" LOC = "p181";


NET "int" LOC = "p34";
NET "led<0>" LOC = "p58";
NET "led<1>" LOC = "p61";
NET "led<2>" LOC = "p62";
NET "led<3>" LOC = "p63";
NET "intout" LOC = "p64";

67
SAACE

OUTPUT:

RESULT:
Thus the interrupt performance characteristics of ARM and FPGA is
performed and verified.

68
SAACE
Ex. No: FLASHING OF LEDs
Date:

AIM:
To perform the flashing of LEDs with ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:
Light Emitting Diodes (LEDs) are the most commonly used components,
usually for displaying pins digital states. The ARM2148 Kit has 8 nos of Point
LEDs connected with port pins (P1.16 to P1.23) to make port pins high LED will
glow.
LEDs present many advantage over traditional light sources including lower
energy consumption, longer life time, improved robustness, smaller size and faster
switching. However, they are relatively expensive and require more precise current
and heat management then traditional light sources.

PIN DETAILS: connect J8 & J9 using 10 pin FRC cable.

LED PORT PIN CONFIGURATION


LED1 P1.16 uC PIN -> 16
LED2 P1.17 uC PIN -> 12
LED3 P1.18 uC PIN -> 8
LED4 P1.19 uC PIN -> 4
LED5 P1.20 uC PIN -> 48
LED6 P1.21 uC PIN -> 44
LED7 P1.22 uC PIN -> 40
LED8 P1.23 uC PIN -> 36

69
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

70
SAACE
PROGRAM:
FLASHING OF LED

#include<LPC214x.h>

void delay(int x);

int main(void)
{
PINSEL2 = 0x00000000;
IO1DIR = 0x00FF0000;
IOPIN1 = 0x00000000;
while(1)
{
IOPIN1 = 0x00FF0000;
delay(2000);
IOPIN1 = 0x00000000;
delay(2000);
}
}

void delay(int x)
{
unsigned int y,z;
for(y = x;y > 0;y--)
for(z = 0;z < x;z++);
}

71
SAACE
OUTPUT:

RESULT:
Thus the flashing of LEDs by ARM processor is performed and verified.

72
SAACE
Ex. No: STEPPER MOTOR
Date:

AIM:
To perform a speed control of stepper motor using ARM processor.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:
A stepper motor is a brushless, synchronous electric motor that converts
digital pulses into mechanical shaft rotation. Every revolution of the stepper motor
is divided into a discrete number of steps, and the motor must be sent a separate
pulse for each step. Sequence 1100, 0110, 0011, and 1001 sent to stepper from arm
processor to rotate in forward direction, sequence is reversed to rotate motor in
reverse direction.

PIN DETAILS: connect J17 & J19 using 10 pin FRC cable.

PORT PIN
CONFIGURATION
Coil_0 P0.15 uC PIN -> 45
Coil_1 P0.14 uC PIN -> 41
Coil_2 P0.13 uC PIN -> 39
Coil_3 P0.12 uC PIN -> 38

73
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (Stepper motor)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

74
SAACE
PROGRAM:
INTERFACING STEPPER MOTOR

#include"lpc21xx.h"

void delay_ms(unsigned int);


int main()
{
int i;
PINSEL0=0x00000000;
IODIR0=0x0000f000;
while(1)
{

for(i=0;i<12;i++)
{

IOSET0=0x00002000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00004000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00001000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00008000;
delay_ms(100);
IOCLR0=0x0000f000;
}

for(i=0;i<12;i++)
{

IOSET0=0x00008000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00001000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00004000;
delay_ms(100);
IOCLR0=0x0000f000;
IOSET0=0x00002000;
delay_ms(100);
IOCLR0=0x0000f000;
}

void delay_ms(unsigned int count)


{

75
SAACE
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop; nop;
}
}
}
}

76
SAACE
OUTPUT:

RESULT:
Thus the stepper motor speed control is performed by interfacing
stepper with ARM processor.

77
SAACE
Ex. No: TEMPERATURE SENSOR
Date:

AIM:
To interface temperature sensor with ARM processor and display the
temperature value.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card

THEORY:
The LM35 series are precision integrated-circuit temperature sensors, whose
output voltage is linearly proportional to the Celsius (Centigrade) temperature. The
LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin,
as the user is not required to subtract a large constant voltage from its output to
obtain convenient Centigrade scaling.

JUMPER DETAILS: connect J27 & J28 using 10 pin FRC cable

PORT PIN
CONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46
(TEMP) AD0.2 P0.28 uC PIN -> 14

78
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (blinking led)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

79
SAACE
PROGRAM:
INTERFACING TEMPERATURE SENSOR

#include <lpc21xx.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000

#define r1 (1<<24)
#define r2 (1<<25)
#define r3 (1<<26)
#define r4 (1<<27)

#define c1 (1<<28)
#define c2 (1<<29)
#define c3 (1<<30)
#define c4 (1<<31)

void lcd_cmd (unsigned char);


void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void ADC_Init(void);
unsigned int Read_ADC(void);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" LM335 Temp "};
unsigned char msg1[]= {"~~~~~~~~~~~~~~~~"};

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++);
} }

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{

80
SAACE
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);

81
SAACE
}

void ADC_Init()
{

PINSEL1 |= 0x04000000;
AD0CR = 0x00210F04; // bust mode on
// AD0CR = 0x00200F04;

}
unsigned int Read_ADC()
{
unsigned int adc_data;
AD0CR |= 0x01000000;
do
{
adc_data = AD0DR2;

}while(!(adc_data & 0x80000000));

AD0CR &= ~0x01000000;

//AD0CR &= 0xFE000000;


adc_data = adc_data>>6;
adc_data = adc_data & 0x3FF;
return (adc_data);
}

int main(void)
{

unsigned int adc_data;


unsigned char ones,tens,hundreds,thousands;

PINSEL0 = 0x00000000;
PINSEL1 = 0x04000000;
PINSEL2 = 0x00000000;

IODIR0 = 0Xffffffff;
IODIR1 = 0x00000000;

lcd_initialize();
lcd_display();

ADC_Init();
delay(1000);

while(1)
{
// lcd_data(keypad());

82
SAACE

adc_data = Read_ADC();
ones = adc_data % 10;
adc_data = adc_data / 10;
tens = adc_data % 10;
adc_data = adc_data / 10;
hundreds = adc_data % 10;
adc_data = adc_data / 10;
thousands = adc_data % 10;

lcd_cmd(0xC0); //Second Row


lcd_data(thousands | 0x30);
lcd_data(hundreds | 0x30);
lcd_data(tens | 0x30);
lcd_data(ones | 0x30);
delay(100000);
delay(100000);
delay(100000);
delay(100000);

}
}

83
SAACE
OUTPUT:

RESULT:
Thus the interfacing of temperature sensor is done and temperature
changes are observed.

84
SAACE
Ex. No: ZIGBEE PROTOCOL
Date:

AIM:
To implementing zigbee protocol with ARM.

APPARATUS REQUIRED:
1. PC
2. Compiler-Keil Vision4
3. Programmer-Flash Magic
4. LPC2148 (ARM7) development board
5. Interfacing cable
6. Power card
THEORY:

JUMPER DETAILS:

PINOUT: USART0 - LPC2148

RxD1 - P0.9 Uc PIN -> 34


TxD1 - P0.8 Uc PIN -> 33

MAX323 PIN: Max3232 IC

MAX232(PIN12) to Uc PIN ->34((P0.9 - RxD1)

MAX232(PIN11) to Uc PIN ->33((P0.8 - TxD

ZIG BEE PIN

Zigbee(pin2) to RxD1(P0.9 -> Uc PIN -> 34)

Zigbee(pin3) to TxD1(P0.8 -> Uc PIN -> 33)

85
SAACE
PROCEDURE:
KEIL:

Double click on Keil Vision4 icon.


Go to the project & click on new uVision project.
Make the folder on the desktop & save the file in that folder (blinking led)
Select the controller (LPC2148) &click on OK.
Then Go to File & select New File for the New project
Write the program and Save it.
Save the File with extension .c &then click on save.
Click on Target & right click on Source group & click on Add files to source
Group.
Select the file & then Add the file &then close.
Go to Target option.
Window will appear & select the crystal (12 MHz).
After that go to Output option & then Tick on Hex file to generate hex file.
Go to build option.
If there is no error in the program it will show 0 errors & 0 warning.

FLASH MAGIC:

Switch on the power supply of the board.


Connect USB cable to the board using USB connector.
Open Flash Magic software.
Press the programming and reset button in the board.
Select LPC2148 & set the COM port, Baud rate, oscillator Frequency (12
MHz).
Browse the Hex file to send the file to the uC.
Click the Start button in the window.
Release the Programming & Reset button.

86
SAACE
PROGRAM:

ZIGBEE PROTOCOL

Transmitter:
#include <LPC21xx.H>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
#define CR 0x0D

void lcd_cmd (unsigned char);


void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void lcd_data (unsigned char);
void init_serial (void);
int putchar (int ch);
int getchar (void);
void delay(unsigned int n);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" LPC 2148 SMART "};
unsigned char msg1[]= {" Zig Bee TX kit "};
unsigned char CH;

unsigned char send_msg[] = {"1100110011"};


unsigned int i = 0;

int main(void)
{

PINSEL1 = 0;
IODIR0 = 0xFF << 16;
lcd_initialize();

VPBDIV = 0x02; // Divide Pclk by two //imp


init_serial();
lcd_display();

while(1)
{

putchar(send_msg[i]);
i++;
if( i == 48 )
{ i = 0; }

delay(100);

}
}

void init_serial (void)


{

87
SAACE
PINSEL0 = 0x00050000; // Enable RxD0->P0.9->UcPIN->34 and
TxD0->P0.8->UcPIN->33
U1LCR = 0x00000083; // 8 bits, no Parity, 1 Stop bit
U1DLL = 0x000000C3; // 9600 Baud Rate @ 30MHz VPB Clock
U1LCR = 0x00000003;
}

int putchar (int ch)


{ if (ch == '\n')
{
while (!(U1LSR & 0x20));
U1THR = CR;
} while (!(U1LSR & 0x20));
return (U1THR = ch);
}

int getchar (void)


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

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<12000;j++);
}

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS; // 0x1000; //RS
IOCLR0 |= RW; // 0x2000; //RW
LCD4_Convert(data);
}

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19; //IOCLR 0/1
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS; //0x1000; //RS
IOCLR0 |= RW; //0x2000; //RW
LCD4_Convert(data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;

88
SAACE
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}

Receiver:

#include <LPC21xx.H>
#include<string.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
#define CR 0x0D

void init_serial (void);


int putchar (int ch);
int getchar (void);

89
SAACE
void lcd_cmd (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void lcd_data (unsigned char);

unsigned char test;


const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};
unsigned char msg[] = {" LPC 2148 SMART "};
unsigned char msg1[]= {" Zig Bee RX kit "};
unsigned char CH;

int main(void)
{

PINSEL1 = 0;
IODIR0 = 0xFF << 16;
lcd_initialize();
VPBDIV = 0x02;
init_serial();
lcd_display();

while(1)
{
lcd_data (getchar());
}

void init_serial (void)


{
PINSEL0 = 0x00050000;
U1LCR = 0x00000083;
U1DLL = 0x000000C3;
U1LCR = 0x00000003;
}

int getchar (void)


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

void delay(unsigned int n)


{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<12000;j++);
}

void lcd_cmd(unsigned char data)


{
IOCLR0 |= RS;
IOCLR0 |= RW;
LCD4_Convert(data);
}

90
SAACE

void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19;
lcd_cmd(cmd[i]);
delay(15);
}
}

void lcd_data (unsigned char data)


{
IOSET0 |= RS;
IOCLR0 |= RW;
LCD4_Convert (data);
}

void LCD4_Convert(unsigned char c)


{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
}

void lcd_display (void)


{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);

91
SAACE
}

RESULT:
Thus the implementation of zigbee protocol is performed in
ARM processor.

92

You might also like