Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

what's wrong with this code?(microC & proteus)

Status
Not open for further replies.

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
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..............
 

Thank you, but same problem exist.
 

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:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top