PIC = Change LED Flash Rate with a button?

Discussion in 'Programmer's Corner' started by stringer85, Oct 22, 2009.

  1. stringer85

    Thread Starter New Member

    Sep 25, 2008
    4
    0
    Alright Guys

    Please forgive me if this sounds trivial, I'm very new with PIC programing.

    Anyway I'm trying to find away to change the rate an LED flashes using a buttons input.

    Any Ideas?

    I made this, which has a delay and turns the LED on and off:

    for (i = 0; i < 130; i++) //I got this type of delay out of the evil genius book.

    for (j = 0; j < 40; j++);

    RA5 = RA5 ^ 1; // Switches LED On and Off


    if (0 == RA3) // If the Button is pressed
    {

    //Somehow increase the delay so the led flashes faster"
    }


    Im using a PICkit1 with the 16f684 PIC.


    Cheers Guys
     
  2. stringer85

    Thread Starter New Member

    Sep 25, 2008
    4
    0
    Sorted it!!

    Code:


    #include <pic.h>

    /*

    RA3 - Button Connection
    RA4 - LED Positive Connection
    RA5 - LED Negative Connection

    Chris Stringer
    22/10/09

    */

    __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
    & UNPROTECT & BORDIS & IESODIS & FCMDIS);

    int i, j, speed = 35;

    main()
    {

    PORTA = 0x3F; // All Bits are High
    CMCON0 = 7; // Turn off Comparators
    ANSEL = 0; // Turn off ADC
    TRISA4 = 0; // Make RA4/RA5 Outputs
    TRISA5 = 0;


    while(1 == 1) // Loop Forever
    {


    if (0 == RA3) // Set values using "if" statement
    {

    speed = speed + 5;

    } // fi



    for (i = 0; i < 255; i++) // Simple 500ms Delay
    for (j = 0; j < speed; j++);

    RA5 = RA5 ^ 1; // Toggle LED State




    } // elihw
    } // End
     
Loading...