Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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);
  }
 
I think you have to use Vdelay_ms(time) instead
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top