Push button variable delays mikroc

Status
Not open for further replies.

bee

Member
I am learning to program in C mikro ,, And i am trying to get a longer or shorter delay by pressing buttons ,, It will not compile with the variable 'time' in the delay , could somebody point me in the right direction

thanks
Bernie


Code:
 // 21 july 2011
// program to Test button 1 and 2 on portA for a high or low
   sbit button1 at ra0_bit;     // assign ra0 to button 1
   sbit button2 at ra1_bit;
    int time ;    // global variable


void main(void)
{ 
                           // Program entry point.
 TRISA0_bit = 1;                   // set porta pin0 as input.
 TRISA1_bit = 1;
 TRISB = 0;                   // set portb pins as output.
 PORTB = 0;                   // set portb pins to low.
 time = 250  ;



   do{

    if (button1 == 1 ){                // if button1 is pressed, execute
      time +=10;                     // the following statement.
     PORTB = 0b0000010;                         // turn on rb1 if button 1 is pressed ra0
     delay_ms(time) ;         
     PORTB = 0b0000000;                                // turn off rb1
     delay_ms(time);

         }

    if(button2 == 1){                // if button1 is pressed, execute
       time -=10;                    // the following statement.
      RB1_bit = 1;  //PORTB = 0b0000010;                                // turn on rb1 if button 1 is pressed ra0
     delay_ms(time);         
      RB1_bit=0;   //PORTB = 0b0000000;                                // turn off rb1
     delay_ms(time);

       }
    }while (1);
  }
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…