karthik chandra
Newbie level 5

led connected to port0.4
pushbutton(pulldown, when button is pressed 3.3v flows) to port0.5
led is getting on without pressing the button
even i checked in keil peripherals(ports)it is making port0.4 high irrespective of port0.5
i tried with some codes too it is not reading the pin
(going inside the if condition without the pin high)
can anyone please suggest me where im going wrong
thankyou
pushbutton(pulldown, when button is pressed 3.3v flows) to port0.5
Code:
#include"lpc17xx.h"
uint32_t value;
int main(void)
{
LPC_GPIO0->FIODIR |=(1<<4); // port0.4 output
LPC_GPIO0->FIODIR &=~(1<<5); //port0.5 input
LPC_PINCON->PINSEL0 &= ~((1<<9)|(1<<8)); // 00 function gpio port0.4
LPC_PINCON->PINSEL0 &= ~((1<<11)|(1<<10)); // 00 function gpio port0.5
LPC_PINCON->PINMODE0 |= ((1<<11)|(1<<10)); // 11 function mode pulldown port0.5
while(1)
{
value = (LPC_GPIO0->FIOPIN & (1 <<5)>>5);// reading the status of input port0.5
LPC_GPIO0->FIOSET=(value<<4); //setting the port0.4 according to port0.5
}
}
led is getting on without pressing the button
even i checked in keil peripherals(ports)it is making port0.4 high irrespective of port0.5
i tried with some codes too it is not reading the pin
Code:
#include "lpc17xx.h"
#define GPIO2_BUTTON1 (1<<10)
void delay(uint32_t c)
{
while(c>0)
c--;
}
int main(void)
{
SystemInit();
LPC_GPIO0->FIODIR |=(1<<4);
LPC_GPIO2->FIODIR &= ~GPIO2_BUTTON1;
while(1)
{
if (LPC_GPIO2->FIOPIN & GPIO2_BUTTON1)
{
LPC_GPIO0->FIOSET=(1<<4);
delay(100);
}
else
{
LPC_GPIO0->FIOCLR=(1<<4);
delay(100);
}
}
}
can anyone please suggest me where im going wrong
thankyou