Create a c-language game with the MCU 8051 IDE

Asked

Viewed 387 times

3

I’m trying to develop a game within the curricular unit of microprocessors, so the game consists of a dummy that has to dodge bombs, so I have to create the dummy, the bombs and get them moving. I already have a good piece of code, but I think it gets stuck in a while loop, and I don’t understand why. Will exposing here a piece of my code are able to help me??

void main (void)
{   
unsigned char i,counter=1;

start=0;
end=0;
IE=0b10000101;
En=1;
LCD_init ();
while(start!=0);
while(end==1);
Inicio();
CriarBonecoBomba();
x=0;
y=0;
score=0;

for(i=0;i<16;i++)
{
    var[0][i]=' ';
    var[1][i]=' ';
}
while(end==0) // salta da 1a interrupção la ao fundo para aqui e não sai daqui
{
    while (start==1)
    {
        MovBoneco();
        desloca_esq();
        if((counter+3)%6==0)
            cria_bomba(1);
        else
            if(counter%6==0)
                cria_bomba(2);
            else
                cria_bomba(0);
        if(var[y][x]==1|| 1==var[y][x-1])
        {
            LCD_comando(0b10000000);
            LCD_date(' ');
            LCD_date(' ');
            LCD_date(' ');
            LCD_date('G');
            LCD_date('A');  
            LCD_date('M');
            LCD_date('E');
            LCD_date(' ');
            LCD_date('O');
            LCD_date('V');
            LCD_date('E');
            LCD_date('R');
            while(1);
        }
    MovBoneco();
    AtualizarLCD();
    counter++;
    if(var[0][0]==1||var[1][0]==1)
        score=score+5;
    display7segmentos();
}
}
}

void RSIEXT0(void)__interrupt (0)
{
start=1;
}

void RSIEXT1(void)__interrupt (2)
{
end==1;
}
  • Which compiler are you using? Where do you detect the collision with the pump? You are resetting the variable value start when the bomb hits the dummy?

  • Missing includes in your code so you can at least try to compile your script

  • I don’t think that question should be suspended as unclear. The following sentence says it all: "I already have a good piece of code but I think it gets stuck in a while loop and I don’t understand why".

  • I have the includes in my code, and it compiles correctly, the problem is that I’ve done everything and something else and I can’t get it to start at all. the complilaqdor I am using is the MCU 8051 IDE.

  • In which of while's it gets stuck?

  • Just in the first while, while(start!= 0).

Show 1 more comment

1 answer

2

So much start as end are initialized with zero (0) at the start of their function main. They were not declared with a type (does the compiler you use not generate any warning of this?) or did you declare them outside the scope of the function and did not put this code in the question.

If case 1, even the compiler (possibly) not claiming the scope of the variables is local (i.e., belongs only to the function main). And then, any external change actually changes different variables (from another scope).

If this is the case 2 (which I think is more likely), the variables are global and everything should work correctly (assuming that their "interruptions" are actually being called). Anyway, there’s a little mistake in the function RSIEXT1 where you use the equal operator (two equal signs: ==) instead of the assignment operator (a single sign of the same: =). :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.