错误:(1089)对“ _forward_flight” XC8编译器的递归函数调用

时间:2019-12-15 11:43:26

标签: c microcontroller mikroc

我正在尝试用LED显示球的飞行情况来模拟乒乓球比赛。两名球员使用连接到RA0和RA1的按钮控制球的飞行。游戏开始于按下各自的按钮。我有两个功能,forward_flight和reverse_flight,它们分别从玩家1和玩家2以及从玩家2点亮LED。当连接到RB7的LED点亮时,玩家2有两个通过按按钮返回球的功能,而当在RB0处的LED指示灯亮起时,玩家1必须将球返回。游戏继续进行,直到其中之一达到9分为止。我使用PORTB作为LED的输出。我正在使用PIC16F873A在c中对其进行编程。下面是配置和源代码:

// 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();
    }  
}
}

这是我得到的错误。

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 个答案:

没有答案