Mar 24, 2013 #1 M mailus Full Member level 4 Joined Mar 6, 2012 Messages 234 Helped 7 Reputation 16 Reaction score 7 Trophy points 1,308 Location - Visit site Activity points 2,706 Code: sbit led1 at rb0_bit; sbit led2 at rb1_bit; sbit sw at ra0_bit; sbit sw2 at ra1_bit; void main() { adcon1=0x07; cmcon=0x07; trisa=0xff; trisb=0x00; portb=0x00; do{ if(Button(&porta,0,10,1)) { led2=1; led1=1; delay_ms(10); }while(sw=~sw); if(button(&porta,1,10,1)) { led1=0; led2=0; }while(sw2=~sw2); delay_ms(10); }while(1); } when i use this code output assign function did not work correctly; it sets the last assigned values only; for example: Code: if(Button(&porta,0,10,1)) { led2=1; led1=1; delay_ms(10); }while(sw=~sw); after executing this code output assigned only for led1 only; here led2 is missed in this step; please clarify my problem..............
Code: sbit led1 at rb0_bit; sbit led2 at rb1_bit; sbit sw at ra0_bit; sbit sw2 at ra1_bit; void main() { adcon1=0x07; cmcon=0x07; trisa=0xff; trisb=0x00; portb=0x00; do{ if(Button(&porta,0,10,1)) { led2=1; led1=1; delay_ms(10); }while(sw=~sw); if(button(&porta,1,10,1)) { led1=0; led2=0; }while(sw2=~sw2); delay_ms(10); }while(1); } when i use this code output assign function did not work correctly; it sets the last assigned values only; for example: Code: if(Button(&porta,0,10,1)) { led2=1; led1=1; delay_ms(10); }while(sw=~sw); after executing this code output assigned only for led1 only; here led2 is missed in this step; please clarify my problem..............
Mar 24, 2013 #2 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Visit site Activity points 0 while(sw=~sw); should be while(sw==~sw); You have used = instead of ==
Mar 24, 2013 #3 M mailus Full Member level 4 Joined Mar 6, 2012 Messages 234 Helped 7 Reputation 16 Reaction score 7 Trophy points 1,308 Location - Visit site Activity points 2,706 Thank you, but same problem exist.
Mar 24, 2013 #4 Z zuisti Advanced Member level 1 Joined Jul 2, 2004 Messages 479 Helped 188 Reputation 376 Reaction score 183 Trophy points 1,323 Location Hungary Visit site Activity points 3,319 First: Code: while(sw=~sw); //??? sw is an input, so not writable //correctly, as jayanth wrote: while (sw == ~sw ); But this is meaningless (generally), can be omit (1 is never equal to 0) 2nd: Your problem is a tipical RMW issue. Try this: Code: if( Button(&porta,0,10,1) ) { led2 = 1; /* led1 = 1; moved after the delay */ delay_ms(10); led1 = 1; } // while ( sw == ~sw ); And look at the MikroC help, what says about the "Read Modify Write Problem" Last edited: Mar 24, 2013
First: Code: while(sw=~sw); //??? sw is an input, so not writable //correctly, as jayanth wrote: while (sw == ~sw ); But this is meaningless (generally), can be omit (1 is never equal to 0) 2nd: Your problem is a tipical RMW issue. Try this: Code: if( Button(&porta,0,10,1) ) { led2 = 1; /* led1 = 1; moved after the delay */ delay_ms(10); led1 = 1; } // while ( sw == ~sw ); And look at the MikroC help, what says about the "Read Modify Write Problem"