Lab Manual - EP - RGB - LED
Lab Manual - EP - 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:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
/*
Initialises the I2C protocol and port pins.
*/
void I2C_Init (void)
{
// Power on I2C1 peripheral
PCONP |= 0x00080000;
// 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.
****************************************************
*/
unsigned int i;
I2C1CONSET = 0x20; // Start set
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();
}
}
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
Conclusion:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "lpc17xx.h"
#include <stdint.h>
#include "pwm.h"
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);
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 ;
}
}
}
}