Thursday, 8 August 2013

Chasing LED i.e. (Flash one LED right to left and left to right at P0.0 to P0.7).



AIM: Chasing LED i.e. (Flash one LED right to left and left to right at P0.0 to P0.7).

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 Chase 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 Chase
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.
Flashing & Chasing:
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:
Chasing
            Observe LED P0.0 to P0.7 of port 0.


Chasing LED i.e. (Flash one LED right to left and left to right at P0.0 to P0.7).
In Embedded c:
#include <LPC214X.H>
void delay(void);
int i,j;
# define right_left     (1<<i)
# define left_right     (1<<j)
int main(viod)
{
  PINSEL0=00;
  IODIR0=0x000000FF;
  while(1)
  {
            for(i=0;i<=7;i++)
            {
            IOSET0= right_left;
            delay();
             IOCLR0= right_left ;
            delay();
            }
            for(j=7;j>=0;j--)
            {
            IOSET0= left_right ;
            delay();
            IOCLR0= left_right;
            delay();
            }
  }
  }
  void delay(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