This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Need Help

Other Parts Discussed in Thread: CC2530

HI

I am using CC2530.

My problems are

- One of my active high push button switch is connected to P0_2 from battery board

- When the switch is press one time i want to count one and i click again one more time it will reach to two and so on.

-Never reach back to zero and count continue.

please give me advice how to write program.

 

  • Please Explain me step by step and very clearly.

    Because I am beginner for this software and i just have basic for c  program.

    Thanks...

  • Hi Alvin,

        You first need to choose whether you are continuously polling the button or if you are using an interrupt on the button press. If you are using the RF capabilities of the CC2530, you may need to use interrupts on the button as the cc2530 will need to service the radio stack. If you do not care about using the radio capabilities, I suggest simply polling the button in a manner similar to the following:

    1. Initialize cpu and set port 0 to be input.
    2. If P0_2==1, add one to counter.
    3. If counter if about to overflow, add one to a secondary counter.
    4. Delay 100 milliseconds for button debounce. (Buttons and switches do not always make a clean transition between voltages, and if you neglect this part, you may occasionally see one button press be counted multiple times)
    5. wait until P0_2 equals 1 again.

    You need the secondary counter because your main counter will overflow at a value of 255 for a counter of type uint8 or 65535 for a counter of type uint16. Is the 8051 CPU an 8 bit or 16 bit machine? The CC253x user's guide will be a good reference: SWRU191b. If you need to service the radio stack and require interrupts, your initialization will require the following items to be set up (and maybe a few others):

     

    • P0IEN: P0 interrupt enable
    • P0SEL: Port 0 function-select register
    • PICTL: P0, P1, and P2 edge configuration
    • P0IFG: P0 interrupt flags

    Your interrupt service routine would look something like:

    // Button ISR
    #pragma vector=PORT0_VECTOR
    __interrupt void Port0_ISR(void)
    {
        make sure that it was P0_2 that caused the interrupt as any change in P0 will trigger this

        add one to your counter
    }

    This should get you started,

    - Craig