Jump to content
Sign in to follow this  
Moonwalker

16Bit Conditions

Recommended Posts

Is there a limit to using 16bit variables/ constants in Conditional statments?

For some reason the following code keeps on looping

 

while  ((firestep < FIRESTEPEND) && (tempC.5 == 0)) // firestep <= xxxx and not end program

   {
	tempA = i2c_read(0); tempD = i2c_read(0); tempC = i2c_read(0);
	if (tempC.7 == 1)
	{
	 putc(firestepH); putc(firestepL);
	 putc(0x88);   putc(tempA);  putc(tempD); putc(tempC);
	}
	firestep++;
	LOBYTE(firestepL,firestep);  HIBYTE(firestepH,firestep);
   }

 

firestep starts at 0x5555 and FIRESTEPEND is defined as 0x8D00

When I changed to the code below to use only 8bit it works ok

 

while (firestepH < 0x8D) //((firestep < FIRESTEPEND) && (tempC.5 == 0)) // firestep <= xxxx and not end program

   {
	tempA = i2c_read(0); tempD = i2c_read(0); tempC = i2c_read(0);
	if (tempC.7 == 1)
	{
	 putc(firestepH); putc(firestepL);
	 putc(0x88);   putc(tempA);  putc(tempD); putc(tempC);
	}
	firestep++;
	LOBYTE(firestepL,firestep);  HIBYTE(firestepH,firestep);
   }

I do have some other 16bit conditionals which seem to work ok but if they are not reliable I will switch to 8bit.

I am using Pic16F1934 and this piece of code may be falling at the middle of the flash memory.

Can this do such tricks?

Edited by Pavel
added code tags

Share this post


Link to post
Share on other sites

Hi

 

Are you sure its a 8bit versus 16bit issue?

In this section of code

 

   while  ((firestep < FIRESTEPEND) && (tempC.5 == 0)) // firestep <= xxxx and not end program
   {
	tempA = i2c_read(0); tempD = i2c_read(0); tempC = i2c_read(0);
	if (tempC.7 == 1)
	{
	 putc(firestepH); putc(firestepL);
	 putc(0x88);   putc(tempA);  putc(tempD); putc(tempC);
	}
	firestep++;
	LOBYTE(firestepL,firestep);  HIBYTE(firestepH,firestep);
   }

I'm seeing a two condition test.

And in this one

   while (firestepH < 0x8D) //((firestep < FIRESTEPEND) && (tempC.5 == 0)) // firestep <= xxxx and not end program
   {
	tempA = i2c_read(0); tempD = i2c_read(0); tempC = i2c_read(0);
	if (tempC.7 == 1)
	{
	 putc(firestepH); putc(firestepL);
	 putc(0x88);   putc(tempA);  putc(tempD); putc(tempC);
	}
	firestep++;
	LOBYTE(firestepL,firestep);  HIBYTE(firestepH,firestep);
   }

There is only a single condition test.

 

This opens the possibility for an issue with the second condition and not if the first one is an 8bit or 16bit condition.

 

 

Just my 2 cents....

 

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

Sorry for not replying back earlier.

 

The problem was that I was using signed Short instead of unsigned Short so I was not getting the full range of 16bits.

I changed to unsigned Short and problem was solved.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...