#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Strange C Compiling Problem


    Hi, i am trying to compile a set of files....

    I have had some problems, and have attempted to fix them along the way, but i would like to check my solutions are valid:

    There was a 16 bit unsigned int (high_voltage), and i needed to extract the lsb byte from it, to form an 8 bit unsigned variable (high_voltage_low), so i did:
    Code:
    char high_voltage_low = high_voltage & 0xff
    Good?

    My compiler gives me some warnings re :
    Code:
    #undef  PI
    Just because "PI" was not previously defined, so i am safe to just ignore these ?

    I would also like some clarification please...
    Within C there are int and char types. I get int is a signed/unsigned number. But also i see lots of use of char for just numbers. Can char be used for numbers, and will it give the same results as int does for all mathematical operations ?
    If char is for characters, then what is the meaning of a signed char ? Also how would a char value be valued, as hex 44 could be "D" or decimal 68 ?

    Finally, i am getting a "expression must evaluate to a constant" when compiling the following :
    Code:
    /*****************************************************************************
    
    		MODE (DEVELOPMENT or STAND_ALONE) DEFINITION
    
    ******************************************************************************/
    #ifdef STAND_ALONE
    // MEMORY USAGE
    // ROM: 1887 Instructions
    // RAM:  101 Bytes
    // Set up for Direct Voltage Sense
    #include <16c72.h>
    // DEVELOPMENT mode
    #else
    // MEMORY USAGE
    // ROM: 3349 Instructions
    // RAM:  153 Bytes
    // Set up for RS232 Communications, I2C Master (DS1803)
    #define DEVELOPMENT
    #include <16c73a.h>
    #include <math.h>
    #include <regs.h>
    #endif
    
    /*****************************************************************************
    
    		BATTERY DEFINITION FOR STANDALONE MODE
    
    ******************************************************************************/
    //	The following are the definitions for the supplied NiCd battery pack.
    //
    //	Battery Charge Temperature 0 to 45 C
    //	Battery Charge Hi Voltage (1.63V per cell) = 6.52 V
    //	Battery Charge Lo Voltage (0.90V per cell) = 3.60 V
    //	Battery Charge Time Limit 60 minutes = 3600 sec
    //	Battery Fast Charge Rate 1.10 A
    //	Battery Trickle Charge Rate 0.01 A
    //	Battery dV/dt Threshold (0.025V per cell) = -0.100 V
    //	Battery  dT/dt Threshold (1deg C per minute)
    //	Battery Discharge Voltage (1.0V per cell) = 4.00V
    
    #define B1_SYSTEM_STATUS 0x60		// Battery 1 Setup: Charge Once, NiCD
    #define B2_SYSTEM_STATUS 0xA0		// Battery 2 Setup: Charge Once, NiCD
    //#define B1_CHARGE_STATUS 0x70		// Battery 1 Setup: Fast Charge, Abs Voltage Termination
    //#define B1_CHARGE_STATUS 0x60		// Battery 1 Setup: Fast Charge, Delta T/Delta t Termination
    #define B1_CHARGE_STATUS 0x50		// Battery 1 Setup: Fast Charge, Delta V Termination
    //#define B2_CHARGE_STATUS 0x70		// Battery 2 Setup: Fast Charge, Abs Voltage Termination
    //#define B2_CHARGE_STATUS 0x60		// Battery 2 Setup: Fast Charge, Delta T/Delta t Termination
    #define B2_CHARGE_STATUS 0x50		// Battery 2 Setup: Fast Charge, Delta V Termination
    #define FAIL_SAFE_FC_TEMP_LO 0x00	// STAND_ALONE MODE: 8-bit signed, 0.5 C per bit
    #define FAIL_SAFE_FC_TEMP_HI 0x5A	// STAND_ALONE MODE: 8-bit signed, 0.5 C per bit
    #define FAIL_SAFE_FC_VOLT_HI 0x70	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_FC_VOLT_LO 0x3D	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_TC_TEMP_LO 0x00	// STAND_ALONE MODE: 8-bit signed, 0.5 C/bit
    #define FAIL_SAFE_TC_TEMP_HI 0x5A	// STAND_ALONE MODE: 8-bit signed, 0.5 C/bit
    #define TERMINATE_ABS_VOLT_HI 0x70	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_FC_TIME_OUT 0x0E10	// STAND_ALONE MODE: 16-bit unsigned, 1 second/bit
    #define FAIL_SAFE_FC_AMP_HI 0x6E	// STAND_ALONE MODE: 8-bit unsigned, 10 ma/bit
    #define FAIL_SAFE_TC_AMP_HI 0x01	// STAND_ALONE MODE: 8-bit unsigned, 10 ma/bit
    #define FAIL_SAFE_DC_VOLT_LO 0x44	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define TERMINATE_DV_THRESHOLD 0x9C	// STAND_ALONE MODE: 8-bit signed, 5.85 mV/bit
    #define TERMINATE_DT_THRESHOLD 0x02	// STAND_ALONE MODE: 8-bit unsigned, 0.5 C/minute
    
    /*****************************************************************************
    
    				HW DEFINITION
    
    ******************************************************************************/
    // Port A:
    #define BI		0	// Battery 1 & 2 current measurement
    #define BT1		1	// Battery 1 temperature measurement
    #define BV1		2	// Battery 1 voltage measurement
    #define BT2		3	// Battery 2 temperature measurement
    #define HANDSHAKE	4	// inter-processor master handshake control
    #define BV2		4	// Battery 2 voltage measurement
    				// BV2 is actually RA5, but is A/D channel 4
    
    // Port B:
    #define DIS_B1		0	// Battery 1 discharge enable
    #define CHG_B1_IND	1	// Battery 1 charge LED enable
    #define DIS_B1_IND	2	// Battery 1 discharge LED enable
    #define CHG_B2_IND	3	// Battery 2 charge LED enable
    #define DIS_B2_IND	4	// Battery 2 discharge LED enable
    #define ERR_LED		5	// Error LED enable
    #define DIS_B2		6	// Battery 2 discharge enable
    #define STANDALONE	7	// Stand alone input
    
    // Port C:
    #define SPARE		0	// Spare pin
    #define CHG_B1		1	// Battery 1 charge enable
    #define PWM		2	// PWM control output
    //#define SCK		3	// I2C clock - Already Defined in PIC16C7X.H
    //#define SDA		4	// I2C data  - Already Defined in PIC16C7X.H
    #define CHG_B2		5	// Battery 2 charge enable
    #define XMIT		6	// RS-232 transmit
    #define RECV		7	// RS-232 receive
    
    /*****************************************************************************
    
    				GLOBAL DEFINES
    
    ******************************************************************************/
    //#define FALSE	0		//Already defined in PIC16C7x.h
    //#define TRUE	1		//Already defined in PIC16C7x.h
    
    #define OFF	0
    #define ON	1
    
    /*******************************
    	TX DATA STRUCTURE
    ********************************/
    #define RTBUF_SIZE	14	// DEVELOPMENT MODE: TX REAL TIME BUFFER SIZE
    #define CONFIG_BUF_SIZE	15	// DEVELOPMENT MODE: RX CONFIG BUFFER SIZE
    #define RX_BUFFER_SIZE	9	// DEVELOPMENT MODE: RX BUFFER SIZE
    
    /*******************************
    	DEVELOPMENT MODES
    ********************************/
    #define IDLE		0x00	// DEVELOPMENT MODE: Idle state
    #define B12_D_C_ONCE	0x03	// DEVELOPMENT MODE: Discharge then Charge Battery 1 & 2
    #define B1_DISCHARGE	0x05	// DEVELOPMENT MODE: Discharge Battery 1
    #define B1_CHARGE	0x06	// DEVELOPMENT MODE: Charge Battery 1
    #define B1_D_C		0x07	// DEVELOPMENT MODE: Discharge then Charge Battery 1
    #define B1_D_C_REPEAT	0x08	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 1
    #define B2_DISCHARGE	0x09	// DEVELOPMENT MODE: Discharge Battery 2
    #define B2_CHARGE	0x0A	// DEVELOPMENT MODE: Charge Battery 2
    #define B2_D_C		0x0B	// DEVELOPMENT MODE: Discharge then Charge Battery 2
    #define B2_D_C_REPEAT	0x0C	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 2
    #define B12_DISCHARGE	0x0D	// DEVELOPMENT MODE: Discharge Battery 1 then Battery 2
    #define B12_CHARGE	0x0E	// DEVELOPMENT MODE: Charge Battery 1 then Battery 2
    #define B12_D_C_REPEAT	0x0F	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 1 & 2
    
    /*******************************
    	TIMERS
    ********************************/
    #define NO_TERMINATE_TIME	30	// No terminate time on start of charge for 30 seconds
    
    /*******************************
    	PWM LIMITS
    ********************************/
    #define DUTY_CYCLE		0x63	// PWM Duty Cycle Frequency
    #define TRICKLE_CHARGE_MIN	0x00	// Minimum PWM for Trickle Charge
    #define TRICKLE_CHARGE_MAX	0x0F	// Maximum PWM for Trickle Charge
    #define FAST_CHARGE_MIN		0x04	// Minimum PWM for Fast Charge
    #define FAST_CHARGE_MAX		0x54	// Maximum PWM for Fast Charge (85% DC)
    
    /*******************************
    	A/D DEFINITIONS
    ********************************/
    #define	BUFFER_SIZE		0x06	// A/D Converter Buffer Size
    #define BUFFER_SIZE_M1		0x05	// A/D Converter Buffer Size - 1
    #define MOVING_AVG_FACTOR	2	// Moving Average Scale Factor
    #define	SAMPLE_TIME		0x01	// A/D Converter Sample Time
    #define	AD_SETUP		0x81	// A/D Converter Setup (Fosc/32, A/D ON)
    
    /*******************************
    	BATTERY DEFINITIONS
    ********************************/
    #define	B1	0	// Battery 1 Flag
    #define	B2	1	// Battery 2 Flag
    
    #define ZERO_CURRENT_DC		0	// Duty Cycle for Zero Current
    #define LOWEST_CURRENT_DC	1	// Duty Cycle for Lowest Current
    
    /*******************************
    	P3 COMMANDS
    ********************************/
    #define SYSTEM_ENABLE	0x04		// DEVELOPMENT MODE: Send System Enable to the PIC16C7X
    #define CONFIGURE	0x2A		// DEVELOPMENT MODE: Send Configuration to PIC16C7X 
    #define SEND_DATA	0x15		// DEVELOPMENT MODE: Request Data from PIC16C7X
    #define SEND_CONFIG	0x3C		// DEVELOPMENT MODE: Request Configuration from PIC16C7X
    #define RESET		0x55		// DEVELOPMENT MODE: Send RESET to PIC16C7X
    #define ERROR		0xFF		// DEVELOPMENT MODE: Send ERROR to PIC16C7X
    
    /*******************************
    	I2C DEFINITIONS
    ********************************/
    #define WrDigPotAddr	0x50		// DEVELOPMENT MODE: DS1803 WRITE Address
    #define WrDigPotB1Cmd	0xAA		// DEVELOPMENT MODE: DS1803 WRITE B1 Command
    #define WrDigPotB2Cmd	0xA9		// DEVELOPMENT MODE: DS1803 WRITE B2 Command
    #define RdDigPotAddr	0x51		// DEVELOPMENT MODE: DS1803 READ Address
    
    /*****************************************************************************
    
    				VARIABLE DEFINITION
    
    ******************************************************************************/
    // Temperature Variables
    int interp_val1;			// Interpolation Value for Thermistor Lookup Table
    int interp_val2;			// Interpolation Value for Thermistor Lookup Table
    char index;				// Index into Thermistor Table Lookup value
    
    char config_buf_new_command;		// Contains the New RX'd Command, FALSE otherwise
    
    /*******************************
    	FLAGS
    ********************************/
    //bits control_bits;
    int control_bits;			// Control Byte
    #define start_new_command	0x00	// TRUE if New Command is RX'd
    #define status_written		0x01	// TRUE if Charge Status Has Been Written to Status Buffer
    #define advance_state		0x02	// TRUE if Current State is Complete (Advance to Next State)
    #define trickle_charge_disable	0x03	// TRUE if Disable Trickle Charge
    
    //bits buffer_bits;
    int buffer_bits;			// Buffer Byte
    #define changed_order		0x00	// TRUE if Buffer Order Has Been Changed
    #define ibuf1_full		0x01	// TRUE if Buffer is Full
    #define ibuf2_full		0x02	// TRUE if Buffer is Full
    #define vbuf1_full		0x03	// TRUE if Buffer is Full
    #define vbuf2_full		0x04	// TRUE if Buffer is Full
    
    //bits flag_bits;
    int flag_bits;				// Flag Byte
    #define error_flag		0x00	// Error Flag
    #define timer_tic_flag		0x01	// TRUE if TIC occurs (0.1 Seconds has Elapsed)
    #define sensor_init_flag	0x02	// TRUE if Sensor is Being Initialized
    #define no_terminate_flag	0x03	// TRUE if Charge is Not Settled (1st 30 Second of Charge)
    #define do_pwm_control_flag	0x04	// TRUE if PWM Control Loop Frame (Every 6 TICs)
    #define temp_flag		0x05	// TRUE if Temperature Error
    
    char gvar1, gvar2, gvar3, gvar4;	// Global scratch char variables
    signed int gvar_signed;			// Global scratch signed char variable
    char *gptr;				// Global char pointer
    
    char states;				// Defines States That State Machine Will Run
    char active_state;			// Defines Current Active State for State Machine
    
    char b1_trickle_dc;			// Battery 1 Trickle Charge Duty Cycle
    char b2_trickle_dc;			// Battery 2 Trickle Charge Duty Cycle
    
    char active_battery;			// Current Active Battery (1 or 2)
    
    // Define Circular Buffers: Battery 1 & 2 Current and Batterry 1 & 2 Voltage
    char ibuf1_buf[BUFFER_SIZE];		// Battery 1 Buffer for Current Reading
    char *ibuf1_ptr;			// Battery 1 Current Reading Buffer Pointer
    char ibuf2_buf[BUFFER_SIZE];		// Battery 2 Buffer for Current Reading
    char *ibuf2_ptr;			// Battery 2 Current Reading Buffer Pointer
    char vbuf1_buf[BUFFER_SIZE];		// Battery 1 Buffer for Voltage Reading
    char *vbuf1_ptr;			// Battery 1 Voltage Reading Buffer Pointer
    char vbuf2_buf[BUFFER_SIZE];		// Battery 2 Buffer for Voltage Reading
    char *vbuf2_ptr;			// Battery 2 Voltage Reading Buffer Pointer
    char *buffer_start;			// Buffer Start Address for Processing Circular Buffers
    char temp_buffer[BUFFER_SIZE];		// Temp Buffer for Ordering IBUF & VBUF Data
    
    // THESE VARIABLES MUST BE IN CONTIGUOUS MEMORY, THEY ARE ACCESSED THROUGH POINTERS
    char rtbuf_b1_volt;			// Battery 1 8-bit unsigned, Voltage 58.5 mV/bit
    signed int rtbuf_b1_temp;		// Battery 1 8-bit signed, Temperature 0.5 C/bit
    char rtbuf_b1_current;			// Battery 1 8-bit unsigned, Current 10 ma/bit
    char rtbuf_b2_volt;			// Battery 2 8-bit unsigned, Voltage 58.5 mV/bit
    signed int rtbuf_b2_temp;		// Battery 2 8-bit signed, Temperature 0.5 C/bit
    char rtbuf_b2_current;			// Battery 2 8-bit unsigned, Current 10 mA/bit
    char rtbuf_system_status;		// System Status Byte
    char rtbuf_charge_status;		// Charge Status
    char rtbuf_b1_error_status;		// Battery 1 Error Status
    char rtbuf_b2_error_status;		// Battery 2 Error Status
    signed int rtbuf_b1_measured_deltav;	// Battery 1 8-bit signed, Delta Voltage Reading  (5.85 mV/bit)
    char rtbuf_b1_measured_deltat;		// Battery 1 8-bit unsigned, Delta Temperature Reading (0.5 C/bit)
    signed int rtbuf_b2_measured_deltav;	// Battery 2 8-bit signed, Delta Voltage Reading  (5.85 mV/bit)
    char rtbuf_b2_measured_deltat;		// Battery 2 8-bit unsigned, Delta Temperature Reading (0.5 C/bit)
    
    unsigned long charge_timer;		// Charger Timer 16-bit unsigned (1.0 Second/bit)
    
    char actual;				// Actual Battery Current Value
    char desired;				// Desired Battery Current Value
    char cumulative_error;			// Integral Error of Current Value
    char tic_counter;			// 0.1 Second TIC Counter
    char control_counter;			// Control Counter for PWM Control Loop
    char count_deltav;			// Counter for 0 deltav detect
    int last_temp1;				// Last Temperature Reading for Battery 1
    int last_temp2;				// Last Temperature Reading for Battery 2
    char temp_b1_counter;			// Temperature Counter
    char temp_b1_old;			// Last Sampled Temperature Reading
    char temp_b1_old_delta;			// Last Sampled Delta Temperature Reading
    char temp_b1_new_delta;			// New Sampled Delta Temperature Reading
    char temp_b2_counter;			// Temperature Counter
    char temp_b2_old;			// Last Sampled Temperature Reading
    char temp_b2_old_delta;			// Last Sampled Delta Temperature Reading
    char temp_b2_new_delta;			// New Sampled Delta Temperature Reading
    
    char this_voltage;			// Current Voltage Reading
    long temp_long;				// Temporarary Long Variable
    long temp_long2;			// Temporarary Long Variable
    
    long high_voltage;			// Highest Charge Voltage Reading 16 bit
    //char high_voltage_low @ high_voltage;	// Char Access to long variable
    char high_voltage_low = high_voltage & 0xff	// high_voltage_low holds the lowest 8 bits of high_voltage	
    
    // Temperature Variables
    //int interp_val1;			// Interpolation Value for Thermistor Lookup Table - above
    //int interp_val2;			// Interpolation Value for Thermistor Lookup Table - above
    //char index;				// Index into Thermistor Table Lookup value - above
    
    //char config_buf_new_command;		// Contains the New RX'd Command, FALSE otherwise - above
    
    #ifdef STAND_ALONE
    
    // THESE VALUES RESIDE IN ROM MEMORY
    const int config_buf_temp_lo = FAIL_SAFE_FC_TEMP_LO;
    const int config_buf_temp_hi = FAIL_SAFE_FC_TEMP_HI;
    const char config_buf_max_voltage = FAIL_SAFE_FC_VOLT_HI;
    const char config_buf_min_voltage = FAIL_SAFE_FC_VOLT_LO;
    const int config_buf_trickle_temp_lo = FAIL_SAFE_TC_TEMP_LO;
    const int config_buf_trickle_temp_hi = FAIL_SAFE_TC_TEMP_HI;
    const char config_buf_abs_volt_high = TERMINATE_ABS_VOLT_HI;
    const unsigned long config_buf_max_time_limit = FAIL_SAFE_FC_TIME_OUT;
    const char config_buf_fast_charge_rate = FAIL_SAFE_FC_AMP_HI;
    const char config_buf_trickle_charge_rate = FAIL_SAFE_TC_AMP_HI;
    const char config_buf_spare = 0x00;	
    const char config_buf_discharge_voltage = FAIL_SAFE_DC_VOLT_LO;
    const int config_buf_deltav_thresh = TERMINATE_DV_THRESHOLD;
    const int config_buf_deltat_deltat_thresh = TERMINATE_DT_THRESHOLD;
    
    // DEVELOPMENT mode
    
    #else
    
    // THESE VARIABLES MUST BE IN CONTIGUOUS MEMORY FOR DEVELOPMENT MODE, THEY ARE ACCESSED THROUGH POINTERS
    
    signed int config_buf_temp_lo;	  	// DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    signed int config_buf_temp_hi;		// DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    char config_buf_max_voltage;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    char config_buf_min_voltage;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    signed int config_buf_trickle_temp_lo;	// DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    signed int config_buf_trickle_temp_hi;	// DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    char config_buf_abs_volt_high;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    unsigned long config_buf_max_time_limit;// DEVELOPMENT MODE: 16-bit unsigned, 1 sec/bit
    char config_buf_fast_charge_rate;	// DEVELOPMENT MODE: 8-bit unsigned, 10 ma/bit
    char config_buf_trickle_charge_rate;	// DEVELOPMENT MODE: 8-bit unsigned, 10 ma/bit
    char config_buf_spare;			// DEVELOPMENT MODE: Spare
    char config_buf_discharge_voltage;	// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    signed int config_buf_deltav_thresh;	// DEVELOPMENT MODE: 8-bit signed, 5.85 mV/bit
    char config_buf_deltat_deltat_thresh;	// DEVELOPMENT MODE: 8-bit unsigned, 0.5 C/minute 
    char config_buf_checksum;		// DEVELOPMENT MODE: one's complement of TX Data
    char config_buf_digpot_setting;		// DEVELOPMENT MODE: digital potentiometer setting
    
    char txbuf_buffer[CONFIG_BUF_SIZE+1];	// DEVELOPMENT MODE: TX Buffer Size
    char txbuf_buffer_full;			// DEVELOPMENT MODE: TX Buffer Full Flag
    char *txbuf_buffer_ptr;			// DEVELOPMENT MODE: TX Buffer Pointer
    char txbuf_buffer_count;		// DEVELOPMENT MODE: TX Buffer Count
    char gCommand;				// DEVELOPMENT MODE: Global Command variable
    char data_size;				// DEVELOPMENT MODE: TX Buffer Data Size Remaining
    char data_byte;				// DEVELOPMENT MODE: TX Buffer Current Data Byte
    char tx_checksum;			// DEVELOPMENT MODE: TX Buffer Checksum Value
    char *config_ptr;			// DEVELOPMENT MODE: Pointer to Configuration Buffer Data
    char this_pot;				// DEVELOPMENT MODE: This Potentiometer Reading
    char railed;				// DEVELOPMENT MODE: TRUE if A/D Converter is Full Scale
    
    /*******************************
    	I2C VARIABLES
    ********************************/
    char gDeviceAddr;			// DEVELOPMENT MODE: DS1803 Device Address
    char gHiAddr;				// DEVELOPMENT MODE: DS1803 Hi Address
    char gData;				// DEVELOPMENT MODE: DS1803 READ/WRITE Data
    char iic_var;				// DEVELOPMENT MODE: I2C Variable
    char iic_index;				// DEVELOPMENT MODE: I2C Index
    
    #endif
    
    /*****************************************************************************
    
    				PROTOTYPE DEFINITION
    
    ******************************************************************************/
    // init.c:
    void init(void);
    
    // sense.c
    void sense(void);
    
    // command.c
    void communicate();
    #ifdef STAND_ALONE
    void read_switch(void);
    // DEVELOPMENT mode
    #else
    void command_parser(void);
    void command_exec(void);
    void tx_char(void);
    #endif
    
    // control.c:
    void control(void);
    
    // library.c:
    void B1Charge(char);
    void B2Charge(char);
    char compare_limit(int, int);
    void check_voltage(void);
    void check_temp(void);
    void check_time(void);
    void FAIL_SAFE(void);
    void TERMINATE(void);
    void FAST_CHARGE(void);
    void TRICKLE_CHARGE(void);
    char MOVING_AVERAGE(void);
    char Read_AD(char);
    void I_SENSE (void);
    void T_SENSE(void);
    void IVT_SENSE(void);
    void V_SENSE(void);
    
    // DEVELOPMENT mode supports DISCHARGE, IIC, or RS232 for STAND_ALONE
    #ifdef DEVELOPMENT
    void B1Discharge(char);
    void B2Discharge(char);
    void COMPARE_VOLTAGES(void);
    void Coarse_Adjust(void);
    char Read_AD_Repeat(char channel);
    void tx_char(void);
    void stop_all_activity(void);
    void i2c_init(void);
    void i2c_start(void);
    void i2c_stop(void);
    void i2c_write(char);
    char i2c_read_many(void);
    char i2c_read_last(void);
    void i2c_WriteByte(void);
    char i2c_ReadBytes(void);
    #endif
    
    //#include <DELAY14.H>
    #include "init.c"
    #include "sense.c"
    #include "control.c"
    #include "command.c"
    #include "library.c"
    Which is the "strange" problem. If i move this red line further up in the listing, then it seems to be happy with the line. If i comment out the line, then the one underneath gives the same error ??? It seems to be anything from this line down gives the same error. The compiler seems to handle all the other files ok?
    What am i doing wrong please ?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,714
    Rep Power
    480

    Least significant byte byte.


    Code:
    //You need to study arithmetic fundamentals.
    //And computer science fundamentals.
    //And then find a copy of limits.h and read it until you understand.
    //Or become a scholar of Mesopotamian literature.
    
    //Here's an interesting fact: Working in base 68, 10 is 68 decimal.
    
    
    //As far as your code snippet goes, the problem is a missing semi-colon in a line considerably earlier:
    
    char high_voltage_low = high_voltage & 0xff	// high_voltage_low holds the lowest 8 bits of high_voltage	
    
    
    //However I seriously doubt that you've adjusted the correct file.  And with all that writing about unsigned why did you not write
    unsigned char high_voltage_low; //?
    Last edited by b49P23TIvg; January 14th, 2014 at 12:51 PM. Reason: Include title
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Brilliant - thanks very much. Shame the compiler did not accurately show the error.
    I did not put the "unsigned" bit in, because my compiler is by default unsigned!
    Have i adjusted the wrong file ??? I don't understand.

    Thanks again. :)
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,594
    Rep Power
    4207
    Originally Posted by chipsuk
    Hi, i am trying to compile a set of files....

    I have had some problems, and have attempted to fix them along the way, but i would like to check my solutions are valid:

    There was a 16 bit unsigned int (high_voltage), and i needed to extract the lsb byte from it, to form an 8 bit unsigned variable (high_voltage_low), so i did:
    Code:
    char high_voltage_low = high_voltage & 0xff
    Good?
    You might want to do this instead:
    Code:
    unsigned char high_voltage_low = (unsigned char) (high_voltage & 0xff)
    That way you're guaranteeing that your high_voltage_low is an unsigned char and you're also explicitly typecasting the result of the bitwise op from int to unsigned char to let the compiler know that you are ok with the type cast.

    Originally Posted by chipsuk
    My compiler gives me some warnings re :
    Code:
    #undef  PI
    Just because "PI" was not previously defined, so i am safe to just ignore these ?
    You should be fine, but I dislike warnings of any kind (because some of them are not a good idea to ignore). Try this instead:
    Code:
    #ifdef PI
    #undef PI
    #endif
    Originally Posted by chipsuk
    I would also like some clarification please...
    Within C there are int and char types. I get int is a signed/unsigned number. But also i see lots of use of char for just numbers. Can char be used for numbers, and will it give the same results as int does for all mathematical operations ?
    Yes, C considers int, char, short, long, long long and all their unsigned variants as integral types. So, it allows you to do arithmetic with all of them. The only thing is that you need watch out for is the ranges of the various types. In many C compilers, char is considered an 8-bit type, therefore on these compilers, you can only use it for values between -128 and 127 (for signed char) and 0-255 (for unsigned char). If you expect to operate on numbers greater than this range, then use another variable type (e.g.) short, int etc.

    Originally Posted by chipsuk
    If char is for characters, then what is the meaning of a signed char ? Also how would a char value be valued, as hex 44 could be "D" or decimal 68 ?
    C allows you to declare any integral type as 'signed' or 'unsigned', that's where the business of a signed char comes in. See previous paragraph about ranges between signed and unsigned types. As to how it is valued, C allows you to treat it either way:
    Code:
    /* These are all equivalent */
    char ch = 0x44;
    char ch = 'D';
    char ch = 68;
    
    /* These are all equivalent */
    if (ch == 'D') 
    if (ch == 68)
    if (ch == 0x44)
    Originally Posted by chipsuk
    Finally, i am getting a "expression must evaluate to a constant" when compiling the following :
    Code:
    /*****************************************************************************
    
    		MODE (DEVELOPMENT or STAND_ALONE) DEFINITION
    
    ******************************************************************************/
    #ifdef STAND_ALONE
    // MEMORY USAGE
    // ROM: 1887 Instructions
    // RAM:  101 Bytes
    // Set up for Direct Voltage Sense
    #include <16c72.h>
    // DEVELOPMENT mode
    #else
    // MEMORY USAGE
    // ROM: 3349 Instructions
    // RAM:  153 Bytes
    // Set up for RS232 Communications, I2C Master (DS1803)
    #define DEVELOPMENT
    #include <16c73a.h>
    #include <math.h>
    #include <regs.h>
    #endif
    
    /*****************************************************************************
    
    		BATTERY DEFINITION FOR STANDALONE MODE
    
    ******************************************************************************/
    //	The following are the definitions for the supplied NiCd battery pack.
    //
    //	Battery Charge Temperature 0 to 45 C
    //	Battery Charge Hi Voltage (1.63V per cell) = 6.52 V
    //	Battery Charge Lo Voltage (0.90V per cell) = 3.60 V
    //	Battery Charge Time Limit 60 minutes = 3600 sec
    //	Battery Fast Charge Rate 1.10 A
    //	Battery Trickle Charge Rate 0.01 A
    //	Battery dV/dt Threshold (0.025V per cell) = -0.100 V
    //	Battery  dT/dt Threshold (1deg C per minute)
    //	Battery Discharge Voltage (1.0V per cell) = 4.00V
    
    #define B1_SYSTEM_STATUS 0x60		// Battery 1 Setup: Charge Once, NiCD
    #define B2_SYSTEM_STATUS 0xA0		// Battery 2 Setup: Charge Once, NiCD
    //#define B1_CHARGE_STATUS 0x70		// Battery 1 Setup: Fast Charge, Abs Voltage Termination
    //#define B1_CHARGE_STATUS 0x60		// Battery 1 Setup: Fast Charge, Delta T/Delta t Termination
    #define B1_CHARGE_STATUS 0x50		// Battery 1 Setup: Fast Charge, Delta V Termination
    //#define B2_CHARGE_STATUS 0x70		// Battery 2 Setup: Fast Charge, Abs Voltage Termination
    //#define B2_CHARGE_STATUS 0x60		// Battery 2 Setup: Fast Charge, Delta T/Delta t Termination
    #define B2_CHARGE_STATUS 0x50		// Battery 2 Setup: Fast Charge, Delta V Termination
    #define FAIL_SAFE_FC_TEMP_LO 0x00	// STAND_ALONE MODE: 8-bit signed, 0.5 C per bit
    #define FAIL_SAFE_FC_TEMP_HI 0x5A	// STAND_ALONE MODE: 8-bit signed, 0.5 C per bit
    #define FAIL_SAFE_FC_VOLT_HI 0x70	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_FC_VOLT_LO 0x3D	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_TC_TEMP_LO 0x00	// STAND_ALONE MODE: 8-bit signed, 0.5 C/bit
    #define FAIL_SAFE_TC_TEMP_HI 0x5A	// STAND_ALONE MODE: 8-bit signed, 0.5 C/bit
    #define TERMINATE_ABS_VOLT_HI 0x70	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define FAIL_SAFE_FC_TIME_OUT 0x0E10	// STAND_ALONE MODE: 16-bit unsigned, 1 second/bit
    #define FAIL_SAFE_FC_AMP_HI 0x6E	// STAND_ALONE MODE: 8-bit unsigned, 10 ma/bit
    #define FAIL_SAFE_TC_AMP_HI 0x01	// STAND_ALONE MODE: 8-bit unsigned, 10 ma/bit
    #define FAIL_SAFE_DC_VOLT_LO 0x44	// STAND_ALONE MODE: 8-bit unsigned, 58.5 mV/bit
    #define TERMINATE_DV_THRESHOLD 0x9C	// STAND_ALONE MODE: 8-bit signed, 5.85 mV/bit
    #define TERMINATE_DT_THRESHOLD 0x02	// STAND_ALONE MODE: 8-bit unsigned, 0.5 C/minute
    
    /*****************************************************************************
    
    				HW DEFINITION
    
    ******************************************************************************/
    // Port A:
    #define BI		0	// Battery 1 & 2 current measurement
    #define BT1		1	// Battery 1 temperature measurement
    #define BV1		2	// Battery 1 voltage measurement
    #define BT2		3	// Battery 2 temperature measurement
    #define HANDSHAKE	4	// inter-processor master handshake control
    #define BV2		4	// Battery 2 voltage measurement
    				// BV2 is actually RA5, but is A/D channel 4
    
    // Port B:
    #define DIS_B1		0	// Battery 1 discharge enable
    #define CHG_B1_IND	1	// Battery 1 charge LED enable
    #define DIS_B1_IND	2	// Battery 1 discharge LED enable
    #define CHG_B2_IND	3	// Battery 2 charge LED enable
    #define DIS_B2_IND	4	// Battery 2 discharge LED enable
    #define ERR_LED		5	// Error LED enable
    #define DIS_B2		6	// Battery 2 discharge enable
    #define STANDALONE	7	// Stand alone input
    
    // Port C:
    #define SPARE		0	// Spare pin
    #define CHG_B1		1	// Battery 1 charge enable
    #define PWM		2	// PWM control output
    //#define SCK		3	// I2C clock - Already Defined in PIC16C7X.H
    //#define SDA		4	// I2C data  - Already Defined in PIC16C7X.H
    #define CHG_B2		5	// Battery 2 charge enable
    #define XMIT		6	// RS-232 transmit
    #define RECV		7	// RS-232 receive
    
    /*****************************************************************************
    
    				GLOBAL DEFINES
    
    ******************************************************************************/
    //#define FALSE	0		//Already defined in PIC16C7x.h
    //#define TRUE	1		//Already defined in PIC16C7x.h
    
    #define OFF	0
    #define ON	1
    
    /*******************************
    	TX DATA STRUCTURE
    ********************************/
    #define RTBUF_SIZE	14	// DEVELOPMENT MODE: TX REAL TIME BUFFER SIZE
    #define CONFIG_BUF_SIZE	15	// DEVELOPMENT MODE: RX CONFIG BUFFER SIZE
    #define RX_BUFFER_SIZE	9	// DEVELOPMENT MODE: RX BUFFER SIZE
    
    /*******************************
    	DEVELOPMENT MODES
    ********************************/
    #define IDLE		0x00	// DEVELOPMENT MODE: Idle state
    #define B12_D_C_ONCE	0x03	// DEVELOPMENT MODE: Discharge then Charge Battery 1 & 2
    #define B1_DISCHARGE	0x05	// DEVELOPMENT MODE: Discharge Battery 1
    #define B1_CHARGE	0x06	// DEVELOPMENT MODE: Charge Battery 1
    #define B1_D_C		0x07	// DEVELOPMENT MODE: Discharge then Charge Battery 1
    #define B1_D_C_REPEAT	0x08	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 1
    #define B2_DISCHARGE	0x09	// DEVELOPMENT MODE: Discharge Battery 2
    #define B2_CHARGE	0x0A	// DEVELOPMENT MODE: Charge Battery 2
    #define B2_D_C		0x0B	// DEVELOPMENT MODE: Discharge then Charge Battery 2
    #define B2_D_C_REPEAT	0x0C	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 2
    #define B12_DISCHARGE	0x0D	// DEVELOPMENT MODE: Discharge Battery 1 then Battery 2
    #define B12_CHARGE	0x0E	// DEVELOPMENT MODE: Charge Battery 1 then Battery 2
    #define B12_D_C_REPEAT	0x0F	// DEVELOPMENT MODE: Repeatedly Discharge then Charge Battery 1 & 2
    
    /*******************************
    	TIMERS
    ********************************/
    #define NO_TERMINATE_TIME	30	// No terminate time on start of charge for 30 seconds
    
    /*******************************
    	PWM LIMITS
    ********************************/
    #define DUTY_CYCLE		0x63	// PWM Duty Cycle Frequency
    #define TRICKLE_CHARGE_MIN	0x00	// Minimum PWM for Trickle Charge
    #define TRICKLE_CHARGE_MAX	0x0F	// Maximum PWM for Trickle Charge
    #define FAST_CHARGE_MIN		0x04	// Minimum PWM for Fast Charge
    #define FAST_CHARGE_MAX		0x54	// Maximum PWM for Fast Charge (85% DC)
    
    /*******************************
    	A/D DEFINITIONS
    ********************************/
    #define	BUFFER_SIZE		0x06	// A/D Converter Buffer Size
    #define BUFFER_SIZE_M1		0x05	// A/D Converter Buffer Size - 1
    #define MOVING_AVG_FACTOR	2	// Moving Average Scale Factor
    #define	SAMPLE_TIME		0x01	// A/D Converter Sample Time
    #define	AD_SETUP		0x81	// A/D Converter Setup (Fosc/32, A/D ON)
    
    /*******************************
    	BATTERY DEFINITIONS
    ********************************/
    #define	B1	0	// Battery 1 Flag
    #define	B2	1	// Battery 2 Flag
    
    #define ZERO_CURRENT_DC		0	// Duty Cycle for Zero Current
    #define LOWEST_CURRENT_DC	1	// Duty Cycle for Lowest Current
    
    /*******************************
    	P3 COMMANDS
    ********************************/
    #define SYSTEM_ENABLE	0x04		// DEVELOPMENT MODE: Send System Enable to the PIC16C7X
    #define CONFIGURE	0x2A		// DEVELOPMENT MODE: Send Configuration to PIC16C7X 
    #define SEND_DATA	0x15		// DEVELOPMENT MODE: Request Data from PIC16C7X
    #define SEND_CONFIG	0x3C		// DEVELOPMENT MODE: Request Configuration from PIC16C7X
    #define RESET		0x55		// DEVELOPMENT MODE: Send RESET to PIC16C7X
    #define ERROR		0xFF		// DEVELOPMENT MODE: Send ERROR to PIC16C7X
    
    /*******************************
    	I2C DEFINITIONS
    ********************************/
    #define WrDigPotAddr	0x50		// DEVELOPMENT MODE: DS1803 WRITE Address
    #define WrDigPotB1Cmd	0xAA		// DEVELOPMENT MODE: DS1803 WRITE B1 Command
    #define WrDigPotB2Cmd	0xA9		// DEVELOPMENT MODE: DS1803 WRITE B2 Command
    #define RdDigPotAddr	0x51		// DEVELOPMENT MODE: DS1803 READ Address
    
    /*****************************************************************************
    
    				VARIABLE DEFINITION
    
    ******************************************************************************/
    // Temperature Variables
    int interp_val1;			// Interpolation Value for Thermistor Lookup Table
    int interp_val2;			// Interpolation Value for Thermistor Lookup Table
    char index;				// Index into Thermistor Table Lookup value
    
    char config_buf_new_command;		// Contains the New RX'd Command, FALSE otherwise
    
    /*******************************
    	FLAGS
    ********************************/
    //bits control_bits;
    int control_bits;			// Control Byte
    #define start_new_command	0x00	// TRUE if New Command is RX'd
    #define status_written		0x01	// TRUE if Charge Status Has Been Written to Status Buffer
    #define advance_state		0x02	// TRUE if Current State is Complete (Advance to Next State)
    #define trickle_charge_disable	0x03	// TRUE if Disable Trickle Charge
    
    //bits buffer_bits;
    int buffer_bits;			// Buffer Byte
    #define changed_order		0x00	// TRUE if Buffer Order Has Been Changed
    #define ibuf1_full		0x01	// TRUE if Buffer is Full
    #define ibuf2_full		0x02	// TRUE if Buffer is Full
    #define vbuf1_full		0x03	// TRUE if Buffer is Full
    #define vbuf2_full		0x04	// TRUE if Buffer is Full
    
    //bits flag_bits;
    int flag_bits;				// Flag Byte
    #define error_flag		0x00	// Error Flag
    #define timer_tic_flag		0x01	// TRUE if TIC occurs (0.1 Seconds has Elapsed)
    #define sensor_init_flag	0x02	// TRUE if Sensor is Being Initialized
    #define no_terminate_flag	0x03	// TRUE if Charge is Not Settled (1st 30 Second of Charge)
    #define do_pwm_control_flag	0x04	// TRUE if PWM Control Loop Frame (Every 6 TICs)
    #define temp_flag		0x05	// TRUE if Temperature Error
    
    char gvar1, gvar2, gvar3, gvar4;	// Global scratch char variables
    signed int gvar_signed;			// Global scratch signed char variable
    char *gptr;				// Global char pointer
    
    char states;				// Defines States That State Machine Will Run
    char active_state;			// Defines Current Active State for State Machine
    
    char b1_trickle_dc;			// Battery 1 Trickle Charge Duty Cycle
    char b2_trickle_dc;			// Battery 2 Trickle Charge Duty Cycle
    
    char active_battery;			// Current Active Battery (1 or 2)
    
    // Define Circular Buffers: Battery 1 & 2 Current and Batterry 1 & 2 Voltage
    char ibuf1_buf[BUFFER_SIZE];		// Battery 1 Buffer for Current Reading
    char *ibuf1_ptr;			// Battery 1 Current Reading Buffer Pointer
    char ibuf2_buf[BUFFER_SIZE];		// Battery 2 Buffer for Current Reading
    char *ibuf2_ptr;			// Battery 2 Current Reading Buffer Pointer
    char vbuf1_buf[BUFFER_SIZE];		// Battery 1 Buffer for Voltage Reading
    char *vbuf1_ptr;			// Battery 1 Voltage Reading Buffer Pointer
    char vbuf2_buf[BUFFER_SIZE];		// Battery 2 Buffer for Voltage Reading
    char *vbuf2_ptr;			// Battery 2 Voltage Reading Buffer Pointer
    char *buffer_start;			// Buffer Start Address for Processing Circular Buffers
    char temp_buffer[BUFFER_SIZE];		// Temp Buffer for Ordering IBUF & VBUF Data
    
    // THESE VARIABLES MUST BE IN CONTIGUOUS MEMORY, THEY ARE ACCESSED THROUGH POINTERS
    char rtbuf_b1_volt;			// Battery 1 8-bit unsigned, Voltage 58.5 mV/bit
    signed int rtbuf_b1_temp;		// Battery 1 8-bit signed, Temperature 0.5 C/bit
    char rtbuf_b1_current;			// Battery 1 8-bit unsigned, Current 10 ma/bit
    char rtbuf_b2_volt;			// Battery 2 8-bit unsigned, Voltage 58.5 mV/bit
    signed int rtbuf_b2_temp;		// Battery 2 8-bit signed, Temperature 0.5 C/bit
    char rtbuf_b2_current;			// Battery 2 8-bit unsigned, Current 10 mA/bit
    char rtbuf_system_status;		// System Status Byte
    char rtbuf_charge_status;		// Charge Status
    char rtbuf_b1_error_status;		// Battery 1 Error Status
    char rtbuf_b2_error_status;		// Battery 2 Error Status
    signed int rtbuf_b1_measured_deltav;	// Battery 1 8-bit signed, Delta Voltage Reading  (5.85 mV/bit)
    char rtbuf_b1_measured_deltat;		// Battery 1 8-bit unsigned, Delta Temperature Reading (0.5 C/bit)
    signed int rtbuf_b2_measured_deltav;	// Battery 2 8-bit signed, Delta Voltage Reading  (5.85 mV/bit)
    char rtbuf_b2_measured_deltat;		// Battery 2 8-bit unsigned, Delta Temperature Reading (0.5 C/bit)
    
    unsigned long charge_timer;		// Charger Timer 16-bit unsigned (1.0 Second/bit)
    
    char actual;				// Actual Battery Current Value
    char desired;				// Desired Battery Current Value
    char cumulative_error;			// Integral Error of Current Value
    char tic_counter;			// 0.1 Second TIC Counter
    char control_counter;			// Control Counter for PWM Control Loop
    char count_deltav;			// Counter for 0 deltav detect
    int last_temp1;				// Last Temperature Reading for Battery 1
    int last_temp2;				// Last Temperature Reading for Battery 2
    char temp_b1_counter;			// Temperature Counter
    char temp_b1_old;			// Last Sampled Temperature Reading
    char temp_b1_old_delta;			// Last Sampled Delta Temperature Reading
    char temp_b1_new_delta;			// New Sampled Delta Temperature Reading
    char temp_b2_counter;			// Temperature Counter
    char temp_b2_old;			// Last Sampled Temperature Reading
    char temp_b2_old_delta;			// Last Sampled Delta Temperature Reading
    char temp_b2_new_delta;			// New Sampled Delta Temperature Reading
    
    char this_voltage;			// Current Voltage Reading
    long temp_long;				// Temporarary Long Variable
    long temp_long2;			// Temporarary Long Variable
    
    long high_voltage;			// Highest Charge Voltage Reading 16 bit
    //char high_voltage_low @ high_voltage;	// Char Access to long variable
    char high_voltage_low = high_voltage & 0xff	// high_voltage_low holds the lowest 8 bits of high_voltage	
    
    // Temperature Variables
    //int interp_val1;			// Interpolation Value for Thermistor Lookup Table - above
    //int interp_val2;			// Interpolation Value for Thermistor Lookup Table - above
    //char index;				// Index into Thermistor Table Lookup value - above
    
    //char config_buf_new_command;		// Contains the New RX'd Command, FALSE otherwise - above
    
    #ifdef STAND_ALONE
    
    // THESE VALUES RESIDE IN ROM MEMORY
    const int config_buf_temp_lo = FAIL_SAFE_FC_TEMP_LO;
    const int config_buf_temp_hi = FAIL_SAFE_FC_TEMP_HI;
    const char config_buf_max_voltage = FAIL_SAFE_FC_VOLT_HI;
    const char config_buf_min_voltage = FAIL_SAFE_FC_VOLT_LO;
    const int config_buf_trickle_temp_lo = FAIL_SAFE_TC_TEMP_LO;
    const int config_buf_trickle_temp_hi = FAIL_SAFE_TC_TEMP_HI;
    const char config_buf_abs_volt_high = TERMINATE_ABS_VOLT_HI;
    const unsigned long config_buf_max_time_limit = FAIL_SAFE_FC_TIME_OUT;
    const char config_buf_fast_charge_rate = FAIL_SAFE_FC_AMP_HI;
    const char config_buf_trickle_charge_rate = FAIL_SAFE_TC_AMP_HI;
    const char config_buf_spare = 0x00;	
    const char config_buf_discharge_voltage = FAIL_SAFE_DC_VOLT_LO;
    const int config_buf_deltav_thresh = TERMINATE_DV_THRESHOLD;
    const int config_buf_deltat_deltat_thresh = TERMINATE_DT_THRESHOLD;
    
    // DEVELOPMENT mode
    
    #else
    
    // THESE VARIABLES MUST BE IN CONTIGUOUS MEMORY FOR DEVELOPMENT MODE, THEY ARE ACCESSED THROUGH POINTERS
    
    signed int config_buf_temp_lo;	  	// DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    signed int config_buf_temp_hi;		// DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    char config_buf_max_voltage;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    char config_buf_min_voltage;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    signed int config_buf_trickle_temp_lo;	// DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    signed int config_buf_trickle_temp_hi;	// DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    char config_buf_abs_volt_high;		// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    unsigned long config_buf_max_time_limit;// DEVELOPMENT MODE: 16-bit unsigned, 1 sec/bit
    char config_buf_fast_charge_rate;	// DEVELOPMENT MODE: 8-bit unsigned, 10 ma/bit
    char config_buf_trickle_charge_rate;	// DEVELOPMENT MODE: 8-bit unsigned, 10 ma/bit
    char config_buf_spare;			// DEVELOPMENT MODE: Spare
    char config_buf_discharge_voltage;	// DEVELOPMENT MODE: 8-bit unsigned, 58.5 mV/bit
    signed int config_buf_deltav_thresh;	// DEVELOPMENT MODE: 8-bit signed, 5.85 mV/bit
    char config_buf_deltat_deltat_thresh;	// DEVELOPMENT MODE: 8-bit unsigned, 0.5 C/minute 
    char config_buf_checksum;		// DEVELOPMENT MODE: one's complement of TX Data
    char config_buf_digpot_setting;		// DEVELOPMENT MODE: digital potentiometer setting
    
    char txbuf_buffer[CONFIG_BUF_SIZE+1];	// DEVELOPMENT MODE: TX Buffer Size
    char txbuf_buffer_full;			// DEVELOPMENT MODE: TX Buffer Full Flag
    char *txbuf_buffer_ptr;			// DEVELOPMENT MODE: TX Buffer Pointer
    char txbuf_buffer_count;		// DEVELOPMENT MODE: TX Buffer Count
    char gCommand;				// DEVELOPMENT MODE: Global Command variable
    char data_size;				// DEVELOPMENT MODE: TX Buffer Data Size Remaining
    char data_byte;				// DEVELOPMENT MODE: TX Buffer Current Data Byte
    char tx_checksum;			// DEVELOPMENT MODE: TX Buffer Checksum Value
    char *config_ptr;			// DEVELOPMENT MODE: Pointer to Configuration Buffer Data
    char this_pot;				// DEVELOPMENT MODE: This Potentiometer Reading
    char railed;				// DEVELOPMENT MODE: TRUE if A/D Converter is Full Scale
    
    /*******************************
    	I2C VARIABLES
    ********************************/
    char gDeviceAddr;			// DEVELOPMENT MODE: DS1803 Device Address
    char gHiAddr;				// DEVELOPMENT MODE: DS1803 Hi Address
    char gData;				// DEVELOPMENT MODE: DS1803 READ/WRITE Data
    char iic_var;				// DEVELOPMENT MODE: I2C Variable
    char iic_index;				// DEVELOPMENT MODE: I2C Index
    
    #endif
    
    /*****************************************************************************
    
    				PROTOTYPE DEFINITION
    
    ******************************************************************************/
    // init.c:
    void init(void);
    
    // sense.c
    void sense(void);
    
    // command.c
    void communicate();
    #ifdef STAND_ALONE
    void read_switch(void);
    // DEVELOPMENT mode
    #else
    void command_parser(void);
    void command_exec(void);
    void tx_char(void);
    #endif
    
    // control.c:
    void control(void);
    
    // library.c:
    void B1Charge(char);
    void B2Charge(char);
    char compare_limit(int, int);
    void check_voltage(void);
    void check_temp(void);
    void check_time(void);
    void FAIL_SAFE(void);
    void TERMINATE(void);
    void FAST_CHARGE(void);
    void TRICKLE_CHARGE(void);
    char MOVING_AVERAGE(void);
    char Read_AD(char);
    void I_SENSE (void);
    void T_SENSE(void);
    void IVT_SENSE(void);
    void V_SENSE(void);
    
    // DEVELOPMENT mode supports DISCHARGE, IIC, or RS232 for STAND_ALONE
    #ifdef DEVELOPMENT
    void B1Discharge(char);
    void B2Discharge(char);
    void COMPARE_VOLTAGES(void);
    void Coarse_Adjust(void);
    char Read_AD_Repeat(char channel);
    void tx_char(void);
    void stop_all_activity(void);
    void i2c_init(void);
    void i2c_start(void);
    void i2c_stop(void);
    void i2c_write(char);
    char i2c_read_many(void);
    char i2c_read_last(void);
    void i2c_WriteByte(void);
    char i2c_ReadBytes(void);
    #endif
    
    //#include <DELAY14.H>
    #include "init.c"
    #include "sense.c"
    #include "control.c"
    #include "command.c"
    #include "library.c"
    Which is the "strange" problem. If i move this red line further up in the listing, then it seems to be happy with the line. If i comment out the line, then the one underneath gives the same error ??? It seems to be anything from this line down gives the same error. The compiler seems to handle all the other files ok?
    What am i doing wrong please ?
    I'd be very careful about moving lines, especially given that there is a warning above that says this:
    Code:
    // THESE VARIABLES MUST BE IN CONTIGUOUS MEMORY FOR DEVELOPMENT MODE, THEY ARE ACCESSED THROUGH POINTERS
    What that means is that the code is written assuming those variables are in a block of memory, one following the other in a particular order. It may be that the embedded system assumes that a block of memory should be formatted in a particular way and therefore you don't want to resize the block. The compiler error you are seeing seems to be unconnected to the line really, it may be something else higher up that is causing the error.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Absolutely fab...
    Thanks so much for making things clearer!!!
    The point about moving the line was only for diagnostics purposes, but you were right the error was not coming from that line - how did you know ? My compiler was pointing to this line.

    I appreciate all your help.
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    The line with the error is (after preprocessing, and ignoring comments) immediately preceded by this line:

    Code:
    char high_voltage_low = high_voltage & 0xff	// high_voltage_low holds the lowest 8 bits of high_voltage
    which is missing a semicolon (;). The error is not "strange", whitespace, including newlines have no syntactic significance in C (with the exception of a // comment delimiter), without the semicolon, the two lines become a single statement - and in that context are syntactically invalid. That is why removing the line simply causes the next line to become an error; whenever you observe that kind of behaviour you should always look at the preceding statement to determine whether it is correctly terminated. If the preceding line is a #include, then the last statement in the included file is suspect.



    Rather than all that char/unsigned char nonsense, in this particular case you'd be better off using explicit width types from <stdint.h>, in this case uint8_t.
    Last edited by clifford; January 14th, 2014 at 02:04 PM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Great - many thanks. Now i know!

IMN logo majestic logo threadwatch logo seochat tools logo