100% found this document useful (1 vote)
31 views78 pages

Systems Lab Manual

nil

Uploaded by

ronike7802
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
31 views78 pages

Systems Lab Manual

nil

Uploaded by

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

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

ENGINEERING

20EC6401
EMBEDDED AND REAL TIME SYSTEMS

NAME :

REG NO :
YEAR/SEM :
BRANCH :

1
BONAFIDE CERTIFICATE

Name :

Roll No : Year / Sem :

Register No : Degree / Branch:

Subject Code :

Subject Name:

Certified that is a bonafide record of work done by the above student during
the year 20 - 20

Staff In-charge Head of the Department

Submitted for the University Practical Examination held on ________

Internal Examiner External Examiner


2
LIST OF EXPERIMENTS

1. Study of ARM evaluation system


2. Interfacing ADC
3. Interfacing DAC
4. Interfacing LED
5. Interfacing PWM
6. Interfacing real time clock
7. Interfacing serial port
8. Interfacing keyboard
9. Interfacing LCD
10. Interfacing EPROM
11. Interfacing interrupt
12. Flashing of LEDS

3
S.NO DATE EXPERIMENT NAME MARKS SIGNATURE

1
Study of ARM evaluation
system
2
Interfacing ADC

3
Interfacing DAC

4
Interfacing LED
5
Interfacing PWM
6

Interfacing real time clock


7

Interfacing serial port


8

Interfacing keyboard

9
Interfacing LCD

10
Interfacing EPROM

11
Interfacing interrupt

12
Flashing of LEDS

4
Exp.no : 1 STUDY OF ARM EVALUATION SYSTEM
Date:

AIM

To study about the ARM microcontroller board

FEATURES:

 Direction control of individual bits


 Separate control of output set and clear
 All I/O default to inputs after reset

ARM 7 has two port named as Port 0 and Port 1. Each port can be used as I/P
or O/P. Port 0 has 0-31 pins and Port1 has 16-31 pins.
Each Port can be used as GPIO(general purpose I/p and O/p) or As
SFR(Special Function).
1. To use it as GPIO we have to set some register.
PINSEL0 --- it must be 0 to use LSB of port 0 as GPIO(0-15)
PINSEL1---it must be 0 to use MSB of port 0 as GPIO(16-31)
PINSEL2 -- it must be 0 to use Port 1 as GPIO

2. To set the direction of any Port as I/P or O/P we have to SET and
CLR a Register named as IODIR
1 -- set as o/p
0 -- set as i/p
Example:
IO0DIR=0x00000000; // it means port 0 will act as i/p
IO1DIR=0x000000ff; // it means lower 8 bit of port 1 will act as o/p

5
3. Now Lets Put some data on register. For that we are using two register
IOSET and IOCLR. As its name shows it can set and clear particular data
bit.
Example:

IO0SET=0x00000001; //it means 0th bit of Port 0 will be set


IO0CLR=0x00000001; //it means 0th bit of Port 0 will be cleared
Power supply ckt of ARM

ARM requires two power supply one is for CPU(+1.6 to 1.95v) and other is for I/O(+3 to
3.6v)

6
ARM CORTEX LPC1768 BLOCK DIAGRAM

7
RESULT
Thus the experiment was helpful in learning the ARM microcontroller board
evaluation system concept.

8
Exp.No: 2 INTERFACING ADC

Date:

AIM:

To write C code for Interfacing ADC and implement the code with the use of ARM
LPC1768.

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables
4. ADC

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.

9
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

10 Select Output Tab and Click on Create Hex File check box then Click OK
Button
11 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
12 You are now ready to Program your Part.
INTERFACING ADC

#include <LPC17xx.H>
#include "GLCD.h"
#include "Serial.h"
#define FI 1
unsigned int Channel_No;
unsigned char result,Digital;
void Decimal_Adjust(unsigned long Channel_No)
{
switch(Channel_No)
{
case 0xa: SER_PutChar('0');
GLCD_DisplayChar(6,12, FI,'0');
break;
case 0xb: SER_PutChar('1');
GLCD_DisplayChar(6,12, FI,'1');
break
case 0xc: SER_PutChar('2');
GLCD_DisplayChar(6,12, FI,'2');
break;
case 0xd: SER_PutChar('3');
GLCD_DisplayChar(6,12, FI,'3');
break;

case 0xe: SER_PutChar('4');


GLCD_DisplayChar(6,12, FI,'4');
break;
case 0xf: SER_PutChar('5');

10
GLCD_DisplayChar(6,12, FI,'5');
break;
}
}
void Convert(void)
{
unsigned long temp = 0,i = 0,temp1 = 0,res;
temp1 = (Channel_No << 15);
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0xFF807FFF) | temp1;
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0xFF807FFF) | ((1 << 20) | temp1);
temp1 = 0;
LPC_GPIO0->FIOPIN = ((LPC_GPIO0->FIOPIN & 0xFF807FFF) | (Channel_No | temp1));
for(i = 0; i <= 10000; i ++);
temp = LPC_GPIO0->FIOPIN & 0x00800000;
temp >>= 23;
temp = temp & 0x01;
while(temp != 0x1)
{
temp = LPC_GPIO0->FIOPIN & 0x00800000;
temp >>= 23;
temp = temp & 0x01;
}

LPC_GPIO0->FIOPIN = ((LPC_GPIO0->FIOPIN & 0x007F8000) | ((1<<21) | Channel_No));


for(i = 0; i <= 10000; i ++);
temp = LPC_GPIO1->FIOPIN & 0x07F80000;
temp >>= 19
temp1 = 0;
LPC_GPIO0->FIOPIN = ((LPC_GPIO0->FIOPIN & 0x007F8000) | (Channel_No | temp1));
res = LPC_GPIO1->FIOPIN & 0x07F80000;
res >>= 19;
result = (unsigned char)res;
}
void Display(void)
{
unsigned char temp = 0;
SER_SendString("\nChannel Number : ");
GLCD_DisplayString(6, 0, FI,"Channel No=");
if(Channel_No <= 9)
{

11
SER_PutChar('0');
SER_SendHex(Channel_No);
GLCD_DisplayChar(6,11, FI, '0');
GLCD_DisplayChar(6,12, FI, '0');
GLCD_DisplayChar(6,12, FI,Channel_No+ 0x30);

}
else if((Channel_No >= 0x0a) && (Channel_No <= 0x0f))
{
SER_PutChar('1');
GLCD_DisplayChar(6,11, FI, '1');
}
Decimal_Adjust(Channel_No);
SER_SendString("\tDigital Value : ");
GLCD_DisplayString(7, 0, FI,"Digital Value=0x");
temp = (result & 0xf0) >> 4;
SER_SendHex(temp);
temp = (result & 0xf0) >> 4;
if( temp <= 9)
temp = temp + 0x30;
else
temp = temp + 0x37;
GLCD_DisplayChar(7,16, FI,temp);
SER_SendHex(result & 0x0f);
temp=(result & 0x0f);
if( temp <= 9)
temp = temp + 0x30;
else
temp = temp + 0x37;
GLCD_DisplayChar(7,17, FI,temp);
SER_SendString("\n\r");
}
void Disp_Update(void)
{
unsigned char c;
c = SER_GetChar();
if(c == ',')
{
if(Channel_No == 15)
Channel_No = 0;

12
else
Channel_No += 1;
}
else if(c == '-')
{
if(Channel_No == 0)
Channel_No = 15;
else
Channel_No -= 1;
}
}
main()
{
LPC_SC->PCONP |= (1 << 15);
LPC_GPIO0->FIODIR |= 0x007F8000;
LPC_GPIO1->FIODIR &= ~(0x07F80000);
SER_Init();
#ifdef USE_LCD
GLCD_Init();
GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " ESA ");
GLCD_DisplayString(1, 0, FI, " Bangalore ");
GLCD_DisplayString(2, 0, FI, " www.esaindia.com ");
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);
GLCD_DisplayString(5, 0, FI, " 16 Channel ADC");
#endif
Channel_No = 0;
while(1)
{
Convert();
Display();
Disp_Update();
}
}
RESULT:

Thus C code for Interfacing ADC was written and implemented with ARM LPC 1768.

13
Exp.No: 3 INTERFACING DAC

Date:

AIM:

To write C code for Interfacing DAC and implement the code with the use of ARM
LPC1768

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables
4. DAC board

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.

14
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

13 Select Output Tab and Click on Create Hex File check box then Click OK
Button
14 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
15 You are now ready to Program your Part.
INTERFACING DAC

#include <LPC17xx.H>
#include "GLCD.H"
#define FI 1
void delay(void)
{
unsigned char i;
for(i=0;i<100;i++);
}
main()
{
unsigned int i,j;
LPC_SC->PCONP |= (1 << 15);
LPC_GPIO0->FIODIR |= 0x007F8000;
LPC_GPIO1->FIODIR |= 0x07F80000;
#ifdef USE_LCD
GLCD_Init();
GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " ESA ");
GLCD_DisplayString(1, 0, FI, " Bangalore ");
GLCD_DisplayString(2, 0, FI, " www.esaindia.com ");
GLCD_SetBackColor(White)
GLCD_SetTextColor(Blue);
GLCD_DisplayString(5, 0, FI, " Dual DAC ");
GLCD_DisplayString(6, 0, FI, " Square Wave ");
#endif
while(1)

15
{
for(i=0; i<0x0FF; i++)
{
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0xFF807FFF) | 0x007F8000;
LPC_GPIO1->FIOPIN = (LPC_GPIO1->FIOPIN & 0xF807FFFF) | 0x07F80000;
delay();
}
for(j=0xFF; j>0; j--)
{
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0xFF807FFF);
LPC_GPIO1->FIOPIN = (LPC_GPIO1->FIOPIN & 0xF807FFFF);
delay();
}
}}

RESULT:

Thus C code for Interfacing DAC was written and implemented with ARM LPC 1768.

16
Exp.No: 4 INTERFACING LED

Date:

AIM:

To write C code for Interfacing LED and implement the code with the use of ARM
LPC1768.

Hardware Required:
1. ARM cortex (LPC1768)
2 Power supply
3. RS232 cables
4. LED’s

Software required:
1 KEIL IDE
2 Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.

17
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

11 Select Output Tab and Click on Create Hex File check box then Click OK
Button
12 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
13 You are now ready to Program your Part.
CODING

#include "lpc17xx.h"
#include "type.h"
#include "pwm.h"

volatile uint32_t match_counter0, match_counter1;

void PWM1_IRQHandler (void)


{
uint32_t regVal;

regVal = LPC_PWM1->IR;
if ( regVal & MR0_INT )
{
match_counter1++;
}
LPC_PWM1->IR |= regVal; return;
}

uint32_t PWM_Init( uint32_t ChannelNum, uint32_t cycle )


{
if ( ChannelNum == 1 )
{
match_counter1 = 0;
LPC_PINCON->PINSEL4 = 0x00001555;

LPC_PWM1->TCR = TCR_RESET;
LPC_PWM1->PR = 0x00;
LPC_PWM1->MCR = PWMMR0I;

18
LPC_PWM1->MR0 = cycle;
LPC_PWM1->MR1 = cycle * 5/6;
LPC_PWM1->MR2 = cycle * 2/3;
LPC_PWM1->MR3 = cycle * 1/2;
LPC_PWM1->MR4 = cycle * 1/3;
LPC_PWM1->MR5 = cycle * 1/6;
LPC_PWM1->MR6 = 0;

LPC_PWM1->LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN |


LER6_EN;
}
else
{
return ( FALSE );
}

NVIC_EnableIRQ(PWM1_IRQn);
return (TRUE);
}

void PWM_Set( uint32_t ChannelNum, uint32_t cycle, uint32_t offset )


{
if ( ChannelNum == 1 )
{
LPC_PWM1->MR0 = cycle;
LPC_PWM1->MR1 = cycle * 5/6 + offset;
LPC_PWM1->MR2 = cycle * 2/3 + offset;
LPC_PWM1->MR3 = cycle * 1/2 + offset;
LPC_PWM1->MR4 = cycle * 1/3 + offset;
LPC_PWM1->MR5 = cycle * 1/6 + offset;
LPC_PWM1->MR6 = offset;

LPC_PWM1->LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN |


LER6_EN;
}
return;
}

void PWM_Start( uint32_t channelNum )

19
{
if ( channelNum == 1 )
{

LPC_PWM1->PCR = PWMENA1 | PWMENA2 | PWMENA3 | PWMENA4 | PWMENA5 |


PWMENA6;
LPC_PWM1->TCR = TCR_CNT_EN | TCR_PWM_EN; }
return;
}
void PWM_Stop( uint32_t channelNum )
{
if ( channelNum == 1 )
{
LPC_PWM1->PCR = 0;
LPC_PWM1->TCR = 0x00;
}
return;
}

RESULT:

Thus C code for Interfacing LED was written and implemented with
ARM LPC 1768

20
Exp.No: 5 INTERFACING PWM

Date:

AIM:

To write C code for Interfacing PWM and implement the code with the use of ARM
LPC2148.

Hardware Required:
1. ARM cortex (LPC2148)
2 Power supply
3 RS232 cables

Software required:
1 KEIL IDE
2 Embedded c programming
Theory:

The LPC2148 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP

21
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

14 Select Output Tab and Click on Create Hex File check box then Click OK
Button
15 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
16 You are now ready to Program your Part.

CODING

#include <LPC21xx.H>

#include "lcd.h"

#include <stdio.h>

#define sw2 (IOPIN0 & (1<<15))

#define sw3 (IOPIN0 & (1<<30))

char lcd_buff[16];

unsigned long duty, duty1;

unsigned long oldval = 0;

void delay(void);

void init_PWM (void);

void PWM0_isr(void) irq

PWMIR |= 0x00000001; // Clear match0 interrupt

VICVectAddr = 0x00000000;

22
unsigned int k;

int main(void)

PINSEL0 |= 0x00000000;

IODIR0 |= 0x000000FF;

init_PWM();

lcd_init();

lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)

goto_cursor(0x00); // Set Cursor Line-1

lcd_print(" RAANA PWM DEMO "); // Display LCD Line-1

duty = 50;

sprintf(lcd_buff, "W%c = %0003d", (int)0x25, duty);

goto_cursor(0x40); // Set Cursor = Line-2

lcd_print(lcd_buff);

duty1 = duty * 10.2;

PWMMR2 = duty1;

PWMLER = 0xF;

oldval = duty1;

while (1)

if ((sw2) == 0 )

IOCLR0 = 0x00000040;

else

23
{

duty++;

if (duty > 100)

duty = 100;

sprintf(lcd_buff, "W%c = %0003d", 0x25, duty);

goto_cursor(0x40);

// Set Cursor = Line-2

lcd_print(lcd_buff);

duty1 = duty * 10.2;

for (k = 0; k < 30000; k++);

PWMMR2 = duty1;

PWMLER = 0xF;

oldval = duty1;

IOSET0 = 0x00000040;

if ((sw3) == 0)

IOCLR0 = 0x00000020;

else

duty--;

if (duty <= 1)

duty = 1;

sprintf(lcd_buff, "W%c = %0003d",0x25, duty);

24
goto_cursor(0x40);

// Set Cursor = Line-2

lcd_print(lcd_buff);

duty1 = duty * 10.2;

for (k = 0; k < 30000; k++);

PWMMR2 = duty1;

PWMLER = 0xF;

oldval = duty1;

IOSET0 = 0x00000020;

void delay(void) // delay loop

int i;

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

void init_PWM (void) {

VICVectAddr8 = (unsigned)PWM0_isr; //PWM ISR vec.addr

VICVectCntl8 = 0x00000028; // Set channel

VICIntEnable = 0x00000100; // Enable the interrupt

PINSEL0 |= 0x00008008; // Enable P0.7&P0.1-PWM

PWMPR = 0x00000000; // Load prescaler

25
PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control */

PWMMCR = 0x00000003; // reset the counter

PWMMR0 = 0x400; // set dutycycle is sixteen ticks

PWMMR1 = 0; // rising edge of PWM2– 100 tricks

PWMMR2 = 0x200; // falling edge of PWM2- 200 ticks

PWMMR3 = 0x100; // rising edge of PWM2– 100 tricks

PWMLER = 0xF; // shadow latch for match 1 – 3

PWMTCR = 0x00000002; // Reset counter and prescaler

PWMTCR = 0x00000009; // release counter from reset

RESULT:

Thus C code for Interfacing PWM was written and implemented with
ARM LPC 2148.

26
Exp.No: 6 INTERFACING REAL TIME CLOCK .
Date:

AIM:

To write C code for Interfacing real time clock and implement the code with the use
of ARM LPC1768

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables
4. Real time clock
5. UART

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
27
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

11 Select Output Tab and Click on Create Hex File check box then Click OK
Button
12 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
13 You are now ready to Program your Part.

CODING

#include <LPC17xx.H>
#include "GLCD.h"
#include "Serial.h"
#define FI 1
void Read_RTC(void);
void Backspace(void);
void space(void);
void delete(void);
void Disp_Month(void);
unsigned char Units_Tens(unsigned int);
void delay(unsigned int x);
unsigned char rtc_val[15];
unsigned char week[15][15]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
void delay(unsigned int x)
{
unsigned int i;
for(i=0x00;i<=x;i++);
}
void Backspace()
{
SER_PutChar(0x08);
}
void space(void)
{
unsigned char i;
for(i=0x00; i<0x03; i++)
SER_PutChar(0x20);
}
28
unsigned char Units_Tens(unsigned int i)
{
unsigned char temp = 0,temp1 = 0;
temp = rtc_val[i] & 0x0F;
i++;
temp1 = rtc_val[i] & 0x0F;
temp1 <<= 4;
temp1 |= temp;
return temp1;
}
void display()
{
unsigned int j = 0,temp = 0,temp1 = 0;
unsigned long t;
unsigned char c;
j = 0x04;
c = Units_Tens(j);
c &= 0x3F;
temp1 = c;
SER_SendString("\n\r");
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,0, FI,t);
SER_SendHex((c & 0xf0) >> 4);
SER_SendHex(temp1 & 0x0f);
t =(temp1 & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,1, FI,t);
GLCD_DisplayChar(5,2, FI,' ');
space();
j = 0x02;
c = Units_Tens(j);
temp1 = c;
SER_SendHex((c & 0xf0) >> 4);

29
SER_SendHex(temp1 & 0x0f);
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,4, FI,t);
t =(temp1 & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,5, FI,t);
GLCD_DisplayChar(5,6, FI,' ');
space();
j = 0x00;
c = Units_Tens(j);
temp1 = c;
SER_SendHex((c & 0xF0) >> 4);
SER_SendHex(temp1 & 0x0F);
space();
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,7, FI,t);
t =(temp1 & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(5,8, FI,t);
GLCD_DisplayChar(5,9, FI,' ');
j = 0x5;
c = (rtc_val[j] & 0x08);
if(c != 0x00)
{
SER_PutChar('-');
SER_PutChar('-');

30
SER_PutChar('-');
space();
GLCD_DisplayString(7,0, FI,"--- ");
Disp_Month();
}
else
{
temp = (rtc_val[j] & 0x04);
if(temp != 0x00)
{
GLCD_DisplayString(7,0, FI," PM ");
SER_SendString("PM");
space();
Disp_Month();
}
else
{
SER_SendString("AM");
space();
GLCD_DisplayString(7,0, FI," AM ");
Disp_Month();
}
}
}
void Read_RTC(void)
{
unsigned int j = 0,index = 0;
unsigned long data;
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0x807FFFFF) | (1 << 27);
delay(0x28);
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & 0xFF7FFFFF) | (3 << 27);
while(j != 0xD)
{
index = (j & 0x0F);
LPC_GPIO1->FIOPIN = ( LPC_GPIO1->FIOPIN & 0xF807FFFF) | ( index << 19);
delay(500);
data = ((LPC_GPIO0->FIOPIN & 0x007F8000) >> 15);
data = (unsigned char)data;
rtc_val[j] = (data & 0x0F);
j++;

31
}
LPC_GPIO0->FIOPIN = ( LPC_GPIO0->FIOPIN & 0x807FFFFF);
}
void delete()
{
unsigned int i = 0;
for(i=0; i<=0x22; i++)
Backspace();
}
void Disp_Month(void)
{
unsigned int j = 0;
unsigned char c = 0,temp = 0;
unsigned long t;
j = 0x6;
c = rtc_val[j];
j = c;
GLCD_DisplayString(7,5, FI,week[j]);
GLCD_DisplayString(7,8, FI," ");
SER_SendString(week[j]);
SER_PutChar(0x20);
SER_PutChar(0x20);
j = 0x7;
c = Units_Tens(j);
temp = c;
SER_SendHex((c & 0xf0) >> 4);
SER_SendHex(temp & 0x0f);
SER_PutChar('-');
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,10, FI,t);
t =(temp & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,11, FI,t);

32
GLCD_DisplayChar(7,12, FI,'-');
j = 0x09;
c = Units_Tens(j);
temp = c;
SER_SendHex((c & 0xf0) >> 4);
SER_SendHex(temp & 0x0f);
SER_PutChar('-');
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,13, FI,t);
t =(temp & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,14, FI,t);
GLCD_DisplayChar(7,15, FI,'-');
j = 0xb;
c = Units_Tens(j);
temp = c;
SER_SendHex((c & 0xf0) >> 4);
SER_SendHex(temp & 0x0f);
t =((c & 0xf0) >> 4);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,16, FI,t);
t =(temp & 0x0f);
if( t <= 9)
t = t + 0x30;
else
t = t + 0x37;
GLCD_DisplayChar(7,17, FI,t);
delete();
}
int main()

33
{
LPC_SC->PCONP |= (1 << 15);
LPC_GPIO0->FIODIR |= 0x7F800000;
LPC_GPIO1->FIODIR |= 0x07F80000;
#ifdef USE_LCD
GLCD_Init();
GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " ESA ");
GLCD_DisplayString(1, 0, FI, " Bangalore");
GLCD_DisplayString(2, 0, FI, " www.esaindia.com ");
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);
GLCD_DisplayString(3, 0, FI, " REAL TIME CLOCK ");
GLCD_DisplayString(4,0, FI,"HRS MIN SEC ");
GLCD_DisplayString(6,0, FI," A/P DAY DD-MM-YY ");
#endif
while(1)
{
Read_RTC();
Read_RTC();
display();
Read_RTC();
}}

RESULT:

Thus C code for Interfacing real time clock was written and
implemented with ARM LPC 1768.

34
Exp.No: 7 INTERFACING SERIAL PORT.

Date:

AIM:

To write C code for Interfacing serial port and implement the code with the use of
ARM LPC2148

Hardware Required:
1. ARM cortex (LPC2148)
2. Power supply
3. RS232 cables
4. UART

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC2148 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.

35
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

14 Select Output Tab and Click on Create Hex File check box then Click OK
Button
15 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
16 You are now ready to Program your Part.

CODING

#include <stdio.h> /* prototype declarations for I/O functions */

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

#include "Serial.h"

#include "lcd.h"

#define MASKSEC 0x3F

// Second 00..59 00000000:00000000:00xxxxxx

#define MASKMIN 0x3F00

// Minute 00..59 00000000:00xxxxxx:00000000

#define MASKHR 0x1F0000

// Hour 00..23 000xxxxx:00000000:00000000

char uart1_buf[];

unsigned char flag = 1;

void RTC_Init(void);

void delay(int count)

int j=0,i=0;

36
for(j=0;j<count;j++)

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

int pcclk_cali;

int main (void) { /* execution starts here */

unsigned char Hour,Minute,Second,Last_Second; // RTC Buffer

Data

lcd_init();

lcd_write_control(0x01); // Clear

Display (Clear Display,Set DD RAM Address=0)

goto_cursor(0x00); // Set

Cursor Line-1

lcd_print(" RAANA RTC DEMO "); //

Display LCD Line-1

uart1_init(); // Initialize UART1

// Initial Internal RTC Function

// Initial RTC Function

HOUR = 7;//0x07;

MIN = 33;//0x03;

SEC = 0;//0x03;

37
RTC_Init();

// CCR = 0x00000002;

// CIIR = 0x00000000;

// AMR = 0x000000FF;

// ILR = 0x00000003;

// CCR = 0x00000011;

Last_Second = 0x00;

while (1) {

do

// Repeat Get Second until Second Change

Hour = (CTIME0 & MASKHR)>>16;

// Read Hour

Minute = (CTIME0 & MASKMIN)>>8;

// Read Minute

Second = CTIME0 & MASKSEC;

// Read Second

while(Last_Second == Second); //

Repeat if Second Not Change

Last_Second = Second;

// Update Current Second

38
sprintf(uart1_buf,"\rRAANA RTC DEMO = ");

uart1_puts(uart1_buf);

sprintf(uart1_buf," %002d : %002d : %002d",Hour,Minute,Second);

uart1_puts(uart1_buf);

uart1_puts("\n");

goto_cursor(0x40);

// Set Cursor = Line-2

lcd_print(uart1_buf);

void RTC_Init(void)

// DOY = 23; //Enter Date

// MONTH = 50; //MONTH

// YEAR = 2013; //Year

HOUR =11; //Hour)

MIN = 15; //Min

SEC = 0; //Sec

PREINT = 0x392/2; //To Generate clock of 32.768KHz for RTC Module

PREFRAC = 0x4380/2; //when PCLK = 30MHz

/*

Formula For Calculation is as follow:-

PREINT = (int)(PCLK/32768)-1

39
PREFRAC = PCLK - ((PREINT+1)*32768

Example:-

if PCLK = 30MHz

PREINT = 914 = 0x392

PREFRAC = 17280 = 0x4380

*/

CIIR = 0x01; //Enables Second Counter Interrupt

CCR = 0x01; //Start RTC

RESULT:

Thus C code for Interfacing serial port was written and implemented
with ARM LPC 2148.

40
Exp.No: 8 INTERFACING KEYBOARD

Date:

AIM:

To write C code for Interfacing keyboard and implement the code with the use of
ARM LPC1768.

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables
4. Keyboard

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.

41
8. Click File Menu and select New. A new window will open up in the Keil IDE.
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

11 Select Output Tab and Click on Create Hex File check box then Click OK
Button
12 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
13 You are now ready to Program your Part.

CODING

#include <LPC17xx.H>
#include "GLCD.h"
#define FI 1
void Display(unsigned char ch);
void Clear_LEDS(void);
unsigned char get_keycode(void);
unsigned char get_number(void);
unsigned char get_Operator(void);
void delay(unsigned int i);

void Display(unsigned char ch)


{
unsigned char i,tmp;
for(i=0;i<8;i++)
{
tmp = ch & 0x80;
if(tmp)
LPC_GPIO0->FIOPIN |= (1<<24);
else
LPC_GPIO0->FIOPIN &= ~(1<<24);

42
LPC_GPIO0->FIOPIN &= ~(1<<23);
LPC_GPIO0->FIOPIN |= (1<<23);
ch = ch << 1;
}
}

void Clear_LEDS()
{
unsigned char i;
for(i=0;i<6;i++)
Display(0xFF);
}

unsigned char get_keycode()


{
unsigned long i,s,code,j;

while(1)
{
code = 0;
for(i=0x00080000; i<=0x00400000; i<<=1)
{
LPC_GPIO1->FIOPIN = ((LPC_GPIO1->FIOPIN & 0xFF87FFFF) | i);
delay(3200);
s= LPC_GPIO0->FIOPIN & 0x000F8000;
s = s >> 15;
if(s>0)
{
for(j=0;j<5;j++)
{
43
s>>=1;
if(s==0)
return(code+j);
}
}
code += 5;
}
}
}

unsigned char get_number()


{
unsigned char num;
while(1)
{
num = get_keycode();
if(num<0x0a || num==0x13)
return(num);
}

unsigned char get_Operator()


{
unsigned int optr;
while(1)
{
optr = get_keycode();
if(optr==0x0C || optr==0x0D || optr==0x10 || optr==0x12 || optr==0x13 || optr==0x0E )

return(optr);
44
}
}

void delay(unsigned int i)


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

main()
{

unsigned char n1=0,n2,Op,Result,Neg;


unsigned char Number[10] = {
0x0C0,0x0F9,0x0A4,0xB0,0x99,0x92,0x82,0x0F8,0x80,0x90 };
unsigned char Operator[7] = { 0x88,0x0C8,0x0AF,0xFF,0x0BF,0xFF,0x0A1};

LPC_SC->PCONP |= (1<<15);
LPC_GPIO0->FIODIR |= 0x7F800000;
LPC_GPIO1->FIODIR |= 0x07F80000;

#ifdef USE_LCD
GLCD_Init();

GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " ESA ");
GLCD_DisplayString(1, 0, __FI, " Bangalore ");
GLCD_DisplayString(2, 0, FI, " www.esaindia.com ");
45
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);
GLCD_DisplayString(5, 0, FI, " Keyboard Display ");

#endif

Clear_LEDS();
while(1)
{

Neg = 0x00;
n1 = get_number();
if(n1==0x13)
{
Clear_LEDS();
continue;
}
Display(Number[n1]);

Op = get_Operator() - 0x0C;
if(Op==0x07)
{
Clear_LEDS();
continue;
}

Display(Operator[Op]);

n2=get_number();
if(n2==0x13)
{
46
Clear_LEDS();
continue;
}
Display(Number[n2]);

while(get_keycode()!=0x0B);
Clear_LEDS();
switch(Op)
{
case 0:

Result = n1 + n2;
break;

case 1:

Result = n1 * n2;
break;
case 2:

Result = n1 % n2;
break;
case 4:
if(n2>n1)
{
Neg = 0x01;
Result = n2 - n1;
break;
}
Result = n1 - n2;
break;
47
case 6:
Result = n1 / n2;
break;
}

Display(Number[Result%10]);
Display(Number[Result/10]);

if(Neg)
Display(0x0BF);

while(get_keycode()!= 0x13)
{
Clear_LEDS();
}
}
}

RESULT:

Thus C code for Interfacing keyboard was written and implemented


with ARM LPC 1768.

48
Exp.No:9 INTERFACING LCD

Date:

AIM:

To write C code for Interfacing LCD and implement the code with the use of ARM
LPC2148

Hardware Required:
1. ARM cortex (LPC2148)
2. Power supply
3. RS232 cables
4. lcd display

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC2148 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP

49
7. Scroll down and select the LPC2148 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

14 Select Output Tab and Click on Create Hex File check box then Click OK
Button
15 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
16 You are now ready to Program your Part.

CODING

#include <LPC21xx.H>

#include "lcd.h"

#include <stdio.h>

#define sw2 (IOPIN0 & (1<<15))

#define sw3 (IOPIN0 & (1<<30))

char lcd_buff[16];

void delay(void);

unsigned int k;

int main(void)

PINSEL0 |= 0x00000000;

IODIR0 |= 0x000000FF;

lcd_init();

lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)

goto_cursor(0x00); // Set Cursor Line-1

50
lcd_print("ROHINI DEMO"); // Display LCD Line-1

while (1)

if ((sw2) == 0 )

IOCLR0 = 0x00000040;

goto_cursor(0x40);

lcd_print(" ");

else

IOSET0 = 0x00000040;

goto_cursor(0x40);

lcd_print("SW3 PRESSED");

if ((sw3) == 0)

IOCLR0 = 0x00000020;

goto_cursor(0x40);

lcd_print(" ");

else

51
IOSET0 = 0x00000020;

goto_cursor(0x40);

lcd_print("SW2 PRESSED");

void delay(void) // delay loop

int i;

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

RESULT:

Thus C code for Interfacing LCD was written and implemented with
ARM LPC 2148.

52
Exp.No: 10 INTERFACING EPROM

Date:

AIM:

To write C code for Interfacing EPROM and implement the code with the use of
ARM LPC1768

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
53
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

11 Select Output Tab and Click on Create Hex File check box then Click OK
Button
12 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
13 You are now ready to Program your Part.

CODING

#include <LPC17XX.H>
#include "GLCD.H"
#define PCF8574AP
#define FI 1
#ifdef PCF8574AP
#define U1 0x70
#define U2 0x72
#define U3 0x74
#define U4 0x76
#endif
#ifdef PCF8574P
#define U1 0x40
#define U2 0x42
#define U3 0x44
#define U4 0x46
#endif
void I2CWrite2402(unsigned char, unsigned char, unsigned char);
unsigned char I2CRead2402(unsigned char, unsigned char);
void LED_display(unsigned char, unsigned char);
void delay(void);
unsigned char Recv_Data[8],
Send_Data[8] = {0xFF,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
unsigned char lookup[0x10] = { 0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E};
main()
{
unsigned char i,k;
54
LPC_SC->PCONP|=(1<<15);
LPC_GPIO0->FIODIR = 3 << 27;
LPC_PINCON-> PINSEL1 |=0x01400000;
LPC_I2C0-> I2SCLH = 0xC0;
LPC_I2C0-> I2SCLL = 0xC0;
#define USE_LCD
#ifdef USE_LCD
GLCD_Init();
GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " ESA ");
GLCD_DisplayString(1, 0, FI, " Bangalore");
GLCD_DisplayString(2, 0, FI, " www.esaindia.com ");
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);
GLCD_DisplayString(5, 0, FI, " I2C EEPROM ");
#endif
while(1)
{
LED_display(U1,0xFF);
LED_display(U2,0xFF);
LED_display(U3,0xFF);
LED_display(U4,0xFF);
I2CWrite2402(0xA0,0x00,0x08);
for(i=0x00; i<0x08; i++)
Recv_Data[i] = I2CRead2402(0xA1,i);
for(i=0x00; i<0x08; i++)
{
k = Recv_Data[i] & 0x0F ;
LED_display(U4,lookup[k]);
k = (Recv_Data[i] & 0xF0) >> 4 ;
LED_display(U3,lookup[k]);
delay();
}}}
void I2CWrite2402(unsigned char Slv_Addr, unsigned char wrd_adrs,unsigned char
no_locations)
{
unsigned char k;
LPC_I2C0-> I2CONSET = 0x40;

55
LPC_I2C0-> I2CONSET = 0x20;
while(LPC_I2C0-> I2STAT != 0x08);
LPC_I2C0-> I2CONCLR = 0x20;
LPC_I2C0-> I2DAT = Slv_Addr;
LPC_I2C0-> I2CONCLR = 0x08;
while(LPC_I2C0-> I2STAT != 0x18);
LPC_I2C0-> I2DAT = wrd_adrs;
LPC_I2C0-> I2CONCLR = 0x08;
while(LPC_I2C0-> I2STAT != 0x28);

for(k=0x00; k < no_locations; k++)


{
LPC_I2C0-> I2DAT = Send_Data[k];
LPC_I2C0-> I2CONCLR = 0x08;
while(LPC_I2C0-> I2STAT != 0x28);
}

LPC_I2C0-> I2CONSET = 0x10;


LPC_I2C0-> I2CONCLR = 0x08;
delay();
LPC_I2C0-> I2CONCLR = 0x40;
}

unsigned char I2CRead2402(unsigned char Slv_Addr,unsigned char word_adrs)


{
unsigned char data;
LPC_I2C0-> I2CONSET = 0x40;
LPC_I2C0-> I2CONSET = 0x20;

while(LPC_I2C0-> I2STAT != 0x08);


LPC_I2C0-> I2CONCLR = 0x20;
LPC_I2C0-> I2DAT = 0xA0;
LPC_I2C0-> I2CONCLR = 0x08;

while(LPC_I2C0-> I2STAT != 0x18);


LPC_I2C0-> I2DAT = word_adrs;
LPC_I2C0-> I2CONCLR = 0x08;

while(LPC_I2C0-> I2STAT != 0x28);


LPC_I2C0-> I2CONCLR = 0x40;

56
LPC_I2C0-> I2CONCLR = 0x08;
LPC_I2C0-> I2CONSET = 0x40;
LPC_I2C0-> I2CONSET = 0x20;

while(LPC_I2C0-> I2STAT != 0x08);


LPC_I2C0-> I2CONCLR = 0x20;
LPC_I2C0-> I2DAT = Slv_Addr;
LPC_I2C0-> I2CONCLR = 0x08;

while(LPC_I2C0-> I2STAT != 0x40);


LPC_I2C0-> I2CONSET = 0x04;
LPC_I2C0-> I2CONCLR = 0x08;

while(LPC_I2C0-> I2STAT != 0x50);


data = LPC_I2C0-> I2DAT ;
LPC_I2C0-> I2CONCLR = 0x04;
LPC_I2C0-> I2CONSET = 0x10;
LPC_I2C0-> I2CONCLR = 0x08;
LPC_I2C0-> I2CONCLR = 0x40;
return(data);
}

void LED_display(unsigned char Slv_Addr, unsigned char Data)


{
LPC_I2C0-> I2CONSET = 0x40;
LPC_I2C0-> I2CONSET = 0x20;
while((LPC_I2C0-> I2STAT != 0x08));
LPC_I2C0-> I2CONCLR = 0x20;

LPC_I2C0-> I2DAT = Slv_Addr;


LPC_I2C0-> I2CONCLR = 0x08;
while((LPC_I2C0-> I2STAT != 0x18));

LPC_I2C0-> I2DAT = Data;


LPC_I2C0-> I2CONCLR = 0x08;

while((LPC_I2C0-> I2STAT != 0x28));

LPC_I2C0-> I2CONSET = 0x10;


LPC_I2C0-> I2CONCLR = 0x08;

57
LPC_I2C0-> I2CONCLR = 0x40;

void delay()
{
unsigned int i,j;

for(j=0; j<0x300; j++)


for(i=0x00; i<=9999; i++);
}

RESULT:

Thus C code for Interfacing EPROM was written and implemented


with ARM LPC 1768.

58
Exp.No: 11 INTERFACING INTERRUPT

Date:

AIM:

To write C code for Interfacing interrupt and implement the code with the use of
ARM LPC2148.

Hardware Required:
1. ARM cortex (LPC2148)
2. Power supply
3. RS232 cables
4. Interrupt controller

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC2148 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
59
9. Write the program in the new window. Click the Save Button.

10. Expand the Source Group 1 in the Tree menu to ensure that the file was
added to the project.

14 Select Output Tab and Click on Create Hex File check box then Click OK
Button
15 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
16 You are now ready to Program your Part.

CODING

#include <LPC214x.h>

#include <stdio.h>

#include <string.h>

#include"lcd.h"

#define MAX 18

#define AA 2

#define SI 3

#define STO 4

#define STA 5

#define I2EN 6

#define sw1 (IOPIN0 & (1<<14))

#define sw3 (IOPIN0 & (1<<30))

char c_rx_data[];

void I2C_ISR(void) irq;

void Wait (unsigned int);

void I2C_Init (void);

60
int I2C_Start (unsigned int Slave_Addr);

int I2C_Write (unsigned char *Buff, unsigned int Count);

void Delay(void);

char ReLoad[MAX] = {0x00,0x00,'R','A','A','N','A',' ','E','E', 'P', ' ','T','S','T'};

char Buff[MAX] ={0x00,0x00,'R','A','A','N','A',' ','E','E', 'P', ' ','T','S','T'};

unsigned char Rec[MAX] = {"NO-DATA!"};

unsigned char index = 0;

unsigned char flag = 0, ii, Ready=0, Erase = 0;

char lcd_buff[50];

char uart1_buf[];

void read_eep();

void I2C_ISR(void) irq

if (I2C0CONSET & 0x08)

switch (I2C0STAT)

case (0x08):

if (flag == 'W')

I2C0CONCLR = 1 << STO;

I2C0CONCLR = 1 << STA ;

I2C0DAT = 0xA0;

61
I2C0CONCLR = 1 << SI;

else if (flag == 'R')

I2C0DAT = 0xA0;

I2C_Start (0xA1);

I2C0CONCLR = 1 << SI;

index = 0;

break;

case (0x10):

I2C0CONCLR = 1 << STA;

if (flag == 'W')

I2C0DAT = 0xA0;

else if (flag == 'R')

I2C0CONCLR = 1 << STA;

I2C0CONCLR = 1 << STO;

I2C0DAT = 0xA1;

I2C0CONCLR = 1 << SI;

index = 0;

break;

62
case (0x18):

I2C0CONCLR = 0x20;

I2C0CONCLR = 0x38;

I2C0DAT = Buff[index];

index++;

break;

case (0x20):

I2C0CONCLR = 0x20;

I2C0CONCLR = 0x38;

I2C0DAT = Buff[index];

index++;

break;

case (0x28):

if (index < MAX)

if (flag == 'W')

I2C0DAT = Buff[index];

I2C0CONCLR = 0x20;

I2C0CONCLR = 0x38;

else if ((index > 1) && flag == 'R')

63
I2C0CONCLR = 0x18;

I2C0CONSET = 1 << STA;

else

I2C0DAT = Buff[index];

I2C0CONCLR = 0x20;

I2C0CONCLR = 0x38;

index++;

else

index = 0;

flag = 'R';

I2C0CONSET = 1 << STO;

if (Erase == 1)

Erase = 0;

else

64
I2C0CONCLR = 1 << STA;

I2C0CONCLR = 1 << SI;

break;

case (0x30):

I2C0CONCLR = 0x20;

if (index < MAX)

if (flag == 'W')

I2C0DAT = Buff[index];

index++;

else

index = 0;

flag = 0;

I2C0CONSET = 0x10;

I2C0CONCLR = 1 << SI;

break;

case (0x38):

65
I2C0CONSET = 0x20;

break;

case (0x40):

I2C0CONSET = 1 << AA;

I2C0CONCLR = 1 << STA;

I2C0CONCLR = 1 << STO;

I2C0CONCLR = 1 << SI;

break;

case (0x48):

I2C0CONSET = 1 << STA;

break;

case (0x50):

I2C0CONSET = 1 << AA;

if (index < MAX)

Rec [index] = I2C0DAT;

index++;

else

I2C0CONSET = 1 << STO;

I2C0CONCLR = 1 << SI;

index = 0;

66
Ready = 'T';

break;

case (0x58):

Rec [index] = I2C0DAT;

I2C0CONCLR = 1 << STA;

I2C0CONCLR = 1 << STO;

break;

I2C0CONCLR = 1 << SI;

VICVectAddr = 0x00;

char uart_rx;

unsigned char rx_true;

int main()

unsigned int i;

//VPBDIV = 0x02;

PINSEL0 = 0x00000050; //P0.2-SCLK0 & P0.3-SDA0

PINSEL2 &= 0xFFFFFFF3;

IODIR0 = 0x000000FF;

IO1DIR |= 0xFF << 16;

67
lcd_init();

uart1_init();

sprintf(uart1_buf,"\r RAANA EEP_INT DEMO ");

uart1_puts(uart1_buf);

lcd_write_control(0x01); // Clear

Display (Clear Display,Set DD RAM Address=0)

goto_cursor(0x00); // Set

Cursor Line-1

lcd_print(" RAANA EEP_INT "); //

Display LCD Line-1

/* Init VIC for I2C0 */

VICIntSelect =(0<< 9); // Setting all interrupts as IRQ(Vectored)

VICVectCntl0 = 0x20 | 9; // Assigning Highest Priority Slot to I2C0 and enabling this

slot

VICVectAddr0 = (unsigned long)I2C_ISR; // Storing vector address of I2C0

VICIntEnable = (1<<9);

I2C_Init();

ii = 0;

read_eep();

while(1)

uart_rx = uart1_getkey();

if(uart_rx == '+')

68
{

Buff [0]=Buff [1]=0x00;

rx_true=1;

ii=2;

while( rx_true)

uart_rx = uart1_getkey();

if(uart_rx == 0x0d)

uart1_putc(0x0A);

rx_true=0;

else

uart1_putc(uart_rx);

if(ii < MAX-2)

Buff [ii]=uart_rx;

ii++;

while(ii<MAX)

69
{

Buff [ii]=' ';

ii++;

IOSET0 = 0x00000040;

IOCLR1 = 0xFF << 16;

IOSET1 = 1 << 16;

Wait (5000);

sprintf(uart1_buf,"\r WRITING EEPROM ");

uart1_puts(uart1_buf);

flag = 'W';

I2C_Start (0x70);

for (i=0;i<30;i++) Wait(10000);

I2C0CONCLR = 1 << SI;

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Delay();

sprintf(uart1_buf,"\r WRITING FINISHED ");

uart1_puts(uart1_buf);

70
Delay();

Delay();

Delay();

sprintf(uart1_buf,"\r READING EEPROM ");

uart1_puts(uart1_buf);

read_eep();

sprintf(uart1_buf,"\r READING FINISHED ");

uart1_puts(uart1_buf);

else if(uart_rx == '-')

sprintf(uart1_buf,"\r ERASIG EEPROM ");

uart1_puts(uart1_buf);

Buff [0]=Buff [1]=0x00;

ii=2;

while(ii<MAX)

Buff [ii]=' ';

ii++;

IOSET0 = 0x00000040;

IOCLR1 = 0xFF << 16;

IOSET1 = 1 << 16;

71
Wait (5000);

flag = 'W';

I2C_Start (0x70);

for (i=0;i<30;i++) Wait(10000);

I2C0CONCLR = 1 << SI;

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Wait (5000);Wait (5000);

Delay();

sprintf(uart1_buf,"\r ERASIG FINISH ");

uart1_puts(uart1_buf);

Delay();

sprintf(uart1_buf,"\r READING EEPROM ");

uart1_puts(uart1_buf);

read_eep();

sprintf(uart1_buf,"\r READING FINISHED ");

uart1_puts(uart1_buf);

void Delay(void)

72
{

unsigned int i,j;

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

for(j=0;j<900;j++);

void Wait (unsigned int Delay)

while(Delay--);

void I2C_Init (void)

I2C0SCLH = 150; //50%duty,I2CFreq->100KHz,PCLK=30MHz

I2C0SCLL = 150;

I2C0CONSET = 1 << I2EN; //Enable I2C 1

int I2C_Start (unsigned int Slave_Addr)

I2C0CONCLR = 1 << STO;

I2C0CONSET = 1 << AA;

I2C0CONSET = 1 << STA;

return 0;

int I2C_Write (unsigned char *Buff, unsigned int Count)

73
{

while(Count--)

I2C0DAT = *Buff++;

return 0;

void read_eep()

unsigned int i;

goto_cursor(0x40);

// Set Cursor = Line-2

IO1CLR = 0xFF << 16;

IOCLR1 = 0xFF << 16;

IOSET1 = 1 << 17;

flag = 'R';

I2C_Start (0x70);

for (i=0;i<30;i++) Wait(10000);

I2C0CONCLR = 1 << SI;

while (Ready == 'F');

if (Ready == 'T')

74
ii=0;

while (ii<MAX)

Wait (1000);

sprintf(lcd_buff,"%c",Rec[ii]);

lcd_print(lcd_buff);

Wait (1000);

Wait (1000);

Wait (1000);

ii++;

Wait (1000);

Ready = 'F';

Wait (5000);Wait (5000);Wait (5000);Wait (5000);

RESULT:

Thus C code for Interfacing interrupt was written and implemented


with ARM LPC 2148.

75
Exp.No: 12 FLASHING OF LEDS

Date:

AIM:

To write C code for flashing LEDs and implement the code with the use of
ARM LPC1768.

Hardware Required:
1. ARM cortex (LPC1768)
2. Power supply
3. RS232 cables

Software required:
1. KEIL IDE
2. Embedded c programming
Theory:

The LPC1768 are ARM Cortex-M3 based microcontrollers for embedded


applications featuring a high level of integration and low power consumption. The
ARM Cortex-M3 is a next generation core that offers system enhancements such as
enhanced debug features and a higher level of support block integration. ARM
Cortex-M3 processor, running at frequencies of up to 100 MHz. A Memory
Protection Unit (MPU) supporting eight regions is included. Up to 512 kB on-chip
flash programming memory. Enhanced flash memory accelerator enables high-
speed 100 MHz operation with zero wait states. In-System Programming (ISP) and
In-Application Programming (IAP) via on-chip boot loader software.

Procedure:

1. Open Keil from the Start menu


2. Select New µVision Project from the Project Menu.
3. Name the project ‘Toggle’ and Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with.
6. Double Click on the NXP
7. Scroll down and select the LPC1768 and Click OK.
8. Click File Menu and select New. A new window will open up in the Keil IDE.
9. Write the program in the new window. Click the Save Button.

76
16 Expand the Source Group 1 in the Tree menu to ensure that the file was added
to the project.
17 Select Output Tab and Click on Create Hex File check box then Click OK
Button
18 Click on Project Menu and select Rebuild all Target Files and In the Build
Window it should report ‘0 Errors (s), 0 Warnings’
19 You are now ready to Program your Part.

CODING

#include <stdio.h>
#include "LPC17xx.H"
#include "GLCD.h"
#include "Serial.h"
#include "LED.h"
#include "ADC.h"
#define FI 1

char text[10];
extern uint8_t clock_1s;
int main (void) {
uint32_t ad_avg = 0;
uint16_t ad_val = 0, ad_val_ = 0xFFFF;
LED_Init();
SER_Init();
ADC_Init();
#ifdef USE_LCD
GLCD_Init();
GLCD_Clear(White);
GLCD_SetBackColor(Blue);
GLCD_SetTextColor(White);
GLCD_DisplayString(0, 0, FI, " MCB1700 Demo ");
GLCD_DisplayString(1, 0, FI, " Blinky ");
GLCD_DisplayString(2, 0, FI, " www.keil.com ");
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);
GLCD_DisplayString(5, 0, FI, "AD value: ");
#endif
SysTick_Config(SystemCoreClock/100);
while (1) {

77
if (AD_done) {
AD_done = 0;

ad_avg += AD_last << 8;


ad_avg ++;
if ((ad_avg & 0xFF) == 0x10) {
ad_val = (ad_avg >> 8) >> 4;
ad_avg = 0;
}
}

if (ad_val ^ ad_val_) {
ad_val_ = ad_val;

sprintf(text, "0x%04X", ad_val);


#ifdef USE_LCD
GLCD_SetTextColor(Red);
GLCD_DisplayString(5, 9, FI, (unsigned char *)text);
GLCD_Bargraph (144, 6*24, 176, 20, (ad_val >> 2));
#endif
}

if (clock_1s) {
clock_1s = 0;

printf("AD value: %s\r\n", text);


}
}
}

RESULT:

Thus C code for flashing LEDs is written and it is implemented with


ARM LPC 1768.

78

You might also like