Jump to content

Recommended Posts

I had a merry time chasing down a bug that turned out to be the result of different behavior between SourceBoost IDE V 6.92 PIC C compiler and the version I upgraded from. I am not sure what that version was but I can find out if it is important. Here is the code that worked differently in the two versions:

 

boolean isZero(int value)

{

if(value) {

return false

}else {

return true

}

}

 

In the prior version of BoostC, the if statement correctly tested for a non-zero value but in 6.92 it did not. I had to change the if statement to:

 

if(value != 0)

 

It isn't clear to me if I was just lucky that it worked the way I expected it to with the first version or if the new version has a bug, but the fact that the two versions work differently caused me some time and grief.

 

Don

Link to post
Share on other sites

I could not reproduce this problem under 6.93. Please try 6.93 and if you still see this problem post code that will demonstrate it (the code that you posted in your original mail does not compile).

 

Pavel

Link to post
Share on other sites
I could not reproduce this problem under 6.93. Please try 6.93 and if you still see this problem post code that will demonstrate it (the code that you posted in your original mail does not compile).

 

Pavel

 

Yeah, that was pseudo-code. The actual code that fails is the following:

 

 

if(loopCnt[curLevel] ){

// do the non-zero process

}

else{

// do the zero process

}

 

where curLevel and loopCnt are defined as follows in the .h file:

 

char curLevel;

int loopCnt[5];

 

With the code shown, the program always does the non-zero process even when loopCnt[curLevel] is zero. If I change the if statement to:

 

 

if(loopCnt[curLevel] != 0 ){

 

the program works as expected for all values of loopCnt[curLevel].

 

This is with 6.92. I haven't tried 6.93 yet.

 

Don

Link to post
Share on other sites

Yes, the issue has started around 6.9.

Look at the following code; the strings should be sent until end of string - NULL - is found. However the conditional statement if (tx_buf1[tx_index1]) is evaluated always as true. You need if (tx_buf1[tx_index1] != 0) in order for the statement to work as intended.

The latest 6.93 has left the issue unfixed.

 

 // test for PIC18F6722 USARTs
#include <system.h>
#pragma DATA _CONFIG1H, _OSC_INTIO67_1H 
#pragma DATA _CONFIG2L, _PWRT_ON_2L
#pragma DATA _CONFIG3H, _MCLRE_ON_3H
#pragma DATA _CONFIG4L, _XINST_OFF_4L

#pragma CLOCK_FREQ 20000000	

void uart1_init(void);
void uart2_init(void);
void uart1_send_chrs (char *str);
void uart2_send_chrs (char *str);

// Global arrays and variables
char str1[] = "Characters are sent to UART1";
char str2[] = "Characters are sent to UART2";
char tx_buf1[64], tx_buf2[64], tx_index1=0, tx_index2=0;

void interrupt( void )
{ if (pir1.TX1IF && pie1.TX1IE)
{ if (tx_buf1[tx_index1])   // replace with <==== if (tx_buf1[tx_index1] != 0) to make it to work !?
   { if (txsta.TRMT)
	  { txreg = tx_buf1[tx_index1++];
		latd.LATD0 = pir1.TX1IF;
	  }
   }
  else
   { // reset tx buffer index and stop transmission for uart1
	 tx_index1 = 0;		 
	 pie1.TX1IE = 0;  
   }
}
  if (pir3.TX2IF && pie3.TX2IE)
{ if (tx_buf2[tx_index2])	// ditto <======== if (tx_buf2[tx_index2] != 0).
   { if (txsta2.TRMT)
	  { txreg2 = tx_buf2[tx_index2++];
		latd.LATD1 = pir3.TX2IF;
	  }
  }
  else
   { // reset tx buffer index an stop transmission for uart2
	 tx_index2 = 0;
	 pie3.TX2IE = 0;  
   }
}
}



void main()
{	// enable portd as an output port.
  portd = 0;
  trisd = 0;
  // Initialize uarts with 9600 bauds.
  uart1_init();
  uart2_init();
  // enable global interrupts.
  intcon.GIE  = 1;  
  // enable peripherals interrupts.
  intcon.PEIE = 1;  

  uart1_send_chrs(str1);
  uart2_send_chrs(str2);

  while (1);
}

void uart1_init(void)
{ spbrg		  = 128;   // Set SPBRG for 9600 baud rate.	
  baudcon.BRG16  = 0;	 // 8-bit Baudrate (redundant, just for test).
  txsta.SYNC	 = 0;	 // Asynchrosous mode (redundant, just for test).  
  txsta.BRGH	 = 1;	 // Baudrate high.
  txsta.TXEN	 = 1;	 // Enable transmission.
  rcsta.SPEN	 = 1; 	   // Enable uart module and set 8,n,1.
  rcsta.CREN	 = 0;	   // Disable receive.
}

void uart2_init(void)
{ spbrg2		 = 128;   // Set SPBRG for 9600 baud rate.	
  baudcon2.BRG16 = 0;	 // 8-bit Baudrate (redundant, just for test).
  txsta2.SYNC	= 0;	 // Asynchrosous mode (redundant, just for test).  
  txsta2.BRGH	= 1;	 // Baudrate high.
  txsta2.TXEN	= 1;	 // Enable transmission.
  rcsta2.SPEN	= 1; 	   // Enable uart module and set 8,n,1.
  rcsta2.CREN	= 0;	 // Disable receive.
}


void uart1_send_chrs (char *str)
{ // pointer to first tx1 buffer element. 
  char *p1 = tx_buf1; 
  // Copy string into transmit buffer 1.
  while (*p1++ = *str++);
  // Start transmissions for uart1.
  pie1.TX1IE = 1;
}

void uart2_send_chrs (char *str)
{ // pointer to first tx2 buffer element. 
  char *p2 = tx_buf2; 
  // Copy string into transmit buffer 2.
  while (*p2++ = *str++);
  // Start transmissions for uart2.
  pie3.TX2IE = 1;
}

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...
×
×
  • Create New...