We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 without the pin high here is my code
#include "lpc17xx.h" void delay(uint32_t c) { while(c>0) c--; } int main(void) { SystemInit(); LPC_GPIO0->FIODIR |=(1<<4); LPC_GPIO2->FIODIR &= ~(1<<10); while(1) { if(((LPC_GPIO2->FIOPIN >> 10) & 1) == 1) { LPC_GPIO0->FIOSET=0x00000010; delay(10000); } else { LPC_GPIO0->FIOCLR=0x00000010; delay(10000); } } }
my project is on hold because of this please help me out
thank you
"the led is getting on(without supplying VCC)"
Don'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.
If you have broken, or incorrectly connected, hardware then it isn't meaningful to sit and stare at the source code.
Right now, we haven't even seen any indication that you are even able to correctly download and start any program in the processor.
sir i mean i dint give logic high to the pin where button is connected forget about the connections same thing happening in keil first im checking in keil then im uploading to my development board in keil only it is giving trouble for me
please help me with the code
In Keil? You mean in simulator? The simulator can't simulate potential issues on the outside of the processor.
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'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'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't pressed, to see if any other bit toggles. When you don't give any feedback what tests you do, then people can't help you.
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'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'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.
sir, led is connected to port0.4 button is connected to port2.10 connection is proper i checked it
In keil, debug-> start debug session and im running the program step by step
"Connection is proper i checked it". But you don't seem to have indicated any voltage levels measured anywhere. And despite me mentioning it, you haven't given any feedback if the voltages measured differs if you keep the reset button pressed or not.
And how are you debugging? On the real hardware? Using what interface? A JTAG adapter? Have you verified that your project doesn'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 "properly connected" button and LED are.
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.
I have mentioned it multiple times now, but you haven'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.