CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

4.093 bug: int1 arrays comparison condition

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

4.093 bug: int1 arrays comparison condition
PostPosted: Mon Nov 09, 2009 11:27 am     Reply with quote

Hello everybody,
I have stumbled upon a terrible bug. I took my project and created the following shorter listening out of it.

The issue is that condition if(PinState[i]!=PinStatePrevious[i]) is always false regardless those variables.
In printf("pin%i: %i %i\n",i,PinState[i],PinStatePrevious[i]); you can see that both variables have the same value!

Use #define SHOW_BUG to show the issue and a workaround.

The application sends a string to the serial line when one of higher 4 bits of PORTB changes its state.
The bug sends the string all the time.

Hope it is clear for you.

Does anybody know whether this issue has been reported to CCS (and solved in later version of the compiler)?
I hope I am not stupid and this issue really is a compiler bug.
Cheers
Code:

#include <18F2420.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=20000000)
#use fast_io(B)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

#define TRIS_B 0b11110010
#define INPUT_COUNT 4

#ZERO_RAM

#define SHOW_BUG 1//change it to 0 to see that the other condition works well

int1 PinState[INPUT_COUNT];
int1 PinStatePrevious[INPUT_COUNT];

void main()
{
   int8 val,i;
   int1 bool1,bool2;
   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);//52ms
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   set_tris_b(TRIS_B);
     
 
   while(1)
   {
      val=input_b();
     
      val=val>>4;//B4-B7
     
      printf("val: %X\n",val);
     
      for(i=0;i<INPUT_COUNT;i++)
      {
         PinState[i]=(val&(1<<i));
         
         bool1=PinState[i];
         bool2=PinStatePrevious[i];
         printf("pin%i: %i %i\n",i,bool1,bool2);
         printf("pin%i: %i %i\n",i,PinState[i],PinStatePrevious[i]);
#if SHOW_BUG     
         if(PinState[i]!=PinStatePrevious[i])//doesnt work, is always false
#else
         if(bool1!=bool2)//works
#endif
         {
            printf("pin%i changed\n",i);
            PinStatePrevious[i]=PinState[i];
         }
      }
   }
}


Last edited by meereck on Tue Nov 10, 2009 1:54 am; edited 1 time in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Nov 09, 2009 12:54 pm     Reply with quote

Still incorrect in V4.099.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Nov 10, 2009 1:56 am     Reply with quote

hello thanks for confirmation.
I wrote it wrong in the previous post, the condition is never satisfied. I have modified it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group