Boa noite
Sou novo nesse universo da programação. Preciso apresenta um projeto para encerramento de cadeira. Pesquisei e encontrei um projeto bacana do "antigo Genius", o problema é que esta dando erro na hora de compilar e não consegui resolver.
Gostaria muito que alguém me ajudasse. Segue o código abaixo, sublinhei a linha que esta dando erro.
Projeto com PIC16f877a; 2 displays 7seg; 1 cristal oscilador externo de 4MHz; 5 botões e resistores de 330.
#define NOTE_A 440
#define NOTE_D 294
#define NOTE_B 523
#define NOTE_C 261
#define NOTE_F 349
#define NOTE_E 329
#define NOTE_G 392
#define NIVEIS 30
//botões
sbit Start at PORTB.B3;
sbit Botao1 at PORTB.B4;
sbit Botao2 at PORTB.B5;
sbit Botao3 at PORTB.B6;
sbit Botao4 at PORTB.B7;
//Leds
sbit Led1 at PORTB.B0;
sbit Led2 at PORTB.B1;
sbit Led3 at PORTB.B2;
sbit Led4 at PORTA.B1;
//selecao do display
sbit Disp1 at PORTD.B6;
sbit Disp2 at PORTD.B7;
//nivel atual do jogo
char level = 1;
//buffers
char Memoria1[NIVEIS];
char Memoria2[NIVEIS];
//numeros para o display
char Display[10] = { 63, 6, 91, 79, 102, 109, 125, 7, 127, 111 };
void Som_Botao1()
{
Led1 = 1;
Sound_Play( NOTE_F, 300 );
Delay_ms( 300 );
Led1 = 0;
}
void Som_Botao2()
{
Led2 = 1;
Sound_Play( NOTE_B, 300 );
Delay_ms( 300 );
Led2 = 0;
}
void Som_Botao3()
{
Led3 = 1;
Sound_Play( NOTE_C, 300 );
Delay_ms( 300 );
Led3 = 0;
}
void Som_Botao4()
{
Led4 = 1;
Sound_Play( NOTE_D, 300 );
Delay_ms( 300 );
Led4 = 0;
}
void Som_Inicial()
{
Led1 = 1; Led2 = 1; Led3 = 1; Led4 = 1;
Sound_Play( 200, 100 );
Delay_ms( 100 );
Sound_Play( 400, 100 );
Delay_ms( 100 );
Sound_Play( 200, 100 );
Delay_ms( 500 );
Led1 = 0; Led2 = 0; Led3 = 0; Led4 = 0;
}
void Som_Perdeu()
{
Led1 = 1; Led2 = 1; Led3 = 1; Led4 = 1;
Sound_Play( 200, 300 );
Delay_ms( 300 );
Sound_Play( 150, 300 );
Delay_ms( 300 );
Sound_Play( 100, 300 );
Delay_ms( 300 );
Led1 = 0; Led2 = 0; Led3 = 0; Led4 = 0;
}
void Som_Ganhou()
{
Led1 = 1; Led2 = 1; Led3 = 1; Led4 = 1;
Sound_Play( 500, 100 );
Delay_ms( 300 );
Sound_Play( 700, 300 );
Delay_ms( 200 );
Sound_Play( 900, 500 );
Delay_ms( 500 );
Sound_Play( 800, 200 );
Delay_ms( 200 );
Sound_Play( 900, 500 );
Delay_ms( 500 );
Led1 = 0; Led2 = 0; Led3 = 0; Led4 = 0;
}
//Gera uma sequencia
void GerarSequencia()
{
unsigned semente;
char random;
char i;
semente = (TMR1H << 8) + TMR1L;
srand( semente );
for( i=0; i < level; i++)
{
random = (char)(rand() % 4);
Memoria1 = random;
if(random == 0)
Som_Botao1();
else if(random == 1)
Som_Botao2();
else if(random == 2)
Som_Botao3();
else
Som_Botao4();
Delay_ms( 200 );
}
}
//Verifica a sequencia do usuário com a
//sequencia gerado pelo pic
char VerificarSequencia()
{
char i;
for( i=0; i < level; i++)
{
if( Memoria2 != Memoria1 )
return 0;
}
return 1;
}
//Escreve os numeros no display
static char flag = 1;
void Write_Display()
{
char temp = level - 1;
Disp1 = flag.B0;
Disp2 = !flag.B0;
if( flag.B0 )
{
PORTC = Display[temp/10];
}
else
{
PORTC = Display[temp%10];
}
flag.B0 = ~flag.B0;
}
//Interrupção a cada 4ms para escreve no display
void Interrupt()
{
TMR0IF_Bit = 0;
Write_Display();
TMR0 = 6;
}
void main()
{
char cnt = 0;
char flags = 0;
T1CON = 0x81; //habilita o timer 1
CMCON = 0x07; //desliga os comparadores analogico
ADCON1 = 0x06; //desliga o conversor AD
TRISB = 0b11111000;
TRISA = 0;
TRISC = 0;
TRISD = 0;
PORTD = 0;
PORTC = 0;
Sound_Init( &PORTA, 0 );
//Configura timer0 para gerar interrupção a cada 4ms
OPTION_REG = 0x04;
TMR0 = 6;
INTCON = 0xA0;
Som_Inicial();
Inicio:
while(Start);
Delay_ms( 2000 );
while(1)
{
cnt = 0;
GerarSequencia();
while(1)
{
if(!Botao1) flags.B0 = 1;
else if(!Botao2) flags.B1 = 1;
else if(!Botao3) flags.B2 = 1;
else if(!Botao4) flags.B3 = 1;
if(Botao1 && flags.B0)
{
flags.B0 = 0;
Memoria2[cnt++] = 0;
Som_Botao1();
}
else if(Botao2 && flags.B1)
{
flags.B1 = 0;
Memoria2[cnt++] = 1;
Som_Botao2();
}
else if(Botao3 && flags.B2)
{
flags.B2 = 0;
Memoria2[cnt++] = 2;
Som_Botao3();
}
else if(Botao4 && flags.B3)
{
flags.B3 = 0;
Memoria2[cnt++] = 3;
Som_Botao4();
}
if( cnt == level )
break;
}
if( VerificarSequencia() )
{
level++;
if(level == NIVEIS)
{
level = 1;
Som_Ganhou();
goto Inicio;
}
}
else
{
level = 1;
Som_Perdeu();
goto Inicio;
}
Delay_ms(1000);
}
}