Saturday, 22 June 2013

Key sensing and activating LED, Relay and Buzzer in ARM LPC2148



AIM: Sense key and activate following devices.

Sense key from P0.0
Activate LED and Relay connected at P0.3 and P0.6 resp.
Sense key from P0.1
Activate LED and Relay connected at P0.4 and P0.7 resp.
Sense key from P0.2
Activate Buzzer connected at P0.5.


THEORY:
Sensing a key connected directly to a pin is simple. We need to read the port to which the key is connected and then test the bit corresponding to the pin connected to the key.
For sensing a key and activating LED based on the key state, we need to,
1.   Set the pin functions as I/O. For this we used PINSEL0 register.
2.   Set the directions of P0.0, P0.1 and P0.2 as input since, the keys are connected to these pins.
3.   Set the directions of pins P0.3, P0.4, P0.5, P0.6 and P0.7 as output since, these are connected to LED, Buzzer and Relay respectively.

PROCEDURE:
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  key_sensing
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.
Key sensing:
1.   Select pin function
2.   Set the direction of the port
3.   Make particular pin high by using IOSET.
4.   Clear pins by using IOCLR.

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:
1.   Observe pins P0.0, P0.1 and P0.2 connected to key & working as a input
2.   Observe pins P0.3 and P0.4 connected to LEDs.
3.   Observe pin P0.5 connected to Buzzer.
4.   Observe pins P0.6 and P0.7 connected to relays.





Sense key and activate devices.
In Embedded c:

#include <LPC214X.H>
int main(void)
{
PINSEL0=00;
IODIR0=0x000000F8;
            while(1)
            {

            if(IOPIN0 & 0x00000001)
                        {
                        IOCLR0 = 0x00000048;
                        }
            else
                        {
                        IOSET0 = 0x00000048;
                        }
            if(IOPIN0 & 0x00000002)
                        {
                        IOCLR0 = 0x00000090;
                        }
            else
                        {
                        IOSET0 = 0x00000090;
                        }
            if(IOPIN0 & 0x00000004)
                        {
                        IOCLR0 = 0x00000020;
                        }
            else
                        {
                        IOSET0 = 0x00000020;
                        }
                        }
             }



Port Pin output:
 














Proteus design:



No comments:

Post a comment