Gordon Henderson wrote: > That's not what that statement is doing. > > One = is an assignment, 2 == is comparision. > > So > if (a = a + 1024) > > evaluates a + 1024, then assigns the result to a, then tests the result > (of the new a) for true or false ... (or zero or non zero) so it'll always > be true... Ok, That makes alot of sense, as i was destroying "a" by assigning to it.
i probably used this in basic51. and got confused. > > > Drop this, > >> if(a = a + 1024) > > replace with: > > if ((a % 1024) == 0) > Yes, thank you That is what i wanted it to do. >> { >> !P3_0; // if true every K toggles led >> } >> *abs_ptr = 0x69 ; >> *abs_ptr++ ; >> P1 = a; // status of "a" variable on port P1 >> } >> _asm ljmp 0 _endasm; // fin. >> } > > The % operator is modulo and an integer division and finds the remainder. > If this isn't acceptable, then keep a separate variable and increment it > and compare to 1024. (or initialise it to 1024, decrement it and test for > zero which may be more efficient if you'rel looking for every last ounce > of speed) > > I don't know anything about the 8051 though, but lots about C... Make sure > 'a' is a variable of enough bits to hold an address (maybe at least 16 > bits if you use things like uint16_t rather than just 'int', etc. > > I'm also not sure what > > !P3_0; > > is doing. I'm not convinced it's actually having any effect, but maybe it > is due to the way the C compiler is working? (I'd check the assembly) To > toggle a bit, assuming P3_0 is a bitfield in a structure pointing to some > hardware, I'd look to using something like: > > P3_0 ^= 1 ; > > Which is shorthand for > > P3_0 = P3_0 ^ 1 ; > > the ^ operator is bitwise-xor. Oops, i meant to put P3_0=!P3_0; But I like your version of it better. > > > Also... > > P1 = a ; > > I'd guess that P1 is an 8-bit port, that will get the bottom 8-bits of a - > but maybe that's the intention? Yes i just wanted to look at the value of "a" in the simulator. Well thanks again Gordon, problem solved. > > Gordon > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sdcc-user > ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user