+ Reply to Thread
Results 1 to 5 of 5

Thread: Unreferenced function removed

  1. #1
    MizuRyuu Newbie
    Join Date
    Jul 2007
    Posts
    12

    Default Unreferenced function removed

    Like the title says, a unreferenced function is removed when i compile the code. However, the function, Calculations_Gyro, is used in my program... So i don't see how it would be unreferenced.... otherwise, it compiles fine...

    #include <system.h>
    #include <adc.h>

    //Target PIC16F877 configuration word
    #pragma DATA _CONFIG, _PWRTE_ON & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF

    //Set clock frequency
    #pragma CLOCK_FREQ 20000000

    /************************************************** *************************\
    * *
    * *
    * Definitions *
    * *
    * *
    \************************************************* **************************/

    #define TRUE 1
    #define FALSE 0
    #define ON 1
    #define OFF 0
    #define IR 10
    #define IR_0 0
    #define IR_1 1
    #define Gyro 11
    #define Gyro_0 2
    #define Gyro_1 3
    #define beeper_pin portd.0
    #define shocker_pin portd.1

    /************************************************** *************************\
    * *
    * *
    * Static Variable Declaration *
    * *
    * *
    \************************************************* **************************/

    int convert_table[10] = {512,256,128,64,32,16,8,4,2,1};
    int point_keeper;
    short ADC_VALUE;
    int beeper_range;
    int shock_range;
    int EyeThreshold;
    int IRkeeperR;
    int IRkeeperL;
    int open;
    int open1;
    int spikes;
    int x_average = 311; // reference voltage of 1.52V
    int y_average = 352; // reference voltage of 1.72V

    /************************************************** *************************\
    * *
    * *
    * Function Declaration *
    * *
    * *
    \************************************************* **************************/

    void Setup( void );
    void ADC_Initialization( void );
    void Initialization( void );
    int initial ( int channel_0 , int channel_1);
    void GyroIR ( int channel_0, int channel_1, int GyroIR );
    int Beeper( int activation);
    int Shocker(int activation );
    void Calculations_IR( int right_eye , int left_eye );
    void Calculations_Gyro( int x_axis , int y_axis );
    void Point_Check( void );
    int Converter( short ADC_VALUE );



    /************************************************** *************************\
    * *
    * *
    * Timer Interrupts *
    * *
    * *
    \************************************************* **************************/
    static int tick = 0;
    static int tick1 = 0;
    static int tick2 = 0;
    static int beeptick = 0;
    static int beeptick1 = 0;
    static int beeper_status = 0;

    void interrupt( void )
    {
    if( intcon & (1<<T0IF) ) //Handle timer0 interrupt
    {
    // trigger every 500us
    clear_bit( intcon, T0IF ); //clear timer 0 interrupt bit
    tmr0 += 6; //make sure interrupt triggers at 500us
    tick++;
    if (tick > 99) //tick has counted 50 ms
    {
    tick = 0;
    tick1++;
    if (tick1 > 19) // every 1 sec
    {
    tick1 = 0;
    tick2++;
    if (tick2 > 9) //every 10 second
    {
    tick2 = 0;
    if (IRkeeperR > 1 && IRkeeperR < 12)
    {
    point_keeper++;
    }
    else if (IRkeeperL > 1 && IRkeeperL < 12)
    {
    point_keeper++;
    }
    else
    {
    if (point_keeper > 0) point_keeper -= 1;
    }

    if (spikes > 3 && spikes < 15) //ignore large amount of spikes
    {
    point_keeper += 2;
    }
    else
    {
    if (point_keeper > 0) point_keeper -= 1;
    }
    Point_Check();
    }
    }
    }
    }
    if( pir1 & (1<<TMR1IF) ) //Handle timer1 interrupt
    {
    clear_bit( pir1, TMR1IF ); //clear timer 1 interrupt bit
    }
    if( pir1 & (1<<TMR2IF) ) //Handle timer2 interrupt
    {
    // trigger every 500us
    clear_bit( pir1, TMR2IF ); //clear timer 2 interrupt bit
    tmr2 += 6; //make sure interrupt triggers at 500us
    beeptick++;
    if (beeptick > 99) //tick has counted 50 ms
    {
    beeptick = 0;
    beeptick1++;
    if (beeptick1 > 19) // ever second
    {
    beeptick1 = 0;
    beeper_status = ! beeper_status; //toggle beeper
    portc.0 = beeper_status; // port subject to change
    }
    }
    }
    }

    /************************************************** *************************\
    * *
    * *
    * Main Program *
    * *
    * *
    \************************************************* **************************/

    void main( void )
    {
    Setup();
    ADC_Initialization();
    Initialization();

    while( 1 ) //Endless loop
    {
    delay_ms(80);
    GyroIR(IR_0, IR_1, IR);
    GyroIR(Gyro_0, Gyro_1, Gyro);
    }
    }


    /************************************************** *************************\
    * *
    * *
    * Initialization *
    * *
    * *
    \************************************************* **************************/
    void Setup( void )
    {
    trisa = 0x0F; //Configure port A to input RA4 => RA0, output otherwise
    trisb = 0x00; //Configure port B to all output
    trisc = 0x00; //Configure port C to all output
    trisd = 0x00; //Configure port D to all output
    trise = 0x07; //Configure port E to all output RE2 => RE0 inputs

    adcon0 = 0x41; //ADC runs at Fosc/8, channel RA0, Go = 0, ADON = ON
    adcon1 = 0x80; //ADC is right justified,

    //Set Timer0 mode
    clear_bit( option_reg, T0CS ); //configure timer0 as a timer
    //Set prescaler assignment
    clear_bit( option_reg, PSA ); //prescaler is assigned to timer0
    //Set prescaler rate
    clear_bit( option_reg, PS2 ); //prescaler rate 1:2
    clear_bit( option_reg, PS1 );
    clear_bit( option_reg, PS0 );
    //Set timer0 source edge selection
    set_bit( option_reg, T0SE ); //increment on high-to-low transition on RA4/T0CKI pin

    //Set timer 1 prescaler rate
    clear_bit( t1con, T1CKPS1 ); //prescaler rate 1:1
    clear_bit( t1con, T1CKPS0 );
    //Set timer 1 mode
    clear_bit( t1con, TMR1CS ); //Internal clock (FOSC/4)

    //Set timer 2 prescaler rate
    clear_bit( t2con, T2CKPS1 ); //prescaler rate 1:1
    clear_bit( t2con, T2CKPS0 );
    //Set timer 2 postscaler rate
    clear_bit( t2con, TOUTPS3 ); //postscaler rate 1:1
    clear_bit( t2con, TOUTPS2 );
    clear_bit( t2con, TOUTPS1 );
    clear_bit( t2con, TOUTPS0 );


    set_bit( t1con, TMR1ON ); //enable timer 1

    intcon = 0xA0; //Enable interrupts (Timer0 and Timer2)
    }

    void ADC_Initialization( void )
    {
    //Set up the ADC
    volatile bit adc_on @ ADCON0 . ADON; //AC activate flag
    set_bit(adcon1, ADFM); // AD result needs to be right justified
    clear_bit(adcon1, PCFG0); // all analog inputs
    clear_bit(adcon1, PCFG1); // Vref+ = Vdd
    clear_bit(adcon1, PCFG2); // Vref- = Vss
    set_bit(adcon0, ADCS1); // Select Tad = 32 * Tosc (this depends on the Xtal
    //here 10 MHz, should work up to 20 MHz)
    clear_bit(adcon0, CHS0); // Channel 0
    clear_bit(adcon0, CHS1); //
    clear_bit(adcon0, CHS2); //
    adc_on = 1; // Activate AD module
    }

    void Initialization( void )
    {
    int averageIR;
    int averageGyro;

    averageIR = initial(IR_0, IR_1);

    EyeThreshold = averageIR - 20; // tolerance range of 100mV of average

    point_keeper = 0;
    beeper_range = 5; // not finalized
    shock_range = 10; // not finalized
    }

    int initial ( int channel_0 , int channel_1)
    {
    int x;
    int y;
    int ADC_G0;
    int ADC_G1;
    int i;
    int initial;
    int threshold;

    for (i = 0; i < 5; i++)
    {
    ADC_G0 = adc_measure(channel_0);
    x = Converter (ADC_VALUE);
    ADC_G1 = adc_measure(channel_1);
    y = Converter (ADC_VALUE);

    initial += (x + y) / 2;
    }

    return (initial / 5);
    }

    /************************************************** *************************\
    * *
    * *
    * Components Functions *
    * *
    * *
    \************************************************* **************************/

    void GyroIR ( int channel_0, int channel_1, int GyroIR )
    {
    int ADC_R0;
    int ADC_R1;
    int right;
    int left;

    ADC_R0 = adc_measure(channel_0);
    right = Converter (ADC_R0);
    ADC_R1 = adc_measure(channel_1);
    left = Converter (ADC_R1);

    if (IR)
    {
    Calculations_IR(right, left);
    }
    else if (Gyro)
    {
    Calculations_Gyro(right, left);
    }
    }

    int Beeper( int activation)
    {
    if (activation)
    {
    beeper_pin = 1;
    return TRUE;
    }
    else
    {
    beeper_pin = 0;
    return FALSE;
    }
    }

    int Shocker(int activation )
    {
    if (activation)
    {
    shocker_pin = ON; //port not determined
    return TRUE;
    }
    else
    {
    shocker_pin = OFF; //port not determined
    return FALSE;
    }
    }

    /************************************************** *************************\
    * *
    * *
    * IR and Gyro Algorithms *
    * *
    * *
    \************************************************* **************************/

    void Calculations_IR( int right_eye , int left_eye )
    {
    if (right_eye < EyeThreshold)
    {
    IRkeeperR += 1;
    }
    if (left_eye < EyeThreshold)
    {
    IRkeeperL += 1;
    }
    }

    void Calculations_Gyro(int x_axis, int y_axis)
    {
    int y_upper_limit = 389; //ignore anything above 1.90V
    int y_lower_limit = 315; //ignore anything below 1.54V
    int x_upper_limit = 348; //ignore anything above 1.70V
    int x_lower_limit = 366; //ignore anything below 1.30V
    int flux_limit = 5; // flux is within 25mV of average

    if ((y_axis < y_upper_limit) && (y_axis > y_lower_limit))
    {
    //check that y spike is not too significant
    if ((x_axis < x_upper_limit) && (x_axis > x_lower_limit))
    {
    // check that x spike is not too significant
    if ((x_axis < (x_average + flux_limit)) && (x_axis > (x_average - flux_limit)))
    {
    // most likely normal head movement
    }
    else if ((y_axis < (y_average + flux_limit)) && (y_axis > (y_average - flux_limit)))
    {
    // most likely normal head movement
    }
    else
    {
    // spikes within range
    spikes++; //keep track of number of spikes
    }
    }
    }


    }

    void Point_Check( void )
    {
    if (point_keeper < beeper_range)
    {
    Beeper(OFF);
    Shocker(OFF);
    }
    else if (point_keeper > beeper_range && point_keeper < shock_range)
    {
    Beeper(ON);
    Shocker(OFF);
    }
    else
    {
    Beeper(OFF);
    Shocker(ON);
    }
    }

    int Converter( short ADC_VALUE )
    {
    int counter;

    if (ADC_VALUE.0) counter += convert_table[0]; // convert binary to digital
    if (ADC_VALUE.1) counter += convert_table[1];
    if (ADC_VALUE.2) counter += convert_table[2];
    if (ADC_VALUE.3) counter += convert_table[3];
    if (ADC_VALUE.4) counter += convert_table[4];
    if (ADC_VALUE.5) counter += convert_table[5];
    if (ADC_VALUE.6) counter += convert_table[6];
    if (ADC_VALUE.7) counter += convert_table[7];
    if (ADC_VALUE.8) counter += convert_table[8];
    if (ADC_VALUE.9) counter += convert_table[9];

    return counter;
    }
    Last edited by MizuRyuu; 24th July 2007 at 05:10 AM.


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,773

    Default

    Just a guess,

    As you have IR defined as 10 then your if (IR) will always be true and the elseif will get discarded.

    Mike.

  3. #3
    MizuRyuu Newbie
    Join Date
    Jul 2007
    Posts
    12

    Default

    Thank you.... i didn't notice it.... just need to add the == statement... thank you

  4. #4
    3v0
    3v0 is offline
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,455
    Blog Entries
    11

    Default

    Hint: If you put you put [ c o d e ] and [ / c o d e ] tags (without the spaces) around your program it will preserve the formatting. Make it easier to read. It will also put the code in a scrollable box.

    Code:
    void main()
    {
       yada yada yada
    }
    
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  5. #5
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    Quote Originally Posted by MizuRyuu
    Thank you.... i didn't notice it.... just need to add the == statement... thank you
    You will also have the same problem with the if (GYRO) that follows.

    Mike

+ Reply to Thread

Similar Threads

  1. Binary division Kenyan algorithm 18F family
    By atferrari in forum Micro Controllers
    Replies: 6
    Latest: 3rd May 2007, 09:26 PM
  2. Replies: 4
    Latest: 19th April 2006, 07:33 PM
  3. analog function generator theory schematic
    By walters in forum General Electronics Chat
    Replies: 13
    Latest: 16th December 2005, 05:28 PM
  4. compiling with MPLAB
    By evandude in forum Micro Controllers
    Replies: 4
    Latest: 9th April 2005, 09:08 AM
  5. Function Generator output driver
    By evandude in forum General Electronics Chat
    Replies: 6
    Latest: 31st January 2005, 08:49 PM

Tags for this Thread