Wednesday, 14 August 2013

Successively off LED and Using AND/OR operation flashing of LED in LPC2148


AIM: 1) Set LED P0.0 to P0.7 first and then successively off it.
            2) Flash LED at P0.1, P0.2, P0.20 and P0.21 using AND/OR operation.

THEORY:
The LED flashing / chasing can be implemented using software delay and port pin handling.
PINSEL, IODIR, IOSET and IOCLR these four registers are very important registers when we consider port I/O operation.

1) PINSEL
function
Code
1st Function (GPIO)
00
2nd Function
01
3rd Function
10
4th Function
11

2) IODIR
IODIR register used for setting Input/output direction of the port. Binary 1 is used for setting pin as an OUTPUT and binary 0 is used for making pin as an INPUT.

3) IOSET and IOCLR
IOSET and IOCLR registers are used for making particular pin high and low.

To flash the LEDs we need to
    1. Select the required port pins as port I/O pins. (i.e.) we have to select the function of the pins using  PINSEL0, PINSEL1 registers. This is not strictly necessary in this experiment since the default pin function is always port I/O.
    2.Then we need to select the direction of above mentioned pins as output. For this we need to use IODIR0 and IODIR1 registers.
    3.Then we need to set the pins as HIGH, provide some delay, make the same pins LOW, provide delay again then loop back.


PORCEDURE:
For creating project, we need to take following steps.
1) Create new project
2) Algorithm
3) Simulation of Algorithm
These three steps are involved in procedure.
1) Create new project
1.   Select a new project and give particular name to that project. e.g  successively_off &
     AND_OR.
2.   Select chip NXP (founded by Philips) LPC2148.
3.   For assembly language don’t add startup file.
4.   Select a new editor file, write logic in that file and save it by using .c extension in embedded c language.

2) Algorithm
Algorithm consists of following steps.
Successively_off & AND/OR :
1.   Select pin function
2.   Set the direction of the port
3.   Make particular pin high by using IOSET.
4.   After setting, call delay.
5.   Clear pins by using IOCLR.
6.   After clearing, call delay.

3) Simulation of Algorithms
It consists of following steps.
1.   After writing program just build it.
2.   If there are any errors, they will be due to some mistake in typing the program. To locate the error, double click on the first error. Check for the error and remove it. Repeat this till all errors are gone.
3.   Now it’s time to debug. Click on the debug tab and debug program and observe contents of the variables in embedded c programming.

OBSERVATIONS:
Successively off
            Observe pins P0.0 to P0.7 of port 0.
Flashing
            Observe pins P0.0, P0.1, P0.20 and P0.21 of port 0.
  
1) Set LED P0.0 to P0.7 first and then successively off it.
In Embedded c:
#include <LPC214X.H>
void delay_1sec(void);
int i;
# define succesively_off     (1<<i)
int main(void)
{
            PINSEL0=00;
            IODIR0=0x000000FF;
             while(1)
            {
            IOSET0=0x000000FF;
            delay_1sec();
            for(i=0;i<=7;i++)
            {
             IOCLR0= succesively_off ;
            delay_1sec();
            }
            }
}
void delay_1sec(void)
{
unsigned int i,j,k;
for(i = 10; i > 0; i--)
{
for(j = 20; j > 0; j--)                            
{
for(k = 250; k > 0; k--)
{;}
}
}

}  
Port Pin output:


Square wave output:


Proteus design:



2) Flash LED at P0.1, P0.2, P0.20 and P0.21 using AND/OR operation
In Embedded c:
#include <LPC214X.H>
void delay_1sec(void);
int main(void)
{
            PINSEL0 = 00;
            IODIR0 = 0x0000000F;
            IODIR0 = IODIR0 | 0x0F00000;
            while(1)
            {

            IOSET0 = 0x00000006 |  0x00300000;
            delay_1sec();

            IOCLR0 = 0x00000006 |  0x00300000;
            delay_1sec();

            }
}
void delay_1sec(void)
            {
            unsigned int i,j,k;
            for(i = 10; i > 0; i--)
            {
            for(j = 20; j > 0; j--)
            {
            for(k = 250; k > 0; k--)
            {;}
            }
            }
}   

Square wave output:


Port Pin Output:


 Proteus Design:

No comments:

Post a Comment