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

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    C compiling questions.....


    Hi, i am a noob (the 2 x o's are intentional :)!!), and do not have any C knowledge, but am trying to complie an old c program from microchip for their "PICREF2" intelligent battery charger.
    So, i am thinking C code is c code, whether it was written today or yestetrday, so a compiler today should be able to compile code from yesterday. However it doesn't.
    My compiler is (PCWH), but any comliler should do? It gives "Illegal C character in input file 0x40", with the battery.h file it is trying to complie being :

    #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>
    #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
    //#define TRUE 1

    #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

    ******************************************************************************/
    /*******************************
    FLAGS
    ********************************/
    //bits control_bits;
    #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;
    #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;
    #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
    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
    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
    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
    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)
    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
    char high_voltage_low @ high_voltage; // Char Access to long variable

    // 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

    #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
    int config_buf_temp_lo; // DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    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
    int config_buf_trickle_temp_lo; // DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    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
    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"

    The compiler highlights the "@" in the line "char high_voltage_low @ high_voltage;".


    Can i ask why please ??

    Many thanks.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    char high_voltage_low @ high_voltage; // Char Access to long variable

    @ has no meaning in C.

    So, i am thinking C code is c code, whether it was written today or yestetrday, so a compiler today should be able to compile code from yesterday.
    Yeah, pretty much. But only so long as the code complies to the standards. In the case of embedded compilers, it's possible that they felt the need to extend the language by introducing some new operation or kind of declaration, for which they used the @ . No idea what that's supposed to mean there.

    Next time, use code tags to post your code. Also, if you are posting more than one file (which I cannot tell whether you are or not, since what you have posted is barely readable, a problem that is solved by code tags), then post each one in a separate pair of code tags. There are many times when we will need to try to compiler something, so the fewer obstacles you arbitrarily throw at us to hinder our efforts to help you, the better.

    PS

    [code] Here insert your properly and consistently indented code [/code]
    Last edited by dwise1_aol; December 18th, 2013 at 05:22 PM.
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    > long high_voltage; // Highest Charge Voltage Reading
    > char high_voltage_low @ high_voltage; // Char Access to long variable
    Looks like they should have used a union to me.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Thanks - and some new questions


    Hi thanks very much for your input - the delay getting back to u was xmas, heavy cold, holiday and xmas again!!!!
    Anyway have been trying to learn a bit of C just to be able to let me compile this code......

    My original question was regarding the "@" used in the code was not recognised by my compiler. So looking at how it was using "high_voltage_low", it seems that it was looking at the low 8 bits of the 16 bit variable "high_voltage" in order to see if the battery voltage has changed. So to extract the lower 8 bits out of "high_voltage" and place this data into the variable "high_voltage_low", i have done :
    Code:
    char high_voltage_low = high_voltage & 0xff
    Does this look ok ??? (even though char is 8 bit and "high_voltage" is 16 bit)

    Now, regarding the code i am trying to compile :

    Code:
    /*****************************************************************************
    *	Filename:	BATTERY.H
    ******************************************************************************
    *
    *	Author:		Bruce Moore
    *	Company:	TRISYS, Inc.
    *	Date:		10-23-96
    *	Compiled Using MPLAB-C Rev 1.21
    *
    ******************************************************************************
    *
    *	Include Files:
    *		
    ******************************************************************************
    *
    *	Description:	The define file is contains the following sections
    *			1) Mode definition (DEVELOPMENT or STAND_ALONE)
    *			2) HW definition (GENERIC for 72/73A)
    *			3) Global Defines
    *			4) Global Variables
    *			5) Function Prototypes
    *
    ******************************************************************************
    *
    *	Revisions:
    *			3/20/97 Updated dV and dT resolutions
    *			3/14/97	Optimized variable usage
    *			3/7/97	Move STAND_ALONE parameters to ROM
    *			2/7/97	Added hooks for DEVELOPMENT and STANDALONE mode.
    *
    *
    *
    ******************************************************************************/
    
    /*****************************************************************************
    
    		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>
    #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
    //#define TRUE	1
    
    #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
    
    ******************************************************************************/
    /*******************************
    	FLAGS
    ********************************/
    //bits control_bits;
    #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;
    #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;
    #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
    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
    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
    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
    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)
    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
    //char high_voltage_low @ high_voltage;	// Char Access to long variable
    char high_voltage_low = high_voltage & 0xff	// masks all but the lowest 8 bits		
    
    // 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
    
    #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
    int config_buf_temp_lo;			// DEVELOPMENT MODE: 8-bit signed, 0.5 C per bit
    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
    int config_buf_trickle_temp_lo;		// DEVELOPMENT MODE: 8-bit signed, 0.5 C/bit
    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
    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"
    My compiler is complaining about:

    Code:
    // 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
    and for the 2 x int lines and the char line it gives "expression must evaluate to a constant".

    Why - all we are doing is defining some int's and a char ???

    Also, with the following code :

    Code:
    /*******************************
    	FLAGS
    ********************************/
    bits control_bits;
    #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;
    #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;
    #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
    The "bits flag_bits;" is not understood by my compiler - is this normal ?

    What is happening elsewhere (in the included files) is that it wants to look/alter a certain bit of a particular byte, and it does this by using :

    for eg. "buffer_bits.ibuf1_full"

    It uses this "byte.bit" quite alot.

    I understand that the bit names above are equivilent to putting numbers, and done so to make the code easier to understand. So, if there is a char called "buffer_bits", how do i address bit "ibuf1_full" by writting :

    "buffer_bits.ibuf1_full"

    What else would i do apart from:
    Code:
    char buffer_bits
    #define ibuf1_full		0x01
    I am thinking that if i preserve the byte.bit format i will not have to re-write the code - or would it be easier, quicker, less complicated to re-write it ??

    Sorry for the long post. hope i have the code brackets done correctly this time!!

    Thnx

IMN logo majestic logo threadwatch logo seochat tools logo