meereck
Joined: 09 Nov 2006 Posts: 173
|
4.093 bug: int1 arrays comparison condition |
Posted: Mon Nov 09, 2009 11:27 am |
|
|
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 |
|