Systems Lab Manual
Systems Lab Manual
ENGINEERING
20EC6401
EMBEDDED AND REAL TIME SYSTEMS
NAME :
REG NO :
YEAR/SEM :
BRANCH :
1
BONAFIDE CERTIFICATE
Name :
Subject Code :
Subject Name:
Certified that is a bonafide record of work done by the above student during
the year 20 - 20
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 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
FEATURES:
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:
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:
Procedure:
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;
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;
}
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:
Procedure:
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:
Procedure:
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"
regVal = LPC_PWM1->IR;
if ( regVal & MR0_INT )
{
match_counter1++;
}
LPC_PWM1->IR |= regVal; return;
}
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;
NVIC_EnableIRQ(PWM1_IRQn);
return (TRUE);
}
19
{
if ( channelNum == 1 )
{
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:
Procedure:
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>
char lcd_buff[16];
void delay(void);
VICVectAddr = 0x00000000;
22
unsigned int k;
int main(void)
PINSEL0 |= 0x00000000;
IODIR0 |= 0x000000FF;
init_PWM();
lcd_init();
duty = 50;
lcd_print(lcd_buff);
PWMMR2 = duty1;
PWMLER = 0xF;
oldval = duty1;
while (1)
if ((sw2) == 0 )
IOCLR0 = 0x00000040;
else
23
{
duty++;
duty = 100;
goto_cursor(0x40);
lcd_print(lcd_buff);
PWMMR2 = duty1;
PWMLER = 0xF;
oldval = duty1;
IOSET0 = 0x00000040;
if ((sw3) == 0)
IOCLR0 = 0x00000020;
else
duty--;
if (duty <= 1)
duty = 1;
24
goto_cursor(0x40);
lcd_print(lcd_buff);
PWMMR2 = duty1;
PWMLER = 0xF;
oldval = duty1;
IOSET0 = 0x00000020;
int i;
25
PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control */
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:
Procedure:
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:
Procedure:
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 "Serial.h"
#include "lcd.h"
char uart1_buf[];
void RTC_Init(void);
int j=0,i=0;
36
for(j=0;j<count;j++)
for(i=0;i<35;i++);
int pcclk_cali;
Data
lcd_init();
lcd_write_control(0x01); // Clear
goto_cursor(0x00); // Set
Cursor Line-1
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
// Read Hour
// Read Minute
// Read Second
while(Last_Second == Second); //
Last_Second = Second;
38
sprintf(uart1_buf,"\rRAANA RTC DEMO = ");
uart1_puts(uart1_buf);
uart1_puts(uart1_buf);
uart1_puts("\n");
goto_cursor(0x40);
lcd_print(uart1_buf);
void RTC_Init(void)
SEC = 0; //Sec
/*
PREINT = (int)(PCLK/32768)-1
39
PREFRAC = PCLK - ((PREINT+1)*32768
Example:-
if PCLK = 30MHz
*/
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:
Procedure:
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);
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);
}
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;
}
}
}
return(optr);
44
}
}
main()
{
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:
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:
Procedure:
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>
char lcd_buff[16];
void delay(void);
unsigned int k;
int main(void)
PINSEL0 |= 0x00000000;
IODIR0 |= 0x000000FF;
lcd_init();
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");
int 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:
Procedure:
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);
56
LPC_I2C0-> I2CONCLR = 0x08;
LPC_I2C0-> I2CONSET = 0x40;
LPC_I2C0-> I2CONSET = 0x20;
57
LPC_I2C0-> I2CONCLR = 0x40;
void delay()
{
unsigned int i,j;
RESULT:
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:
Procedure:
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
char c_rx_data[];
60
int I2C_Start (unsigned int Slave_Addr);
void Delay(void);
char lcd_buff[50];
char uart1_buf[];
void read_eep();
switch (I2C0STAT)
case (0x08):
if (flag == 'W')
I2C0DAT = 0xA0;
61
I2C0CONCLR = 1 << SI;
I2C0DAT = 0xA0;
I2C_Start (0xA1);
index = 0;
break;
case (0x10):
if (flag == 'W')
I2C0DAT = 0xA0;
I2C0DAT = 0xA1;
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 (flag == 'W')
I2C0DAT = Buff[index];
I2C0CONCLR = 0x20;
I2C0CONCLR = 0x38;
63
I2C0CONCLR = 0x18;
else
I2C0DAT = Buff[index];
I2C0CONCLR = 0x20;
I2C0CONCLR = 0x38;
index++;
else
index = 0;
flag = 'R';
if (Erase == 1)
Erase = 0;
else
64
I2C0CONCLR = 1 << STA;
break;
case (0x30):
I2C0CONCLR = 0x20;
if (flag == 'W')
I2C0DAT = Buff[index];
index++;
else
index = 0;
flag = 0;
I2C0CONSET = 0x10;
break;
case (0x38):
65
I2C0CONSET = 0x20;
break;
case (0x40):
break;
case (0x48):
break;
case (0x50):
index++;
else
index = 0;
66
Ready = 'T';
break;
case (0x58):
break;
VICVectAddr = 0x00;
char uart_rx;
int main()
unsigned int i;
//VPBDIV = 0x02;
IODIR0 = 0x000000FF;
67
lcd_init();
uart1_init();
uart1_puts(uart1_buf);
lcd_write_control(0x01); // Clear
goto_cursor(0x00); // Set
Cursor Line-1
VICVectCntl0 = 0x20 | 9; // Assigning Highest Priority Slot to I2C0 and enabling this
slot
VICIntEnable = (1<<9);
I2C_Init();
ii = 0;
read_eep();
while(1)
uart_rx = uart1_getkey();
if(uart_rx == '+')
68
{
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);
Buff [ii]=uart_rx;
ii++;
while(ii<MAX)
69
{
ii++;
IOSET0 = 0x00000040;
Wait (5000);
uart1_puts(uart1_buf);
flag = 'W';
I2C_Start (0x70);
Delay();
uart1_puts(uart1_buf);
70
Delay();
Delay();
Delay();
uart1_puts(uart1_buf);
read_eep();
uart1_puts(uart1_buf);
uart1_puts(uart1_buf);
ii=2;
while(ii<MAX)
ii++;
IOSET0 = 0x00000040;
71
Wait (5000);
flag = 'W';
I2C_Start (0x70);
Delay();
uart1_puts(uart1_buf);
Delay();
uart1_puts(uart1_buf);
read_eep();
uart1_puts(uart1_buf);
void Delay(void)
72
{
for(i=0;i<150;i++)
for(j=0;j<900;j++);
while(Delay--);
I2C0SCLL = 150;
return 0;
73
{
while(Count--)
I2C0DAT = *Buff++;
return 0;
void read_eep()
unsigned int i;
goto_cursor(0x40);
flag = 'R';
I2C_Start (0x70);
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';
RESULT:
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:
Procedure:
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;
if (ad_val ^ ad_val_) {
ad_val_ = ad_val;
if (clock_1s) {
clock_1s = 0;
RESULT:
78