Tekil Mesaj gösterimi
Alt 5. December 2012, 09:42 PM   #1 (permalink)
parametre
Misafir
 
Mesajlar: n/a
Standart PIC16F877A ile C Dili Kullanılarak LED Küpü (3D) Uygulaması

- Besleme Devresi -


- PIC Devresi -


- PCB Yerleşimi -


- LED Yerleşimi -


[Sadece Üyelere Linkler Açıktır.Üye Olun !!! Tıklayarak Üye Olun !!!]

- Diğer İndirme Seçeneği -
[Sadece Üyelere Linkler Açıktır.Üye Olun !!! Tıklayarak Üye Olun !!!]

Kod:
// PIC16F877A ile LED kupu uygulamasi

#include <pic.h>
#include <delay.c>
#include <stdlib.h>

// Konfigurasyon ayarlari (4MHz rezonator)
__CONFIG(XT&WDTDIS&PWRTEN&LVPDIS);

//============================================================
//			ANA PROGRAM
//============================================================
main (void)
{

unsigned const char secme[4]={0xFE0xFD0xFB0xF7};
unsigned char aicktxym;
unsigned const char donus1[6]={0x100x010x020x040x080x80};
unsigned const char donus2[6]={0x080x800x400x200x100x01};

unsigned const char altD[4]={0x0F0xF00x000x00};
unsigned const char altB[4]={0x000x000x0F0xF0};

unsigned const char ustD[4]={0x000x000xF00x0F};
unsigned const char ustB[4]={0xF00x0F0x000x00};

unsigned const char dizi[4]={0x880x440x220x11};

unsigned const char xyzD[4]={0x1F0x010x010x01};
unsigned const char xyzB[4]={0x110x000x000x00};

unsigned const char izgaraD[4]={0x9F0x090x090x9F};
unsigned const char izgaraB[4]={0xF90x900x900xF9};

unsigned const char kucukizgaraD[4]={0x000x600x600x00};
unsigned const char kucukizgaraB[4]={0x000x060x060x00};

unsigned const char havaifisekD[36]={0xF00x000x000x00
	 	 		     0xF00x000x000x00
	 	 		     0xF00xF00x000x00
	 	 		     0xF00xF00xF00x00
		 		     0xF00xF00xF00xF0
		 		    
				     0x000x000x000x0F
	 	 		     0x000x000x0F0x0F
	 	 		     0x000x0F0x0F0x0F
	 	 		     0x0F0x0F0x0F0x0F
 	 	 		     };
		       
unsigned const char havaifisekB[36]={0x0F0x000x000x00
		       	     	     0x0F0x000x000x00
 		       	     	     0x0F0x0F0x000x00
	 	 		     0x0F0x0F0x0F0x00
	 	 		     0x0F0x0F0x0F0x0F
	 	 		    
	 	 		     0x000x000x000xF0
	 	 		     0x000x000xF00xF0
	 	 		     0x000xF00xF00xF0
	 	 		     0xF00xF00xF00xF0
	 	 		     };
	 	 		        
//--------------------------------------------------------
// 		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(100);
	}

	PORTD=0;

	for(i=0;i<8;i++){ // RB0'dan RB7'ye
		PORTB=1<<i;
		DelayMs(100);
		}

	PORTB=0;
}
//-------------------------------------


//-------------------------------------
// (2) 64 adet LED'i S seklinde yakmak icin
//-------------------------------------
c=80;
for(a=0;a<4;a++){

	PORTC=secme[a]; // duzlemi sec

	for(i=0;i<4;i++){ // RD0'dan RD3'e
		PORTD=0x01<<i; 
		DelayMs(c);
	}
	for(i=0;i<4;i++){ // RD7'dan RD4'e
		PORTD=0x80>>i; 
		DelayMs(c);
	}
	
	PORTD=0;

	for(i=0;i<4;i++){ // RB0'dan RB3'e
		PORTB=0x01<<i; 
		DelayMs(c);
	}
	for(i=0;i<4;i++){ // RB7'dan RB4'e
		PORTB=0x80>>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<t;a++){ 
	PORTC=secme[a]; // duzlemleri sirayla sec
	PORTD=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<t;a++){ 
	PORTC=secme[a]; // duzlemleri sirayla sec
	PORTB=PORTB|donus2[i]; // dikey duzlem
	DelayMs(1);
	}
}
}
PORTB=0;
}
//-------------------------------------


//-------------------------------------
// (12) Yatayda karasimsek (duzlemler sirayla)
//-------------------------------------
c=100;

for(a=0;a<4;a++){ // yukari dogru

	PORTC=secme[a]; // duzlemi sec

	PORTD=0x0F; 
	DelayMs(c);
	PORTD=0xF0; 
	DelayMs(c);PORTD=0;
	PORTB=0x0F; 
	DelayMs(c);
	PORTB=0xF0; 
	DelayMs(c);

	PORTB=0xF0; 
	DelayMs(c);
	PORTB=0x0F; 
	DelayMs(c);PORTB=0;
	PORTD=0xF0; 
	DelayMs(c);
	PORTD=0x0F; 
	DelayMs(c);
		
}
//-------------------------------------


//-------------------------------------
// (13) Alt ve ust duzlemde eszamanli karasimsek (tersten)
//-------------------------------------
c=100;

for(i=0;i<4;i++){ // tekrar sayisi

for(t=0;t<4;t++){ // duzlem secimi

for(k=0;k<50;k++){ // 50 kez tara

	PORTB=0; PORTD=0;
	PORTC=secme[0]; // 1. duzlemi sec
	PORTD=altD[t];
	PORTB=altB[t];
	DelayMs(1);

	PORTB=0; PORTD=0;
	PORTC=secme[3]; // 4. duzlemi sec
	PORTB=ustB[t];
	PORTD=ustD[t];
	DelayMs(1);
}
}

for(t=0;t<4;t++){

for(k=0;k<50;k++){ 

	PORTB=0; PORTD=0;
	PORTC=secme[0]; // 1. duzlemi sec
	PORTD=ustD[t];
	PORTB=ustB[t];
	DelayMs(1);

	PORTB=0; PORTD=0;
	PORTC=secme[3]; // 4. duzlemi sec
	PORTB=altB[t];
	PORTD=altD[t];
	DelayMs(1);
}
}
}
//-------------------------------------

//-------------------------------------
// (14) rastgele sayi uretimi
//-------------------------------------

for(t=0;t<10;t++){

x=rand();
y=rand();
	
for(k=0;k<100;k++){ 
for(a=0;a<4;a++){
	PORTB=0; PORTD=0;
	PORTC=secme[a]; // duzlemi sec

	PORTD=x;
	PORTB=y;
	DelayMs(1);
}
}
}
//-------------------------------------


//-------------------------------------
// (15) Havaifisek
//-------------------------------------

for(t=0;t<9;t++){

for(k=0;k<40;k++){ // 40 kez tara
for(a=0;a<4;a++){
	PORTB=0; PORTD=0;
	PORTC=secme[a]; // duzlemi sec

	PORTD=havaifisekD[4*t+a];
	PORTB=havaifisekB[4*t+a];
	DelayMs(1);
}
}
}
//-------------------------------------


//-------------------------------------
// (16) Yukselen-alcalan 4 kose kule
//-------------------------------------
for(a=0;a<4;a++){ 
	
for(k=0;k<150;k++){ // 150 kez tara
	PORTB=0; PORTD=0;
	PORTC=secme[a]; // duzlemi sec

	PORTD=0x09;
	PORTB=0x90;
	DelayMs(1);
}
}
for(a=0;a<4;a++){
for(k=0;k<150;k++){ // 150 kez tara
	PORTB=0; PORTD=0;
	PORTC=secme[3-a]; // duzlemi sec

	PORTD=0x09;
	PORTB=0x90;
	DelayMs(1);
}
}
//-------------------------------------


//-------------------------------------
// (17) Dans eden kuleler
//-------------------------------------

t=15; // gecikme

for(m=0;m<8;m++){
		
for(i=0;i<4;i++){
for(k=0;k<t;k++){ // t kez tara
	for(a=0;a<4;a++){ 
		if(i>=a){
		PORTC=secme[a]; // duzlemleri sirayla sec
		PORTD=1<<m;
		PORTB=0x80>>m;
		}
	DelayMs(1);
	PORTB=0; PORTD=0;
	}

}
}

// sonra asagi dogru
for(i=4;i>0;i--){

for(k=0;k<t;k++){ // t kez tara
	for(a=4;a>0;a--){ 
		if(i>=a){
		PORTC=secme[a-1]; // duzlemleri sirayla sec
		PORTD=1<<m;
		PORTB=0x80>>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----------------------------
  Alıntı ile Cevapla