I have found an error when comparing two variables. No matter of the
values, it always gives FALSE.

In this app an error happens in line 110 when comparing two variables.
It's been compiled for a 16F877 PIC with SDCC version (compiled from
repository):

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.8.5 #5276 (Nov 26 2008) (UNIX)

The error is here:

==========

temete3.c, from line 109 to 116

=====

  // This reads memory until it gets to the correct language.
  for (i=0; i>language; i++)
  {
    while (text[0] != 0)
    {
      text[0] = SerialReadPostIncr();
    }
  }

=========


It's being called with this code:

=========

temete1.c, from line 203 to 204:

=====

  language=I18N_FR;
  PrintLineAlignXYI18n(I18N_TOTAL_TIME_H, I18N_TOTAL_TIME_L, 26, 8,
ALIGN_LEFT, NORMAL);

=========

I attach some files so you can give it a look. The Makefile specifies
how I compile the sources. Don't hesitate to ask me for the complete
project's code. I'm working on a test suite, but I'm not yet able to
reproduce the error with less code.

Thank you

-- 
Néstor
+34 687 96 74 81
#include "temete3.h"
#include "temete4.h"

BYTE getValueMesoestetic(BYTE value, BYTE pos)
{
  return(0);
}


void PaintGfxMesoestetic(BYTE x, BYTE y)
{
  BYTE i, line, repeat, column;
  
  column = 0;
  
  for (column = 0; column <=17; column++)
  {
    line = 1;
    for (i = 0; i <12; i++)
    {
      repeat = 0;
      // While repeat is less than the two MSB's of gfx[i-1] do:
      while ( repeat <= ( (getValueMesoestetic(column, i)>>6) & 0x03 ) )
      {
        PaintScanLine((getValueMesoestetic(column, i) & 0x3f), x+column, line + repeat + y-1);
        repeat++;
      }
      line += repeat;
    }
  }
}


void PrintLineAlign(BYTE* text, BYTE y, BYTE align, TStyle style)
{
  BYTE lenght;
  
  lenght = 0;
  
  while (text[lenght] != 0)
  {
    if (lenght == 255)
    {
      BeepError(ERROR_LINEEND); // Error. There is no line end.
    }
    lenght++;
  }
  
  if ((lenght > 40) || (lenght < 1))
  {
    BeepError(ERROR_TEXTLENGTH);     // Error. Text must be between 1 and 40 characters long.
  }
  
  if (align == ALIGN_LEFT)
  {
    PrintLine(text, 1, y, style);
  }
  else if (align == ALIGN_RIGHT)
  {
    PrintLine(text, 40-(lenght-1), y, style);
  }
  else if (align == ALIGN_CENTER)
  {
    PrintLine(text, ((40-(lenght-1)) >> 1)+1, y, style);
  }
}


void PrintLineAlignXY(BYTE* text, BYTE x, BYTE y, BYTE align, TStyle style)
{
  BYTE size=0;
  if (align == ALIGN_LEFT)
  {
    PrintLine(text, x, y, style);
  }
  else
  {
    for (size=0; text[size]!=0; size++);
    if (align == ALIGN_CENTER)
    {
      PrintLine(text, x-(size/2), y, style);
    }
    else if (align == ALIGN_RIGHT)
    {
      PrintLine(text, x-size, y, style);
    }
    else
    {
      // ERROR
    }
  }
}


// PrintLineAlignXYI18n - Prints a line at some coordinates with a specific
//                        alignment for the current language
// addH, addrL: Address High, Low
// x, y:        LCD Screen position
// align:       Alignment (Left, Center, Right)
// style:       Style (AND, OR, EXOR mode)

void PrintLineAlignXYI18n(BYTE addrH, BYTE addrL, BYTE x, BYTE y, BYTE align, TStyle style)
{
  BYTE size=0, i=0;
  BYTE text[]={0xff,0};
  
  SerialSetAddr(addrH, addrL);
  
  // This reads memory until it gets to the correct language.
  for (i=0; i>language; i++)
  {
    while (text[0] != 0)
    {
      text[0] = SerialReadPostIncr();
    }
  }
  
  // This reads memory to print the characters for the proper language.
  if (align == ALIGN_LEFT)
  {
    while (i <= 40)
    {
      text[0] = SerialReadPostIncr();
      if ((text[0] == 0) || (text[0] == 255))
      {
        return;
      }
      PrintLine(text, x+i, y, style);
      i++;
    }
  }
  
  // TODO: Implement cases where align != ALIGN_LEFT
  
  /*
  else
  {
    for (size=0; text[size]!=0; size++);
    if (align == ALIGN_CENTER)
    {
      PrintLine(text, x-(size/2), y, style);
    }
    else if (align == ALIGN_RIGHT)
    {
      PrintLine(text, x-size, y, style);
    }
    else
    {
      // ERROR
    }
  }
  */
}


void DrawMenuItemIcon(BYTE x, BYTE y, BYTE width, BYTE height, bool delete)
{
  BYTE i, offset_l, offset_r, col_l, col_r, mask;
  
  if (delete)
  {
    mask = 0x00;
  }
  else
  {
    mask = 0xff;
  }
  
  col_l = (x/6)+1;
  col_r = (x+width)/6;
  offset_l = x%6;
  offset_r = (x+width)%6;
  
  PaintScanLine(31 & mask, col_l, y);
  PaintScanLine(31 & mask, col_l, y+height);
  PaintScanLine(62 & mask, col_r, y);
  PaintScanLine(62 & mask, col_r, y+height);
  
  PaintScanLine(32 & mask, col_l, y+2);
  PaintScanLine(32 & mask, col_l, y+height-2);
  PaintScanLine( 1 & mask, col_r, y+2);
  PaintScanLine( 1 & mask, col_r, y+height-2);
  
  for (i=col_l+1; i<col_r; i++)
  {
    PaintScanLine(63 & mask, i, y);
    PaintScanLine(63 & mask, i, y+height);
  }
  
  for (i=col_l; i<=col_r; i++)
  {
    PaintScanLine(63 & mask, i, y+1);
    PaintScanLine(63 & mask, i, y+height-1);
  }
  
  
}


void DrawIcons()
{
  DrawIcon(ADDR_STOP_H, ADDR_STOP_L, 1, 109, ICON_GREY);
  DrawIcon(ADDR_PLAY_H, ADDR_PLAY_L, 6, 109, ICON_NORMAL);
  DrawIcon(ADDR_LANGES_H, ADDR_LANGES_L, 11, 109, ICON_NORMAL);
  DrawIcon(ADDR_SOUNDON_H, ADDR_SOUNDON_L, 16, 109, ICON_NORMAL);
  DrawIcon(ADDR_BODY_H, ADDR_BODY_L, 26, 109, ICON_NORMAL);
  DrawIcon(ADDR_FACE_H, ADDR_FACE_L, 31, 109, ICON_GREY);
  DrawIcon(ADDR_TRANSFER_H, ADDR_TRANSFER_L, 36, 109, ICON_GREY);
}


BYTE getValueClock(BYTE value, BYTE pos)
{
  return(0);
}


//void setCustomChar(BYTE value)
void setCustomChar(BYTE addr1, BYTE addr2, BYTE value)
{
  cmd(MODE_OR); // OR Mode
  dt2(addr1, addr2);
	cmd(ADPSET);
  dt1(value);
	cmd(0xc4); // Write data and not change ADP
}


static BYTE getValueAddr1(BYTE input_i)
{
  if (input_i > 31)
  {
    return 253;
  }
  else
  {
    return 252;
  }
}


static BYTE getValueAddr2(BYTE input_i, BYTE input_j)
{
  if (input_i > 31)
  {
    input_i -= 32;
  }

  return (input_i*8 + input_j);
}


void setCustomCharacters()
{
  
  BYTE i = 0, j = 0;
  
  //dt2(0xfc, 00);
  for (i=0; i<33; i++)
  {
    for (j=0; j<8; j++)
    {
      setCustomChar(getValueAddr1(i), getValueAddr2(i,j), getValueClock(i, j));
    }
  }
}

#ifndef TEMETE3_H
#define TEMETE3_H

#include "temete2.h"

void setCustomChar(unsigned char addr1, unsigned char addr2, unsigned char value);
//void setCustomChar(unsigned char value);

unsigned char getValueMesoestetic(unsigned char value, unsigned char pos);

void PaintGfxMesoestetic(BYTE x, BYTE y);

void DrawMenuItemIcon(BYTE x, BYTE y, BYTE width, BYTE height, bool delete);

void PrintLineAlign(BYTE* text, BYTE y, BYTE align, TStyle style);
void PrintLineAlignXY(BYTE* text, BYTE x, BYTE y, BYTE align, TStyle style);
void PrintLineAlignXYI18n(BYTE memL, BYTE memH, BYTE x, BYTE y, BYTE align, TStyle style);

void DrawIcon(BYTE addrH, BYTE addrL, BYTE x, BYTE y, BYTE mode);
void DrawIcons();

unsigned char getValueClock(unsigned char value, unsigned char pos);

void setCustomCharacters();

#endif
/* Define processor and include header file. */
#ifndef TEMETE4_H
#define TEMETE4_H


#define A_OUTPUTS   0x06    /* value used to setup TRISA */
#define B_OUTPUTS   0x00    /* value used to setup TRISB */
#define C_OUTPUTS   0x40    /* value used to setup TRISC */
#define D_OUTPUTS   0x0c    /* value used to setup TRISD */
#define E_OUTPUTS   0x00    /* value used to setup TRISE */

#define TXHOME			0x40
#define TXAREA			0x41
#define GRHOME			0x42
#define GRAREA			0x43
#define OFFSET			0x22
#define ADPSET			0x24
#define AWRON				0xB0
#define AWROFF			0xB2
#define CMDP				0x01
#define DP					0x00

#define I2C_SLEEP_ITER 2
#define I2C_SLEEP_ITER_LONG 5

#define DISP_GR_ON_TXT_ON 0x9c

#define MODE_OR     0x80
#define MODE_EXOR   0x81
#define MODE_AND    0x82

#define ICON_NORMAL 0
#define ICON_GREY   1

#define ALIGN_LEFT   0
#define ALIGN_RIGHT  1
#define ALIGN_CENTER 2

#define BEEP_START        1
#define BEEP_END          2
#define ERROR_LINEEND     3
#define ERROR_TEXTLENGTH  4
#define ERROR_TEXTPOS     5
#define ERROR_LOGO        6


#define ADDR_BODY_H 0
#define ADDR_BODY_L 0

#define ADDR_FACE_H 0
#define ADDR_FACE_L 0x25

#define ADDR_LANGEN_H 0
#define ADDR_LANGEN_L 0x59

#define ADDR_LANGES_H 0
#define ADDR_LANGES_L 0x7d

#define ADDR_LANGFR_H 0
#define ADDR_LANGFR_L 0xa2

#define ADDR_PLAY_H 0
#define ADDR_PLAY_L 0xc6

#define ADDR_SOUNDOFF_H 0
#define ADDR_SOUNDOFF_L 0xe6

#define ADDR_SOUNDON_H 1
#define ADDR_SOUNDON_L 0x03

#define ADDR_STOP_H 1
#define ADDR_STOP_L 0x28

#define ADDR_TRANSFER_H 1
#define ADDR_TRANSFER_L 0x45


// I18n =>

#define I18N_ES 0
#define I18N_EN 1
#define I18N_FR 2

#define I18N_TOTAL_TIME_L 0x6b
#define I18N_TOTAL_TIME_H 0x01
#define I18N_POWER_L      0x8f
#define I18N_POWER_H      0x01
#define I18N_SPOT_TIME_L  0xa8
#define I18N_SPOT_TIME_H  0x01

// <= I18n


#define DATA				FALSE
#define	CMD					TRUE

// Serial I2C Memory pins
#define SDA RC2
#define SCL RC3

// Encoder pins
#define ENCODER_A RD3
#define ENCODER_B RC6
#define ENCODER_P RD2


#define __16f877
#include "pic/pic16f877.h"

typedef enum t_menuitem { ITEM_STOP, ITEM_START, ITEM_LANG, ITEM_SND,
                          ITEM_BODY, ITEM_FACE, ITEM_TRANSF, ITEM_TTIME,
                          ITEM_STIME, ITEM_POW } TMenuItem;
typedef enum t_treatment{TREAT_BODY, TREAT_FACE, TREAT_TRANS} TTreatment;

typedef enum { FALSE, TRUE } bool;
typedef enum t_style{NORMAL, INVERTED} TStyle;

typedef unsigned char BYTE;

static BYTE addressH=0;
static BYTE addressL=0;
static BYTE status[]={0,0};
static TMenuItem menu_option=0;
static TMenuItem selected_item=255;

static TTreatment treatment=TREAT_BODY;
static BYTE power=75;
static BYTE spottime=15;
static BYTE totaltime[]={1,30};
static bool sound=FALSE;
static BYTE language=I18N_ES;

#define MIN 0
#define SEC 1

void PaintScanLine(BYTE pattern, BYTE x, BYTE y);

void cmd(BYTE parameter);
void Save(bool param, BYTE data_);
void dt2(BYTE h, BYTE l);
void dt1(BYTE inData);

void PaintChar(BYTE value, BYTE x, BYTE y, BYTE mode);
void PaintHex(BYTE value, BYTE x, BYTE y, BYTE mode);
void PaintDec(BYTE value, BYTE x, BYTE y, BYTE mode);

void PauseLong();
void PauseQuarterSecond();
void Beep(BYTE mode);
void BeepError(BYTE mode);
void Pause();
void Sleep(BYTE steps);
void WaitReady(void); /* LEER */

void SerialStart();
void SerialStop();
void SerialByteSend(BYTE data);
BYTE SerialByteRecv();
BYTE SerialRead(BYTE addrH, BYTE addrL);

void SerialSetAddr(BYTE high, BYTE low);
BYTE SerialReadPostIncr();
BYTE SerialReadCurrent();

void Borrar();
void Paint(BYTE pattern[8], BYTE x, BYTE y);

#endif
/*
    temete.c
    Néstor Amigo Cairo - [email protected]
    05 Jan 2009
    
    The code for the TMT System. Precautions should be taken on using it
    or you can get burnt!!
*/

#include "temete2.h"
#include "temete3.h"
#include "temete4.h"

/* Setup chip configuration */
typedef unsigned int config;
config at 0x2007 __CONFIG = _CP_OFF & 
                          _WDT_OFF & 
                          _BODEN_OFF & 
                          _PWRTE_OFF &
                          _HS_OSC &
                          _LVP_OFF &
                          _WRT_ENABLE_OFF;


static void Pantini(void)
{
  //BYTE i;
  
	PORTD = 0xf0;   /* WR, RD, CE, CMD */
	PORTC = 0x01;   /* FS */
	
	RC5 = 0;        /* Reset */
	
	Pause();
	
	RC5 = 1;         /* Reset off */
	
	PauseLong();
	
	dt2(0,0);
	cmd(TXHOME);    /* Text home address 0x0000 */
	dt2(2,128);
	cmd(GRHOME);    /* Set graphic home address 0x280 */
	dt2(0,0x28);
	cmd(TXAREA);    /* Text area: 40 col 6x8 */
	dt2(0,0x28);
	cmd(GRAREA);    /* Graphic area: 40 col */
	cmd(MODE_EXOR); /* Modeset (XOR mode, internal character gen mode) */
	cmd(DISP_GR_ON_TXT_ON);      // Text on, graphics on
	Borrar();
}


void PaintClockTest(BYTE x, BYTE y)
{
  BYTE i = 0;
  /*
	// We paint the border
	
  for (i = 1; i <= 6; i++)
  {
    PaintChar(128+i-1, x+i, y+1, MODE_EXOR);
	}
	
	PaintChar(134, x+1, y+2, MODE_EXOR);
	PaintChar(135, x+6, y+2, MODE_EXOR);
	PaintChar(136, x+1, y+3, MODE_EXOR);
	PaintChar(137, x+6, y+3, MODE_EXOR);
	
  for (i = 1; i <= 6; i++)
  {
    PaintChar(137+i, x+i, y+4, MODE_EXOR);
	}
	
	// And also the inner blank space:
	
  for (i = 2; i <= 5; i++)
  {
    PaintChar(0, x+i, y+2, MODE_EXOR);
	}
  for (i = 2; i <= 5; i++)
  {
    PaintChar(0, x+i, y+3, MODE_EXOR);
	}
	
	PauseQuarterSecond();
  	
  while(TRUE)
  {
  	// Now, we paint the inner 1st quarter of the clock:
  	PaintChar(147, x+4,y+1, MODE_EXOR);
  	PaintChar(148, x+5,y+1, MODE_EXOR);
  	PaintChar(149, x+6,y+1, MODE_EXOR);
  	PaintChar(160, x+4,y+2, MODE_EXOR);
  	PaintChar(160, x+5,y+2, MODE_EXOR);
  	PaintChar(151, x+6,y+2, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  	// Now, we show the 2nd:  	
  	PaintChar(160, x+4,y+3, MODE_EXOR);
  	PaintChar(160, x+5,y+3, MODE_EXOR);
  	PaintChar(153, x+6,y+3, MODE_EXOR);
  	PaintChar(157, x+4,y+4, MODE_EXOR);
  	PaintChar(158, x+5,y+4, MODE_EXOR);
  	PaintChar(159, x+6,y+4, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  	// Now, we show the 3rd:  	
  	PaintChar(152, x+1,y+3, MODE_EXOR);
  	PaintChar(160, x+2,y+3, MODE_EXOR);
  	PaintChar(160, x+3,y+3, MODE_EXOR);
  	PaintChar(154, x+1,y+4, MODE_EXOR);
  	PaintChar(155, x+2,y+4, MODE_EXOR);
  	PaintChar(156, x+3,y+4, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  	// Now, we show the 4th:  	
  	PaintChar(144, x+1,y+1, MODE_EXOR);
  	PaintChar(145, x+2,y+1, MODE_EXOR);
  	PaintChar(146, x+3,y+1, MODE_EXOR);
  	PaintChar(150, x+1,y+2, MODE_EXOR);
  	PaintChar(160, x+2,y+2, MODE_EXOR);
  	PaintChar(160, x+3,y+2, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  
  	// We clean the 1st quarter
  	
    for (i = 4; i <= 6; i++)
    {
      PaintChar(128+i-1, x+i, y+1, MODE_EXOR);
  	}
    PaintChar(  0, x+4, y+2, MODE_EXOR);
    PaintChar(  0, x+5, y+2, MODE_EXOR);
  	PaintChar(135, x+6, y+2, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  	// We clean the 2nd quarter
  	
    PaintChar(  0, x+4, y+3, MODE_EXOR);
    PaintChar(  0, x+5, y+3, MODE_EXOR);
  	PaintChar(137, x+6, y+3, MODE_EXOR);
  	
    for (i = 4; i <= 6; i++)
    {
      PaintChar(137+i, x+i, y+4, MODE_EXOR);
  	}
  	
  	PauseQuarterSecond();
  	
  	// We clean the 3rd quarter
  	
    for (i = 1; i <= 3; i++)
    {
      PaintChar(137+i, x+i, y+4, MODE_EXOR);
  	}
  	
  	PaintChar(136, x+1, y+3, MODE_EXOR);
    PaintChar(  0, x+2, y+3, MODE_EXOR);
    PaintChar(  0, x+3, y+3, MODE_EXOR);
  	
  	PauseQuarterSecond();
  	
  	// We finally clean the 4th quarter
  	
    for (i = 1; i <= 3; i++)
    {
      PaintChar(128+i-1, x+i, y+1, MODE_EXOR);
  	}
  	
  	PaintChar(134, x+1, y+2, MODE_EXOR);
    PaintChar(  0, x+2, y+2, MODE_EXOR);
    PaintChar(  0, x+3, y+2, MODE_EXOR);
  	
  	PauseQuarterSecond();
	}
	*/
	
	
	//PaintChar(128, 1, 1);
	
}


void Menu()
{
  PrintLineAlign("RADIOFREQUENCY SYSTEM", 2, ALIGN_CENTER, NORMAL);
  
  PrintLineAlignXY("TIEMPO TOTAL", 16, 5, ALIGN_RIGHT, NORMAL);
  PrintLineAlignXY("1'30\"", 16, 7, ALIGN_RIGHT, MODE_EXOR);
  
  PrintLineAlignXY("TIEMPO SPOT", 16, 10, ALIGN_RIGHT, NORMAL);
  PrintLineAlignXY("15\"", 16, 12, ALIGN_RIGHT, MODE_EXOR);
  
  PrintLineAlignXY("POTENCIA", 26, 5, ALIGN_LEFT, NORMAL);
  PrintLineAlignXY("75%", 26, 7, ALIGN_LEFT, MODE_EXOR);
  
  language=I18N_FR;
  PrintLineAlignXYI18n(I18N_TOTAL_TIME_H, I18N_TOTAL_TIME_L, 26, 8, ALIGN_LEFT, NORMAL);
  
  PrintHorizStrike();
  DrawIcons();
}


void main(void) {
    
    /* Assign input/output state to tristates */     
    TRISA = A_OUTPUTS;
    TRISB = B_OUTPUTS;
    TRISC = C_OUTPUTS;
    TRISD = D_OUTPUTS;
    TRISE = E_OUTPUTS;
    /* Initialize ports */
    PORTA=0;
    PORTB=0;
    PORTC=0;
    PORTD=0;
    PORTE=0;
    
    Beep(BEEP_START);
    Pantini();
    Menu();
    
    T1CON = 0x21;
    T2CON = 0x06;
    PR2 = 0xff;
    CCP2CON = 0x0c;
    CCPR2L = 0x30;
    
    /*
    // Timer 2
    PR2=0xff;   // 4 MHz clock -> 5kHz PWM frequency
    T2CON = (1<<TMR2ON);

    // Initialize Control PWM
    CCPR2L  = 30;    // Initial Duty
    CCP2CON = 0x0f;  // PWM mode set and 5,4 duty = 0
    */
    Beep(BEEP_END);
    testEncoder();
    while(1);
}

Attachment: Makefile
Description: Binary data

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to