// PIC16F877A ile LED kupu uygulamasi #include #include #include // Konfigurasyon ayarlari (4MHz rezonator) __CONFIG(XT&WDTDIS&PWRTEN&LVPDIS); //============================================================ // ANA PROGRAM //============================================================ main (void) { unsigned const char secme[4]={0xFE,0xFD,0xFB,0xF7}; unsigned char a,i,c,k,t,x,y,m; unsigned const char donus1[6]={0x10,0x01,0x02,0x04,0x08,0x80}; unsigned const char donus2[6]={0x08,0x80,0x40,0x20,0x10,0x01}; unsigned const char altD[4]={0x0F,0xF0,0x00,0x00}; unsigned const char altB[4]={0x00,0x00,0x0F,0xF0}; unsigned const char ustD[4]={0x00,0x00,0xF0,0x0F}; unsigned const char ustB[4]={0xF0,0x0F,0x00,0x00}; unsigned const char dizi[4]={0x88,0x44,0x22,0x11}; unsigned const char xyzD[4]={0x1F,0x01,0x01,0x01}; unsigned const char xyzB[4]={0x11,0x00,0x00,0x00}; unsigned const char izgaraD[4]={0x9F,0x09,0x09,0x9F}; unsigned const char izgaraB[4]={0xF9,0x90,0x90,0xF9}; unsigned const char kucukizgaraD[4]={0x00,0x60,0x60,0x00}; unsigned const char kucukizgaraB[4]={0x00,0x06,0x06,0x00}; unsigned const char havaifisekD[36]={0xF0,0x00,0x00,0x00, 0xF0,0x00,0x00,0x00, 0xF0,0xF0,0x00,0x00, 0xF0,0xF0,0xF0,0x00, 0xF0,0xF0,0xF0,0xF0, 0x00,0x00,0x00,0x0F, 0x00,0x00,0x0F,0x0F, 0x00,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F }; unsigned const char havaifisekB[36]={0x0F,0x00,0x00,0x00, 0x0F,0x00,0x00,0x00, 0x0F,0x0F,0x00,0x00, 0x0F,0x0F,0x0F,0x00, 0x0F,0x0F,0x0F,0x0F, 0x00,0x00,0x00,0xF0, 0x00,0x00,0xF0,0xF0, 0x00,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0 }; //-------------------------------------------------------- // Port konfigurasyonu //-------------------------------------------------------- TRISB=0x00; // Hepsi cikis (8 adet LED icin) TRISD=0x00; // Hepsi cikis (8 adet LED icin) TRISC=0x00; // Hepsi cikis (4 adet transistoru secmek icin) //-------------------------------------------------------- //-------------------------------------------------------- // Baslangic durumu ayarlari //-------------------------------------------------------- PORTC=0xFF; // hicbir transistor secili degil PORTB=0x00; // Data lojik 0 PORTD=0x00; // LED'ler sonuk //-------------------------------------------------------- //------------------------------------- // (1) 64 adet LED'i sirayla yakmak icin //------------------------------------- for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemi sec for(i=0;i<8;i++){ // RD0'dan RD7'ye PORTD=1<>i; DelayMs(c); } PORTD=0; for(i=0;i<4;i++){ // RB0'dan RB3'e PORTB=0x01<>i; DelayMs(c); } PORTB=0; } //------------------------------------- //------------------------------------- // (3) x-y-z koordinat ekseni //------------------------------------- for(k=0;k<200;k++){ // 200 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=xyzD[a]; PORTB=xyzB[a]; DelayMs(1); PORTB=0; PORTD=0; } } //------------------------------------- //------------------------------------- // (4) Kup izgara //------------------------------------- // Once buyuk izgara for(t=0;t<2;t++){ // 2 kez tekrarla for(k=0;k<200;k++){ // 200 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=izgaraD[a]; PORTB=izgaraB[a]; DelayMs(1); PORTB=0; PORTD=0; } } //------------------------------------- // Sonra kucuk izgara for(k=0;k<200;k++){ // 200 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=kucukizgaraD[a]; PORTB=kucukizgaraB[a]; DelayMs(1); PORTB=0; PORTD=0; } } } //------------------------------------- //------------------------------------- // (5) yukari-asagi //------------------------------------- for(t=0;t<2;t++){ // once yukari dogru for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ if(a==i){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=0xFF; PORTB=0xFF; } DelayMs(1); PORTD=0;PORTB=0; } } } // sonra asagi dogru for(i=4;i>0;i--){ for(k=0;k<40;k++){ // 40 kez tara for(a=4;a>0;a--){ if(a==i){ PORTC=secme[a-1]; // duzlemleri sirayla sec PORTD=0xFF; PORTB=0xFF; } DelayMs(1); PORTD=0;PORTB=0; } } } } //------------------------------------- //------------------------------------- // (6) yukari asagi eklemeli //------------------------------------- for(t=0;t<2;t++){ // once yukari dogru for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ if(i>=a){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=0xFF; PORTB=0xFF; } DelayMs(1); PORTD=0;PORTB=0; } } } // sonra asagi dogru for(i=4;i>0;i--){ for(k=0;k<40;k++){ // 40 kez tara for(a=4;a>0;a--){ if(i>=a){ PORTC=secme[a-1]; // duzlemleri sirayla sec PORTD=0xFF; PORTB=0xFF; } DelayMs(1); PORTD=0;PORTB=0; } } } } //------------------------------------- //------------------------------------- // (7) sola-saga //------------------------------------- for(t=0;t<2;t++){ //once sola for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=altD[i]; PORTB=altB[i]; DelayMs(1); } } PORTD=0;PORTB=0; } // sonra saga for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=ustD[i]; PORTB=ustB[i]; DelayMs(1); } } PORTD=0;PORTB=0; } } //------------------------------------- //------------------------------------- // (8) one-arkaya //------------------------------------- for(t=0;t<2;t++){ // once onden arkaya dogru for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=dizi[i]; PORTB=dizi[i]; DelayMs(1); } } PORTB=0; PORTD=0; } // sonra arkadan one dogru for(i=0;i<4;i++){ for(k=0;k<40;k++){ // 40 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=dizi[3-i]; PORTB=dizi[3-i]; DelayMs(1); } } PORTB=0; PORTD=0; } } //------------------------------------- //------------------------------------- // (9) Dairesel donus //------------------------------------- PORTB=0; PORTD=0; for(i=0;i<6;i++){ for(k=0;k<20;k++){ // 20 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=donus1[i]; // dikey duzlem DelayMs(1); } } } PORTD=0; for(i=0;i<6;i++){ for(k=0;k<20;k++){ // 20 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTB=donus2[i]; // dikey duzlem DelayMs(1); } } } PORTB=0; //------------------------------------- //------------------------------------- // (10) Dairesel donus-2 //------------------------------------- PORTB=0; PORTD=0; for(i=0;i<6;i++){ for(k=0;k<20;k++){ // 20 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=PORTD|donus1[i]; // dikey duzlem DelayMs(1); } } } for(i=0;i<6;i++){ for(k=0;k<20;k++){ // 20 kez tara for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec PORTB=PORTB|donus2[i]; // dikey duzlem DelayMs(1); } } } //------------------------------------- //------------------------------------- // (11) Dairesel donus-3 //------------------------------------- PORTB=0; PORTD=0; for(t=1;t<=4;t++){ for(i=0;i<6;i++){ for(k=0;k<20;k++){ // 20 kez tara for(a=0;a=a){ PORTC=secme[a]; // duzlemleri sirayla sec PORTD=1<>m; } DelayMs(1); PORTB=0; PORTD=0; } } } // sonra asagi dogru for(i=4;i>0;i--){ for(k=0;k0;a--){ if(i>=a){ PORTC=secme[a-1]; // duzlemleri sirayla sec PORTD=1<>m; } DelayMs(1); PORTD=0;PORTB=0; } } } DelayMs(4*t); } //------------------------------------- //------------------------------------- // (18) Spiral hareket //------------------------------------- // once saat yonunde, sonra ters yonde yukari for(m=7;m<30;m+=5){ PORTB=0; PORTD=0; for(a=0;a<4;a++){ PORTC=secme[a]; // duzlemleri sirayla sec for(i=0;i<6;i++){ PORTD=donus1[i]; DelayMs(m); } PORTD=0; PORTC=secme[a]; // duzlemleri sirayla sec for(i=0;i<6;i++){ PORTB=donus2[i]; DelayMs(m); } PORTB=0; } // ters PORTB=0; PORTD=0; for(a=0;a<4;a++){ PORTC=secme[3-a]; // duzlemleri sirayla sec for(i=0;i<6;i++){ PORTD=donus1[5-i]; DelayMs(m); } PORTD=0; PORTC=secme[3-a]; // duzlemleri sirayla sec for(i=0;i<6;i++){ PORTB=donus2[5-i]; DelayMs(m); } PORTB=0; } } //------------------------------------- } //---------------PROGRAM SONU----------------------------