On Wed, 6 Jan 2010, Sean Cross wrote:

> First off, Sorry for the new thread, my old free email account was
> bouncing your replies, and by chance i saw your replies through the
> archived lists.
> I have since changed e-mail accounts, so there should not be any more of
> a bounce problem. (i hope)
>
> using sdcc 2.9.0 and mcu8051ide for simulator
>
> I am kind of new to C programming and esp the whole embedded 8051 thing.
> Thank you for all of your input on this matter
>
> Hi Putu,
> > each time the "if( a = a + 1024 )" statement is executed, the value of
> > a is increased by 1024.
>
> Yes, thats what i want, so i can count how many K of bytes have passed.

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...

Maybe what you want is:

> xdata unsigned char *abs_ptr = (xdata unsigned char *) RAM_START; //
> Initialize pointer to RAM_START
>       for(a = RAM_START; a <= RAM_END; a++)
>       {

Drop this,

>               if(a = a + 1024)

replace with:

                if ((a % 1024) == 0)

>               {
>               !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.


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?

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

Reply via email to