Hi Nuri, After a quick look I would say you are not sampling your button in real time, are events happening too quickly for you to see? I would use a 50mS interrupt from TMR0 to poll the button so you can control the rate at which pos is updated. Regards. Nigel On Thursday, February 08, 2001 9:14 AM, Nuri ERGINER [SMTP:nerginer@SSM.GOV.TR] wrote: > Hi, > > Please have a look at the below code. The chip is 16f84a. The osilator is > selected as xt and the wdt is disabled. There is a button on RB0 to trigger > the interrupt and there is a motor driver on pins RB1 and RB2. > What I want to do is to count the button presses and change the direction of > the motor when It reaches to the specified values (max and min) > I will be very happy if someone can help me in the project. > The hi-tech C code (lite version): > > #include > #define PIC_CLK 4000000 > #include > #define CP_off|=0x3FFF//copy protect off > > #define OUTPUT 0; > #define INPUT 1; > > unsigned char max; > unsigned char min; > unsigned char pos=9; > unsigned char dir=1; > > > main(){ > > // init > TRISB=49; > PORTB=0; > > max=20; > min=10; > > INTE=1; > GIE=1; > > for(;;){ > if (pos>max) { > dir=0; > RB1=0;//motor left > RB2=1;//motor left > } > if (pos dir=1; > RB1=1;//motor right > RB2=0;//motor right > } > > > }//for > > }//main > > static void interrupt isr(void){ > > if (INTF) { > if (dir==0){pos--;} > if (dir==1){pos++;} > INTF=0; > }//if > > } > > Regards, > Nuri Erginer > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.