<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/32660/getting-input-from-pushbutton-lpc1768</link><description> 
hi, im using lpc1768 development board 
i have written a code for push button 
when button pressed led should turn on 
but the led is not responding to button, it is on always 
even i checked in keil peripherals(ports)it is going inside the if
condition</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/145649?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 08:00:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:feb63ffb-dc03-4e01-a4a1-418f8e9f4126</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;Connection is proper i checked it&amp;quot;. But you don&amp;#39;t seem to have
indicated any voltage levels measured anywhere. And despite me
mentioning it, you haven&amp;#39;t given any feedback if the voltages
measured differs if you keep the reset button pressed or not.&lt;/p&gt;

&lt;p&gt;
And how are you debugging? On the real hardware? Using what
interface? A JTAG adapter? Have you verified that your project
doesn&amp;#39;t just start the simulator, in which case you can single-step
your program as much as you like without a single instruction being
sent to - or run on - the hardware where your &amp;quot;properly connected&amp;quot;
button and LED are.&lt;/p&gt;

&lt;p&gt;
And the simulator will not know anything about button presses on
the real hardware. And it will not be able to turn on or off any LED
on the real hardware.&lt;/p&gt;

&lt;p&gt;
I have mentioned it multiple times now, but you haven&amp;#39;t given one
single indication that you are actually able to run any code on real
hardware. So right now, the progress is just about zero.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/143608?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 07:27:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b22b7ae8-0071-4dd0-bdbf-7ecc4fd98624</guid><dc:creator>karthik c</dc:creator><description>&lt;p&gt;&lt;p&gt;
sir,&lt;br /&gt;
led is connected to port0.4&lt;br /&gt;
button is connected to port2.10&lt;br /&gt;
connection is proper i checked it&lt;/p&gt;

&lt;p&gt;
In keil, debug-&amp;gt; start debug session&lt;br /&gt;
and im running the program step by step&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/140863?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 06:10:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cad53949-c7b0-493e-a498-e02b42e747de</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
In Keil? You mean in simulator? The simulator can&amp;#39;t simulate
potential issues on the outside of the processor.&lt;/p&gt;

&lt;p&gt;
Have you tried a trivial program that only does set the pin high
and then hang in a loop? Corresponding program that only sets the pin
low and then hang in a loop? You haven&amp;#39;t given any indication that
you have actually verified that the LED is on the exact pin you
claim. And that the LED is correctly connected. No report of what a
multimeter or oscilloscope measures when your program tries to hold
the pin high. Or when you try to hold the pin low. And you haven&amp;#39;t
given any indication how you have verified that the push button is on
the pin you claim. Or that you have tried to verify the full 32-bit
content of the port when the button is pressed or when it isn&amp;#39;t
pressed, to see if any other bit toggles. When you don&amp;#39;t give any
feedback what tests you do, then people can&amp;#39;t help you.&lt;/p&gt;

&lt;p&gt;
Debugging is the processor splitting problems into smaller
sub-problems until each sub-problem is small enough that you can
deduce if it works or not - and can figure out what to do to fix. You
don&amp;#39;t seem to have been able to deduce if your issue is to detect the
button. Or if the problem is to drive the LED. Or if the problem is
to download and run an application in the board. Step one is to prove
that you can download and run a trivial program. Then you can start
to verify individual subsystems. Right now we don&amp;#39;t know if the LED
is always lit. Or if you get any difference on any port pin if you
keep the reset button pressed or not.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/131527?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 05:55:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:263bbec5-15b2-4faf-8fd7-1ae9b8127dff</guid><dc:creator>karthik c</dc:creator><description>&lt;p&gt;&lt;p&gt;
sir i mean i dint give logic high to the pin where button is
connected&lt;br /&gt;
forget about the connections same thing happening in keil&lt;br /&gt;
first im checking in keil then im uploading to my development
board&lt;br /&gt;
in keil only it is giving trouble for me&lt;/p&gt;

&lt;p&gt;
please help me with the code&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/128968?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 02:08:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:26b231cc-85a9-404d-ab42-847dde2fbb39</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;the led is getting on(without supplying VCC)&amp;quot;&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t you think you should think some more about this? The LED
turns on without any VCC supplied? Where does the LED get any current
from? So start solving that before you worry about your source
code.&lt;/p&gt;

&lt;p&gt;
If you have broken, or incorrectly connected, hardware then it
isn&amp;#39;t meaningful to sit and stare at the source code.&lt;/p&gt;

&lt;p&gt;
Right now, we haven&amp;#39;t even seen any indication that you are even
able to correctly download and start any program in the
processor.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/117816?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2015 00:17:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c447fdd3-6ee1-4588-acd5-9d6695933bb2</guid><dc:creator>karthik c</dc:creator><description>&lt;p&gt;&lt;pre&gt;
#include &amp;lt;avr/io.h&amp;gt;
#include &amp;lt;util/delay.h&amp;gt;
void main(void)
{
        DDRB |= (1&amp;lt;&amp;lt;PB0);
        DDRC &amp;amp;= ~(1&amp;lt;&amp;lt;PC0);
        while(1)
        {

        while(PINC &amp;amp; (1&amp;lt;&amp;lt;PC0) ==1) //button is pressed
        {
                PORTB |= 1&amp;lt;&amp;lt;PINB0; // led on
        }
        PORTB &amp;amp;= ~(1&amp;lt;&amp;lt;PINB0); // led off
        }
}
&lt;/pre&gt;

&lt;p&gt;
sir, this is my AVR code for push button which is working
absolutely fine&lt;br /&gt;
when button is pressed led getting on else off.&lt;/p&gt;

&lt;p&gt;
i just want my led to get on when button is pressed(when i
supply&lt;br /&gt;
VCC to that pin).&lt;/p&gt;

&lt;pre&gt;
#include &amp;quot;lpc17xx.h&amp;quot;
#define GPIO2_BUTTON1  (1&amp;lt;&amp;lt;10)
#define GPIO0_LED (1&amp;lt;&amp;lt;4)
int main(void)
{
        SystemInit();
        LPC_GPIO0-&amp;gt;FIODIR |= GPIO0_LED;
        LPC_GPIO2-&amp;gt;FIODIR &amp;amp;= ~GPIO2_BUTTON1;
        while(1)
        {
                if ((LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; GPIO2_BUTTON1))
                {
                        LPC_GPIO0-&amp;gt;FIOSET=GPIO0_LED;
                }
                else
                {
                        LPC_GPIO0-&amp;gt;FIOCLR=GPIO0_LED;
                }
        }
}
&lt;/pre&gt;
&lt;pre&gt;

#include &amp;quot;lpc17xx.h&amp;quot;
#define GPIO2_BUTTON1  (1&amp;lt;&amp;lt;10)
#define GPIO0_LED (1&amp;lt;&amp;lt;4)
uint32_t status;
int main(void)
{
        SystemInit();
        LPC_GPIO0-&amp;gt;FIODIR |=GPIO0_LED;
        LPC_GPIO2-&amp;gt;FIODIR &amp;amp;= ~GPIO2_BUTTON1;
        while(1)
        {
                status=(LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; (GPIO0_LED) &amp;gt;&amp;gt;10);
                        LPC_GPIO0-&amp;gt;FIOSET=(status&amp;lt;&amp;lt;4);

        }
}
&lt;/pre&gt;

&lt;p&gt;
without pressing the button the led is getting on(without
supplying VCC) for both the codes&lt;br /&gt;
even in keil peripherals same thing happening.&lt;/p&gt;

&lt;p&gt;
can you please explain me where am i going wrong&lt;br /&gt;
thank you&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/108316?ContentTypeID=1</link><pubDate>Thu, 09 Jul 2015 23:15:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cba755a4-1d0f-4a26-b3fe-5377b0aa7235</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
How can this expression be true?&lt;/p&gt;

&lt;pre&gt;
if((LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; GPIO2_BUTTON1)==1)
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
The left side of the compare can not extract a value 1, since
GPIO2_BUTTON1 isn&amp;#39;t the value 1. Just because a bit operation
extracts the value of a single bit, it need not give a result that is
0 or 1 - the actual value will depend on the bit position of the
extracted bit. And comparing with a value isn&amp;#39;t needed since C
performs an implicit &amp;quot;!= 0&amp;quot; in conditional statements.&lt;/p&gt;

&lt;p&gt;
So your conclusion that it always matches the &amp;quot;if&amp;quot; and never
reaches the &amp;quot;else&amp;quot; can&amp;#39;t be true, when you have a left part of the
expression that can never take the value 1.&lt;/p&gt;

&lt;p&gt;
So is your LED really connected to the pin you think?&lt;/p&gt;

&lt;p&gt;
And have you really verified the value of all the registers?&lt;/p&gt;

&lt;p&gt;
And why didn&amp;#39;t you modify the code with a #define for your LED
too, instead of still leaving magic values in your code? It isn&amp;#39;t a
good thing to have the same value duplicated to three different
locations of the code, which means you must modify three locations to
switch to a different LED.&lt;/p&gt;

&lt;p&gt;
Another thing - what is the purpose of your delay? To keep the LED
still lit a while after you release the button? Or you think it&amp;#39;s
some kind of debounce to avoid flicker from switch bounces? That&amp;#39;s
not a very long delay. And the compiler can even decide to totally
ignore it.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/82685?ContentTypeID=1</link><pubDate>Thu, 09 Jul 2015 22:10:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:71f7e0c7-4a79-4267-afa0-fea36dbe1390</guid><dc:creator>karthik c</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for the reply sir&lt;/p&gt;

&lt;p&gt;
im facing the same problem&lt;/p&gt;

&lt;pre&gt;
#include &amp;quot;lpc17xx.h&amp;quot;
#define GPIO2_BUTTON1  (1&amp;lt;&amp;lt;10)
void delay(uint32_t c)
{
        while(c&amp;gt;0)
        c--;
}
int main(void)
{
        SystemInit();
        LPC_GPIO0-&amp;gt;FIODIR |=(1&amp;lt;&amp;lt;4);
        LPC_GPIO2-&amp;gt;FIODIR &amp;amp;= ~GPIO2_BUTTON1;
        while(1)
        {
                if (LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; GPIO2_BUTTON1)
                {
                        LPC_GPIO0-&amp;gt;FIOSET=(1&amp;lt;&amp;lt;4);
                         delay(100);
                }
                else
                {
                        LPC_GPIO0-&amp;gt;FIOCLR=(1&amp;lt;&amp;lt;4);
                        delay(100);
                }
        }
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
after uploading the code to development board the led turns on
irrespective of button&lt;br /&gt;
even in keil peripherals(ports)it is going inside the if condition
without the pin high&lt;br /&gt;
i checked the button state also in multimeter when i press it is
giving 3.3v else 0v&lt;/p&gt;

&lt;pre&gt;
 if((LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; GPIO2_BUTTON1)==1)
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
i tried even with this condition it is not working for me&lt;br /&gt;
can u please help me out&lt;/p&gt;

&lt;p&gt;
thank you&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting input from pushbutton(lpc1768)</title><link>https://community.arm.com/thread/69273?ContentTypeID=1</link><pubDate>Thu, 09 Jul 2015 04:50:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:01330697-5094-4b81-9d3a-291269ca2c16</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
1) You don&amp;#39;t think it would have helped if you had read the
posting instructions for posting source code? It&amp;#39;s available directly
above the message input box.&lt;/p&gt;

&lt;p&gt;
2) Why use magic numbers? Why using two different forms of magic
numbers when you initialize the port compared to when you use the
port? In one situation you use a shift value. In another situation
you use an already shifted bit pattern.&lt;/p&gt;

&lt;p&gt;
Why not&lt;/p&gt;

&lt;pre&gt;
#define GPIO2_BUTTON1  (1&amp;lt;&amp;lt;10)

...

LPC_GPIO2-&amp;gt;FIODIR &amp;amp;= ~GPIO2_BUTTON1;       // Clear direction bits for input.

...

if (LPC_GPIO2-&amp;gt;FIOPIN &amp;amp; GPIO2_BUTTON1) {
    ...
} else {
    ...
}
&lt;/pre&gt;

&lt;p&gt;
It feels easier to read.&lt;br /&gt;
And easier to maintain.&lt;br /&gt;
And if you move the button to a different port then the symbol name
changes which means you get compilation errors that informs you that
you must also modify the initialization and test code to switch to
the correct GPIO port.&lt;/p&gt;

&lt;p&gt;
3) Your project is currently on hold? Why? Because you expect
someone else to solve your problems? Aren&amp;#39;t you busy trying to figure
out the problem yourself? How do you know you have the correct pin on
the correct port? Have you measured the actual voltage level of the
pin when you expect it to be high? And when you expect it to be low?
Have you verified the actual contents of your registers? Any external
or internal pull-up? Any alternative mode configured? Any other GPIO2
port pin that can correctly detect both low and high levels?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>