AIM: Flashing LED at P0.0, P0.1, P0.2 and P0.3 with 1 sec delay.
THEORY:
The
LED flashing 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 Flash
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 :
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.
Flashing
Observe
LED P0.0 to P0.3 of port 0.
Flashing LED at P0.0, P0.1, P0.2 and P0.3 with 1 sec delay.
In
Embedded c:
#include
<LPC214X.H>
void
delay_1sec(void);
int main(void)
{
PINSEL0=00;
IODIR0=0x0000000F;
while(1)
{
IOSET0=0x0000000F;
Delay_1sec();
IOCLR0=0x0000000F;
Delay_1sec();
}
}
void delay_1sec(void)
{
unsignedinti,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:



Very well explained Arjun sir.
ReplyDeleteI am now awaiting for an individual article on basic commands and interrupts associated with ARM7.
I will get back soon with your basic commands and interrupts associated with ARM7.
ReplyDeletesir would u please explain the function of IOSET,IOCLR,IODIR with example
ReplyDeletesir can you give same analysis for eeprom i2c ic interfacing to lpc 2148 and displaying the data on lcd . i would be very thankful
ReplyDeletesir can please send me that proteus file, because i am starter for arm so can u sir...
ReplyDelete