This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Single Button Swtiching LED

Hi,

I need help in writing this C Program

Circuit : LED are connected to P1.0 to P1.4 , a push button (push to on) Switch is connected to P1.7
When button is pressed first time, LED on P1.0 switches on, when switch is pressed again, LED on P1.0 switches off and then LED on P1.1 glows, same cycle repeats (P1.2, P1.3, P1.4 then again P1.0) whenever push button is pressed.

Thanks
suds
sudhirmt@gmail.com

  • It seems like your teacher have already given you a good description of the problem. So what more information do you need?

  • I ditto what Per has stated.

    Also you should look at what you selected. C251 is a different beast than the C51. They are not the same (different IS although it was downward compatible).

    Please don't flood this forum with your class assignments, basic C questions, and basic C51 questions. This has little to do with Keil C or their compilers (only in the likely hood you are using Keil tools is it related). Do some of your own research, these are things YOU need to learn how to do, just like all the professionals here who do this for a living had to.

    Stephen

  • Sorry I did not mention that..
    I suppose to do this project with 89C2051

    I need help with code..

    I wrote this using " if else " but program becomes big, its overloading cpu in simulation.

  • Say that again:

    "I suppose to do this project"

    So, you are supposed to be doing this project - not asking people to do it for you!

    "I wrote this using 'if else' but program becomes big"

    So think more carefully, and re-write it so that it's not too big!

    The problem is really quite simple, and certainly should not be too big even for an 89C2051!

  • The biggest part of the code may be the debounce of the switch. The business logic that is making the decisions is just a very few lines of code. Managing to use ten times as many lines as needed, the business logic would still be quite small, since the original problem is so very simple.

    The project you have in front of you is not even near a real commercial project. It is comparable to a tiny paragraph hidden in a footnote somewhere in the specification of a real product. It is a very simple project intended to be reasonably easy for beginners.

    But it is vital that you solve it yourself, because the future tasks will be continuously harder and if you do not keep up, you will not even be able to understand the specifications of the following tasks. And if you let it slide until you can't understand the requirements specification, you will not even be able to get someone else to write the solution for you.

  • Thanks

    Best part is I have finished with switch de-bounce code. working fine.. I have completed push button, on off code also.

    now .. breaking my head on finding out how to switch on pins one after another
    Here is the flow..

    (Start) -> [p1 =0 ] -> <if p1.0 - p1.4 is 0, then p1.1 if 1] -> <if p1.0 ||p1.1||p1.2||p1.3||p1.4 = 1 > !! ?? !!

    Not understanding how to keep track which pin is 1 , and how to make that pin 0, then next pin 1 on key press.

    can some one show me relevant code, some example code.. which will help me in understanding .. so I can write further code myself.

  • How would anyone be able to show you relevant code "just as an example" without giving you exactly the code you are expected to figure out yourself?

    Do you see any pattern in the following?

    0001
    0010
    0100
    1000
    0001
    0010
    0100
    1000
    0001
    ...
    


    What is that pattern? How many possible combinations are there? Would you be able to convert from an integer value into a specific pattern in some way?