SİMON GAME

Başlatan gilestel, 26 Ekim 2014, 15:27:26

gilestel

pic random sayı tutar tutuğu sayıyı da ledlere basar karşılık gelen butonlara basarak level atlarsınız.Bir nevi hafıza oyunu
:)
#include <16F877A.h>


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT                    //No Power Up Timer
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD

#use delay(clock=4000000)


#use fast_io(d)
#use fast_io(b)
#use fast_io(c)
#define buton1 pin_C0
#define buton2 pin_C1
#define buton3 pin_C2
#define buton4 pin_C3
#include <stdlib.h>

int a=0,i=0,b,led[10],level,x=0,j,k,l,tarama=0,buton[10],t,q,c,z;
const int dizi[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};

int rastgele;

void main()
{

restart:
setup_timer_0(RTCC_INTERNAL  | RTCC_DIV_256);
set_timer0(60);
enable_interrupts(INT_timer0);
enable_interrupts(GLOBAL);

set_tris_b(0x00);
output_b(0x00);
set_tris_d(0x00);
output_d(0x00);
set_tris_c(0xFF);
b=read_eeprom(1);
if(b>=255)
b=0;
for(q=0;q<=3;q++)
{
z=0b00000001;
for(c=0;c<4;c++)
{
output_d(z);
delay_ms(50);
output_d(0x00);
z=z<<1;
}
z=0b00001000;
for(c=0;c<4;c++)
{
output_d(z);
delay_ms(50);
output_d(0x00);
z=z>>1;

}
}

level=1;
while(level<=10)//||oyun sona erene kadar

{
output_b(dizi[level]);
for(j=1;j<=level;j++)
{
for(k=1;k<=level;k++)
{
basla:
write_eeprom(1,b);
a=b;
write_eeprom(1,a);
b=read_eeprom(1);
delay_us(1);
srand(a);
rastgele=rand()%4+1;
delay_ms(50);
delay_ms(50);
delay_us(1);
a=timer0_kesme();
write_eeprom(1,a);
b=read_eeprom(1);
a=b;
delay_us(1000);
if(rastgele==x)
goto basla;

switch (rastgele)
{
case 1:

output_d(0b00000001);
delay_ms(250);
output_d(0x00);
led[k]=1;

break;

case 2:

output_d(0b00000010);
delay_ms(250);
output_d(0x00);
led[k]=2;
break;

case 3:

output_d(0b00000100);
delay_ms(250);
output_d(0x00);
led[k]=4;
break;

case 4:

output_d(0b00001000);
delay_ms(250);
output_d(0x00);
led[k]=8;
break;




}//switch
x=rastgele;

a=timer0_kesme();
write_eeprom(1,a);
b=read_eeprom(1);
a=b;

} //for k
t=1;
while(t<=level)

{
if(input(buton1))
{

buton[t]=1;
t=t+1;
while(input(buton1));

}



if(input(buton2))
{

buton[t]=2;
t=t+1;
while(input(buton2));

}


if(input(buton3))
{

buton[t]=4;
t=t+1;
while(input(buton3));

}

if(input(buton4))
{

buton[t]=8;
t=t+1;
while(input(buton4));

}


}//while(t<=level



for(l=1;l<=level;l++)

{
if(buton[l]==led[l])
{
tarama++;

}//if(buton[l]==led[l])


}//l for l

if(tarama==level)
{
tarama=0;
}
else
{
tarama=0;
goto restart;


}



}//level*level
level=level+1;
}

}

Powered by EzPortal