error: (1089) recursive function call to "_forward_flight" XC8 compiler

689 Views Asked by At

I am trying to emulate a pingpong game with LED's showing the flight of the ball. Two players using buttons connected to RA0 and RA1 control the flight of the ball. Game starts with either pressing their respective button. I have two functions, forward_flight and reverse_flight which light the led's from player one two player 2 and vice versa. Player 2 has two return the ball by pressing his button when Led connected to RB7 is on and player 1 has to return the ball when led at RB0 is on. The game continues until one of them reaches a score of 9. I am using PORTB as output for the LED's. I am using PIC16F873A programming it in c. Below is the configuration and source code:

// PIC16F873A Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)



#include <xc.h>
#define _XTAL_FREQ 20000

unsigned char x = 0;
unsigned char y = 0;
unsigned char h;
unsigned char sc;
unsigned char lookup(unsigned char sc);

void forward_flight();
void reverse_flight();
void game_Over();

void forward_flight(){
        PORTBbits.RB0 = 1;
        __delay_ms(50);
        PORTBbits.RB0 = 0;

        PORTBbits.RB1 = 1;
        __delay_ms(50);
        PORTBbits.RB1 = 0;

        PORTBbits.RB2 = 1;
        __delay_ms(50);
        PORTBbits.RB2 = 0;

        PORTBbits.RB3 = 1;
        __delay_ms(50);
        PORTBbits.RB3 = 0;

        PORTBbits.RB4 = 1;
        __delay_ms(50);
        PORTBbits.RB4 = 0;

        PORTBbits.RB5 = 1;
        __delay_ms(50);
        PORTBbits.RB5 = 0;

        PORTBbits.RB6 = 1;
        __delay_ms(50);
        PORTBbits.RB6 = 0;

        PORTBbits.RB7 = 1;
        while(PORTBbits.RB7){
            if(PORTAbits.RA1==1){
                reverse_flight();
            }
            else if(PORTAbits.RA1==0){
            __delay_ms(50);
            PORTBbits.RB7 = 0;
            x++;

            if(x<=9){
                PORTC = lookup(x);
            }else{
                game_Over();
                break;
            }
            }
        }

        return;
    }


void reverse_flight(){
        PORTBbits.RB7 = 1;
        __delay_ms(50);
        PORTBbits.RB7 = 0;

        PORTBbits.RB6 = 1;
        __delay_ms(50);
        PORTBbits.RB6 = 0;

        PORTBbits.RB5 = 1;
        __delay_ms(50);
        PORTBbits.RB5 = 0;

        PORTBbits.RB4 = 1;
        __delay_ms(50);
        PORTBbits.RB4 = 0;

        PORTBbits.RB3 = 1;
        __delay_ms(50);
        PORTBbits.RB3 = 0;

        PORTBbits.RB2 = 1;
        __delay_ms(50);
        PORTBbits.RB2 = 0;

        PORTBbits.RB1 = 1;
        __delay_ms(50);
        PORTBbits.RB1 = 0;

        PORTBbits.RB0 = 1;
        while(PORTBbits.RB0){
            if(PORTAbits.RA0==1){
                forward_flight();
            }
            else if(PORTAbits.RA0==0){
            __delay_ms(50);
            PORTBbits.RB0 = 0;
            y++;

            if(y<=9){
                PORTC = lookup(y);
            }else{
                game_Over();
                break;
            }

            }

        }

        return ;
    }


unsigned char lookup(unsigned char sc){
    switch(sc){
        case 0: sc = 0x00; break;
        case 1: sc = 0x01; break;
        case 2: sc = 0x02; break;
        case 3: sc = 0x03; break;
        case 4: sc = 0x04; break;
        case 5: sc = 0x05; break;
        case 6: sc = 0x06; break;
        case 7: sc = 0x07; break;
        case 8: sc = 0x08; break;
        case 9: sc = 0x09; break;
    }
    return (sc);

}
void game_Over(){
    x = 0;
    y = 0;

}


void main(){      
   ADCON1 = 0xFF;
   TRISAbits.TRISA0 = 1;
   TRISAbits.TRISA1 = 1;
   TRISB = 0x00;
   PORTB = 0x00;
   TRISC = 0x00;
   PORTC = 0x00;

    while(x <9 && y<9){
        if(PORTAbits.RA0 == 1){
            forward_flight();
        }



    else if(PORTAbits.RA1==1){
        reverse_flight();
    }  
}
}

And this is the error I get.

source.c:14:: error: (1089) recursive function call to "_forward_flight"
source.c:66:: error: (1089) recursive function call to "_reverse_flight"
make[2]: *** [dist/default/production/Pingpong.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:154: recipe for target 'dist/default/production/Pingpong.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/PAKO MOARO/MPLABXProjects/Pingpong.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/PAKO MOARO/MPLABXProjects/Pingpong.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
0

There are 0 best solutions below