0% found this document useful (0 votes)
13 views

Embedded Lab

The document outlines a series of experiments involving interfacing various input devices with the LPC2148 microcontroller, including LEDs, seven-segment displays, ADC, and DAC. Each experiment includes an aim, description, requirements, program code, procedure, and results, demonstrating how to implement and verify the functionality of each interfacing task. The document serves as a practical guide for students or engineers working with microcontroller applications.

Uploaded by

vijay
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
0% found this document useful (0 votes)
13 views

Embedded Lab

The document outlines a series of experiments involving interfacing various input devices with the LPC2148 microcontroller, including LEDs, seven-segment displays, ADC, and DAC. Each experiment includes an aim, description, requirements, program code, procedure, and results, demonstrating how to implement and verify the functionality of each interfacing task. The document serves as a practical guide for students or engineers working with microcontroller applications.

Uploaded by

vijay
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/ 46

S.

No Date Experiments Page Date of Mark


No Submission
1 Interfacing Input Device with PIC16F877A
2 Interfacing Input Device Seven Segment
Display Interfacing
3 Interfacing ADC with 8051
4 Interfacing DAC with 8051
5 PWM Wave Generation
6 Interfacing RTC Module
7 Serial Data Transmission Through Universal
Asynchronous Receiver(UART)
8 interrupt performance characteristics of ARM and
FPGA
Ex. No:1 Interfacing Input Device
Aim:
To blink the LEDs by using LPC2148 Dev. Board
Description:
Light Emitting Diodes (LED) is the most commonly used components, usually for
displaying pins digital states. Typical uses of LEDs include alarm devices, timers and
confirmation of user input. FIG shows how to interface the LED to microcontroller. As you
can see the Anode is connected through a resistor to the Microcontroller pin and the Cathode
is connected to ground. So when the Port Pin is HIGH the LED is on & when the Port Pin is
LOW the LED is turned off. The board contains 8 LEDs connected to PORT1 pins 24 to 31.

Block diagram:

Power
Supply

12 MHz LPC 2148


XTAL Processor

RUN/
PRO

GPIO
LED
Port

Reset

*For the module to work, DIP switch S2 must be in ON position


Requirements:
 LPC2148 Dev. Board
 Power Adaptor
 USB Cable

Program:
#include<lpc21xx.h>
void delay(unsigned long val);
int main()
{
IO1DIR = 0xff000000;
while(1)
{

2
IO1SET = 0xff000000;
delay(1000000);
IO1CLR = 0xff000000;
delay(1000000);
}
}
void delay(unsigned long val)
{
while(val>0)
{
val--;
}
}
Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Verify the corresponding DIP switch positions as per in the manual*.
 Reset the dev. Board by using toggle switch.
 Verify the output in the dev board.

Result:
Thus the LEDs are blinked in the board

3
Ex.No.2: Interfacing Input Device Seven Segment Display Interfacing
Aim:
To interface the seven segment, display with LPC2148

Description:
Each segment of the 7-segment display is an individual LED. The standard 7-segment
LED display in the development kit consists of illuminated segments arranged to show
numerical symbols when switched on in the appropriate combination.
Each common anode segment is driven separately from P1.16 – P1.21 via a current-
limiting resistor.
There are 6 seven segment modules in the board. P1.16 – P1.21 pins are used to select
among the modules.

Block Diagram:

Power
Supply

LPC 2148
12 MHz
Processor
XTAL

RUN/ GPIO
7 Segment
PRO Port Display

Reset

*For the module to work, all the switches in the DIP switch (S10 &S11) must be in ON
position.

Requirements:
 LPC2148 Dev. Board
 Power Adaptor
 USB Connector

4
Program:
#include <LPC214X.H>
#define DS1 1<<16 // P1.16
#define DS2 1<<17 // P1.17
#define DS3 1<<18 // P1.18
#define DS4 1<<19 // P1.19
#define DS5 1<<20 // P1.20
#define DS6 1<<21 // P1.21
//#define DS7 1<<22 // P1.22
//#define DS8 1<<23 // P1.23
#define SEG_CODE 0xFF<<16 // Segment Data from P0.16 to P0.23
unsigned char const seg_dat[]={0x5f, 0x06, 0x3b, 0x2f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x67};
void delayms(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<1007;j++) //5035 for 60Mhz ** 1007 for 12Mhz
{;}
}
}
void dirsel()
{
IOCLR0 = SEG_CODE;
IOSET1 = DS1;IOSET1 = DS2;IOSET1 = DS3;IOSET1 = DS4; IOSET1 = DS5;IOSET1 =
DS6;// IOSET1 = DS7; IOSET1 = DS8;
}
int main (void)
{
PINSEL0 = 0; // Configure Port0 as General Purpose IO => P0.0 to P0.15
PINSEL1 = 0; // Configure Port0 as General Purpose IO => P0.16 to P0.31
PINSEL2 = 0;
IODIR0 = SEG_CODE; //Configure Segement data & Select signal as output
while(1)
{
dirsel();
IODIR1 = DS1;
IOCLR1=DS1; //Select DS1
IOSET0 = seg_dat[8]<<16; //Display '8' in DS1
delayms(20);
dirsel();
IODIR1 = DS2;
IOCLR1=DS2; //Select DS2
IOSET0 = seg_dat[7]<<16; //Display '7' in DS2
delayms(50);
dirsel();
IODIR1 = DS3;
IOCLR1=DS3; //Select DS3
IOSET0 = seg_dat[6]<<16; //Display '6' in DS3
delayms(50);

5
dirsel();
IODIR1 = DS4;
IOCLR1=DS4; //Select DS4
IOSET0 = seg_dat[5]<<16; //Display '5' in DS4
delayms(50);
dirsel();
IODIR1 = DS5;
IOCLR1=DS5; //Select DS5
IOSET0 = seg_dat[1]<<16; //Display '1' in DS5
delayms(50);
dirsel();
IODIR1 = DS6;
IOCLR1=DS6; //Select DS6
IOSET0 = seg_dat[2]<<16; //Display '2' in DS4
delayms(50);
dirsel();
IODIR1 = DS7;
IOCLR1=DS7; //Select DS7
IOSET0 = seg_dat[6]<<16; //Display '3' in DS4
delayms(20);
dirsel();
IODIR1 = DS8;
IOCLR1=DS8; //Select DS8
IOSET0 = seg_dat[4]<<16; //Display '4' in DS4
delayms(20);
}
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Verify the corresponding DIP switch positions as per in the manual*.
 Reset the dev. Board by using toggle switch.
 Verify the output.

Result:
Thus the output is displayed in the seven segment display on LPC2148 Dev. Board.

6
Ex.No.3: Interfacing ADC with 8051

Aim:
To study about analog to digital conversion on LPC2148 Dev. Board.
Objective:
The Pot meter is inbuilt in the ARM board to vary the values. The values are displayed in the
display
Description:
A pot meter is an electrical circuit allows reducing the voltage level from the circuit
maximum to ground, or zero level. In order to measure and control the action of the
potentiometer, we need to quantify its action by producing a digital value within the physical
range of the circuit; that is, we need to convert an analog quantity that varies continuously
between 0 and 3.3 volts, to a discrete digital value range. If, in this case, the voltage range of
the potentiometer is from 3.3 to 0 volts, we can digitize its action into a numeric range of 0 to
1023 units. The device that performs either conversion is called an A/D or analog-to-digital
converter. Potentiometer connected to PORT0 29th pin (P0.29) analog channel two. External
analog input is given to PORT0 28th pin (P0.28) analog channel one.
Block Diagram:

Power
Supply

LPC 2148
12 Processor
MHz

RUN/ ADC Analog voltage


PRO
POT Meter

Reset 7 Segment
GPIO Display
Port

*For the internal ADC mode (using pot meter), close the jumper J2.
*For External ADC mode (giving analog voltage<max 3.3v> to the module j11), close the
jumper j1.
*For the module to work, all the switches in the DIP switch (S11 &S10) must be in ON
position.

7
Requirements:

 LPC2148 Dev. Board


 Power Adaptor
 USB Connector
Program:
#include <LPC21xx.H> /* LPC21xx definitions*/
#define DS1 1<<16 // P0.4
#define DS2 1<<17 // P0.5
#define DS3 1<<18 // P0.19
#define DS4 1<<19 // P0.20
#define SEG_CODE 0xFF<<16 // Segment Data from P0.16 to P0.23
unsigned char const seg_dat[]={0x5F, 0x06, 0x3B, 0x2F, 0x66, 0x6D, 0x7d, 0x07, 0x7F,
0x67}; void delayms(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<1007;j++) //5035 for 60Mhz ** 1007 for 12Mhz
{;}
}
}
void dirsel()
{
PINSEL0 = 0; // Configure Port0 as General Purpose IO => P0.0 to P0.15
PINSEL1 = 0; // Configure Port0 as General Purpose IO => P1.16 to P1.31
PINSEL2 = 0;
IODIR0 = SEG_CODE; //Configure Segment data & Select signal as output
IOCLR0 = SEG_CODE;
IOSET1 = DS1;IOSET1 = DS2;IOSET1 = DS3;IOSET1 = DS4;
}
void init_adc()
{
PINSEL1 |= 0X01000000;
ADCR = 0X00200602;
}
int read_adc(void)
{
int val;
ADCR |= 0x01000000; /* Start A/D Conversion */
Do
{
val = ADDR; /* Read A/D Data Register */
}
while (!(val & 0x80000000)); /* Wait for end of A/D Conversion */
ADCR &= ~0x01000000; /* Stop A/D Conversion */
val >>=6;
val= val & 0x3FF;
return(val);
}

8
int main(void)
{
int dat;
int dig4=0,digt3=0,dig3=0,digt2=0,dig2=0,dig=0;
init_adc();
while(1)
{
init_adc();
dat = read_adc();
dig4=dat/1000; // ADC value 1-digit
digt3=(dat-(dig4*1000));
dig3= digt3/100; // ADC value 2-digit
digt2=(dat-((dig4*1000)+(dig3*100)));
dig2=digt2/10; // ADC value 3-digit
dig=(dat-((dig4*1000)+(dig3*100)+(dig2*10))); // ADC value 4-digit
dirsel();
IODIR1 = DS1;
IOCLR1=DS1; //Select DS1
IOSET0 = seg_dat[dig]<<16; //Display '4-digit' in DS1
delayms(20);
dirsel();
IODIR1 = DS2;
IOCLR1=DS2; //Select DS2
IOSET0 = seg_dat[dig2]<<16; //Display '3-digit' in DS2
delayms(20);
dirsel();
IODIR1 = DS3;
IOCLR1=DS3; //Select DS3
IOSET0 = seg_dat[dig3]<<16; //Display '2-digit' in DS3
delayms(20);
dirsel();
IODIR1 = DS4;
IOCLR1=DS4; //Select DS4
IOSET0 = seg_dat[dig4]<<16; //Display '1-digit' in DS4
delayms(20);
}
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.

9
 Put the kit into run mode by using slide switch.
 Reset the dev. Board by using toggle switch.
 Vary the pot meter
 Verify the output in the 7 segment display of the dev board.

Result:
Thus the output is obtained in the 7 segment display on LPC2148 Dev. Board.

10
Ex.No.4 Interfacing DAC with 8051

Aim:
To generate the Sine, Square, Triangular waveform by using DAC.
Description:
LPC2148 has on-chip 10 bit DAC module. Bits 19:18 of the PINSEL1 register, control
whether the DAC is enabled and controlling the state of pin P0.25/AD0.4/AOUT. When these
bits are 10, the DAC is powered on and active.
Block Diagram:

Power
Supply

LPC 2148
12 MHz Processor
XTAL

RUN/
PRO
DAC CRO

Reset

*For the module to work, DIP switch S5 must be ON.

Requirements:
 LPC2148 Dev. Board
 Power Adaptor
 USB Connector
Program:
Sine Wave:
#include <lpc214x.h>
#include <math.h>
#define MSEL 4 //M-1 since M=5
#define PSEL 1<<5 //P-1 since P=2
#define AOUT 1<<19 // PINSEL1 value for AOUT config.
#define PI2 6.28 //2Pi = 3.14*2
#define STEPS 500 // No. of Steps per Cycle.
void clock_select(void)
{
//Fosc = 12Mhz

11
//Select CCLK = 60Mhz & Fcco = 240Mhz
PLL0CFG = PSEL | MSEL;
PLL0FEED=0xAA;
PLL0FEED=0x55;
PLL0CON = 3; //Enable PLL0
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV = 0; //PCLK = CCLK/4 So PCLK = 15Mhz
}
int main(void)
{
unsigned short val, dval; //16bit variable
float sa; //sine angle varies from 0 - 2pi
clock_select(); //CPU Clock Configuration
PINSEL0 = 0; //Configure Port0.0 to P0.15 as General Purpose IO
PINSEL1 = AOUT; //Configure Port0.25 as Analog Output PIN
while(1)
{
for(val=0; val<STEPS; val++)
{
sa = (val*PI2)/STEPS;
sa = sin (sa);
sa = (sa*511.0) + 511.0; //Mid point of 511
dval = sa;
DACR = dval<<6; //Send value to DAC
}
}
}

Square Wave:
#include "lpc214x.h"
#define MSEL 4 //M-1 since M=5
#define PSEL 1<<5 //P-1 since P=2
#define AOUT 1<<19 // PINSEL1 value for AOUT config.
void delayms(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<5035;j++) //5035 for 60Mhz ** 1007 for 12Mhz
{;}
}
}
void clock_select(void)
{
//Fosc = 12Mhz
PLL0CFG = PSEL | MSEL;
PLL0FEED=0xAA;
PLL0FEED=0x55;
PLL0CON = 3; //Enable PLL0
PLL0FEED=0xAA;

12
PLL0FEED=0x55;
VPBDIV = 0; //PCLK = CCLK/4 So PCLK = 15Mhz
}
int main(void)
{
clock_select(); //CPU Clock Configuration
PINSEL0 = 0; //Configure Port0.0 to P0.15 as General Purpose IO
PINSEL1 = AOUT; //Configure Port0.25 as Analog Output PIN
while(1)
{
DACR = 0; //DAC output = 0V
delayms(1); //1 msec Delay
DACR = 0x3FF << 6; //DAC ouput = 2.2V
delayms(1); //1 mSec Delay
}
}

Triangular Wave:
#include "lpc214x.h"
#define MSEL 4 //M-1 since M=5
#define PSEL 1<<5 //P-1 since P=2
#define AOUT 1<<19 // PINSEL1 value for AOUT config.
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<5;j++)
{;}
}
}
void clock_select(void)
{
//Fosc = 12Mhz
PLL0CFG = PSEL | MSEL;
PLL0FEED=0xAA;
PLL0FEED=0x55;
PLL0CON = 3; //Enable PLL0
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV = 0; //PCLK = CCLK/4 So PCLK = 15Mhz
}
int main(void)
{
unsigned short val; //16bit variable
clock_select(); //CPU Clock Configuration
PINSEL0 = 0; //Configure Port0.0 to P0.15 as General Purpose IO
PINSEL1 = AOUT; //Configure Port0.25 as Analog Output PIN
while(1)
{
for(val=0; val<1024; val++)

13
{
DACR = val<<6; //Send value to DAC
delay(3); //3 micro sec Delay
}
for(val=1023; val!=0; val--)
{
DACR = val<<6; //Send value to DAC
delay(3); //3 micro sec Delay
}
}
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Reset the dev. Board by using toggle switch.
 Connect the DAC output terminal to CRO
 Verify the output in the CRO.

Result:
Thus the waveforms are displayed

14
Ex.No.5: PWM WAVE GENERATION
Aim:
To generate PWM waveform in LPC2148 Dev. Board
Description:
In LPC2148 Dev. Board, PWM is generated from PORT0 7th pin which is connected
to the connector J13. The duty cycle of the PWM wave can be varied by using POT METER
(R8).
Block Diagram:

Power
Supply

LPC2148
12 MHz Processor
XTAL

RUN/
PRO
Pot meter

Reset GPIO
PWM
Port
Wave

*For the pot meter module to work, close the jumper J2

Requirements:
 LPC2148 Dev. Board
 USB Connector
 Power Adaptor
Program:
#include <LPC21xx.H> /* LPC21xx definitions */
void PWM0_isr(void) irq
{
PWMIR |= 0x00000001; /* Clear match0 interrupt */
VICVectAddr = 0x00000000;
}
void init_PWM (void)
{
VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWM ISR vector address */
VICVectCntl8 = 0x00000028; /* Set channel */
VICIntEnable = 0x00000100; /* Enable the interrupt */
PINSEL0 |= 0x00008000; /* Enable P0.7 and P0.1 as PWM output */
15
PWMPR = 0x00000000; /* Load prescaler */
PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control, output
enabled*/ PWMMCR = 0x00000003; /* On match with timer reset the counter
*/
PWMMR0 = 0x400; /* set cycle rate to sixteen ticks */
PWMMR1 = 0; /* set rising edge of PWM2 to 100 ticks */
PWMMR2 = 0x200; /* set falling edge of PWM2 to 200 ticks */
PWMMR3 = 0x100; /* set rising edge of PWM3 to 100 ticks */
PWMLER = 0xF; /* enable shadow latch for match 1 - 3 */
PWMTCR = 0x00000002; /* Reset counter and prescaler */
PWMTCR = 0x00000009; /* enable counter and PWM, release counter from reset */
}
void init_adc()
{
PINSEL1 |= 0X04000000;
ADCR = 0X00200604;
}
int read_adc(void)
{
int val;
ADCR |= 0x01000000; /* Start A/D Conversion */
Do
{
val = ADDR; /* Read A/D Data Register */
}
while (!(val & 0x80000000)); /* Wait for end of A/D Conversion */
ADCR &= ~0x01000000; /* Stop A/D Conversion */
val >>=6;
val= val & 0x3FF;
return(val);
}
void Delay ()
{
unsigned int i,j;
for (i=0;i<250;i++)
for (j=0;j<700;j++);
}
int main (void)
{
int dat;
unsigned long oldval = 0;
init_PWM();
while (1)
{ /* Loop forever */
init_adc();
dat = read_adc();
if (dat != oldval)
{
PWMMR2 = dat;
PWMLER = 0xF;
oldval = dat;

16
}
}
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Verify the corresponding DIP switch positions as per in the manual*.
 Reset the dev. Board by using toggle switch.
 Verify the output by connecting the dev board to CRO
 Duty cycle of the PWM can be varied by using Pot meter(R8)

Result:
Thus the PWM waveform is generated.

17
Ex.No.6: Interfacing RTC MODULE
Aim:
To display the real time clock in LCD on LPC2148 Dev. Board.

Description:
LPC2148 has on-chip RTC. The RTC is designed to provide a set of counters to measure
time when normal or idle operating mode is selected. The RTC has been designed to use little
power, making it suitable for battery powered systems where the CPU is not running
continuously (Idle mode).Dedicated power supply pin can be connected to a battery or the main
3.3 V.

Block Diagram:

Power
Supply

LPC 2148
12 MHz Processo
XTAL
r

RUN/
PRO

LCD
GPIO
Port
Reset

*For the LCD module to work, DIP switch S3 & S4 must be ON.

Requirements:

 LPC2148 Dev. Board


 Power Adaptor
 USB Connector

Required Files:
//clcd.h
//clcd.c
//config.h

18
Program:
#include "config.h"
#include "clcd.c"
#define O1 0X07000000
#define O2 0X0B000000
#define O3 0X0D000000
#define O4 0X0E000000
#define I1 0X70000000
#define I2 0XB0000000
#define I3 0XD0000000
#define I4 0XE0000000
#define CLR 0x0F000000
#define SS 0 // Set seconds
#define MN 46 // Set Minutes
#define HH 17 // Set Hour
#define DD 24 // Set Date
#define MM 2 // Set Month
#define YY 15// Set Year
char scan (int);
void delay(int);
void _DelayMs(unsigned int count);
void RtcInit(void);
void RtcSetTime(void);
void CLcdPutTime(void);
void RtcInit(void)
{
PCONP |= 0x00000200;
CCR = 0x00000002;
CIIR = 0x00000000;
AMR = 0x000000FF;
ILR = 0x00000003;
CCR = 0x00000011;
}
void RtcSetTime(void)
{
CCR = 0x00000002;
YEAR = YY;
MONTH = MM;
DOM = DD;
HOUR = HH;
MIN = MN;
SEC = SS;
CCR = 0x00000011;
}
void CLcdPutTime(void)
{
ClcdPutCh('0'+(HOUR/10)); //hour 1-dig
ClcdPutCh('0'+(HOUR%10)); //hour 2-dig
ClcdPutCh(':');
ClcdPutCh('0'+(MIN/10)); //min 1-dig

19
ClcdPutCh('0'+(MIN%10)); //min 2-dig
ClcdPutCh(':');
ClcdPutCh('0'+(SEC/10)); //sec 1-dig
ClcdPutCh('0'+(SEC%10)); //sec 2-dig
}
/* void CLcdPutdate(void)
{
ClcdPutCh('0'+(DOM/10)); //hour 1-dig
ClcdPutCh('0'+(DOM%10)); //hour 2-dig
ClcdPutCh(':');
ClcdPutCh('0'+(MONTH/10)); //min 1-dig
ClcdPutCh('0'+(MONTH%10)); //min 2-dig
ClcdPutCh(':');
ClcdPutCh('0'+(YEAR/10)); //sec 1-dig
ClcdPutCh('0'+(YEAR%10)); //sec 2-dig
} */
int main(void)
{
RtcInit(); //RTC Initialization
ClcdInit();
ClcdCursorOff();
//RtcSetTime(); //Sets time every time the system is reset
ClcdGoto(1,1);
ClcdPutS_P("Real Time Clock");
ClcdGoto(4,2);
ClcdPutS("LABTECH");
_DelayMs(1000);
ClcdClear();
while(1)
{
ClcdGoto(1,1);
ClcdPutS_P("Real Time Clock");
ClcdGoto(5,2);
CLcdPutTime();
_DelayMs(500);
}
}
void _DelayMs(unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
asm
{
nop;
nop;
}
}
}

20
}
void delay(int n) /* generates one milisecond delay */
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Verify the corresponding DIP switch positions as per in the manual*.
 Reset the dev. Board by using toggle switch.
 Verify the output in the dev board.

Result:
Thus the output is displayed in LCD on LPC2148 Dev. Board.

21
Ex.No.7: Serial Data Transmission Through Universal Asynchronous Receiver(UART)

Aim:
To create the communication between PC and LPC2148 using UART on LPC2148 Dev.
Board.
Description:
There are two UART channels on the LPC2148 and only channel #1 has all control signals
needed for a full modem implementation. Channel #0 only has receive and transmit signals.
Channel #1 is free and used by some of the expansion boards.
UART#0 and ISP:
UART#0 on the LPC2148 is connected to a USB-to-serial bridge chip (FT232RL from
FTDI). The serial interface is not a full interface, only the receive and transmit signals are
connected to UART#0. There are two LEDs connected to the USB-to-serial bridge chip. These
indicate Rx and Tx activity and can be a good help when determining if a connection with the
board is working properly. This module is used for programming the MCU.
UART#1:
Here UART#1 is used for serial communication (RS-232).RS-232 communication
enables point-to-point data transfer. It is commonly used in data acquisition applications, for
the transfer of data between the microcontroller and a PC. The voltage levels of a
microcontroller and PC are not directly compatible with those of RS-232, a level transition
buffer such as MAX3232 be used.
Block Diagram:

Power
Suppl

LPC 2148
12 MHz Processor
XTAL

RUN/
PRO UART PC

GPIO
Reset LCD
Port

*For the module to work, all the switches in the

DIP switches S3 and S4 must be in ON position

22
Requirements:
 LPC2148 Dev. Board
 Power Adaptor
 USB Connector
Required Files:
//serial.h
//serial.c
//clcd.h
Program:
#include <LPC21xx.H> /* LPC21xx definitions*/
#include "serial.h"
#include "clcd.h"
#include "string.h"
#define _SET_RS() CTRL_PORT_SET |= ((unsigned long)(1)<<CTRL_RS)
#define _SET_EN() CTRL_PORT_SET |= ((unsigned long)(1)<<CTRL_EN)
#define _SET_RW() CTRL_PORT_SET |= ((unsigned long)(1)<<CTRL_RW)
#define _CLEAR_RS() CTRL_PORT_CLR |= ((unsigned long)(1)<<CTRL_RS)
#define _CLEAR_EN() CTRL_PORT_CLR |= ((unsigned long)(1)<<CTRL_EN)
#define _CLEAR_RW() CTRL_PORT_CLR |= ((unsigned long)(1)<<CTRL_RW)
#define _EnToggle() {_SET_EN(); asm{nop;nop;}_CLEAR_EN();}
#define _TYPE_CMD 0
#define _TYPE_DATA 1
volatile unsigned char uSDelay;
void _Itoa(int n, char *s);
void _Reverse(char *s);
void _ClcdDelayMs(unsigned int delay);
void _ClcdDelay45Us(void);
void ClcdInit(void)
{
DATA_DIR |= (unsigned long)(DATA_PORT); //initialize D4:D7 pins as output
CTRL_DIR |= ((unsigned long)(1)<<CTRL_RS); //initialize RS pins as output
CTRL_DIR |= ((unsigned long)(1)<<CTRL_EN); //initialize EN pins as output
CTRL_DIR |= ((unsigned long)(1)<<CTRL_RW); //initialize EN pins as output
_CLEAR_EN(); //clear EN
_CLEAR_RS();
_CLEAR_RW(); //clear RS
_ClcdDelayMs(300);
ClcdSendByte(0X03,0); //Configure bus width as 8-bit
_ClcdDelayMs(50);
ClcdSendByte(0X02,0); //Configure bus width as 4-bit, 1 line,5X7 dots
_ClcdDelayMs(50);
ClcdSendByte(0X28,0); //Configure bus width as 4-bit, 2 line,5X7 dots
_ClcdDelayMs(50);
ClcdSendByte(0X10,0); //Cursor move and Shift to left
_ClcdDelayMs(1);
ClcdSendByte(0x0D,0); // DisplayOn,CursorOff

23
_ClcdDelayMs(1);
ClcdSendByte(0x06,0); // EntryMode,Automatic Increment - No Display shift.
_ClcdDelayMs(1);
ClcdSendByte(0x01,0); //Clear Display and set address DDRAM with 0X00
_ClcdDelayMs(5);
}
void ClcdSendByte(unsigned char byte,unsigned char type)
{
_CLEAR_EN();
if(type==_TYPE_DATA)
{
_SET_RS(); // Selects data Register for read / write
}
else if(type==_TYPE_CMD)
{
_CLEAR_RS(); // Selects cmd Register for write
}
_ClcdDelay45Us();
DATA_PORT_CLR |= DATA_PORT; //Clear Data Port
DATA_PORT_SET |= ((((unsigned long)byte >> 4) & 0x0F)<<D4);//Send byte to Data port
_EnToggle();
_ClcdDelay45Us();
DATA_PORT_CLR |= DATA_PORT; //Clear Data Port
DATA_PORT_SET |= (((unsigned long)byte & 0x0F)<<D4); //Send byte to Data
port
_EnToggle();
_ClcdDelay45Us();
}
void ClcdPutS(char *str)
{
unsigned char *str1 = (unsigned char*) str;
while(*str1) //Check for valid character
{
ClcdSendByte(*str1++,_TYPE_DATA); //Send out the current byte pointed to
}
}
void ClcdPutS_P(const char *str)
{
while(*str) //Check for valid character
{
ClcdSendByte(*str++,_TYPE_DATA);//Send out the current byte pointed to
}
}
void _Reverse(char *s)
{
unsigned char i, j;
char c;
for (i = 0, j = strlen(s)-1; i<j; i++, j--)
{
c = s[i];
s[i] = s[j];

24
s[j] = c;
}
}
void _Itoa(int n, char *s)
{
int sign;
unsigned char i;
if ((sign = n) < 0) // record sign
n = -n; // make n positive
i = 0;
do
{ // generate digits in reverse order
s[i++] = n % 10 + '0'; // get next digit
}
while ((n /= 10) > 0); // delete it
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
_Reverse(s);
}
void ClcdPutNum(int n)
{
char str[7];
_Itoa(n, str);
ClcdPutS(str);
}
void ClcdPutFloat(float f)
{
char str[7]={0};
char a;
_Itoa((int)f, str);
ClcdPutS(str);
ClcdPutCh('.');
a = ((char)(100*(f - (int)f)));
if(a<0)
{
a = -a;
}
_Itoa(a, str);
ClcdPutS(str);
}
void ClcdGoto(unsigned char x,unsigned char y)
{
switch(y)
{
case 1:
y=0x80 ;
break;
case 2:
y=0xC0 ;
break;

25
case 3:
y=0x94 ;
break;
case 4:
y=0xD4 ;
break;
default:
break;
}
ClcdSendByte((x-1+y),_TYPE_CMD);
}
void ClcdClear()
{
ClcdSendByte(0x01,_TYPE_CMD); //Clear Display and set address DDRAM with 0X00
_ClcdDelayMs(2); // delay after sending clear command
}
void _ClcdDelayMs(unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
asm
{
nop;
nop;
}
}
}
}
void _ClcdDelay45Us(void)
{
volatile unsigned int k;
for(k=0;k<409;k++)
{
asm
{
nop;
}
}
}

void _DelayMs(unsigned int count)


{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
asm

26
{
nop;
nop;
}
}
}
}
int main(void)
{
int j=0;
char str[2];
ClcdInit();
ClcdPutS(" LABTECH'S ");
ClcdGoto(1,2);
ClcdPutS(" ARM TRAINER ");
_DelayMs(1000);
ClcdClear(); //clear display
init_serial (); /* initialise serial port with 9600bps*/
sendchar ('B');
while(1)
{
str[0]=getchar();
sendchar(str[0]);
ClcdPutS(str);
}
}

Procedure:
 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Reset the dev. Board by using toggle switch.
 Open the HyperTerminal to check the communication.
 Follow the Steps given in the Appendix-C to open hyper terminal
 Set the Baud Rate as 4800.
 Connect the UART cable to the PC and type any letter in the PC. It will be displayed
in the LCD.
 Verify the output in the dev board.

27
Result:
Thus the output is obtained by using UART communication on LPC2148 Dev. Board.

28
Ex.No.18: INTERRUPT PERFORMANCE CHARACTERISTICS OF ARM AND
FPGA

Aim:
To study the interrupt performance characteristics of ARM and FPGA using LPC2148
Dev. Board and FPGA trainer.

Description:

An interrupt is an asynchronous signal calling for processor attention. Interrupts can


originate in hardware or in software. The interrupt mechanism is a way to avoid wasting
processor time, since without interrupts code has to poll hardware devices in ineffective, closed
loops. With interrupts, the processor can continue to do its work since the interrupt mechanism
ensures that the CPU receives a signal whenever an event occurs that requires its attention.
Interrupt performance analysis can be made here by generate the interrupt to initiate the BCD
counter in both ARM and FPGA trainers. The external interrupt pin of LPC2148 is PORT0
15th pin (P0.15).Also for FPGA trainer we can set any pin as interrupt pin (here p106).

Block Diagram:
LPC2148 Dev. Board:

Power
Suppl

12 MHz LPC 2148


XTAL Processor

RUN/
PRO
External
GPIO Interrupt
Port

Reset
LED

*For interrupt module to work, the jumper J10 should be closed.

*For LED module to work, DIP switch(S2) must be in ON position.

29
FPGA trainer:

Power
Suppl

Xilinx
SPARTAN3E
4 MHz XC3S250E
XTAL

External
Interrupt
Switch

GPIO
Port
Reset
LED

Requirements:
 LPC2148 Dev. Board
 FPGA trainer
 Power Adaptor
 USB Connector
 Parallel cable

Program for LPC2148 Dev. Board:


#include <lpc214x.h>
#define PLOCK 0x00000400
#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1
int volatile EINT2 = 0;
void ExtInt_Serve2(void) irq;
void delay(unsigned int milliseconds);
void initClocks(void);
void initTimer0(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also =
60Mhz.*/
T0CTCR = 0x0;
T0PR = PRESCALE-1;

30
//(Value in Decimal!) - Increment T0TC at every 60000 clock cycles //Count
begins from zero hence subtracting 1 //60000 clock cycles @60Mhz = 1 m
T0TCR = 0x02; //Reset Timer
}
void delay(unsigned int milliseconds) //Using Timer0
{
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
while(T0TC < milliseconds); //wait until timer counter reaches the desired delay
T0TCR = 0x00; //Disable timer
}
void initClocks(void)
{
setupPLL0();
feedSeq(); //sequence for locking PLL to desired freq.
connectPLL0();
feedSeq(); //sequence for connecting the PLL as system clock
//SysClock is now ticking @ 60Mhz!
VPBDIV = 0x01; // PCLK is same as CCLK i.e 60Mhz //PLL0 Now configured!
}
//---------PLL Related Functions :---------------
void setupPLL0(void)
{
//Note : Assuming 12Mhz Xtal is connected to LPC2148.
PLL0CON = 0x01; // PPLE=1 & PPLC=0 so it will be enabled
// but not connected after FEED sequence
PLL0CFG = 0x24; // set the multipler to 5 (i.e actually 4)
// i.e 12x5 = 60 Mhz (M - 1 = 4)!!!
// Set P=2 since we want FCCO in range!!!
// So , Assign PSEL =01 in PLL0CFG as per the table.
}
void feedSeq(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}
void connectPLL0(void)
{
// check whether PLL has locked on to the desired freq by reading the lock bit
// in the PPL0STAT register
while( !( PLL0STAT & PLOCK ));
// now enable(again) and connect
PLL0CON = 0x03;
}
/* < INT2 Initialization > */
void ExtInt_Init2(void)
{
EXTMODE |= 4; //Edge sensitive mode on EINT2
EXTPOLAR = 0; //Falling Edge Sensitive
PINSEL0 |= 0x80000000; //Enable EINT2 on P0.15
VICVectCntl1 = 0x20 | 16; //Use VIC1 for EINT2 ; 16 is index of EINT2

31
VICVectAddr1 = (unsigned long) ExtInt_Serve2;//Set Interrupt Vec Addr in
VIC1
VICIntEnable |= 1<<16; //Enable EINT2
}

/* < Main Function > */


int main(void)
{
initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz
initTimer0(); //Initialize Timer0
IO1DIR = 0xff000000;
ExtInt_Init2(); //Initialize Interrupt 2
while(1)
{
IO1SET = 0xf0000000;
delay(500);
IO1CLR = 0xff000000;
delay(500);
IO1SET = 0xf0000000;
delay(500);
IO1CLR = 0xff000000;
while(EINT2==1)
{
IO1SET = 0x01000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x02000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x03000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x04000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x05000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x06000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x07000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x08000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x09000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0a000000;

32
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0b000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0c000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0d000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0e000000;
delay(1000);
IO1CLR = 0xff000000;
IO1SET = 0x0f000000;
delay(1000);
IO1CLR = 0xff000000;
}
else EINT2=0;
}}
/* < Interrupt Sub-Routine > */
void ExtInt_Serve2(void) irq
{
++EINT2;
EXTINT |= 4;
VICVectAddr = 0;
}

Procedure for Programming the LPC 2148 Dev.Board:


 Open Keil Compiler software in PC.
 Follow the steps given in Appendix-A.
 Type the program as given above.
 Build the program and create the hex file.
 Connect the USB cable between PC and LPC2148 Dev. Board.
 Put the kit into program mode by using slide switch.
 Open Flash Magic software.
 Follow the steps given in Appendix-B.
 Browse the file and embed in the kit.
 Put the kit into run mode by using slide switch.
 Verify the corresponding DIP switch positions as per in the manual*.
 Reset the dev. Board by using toggle switch.
 Initially the LEDs are blinking with interval of 1 second.
 When you press the interrupt switch, then the LEDs are act as a BCD counter. Here the
delay will be 1 second.
 Verify the output.

33
Program for FPGA Trainer:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity intcounter is
Port ( clk : in STD_LOGIC;
blink :in std_logic;
intrpt : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (3 downto 0);
le_out : out STD_LOGIC_VECTOR (3 downto 0));
end intcounter;
architecture Behavioral of intcounter is
signal count,delay,coun,dela :integer:=0;
begin

process (clk)
begin
if rising_edge(clk) then
coun<=coun+1;
if coun=4000000 then
dela<=dela+1;
coun<=0;
end if;
if blink='1' then
case dela is
when 1=>
le_out<="1111";
when 2=>
le_out<="0000";
dela<=0;
when others =>
end case;
else
le_out<="0000";
dela<=0;
coun<=0;
end if;
end if;
end process;

process(clk)
begin
if rising_edge(clk) then
count<=count+1;
if count=1000000 then
delay<=delay+1;
count<=0;
end if;
if intrpt='1' then

34
case delay is
when 1=>
led <= "0001";
when 2=>
led <= "0010";
when 3=>
led <= "0011";
when 4=>
led <= "0100";
when 5=>
led <= "0101";
when 6=>
led <= "0110";
when 7=>
led <= "0111";
when 8=>
led <= "1000";
when 9=>
led <= "1001";
when 10=>
led <= "1010";
when 11=>
led <= "1011";
when 12=>
led <= "1100";
when 13=>
led <= "1101";
when 14=>
led <= "1110";
when 15=>
led <= "1111";
delay<=0;
when others =>
end case;
else
led<="0000";
delay<=0;
count<=0;
end if;
end if;
end process;
end Behavioral;

35
Procedure for Programming FPGA Trainer:
 Open Xilinx software
 Create new project and save the project
 Create the VHDL module and type the above program
 Assign package pins(clk-p181,intrpt-p106,blink-p107,
led-p200, p199, p197, p196, le_out-p179, p187, p189, p190)
 Synthesis the project and generate PROM file
 Connect the kit with PC using Parallel cable
 Download the program into the kit
 Reset the trainer
 Now enable the blink switch, the LEDs are blinking
 Also enable the interrupt switch then the LEDs are act as a BCD counter, here the delay
will be 1second.
 Verify the output

Result:

Thus the interrupt performance characteristics of ARM and FPGA were studied and analyzed
using LPC2148 Dev. Board and FPGA trainer.

36
Keil Compiler:

Step1: Click for KEIL μVISION4 Icon, which appears after Installing Keil KEIL μVISION4.

37
Step2: Click on Project Menu, Then New μVision Project.

Step3: Create New Project Folder named as “Keil Test”.

38
Step 4: Select Target Device Vendor (i.e.).

Step 5: Then select specific chip LPC2148.

 Then you will see following window.

39
Step 6: Now Click on File Menu and Click on New.

Step 7: Write Code for Blink LED in C and FileName.c Save.

40
Step 8: Now you Window in C Syntax.

Step 9: Now you add LED.c file by adding Source Group 1 Add files to Group ‘Source
Group 1’.

41
Step 10: Add LED.C file.

Step 11: Now Click on Options for Target ‘Target 1’.

42
Step 12: Go to Options for Target ‘Target 1’. Click on Check Box Create HEX File.

Step 13: Then go to Linker. Click on Use Memory Layout for Target Dialog.

43
Step 14: Then Click on Rebuild All Target Files

Step 15: Now you see 0 Error(s), 0 Warning (s). Then Hex File will create in Specific Folder.
Now to download it for you target hardware.

44
Flash Magic:

Step 1: Run the Flash Magic

45
Step 2: Change the settings as shown below

46

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy