0% found this document useful (0 votes)
22 views9 pages

Lab Manual - EP - RGB - LED

Uploaded by

glvyshnavi
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)
22 views9 pages

Lab Manual - EP - RGB - LED

Uploaded by

glvyshnavi
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/ 9

EXPERIMENT NO.

:____ Date of performance:_________

Title: Interfacing LPC1768 to Seven Segment Display/RGB LED

PART A
Aim: Write Embedded ‘C’ program to interface seven segment using LPC1768.

Learning Objectives:
The objective of this lab is to learn how to interface seven segment to LPC1768.

Equipments used:
SOFTWARE: LPCXPRESSO, Flash Magic. OS-Window 7
HARDWARE: PC, LPC1768 board, DB-9 Connector (female-Male), Seven Segment, Connecting Wires,
registers.

PRELAB:
1. Explain the function of PCON and PCONP register.
2. Which registers are associated with fast GPIO? Explain.
3. Draw the interfacing diagram.

Introduction

Seven segment:

Seven segment displays are commonly used to display digits in many applications. Out
of ten pins in the display the middle pin of each row are the power pins and the
remaining eight pins to control the seven segment digits. Since the seven segments
used is common anode the corresponding segments connected to ground is turned ON.

Shift register:

These are integrated circuits which provides easy control of 7 segment LED
displays using a minimum of 3 digital outputs; clock pin, data pin, latch pin to
the LPC1768.

Example: counter to count from 0-99 using two seven segment display
A seven segment display is the most basic electronic display device that can
display the digits from 0-F (hexadecimal numbers). The seven segment pins
(a,b,c,d,e,f,g) plus the decimal point of a common anode display are connected
to port pins of LPC1768 via current limiting resistors (220Ω). The program is
developed using LPCxpresso software to display hexadecimal numbers 0-F on
the display. The software is developed based on following algorithm.
 Initialize the board
T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.
 Initialize the seven segment display with variables.
 Set the control direction register IODIR to configure the GPIO port pins as output pins.
 Display the hex numbers on seven segment display in up counter manner.

POSTLAB:
1. What is the role of pin connect block? How it is used to configure port pins?
Conclusion:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

Staff I/C signature


Appendix I: Program
Appendix II: Algorithm and Flowchart

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


#include "LPC17xx.h"
#include <Stdio.h>
#include "sevenseg.h"

/*
Initialises the I2C protocol and port pins.
*/
void I2C_Init (void)
{
// Power on I2C1 peripheral
PCONP |= 0x00080000;

// Define port pin as SDA and SCL


PINSEL0 |= 0x0000000F ;

I2C1CONCLR = 0x6C; // clear all I2C config bits


I2C1CONSET = 0x40; // set I2EN

// I2C Clock Duty Cycle (high and low), Bit freq.= 100KHz
I2C1SCLH = 60;
I2C1SCLL = 60;
}

/*
Waits until given status occured.
Return: True on status occured and
False on time out
*/

/***************************************************
Main function.
****************************************************
*/

void SevenSeg(unsigned char dis1, unsigned char dis2);


void SevenSeg(unsigned char dis1, unsigned char dis2)
{

unsigned int i;
I2C1CONSET = 0x20; // Start set

I2C1CONCLR = 0x2C; // clear all except I2EN


I2C1DAT = I2CEXPANDER_ADDR;// addr[0]=0 means I2C write
for(i=0;i<300;i++);
I2C1CONCLR = 0x2C; // clear all except I2EN

I2C1DAT = dis1 ; // Data on DIS1


for(i=0;i<300;i++);
I2C1CONCLR = 0x2C; // clear all except I2EN

I2C1DAT = dis2 ; // Data on DIS2


for(i=0;i<300;i++);
I2C1CONCLR = 0x2C; // clear all except I2EN

I2C1CONSET = 0x10; // generate stop condition


for(i=0;i<300;i++);
I2C1CONCLR = 0x2C;

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


}

void SmallDelay()
{
unsigned int i,j ;
for( i = 0 ; i < 3000000 ; i++)
{
j++ ;
j--;
}
}
void main(void)
{
TargetResetInit();
I2C_Init();

while(1)
{
SevenSeg(DISPLAY_0, DISPLAY_1);
SmallDelay();
SevenSeg(DISPLAY_2, DISPLAY_3);
SmallDelay();
SevenSeg(DISPLAY_4, DISPLAY_5);
SmallDelay();
SevenSeg(DISPLAY_6, DISPLAY_7);
SmallDelay();
SevenSeg(DISPLAY_8, DISPLAY_9);
SmallDelay();
SevenSeg(DISPLAY_A, DISPLAY_B);
SmallDelay();
SevenSeg(DISPLAY_C, DISPLAY_D);
SmallDelay();
}
}

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


PART B
Aim: Write Embedded ‘C’ program to interface RGB LED using LPC1768.

Learning Objectives:
The objective of this lab is to learn how to interface RGB LED to LPC1768.

Equipments used:
SOFTWARE: LPCXPRESSO, Flash Magic. OS-Window 7
HARDWARE: PC, LPC1768 board, DB-9 Connector (female-Male), Seven Segment, Connecting Wires,
registers.

PRELAB:
1. Draw the interfacing diagram.
2. List the SFR used to generate PWM in LPC 1768.

Introduction
PWM

Pulse Width Modulation, or PWM, is a well known technique used in power controlling delivering the
preferred amount of power to the load. It outputs the analog results with digital means.

Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern
can simulate voltages in between full on (3.3 Volts) and off (0 Volts) by changing the portion of the time
the signal spends on versus the time that the signal spends off. The duration of "on time" is called the
pulse width. The longer the ON period compared to the OFF period, the higher the power supplied to the
load is. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off
pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0
and 3.3v controlling the brightness of the LED.

RGB LED

RGB led is nothing but three primary color LEDs namely Red, Green, Blue are cascaded in a single
package. This LED's are widely used to obtain the desired colors by the additive mixing of these colors.
The RGB LEDs are available either in common anode or common cathode mode If these three LEDs
share the same positive (anode) terminal, which means that this RGB LED has a "common anode"
connection. To control each color, simply connect its cathode pin to ground (through a resistor as a
current limiter), and it will light up.

Controlling the Brightness of the RGB LED with PWM outputs from the controller

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


For this demo, we are connecting a tri-color RGB LED to the microcontroller with PWM ("virtual
analog") outputs to control the brightness of each color, the PWM values are continuously varied using
simple looping statements within the coding hence you can see the different colors at the output.

Conclusion:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

Staff I/C signature


Appendix I: Program
Appendix II: Algorithm and Flowchart

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically


// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "lpc17xx.h"
#include <stdint.h>
#include "pwm.h"

volatile unsigned int *MR_Reg ;


unsigned char flag=0,flag1 = 0;
int i = 0;

void RedLedGlow(void);
void GreenLedGlow(void);
void BlueLedGlow(void);
void ALLLedGlow(void);
void updateCount(unsigned int *MR_Register, int val );
/******************************************************************************
** Main Function main()
******************************************************************************/
int main (void)
{
SystemInit();
while(1)
{
RedLedGlow();
GreenLedGlow();
BlueLedGlow();
ALLLedGlow();
}//end of while
}

void RedLedGlow(void)
{
PWM_Init( RED, PWM_CYCLE );
MR_Reg = (volatile unsigned int *)&(LPC_PWM1->MR1);
updateCount(MR_Reg,LER1_EN);
}

void GreenLedGlow(void)
{
PWM_Init( GREEN, PWM_CYCLE );
MR_Reg = (volatile unsigned int *)&(LPC_PWM1->MR2);
updateCount(MR_Reg,LER2_EN);
}

void BlueLedGlow(void)
{
PWM_Init( BLUE, PWM_CYCLE );
MR_Reg = (volatile unsigned int *)&(LPC_PWM1->MR3);

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


updateCount(MR_Reg,LER3_EN);
}

void ALLLedGlow(void)
{
int complete = 0, count = 0;

flag = 0x00;
flag1 = 0x00;
PWM_Init( ALL, PWM_CYCLE );
while(complete == 0)
{
for(i=0;i<=PWM_OFFSET;i++); // delay
if(flag == 0x00)
{
LPC_PWM1->MR1 = LPC_PWM1->MR1 + 10;
LPC_PWM1->MR2 = LPC_PWM1->MR2 + 10;
LPC_PWM1->MR3 = LPC_PWM1->MR3 + 10;
LPC_PWM1->LER = LER1_EN | LER2_EN | LER3_EN ;
if(LPC_PWM1->MR2 >= 49000)
{
flag = 0xff;
flag1 = 0xff;
if(count == 1)
complete = 1;
LPC_PWM1->LER = LER1_EN | LER2_EN | LER3_EN ;
}
}
else if(flag1 == 0xff)
{
LPC_PWM1->MR1 = LPC_PWM1->MR1 - 10;
LPC_PWM1->MR2 = LPC_PWM1->MR2 - 10;
LPC_PWM1->MR3 = LPC_PWM1->MR3 - 10;
LPC_PWM1->LER = LER2_EN ;
if(LPC_PWM1->MR2 <= 500)
{
flag1 = 0x00;
flag = 0x00;
count = 1;
LPC_PWM1->LER = LER1_EN | LER2_EN | LER3_EN ;
}
}
}
}

void updateCount(unsigned int *MR_Register, int val )


{
int complete = 0, count = 0;
flag = 0x00;
flag1 = 0x00;
while(complete == 0)
{
for(i=0;i<=PWM_OFFSET;i++); // delay
if(flag == 0x00)
{
*MR_Register = *MR_Register + 10;
LPC_PWM1->LER = val ;
if(*MR_Register >= 49000)

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.


{
flag1 = 0xff;
flag = 0xff;
if(count == 1)
complete = 1;
LPC_PWM1->LER = val ;
}
}
else if(flag1 == 0xff)
{
*MR_Register = *MR_Register - 10;
LPC_PWM1->LER = val ;
if(*MR_Register <= 500)
{
flag = 0x00;
flag1 = 0x00;
count = 1;
LPC_PWM1->LER = val ;
} }
} }

uint32_t PWM_Init( enum color Color, uint32_t cycle )


{
if(Color == RED)
{
LPC_PINCON->PINSEL4 = 0x00000001 ;//0x00001555; /* set GPIOs for all PWM pins on PWM0 */
LPC_PWM1->LER = LER0_EN | LER1_EN ;
LPC_PWM1->PCR = PWMENA1 ;
}
else if (Color == GREEN)
{
LPC_PINCON->PINSEL4 = 0x00000004 ;//0x00001555; /* set GPIOs for all PWM pins on PWM0 */
LPC_PWM1->LER = LER0_EN | LER2_EN ;
LPC_PWM1->PCR = PWMENA2 ;
}
else if(Color == BLUE)
{
LPC_PINCON->PINSEL4 = 0x00000010 ;//0x00001555; /* set GPIOs for all PWM pins on PWM0 */
LPC_PWM1->LER = LER0_EN | LER3_EN ;
LPC_PWM1->PCR = PWMENA3 ;
}
else if(Color == ALL)
{
LPC_PINCON->PINSEL4 = 0x00000015 ;//0x00001555; /* set GPIOs for all PWM pins on PWM0 */
LPC_PWM1->LER = LER0_EN | LER2_EN | LER2_EN | LER3_EN;
LPC_PWM1->PCR = PWMENA1 | PWMENA2 | PWMENA3;
}
LPC_PWM1->TCR = TCR_RESET; /* Counter Reset */
LPC_PWM1->PR = 0x00; /* count frequency:Fpclk */
LPC_PWM1->MCR = PWMMR0I; /* interrupt on PWMMR0, reset on PWMMR0, reset
TC if PWM0 matches */
LPC_PWM1->MR0 = cycle; /* set PWM cycle */
LPC_PWM1->MR1 = cycle * 5/6;
LPC_PWM1->MR2 = cycle * 5/6; //cycle * 2/3;
LPC_PWM1->MR3 = cycle * 5/6 ; // cycle * 1/2;
LPC_PWM1->TCR = TCR_CNT_EN | TCR_PWM_EN; /* counter enable, PWM enable */
return (1); }

T.E. E& TC (Embedded Processors) Department of E & TC, SITRC, Nashik.

You might also like