12f675 tetik ucu programlama sorunu

tekcarem

Üye
Katılım
19 Şub 2009
Mesajlar
10
Puanları
1
Yaş
35
Merhabalar ccs c ile programlama yapmaya çalışyorum.

GP0 Yeşil led
GP1 Tetik ucu
GP2 kırmızı led

olarak devrede tanımlı

tetik ucunda 5v geldiginde kırmızı led 2 saniye yanıp sönecek
5v gelmediginde yeşil led 2 saniye yanıp sönecek


kodlar


#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5


void init()
{
//set_tris_a( 0b00000010 ); // set GP1 input, all other output
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input

setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D

}
main()
{

init();

//koşul oluştur



if (!input(GP1) == 1)
{

output_high( GP0 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP0 ); // turn LED off
delay_ms( 250 ); // wait 250ms


}

if (!input(GP1) == 0) {
output_high( GP2 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP2 ); // turn LED off
delay_ms( 250 ); // wait 250ms
}

}
 
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5


void init()
{
//set_tris_a( 0b00000010 ); // set GP1 input, all other output
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input

setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D

}
main()
{
int durum=1
;
init();

//koşul oluştur



if (input(GP1) && durum==1)
{

output_high( GP0 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP0 ); // turn LED off
delay_ms( 250 ); // wait 250ms
durum=0;

}

if (!input(GP1) && durum== 0) {
output_high( GP2 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP2 ); // turn LED off
delay_ms( 250 ); // wait 250ms
durum=1;
}

}
 
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5


void init()
{
//set_tris_a( 0b00000010 ); // set GP1 input, all other output
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input

setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D

}
main()
{
int durum=1
;
init();

//koşul oluştur



if (input(GP1) && durum==1)
{

output_high( GP0 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP0 ); // turn LED off
delay_ms( 250 ); // wait 250ms
durum=0;

}

if (!input(GP1) && durum== 0) {
output_high( GP2 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP2 ); // turn LED off
delay_ms( 250 ); // wait 250ms
durum=1;
}

}
Çok teşekkür ederim cevap için. Bu konularda çok acemiyim
Proteus 8 çalıştırıyorum ama çalışmıyor

isis
şeması şu şekilde
54258


buton ile input değerine 5v veriyorum

input değerlerini doğrumu yapıyorum bilemedim
 
init(); den sonraki kısmı while(1){} içine alın düzelir.

Birde GP1 butonun bağlı olduğu pini
4.7k 10k gibi bir direnç ile gnd ye çekin.


Kod paylaşırken kod tag ını kullanırsanız aşağıdaki gibi düzenli görebiliriz ve
bazı karakterlerin bozulma ihtimali önlenmiş olur.

Kod:
#include <12F675.h>
#device ADC=10

#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5


void init()
{
set_tris_a( 0b00000010 ); // set GP1 input, all other output
//set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input

setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D

}
main()
{
int durum=1;
init();

//koşul oluştur

   while(1)
   {
      if (input(GP1) && durum==1)
      {
    
      output_high( GP0 ); // turn LED on
      delay_ms( 250 ); // wait 250ms
      output_low( GP0 ); // turn LED off
      delay_ms( 250 ); // wait 250ms
      durum=0;
    
      }
 
      if (!input(GP1) && durum== 0) {
      output_high( GP2 ); // turn LED on
      delay_ms( 250 ); // wait 250ms
      output_low( GP2 ); // turn LED off
      delay_ms( 250 ); // wait 250ms
      durum=1;
      }

   }
}
 
init(); den sonraki kısmı while(1){} içine alın düzelir.

Birde GP1 butonun bağlı olduğu pini
4.7k 10k gibi bir direnç ile GND ye çekin.


Kod paylaşırken kod tag ını kullanırsanız aşağıdaki gibi düzenli görebiliriz ve
bazı karakterlerin bozulma ihtimali önlenmiş olur.

Kod:
#include <12F675.h>
#device ADC=10

#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5


void init()
{
set_tris_a( 0b00000010 ); // set GP1 input, all other output
//set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input

setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D

}
main()
{
int durum=1;
init();

//koşul oluştur

   while(1)
   {
      if (input(GP1) && durum==1)
      {
   
      output_high( GP0 ); // turn LED on
      delay_ms( 250 ); // wait 250ms
      output_low( GP0 ); // turn LED off
      delay_ms( 250 ); // wait 250ms
      durum=0;
   
      }

      if (!input(GP1) && durum== 0) {
      output_high( GP2 ); // turn LED on
      delay_ms( 250 ); // wait 250ms
      output_low( GP2 ); // turn LED off
      delay_ms( 250 ); // wait 250ms
      durum=1;
      }

   }
}
Teşekkür ederim dediginiz gibi çalıştı
 

Forum istatistikleri

Konular
127,959
Mesajlar
913,914
Kullanıcılar
449,606
Son üye
rasit.

Yeni konular

Geri
Üst