12f675 direkt çalışma sorunu

Başlatan ironeyes, 25 Ekim 2022, 15:20:24

ironeyes

Arkadaşlar merhaba kolay gelsin öncelikle.Aşağıda yer alan kodu pice attığımda pic direkt çalışıyor normalde 3 numaralı bacağa bağlı butona basıldığında çalışması gerekirken.
İşin içinden bir türlü çıkamadım yardımcı olursanız sevinirim.


#include <12f675.h>
#fuses XT,NOWDT,NOBROWNOUT,NOPUT,NOCPD,XT,NOWDT,NOBROWNOUT,NOPUT,NOMCLR,PROTECT
#use delay(clock=4M)
#use fast_io(a)
//0000000
//if(input(pin_a4)==1);
//output_high(pin_a3);
//delay_ms(1000);
//output_low(pin_a5);
//output_a(0b000000);
//set_tris_a(0b0001000);

#define GP0 PIN_a0 
#define GP1 PIN_a1 
#define GP2 PIN_a2 
#define GP3 PIN_a3 
#define GP4 PIN_a4 
#define GP5 PIN_a5 
#byte OSCCAL = 0x90
#define button pin_a3

Void main()
{ 

sleep:
OSCCAL = 0x80; // set internal oscillator to mid frequency 
setup_timer_1(T1_DISABLED);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_comparator( NC_NC_NC_NC ); // disable comparators 
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D 

set_tris_a(0b0001000);
output_a(0b0011111);

basla:
while(true)

{

delay_ms(200);

if(input(button))

{
delay_ms(200);
output_high(pin_a2);
delay_ms(10000);
}
else

{
output_low(pin_a2);

}

output_low(pin_a1);
goto basla;
}
}

sifirzero

tris ile portlari sıfırlama yapmak gerekli. yada hex dosyasini içine attigina emin olmalisi
sifirzero.blogspot.com [email]sifirrzero@gmail.com[/email] iman hem nurdur hem kuvvettir

ironeyes

Alıntı yapılan: sifirzero - 25 Ekim 2022, 15:44:42tris ile portlari sıfırlama yapmak gerekli. yada hex dosyasini içine attigina emin olmalisi

 Rica etsem nasıl yapacağımı açıklar mısın.Kodu attığıma eminim.

ziyaretci

#3

efsanepoldem

    Giriş olarak ayarladığın butona  pull down direnci bağladın mı?

mehmet

35. satırı 0b00000000 olarak düzeltiniz.
59. satırı siliniz.
44. satırdan sonra debounce gecikmesi ve
şartı ilave ediniz.

MPLABX ile daha fazla yardım edebilirim.
GP3 pini mutlaka direnç ile şasede olsun.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

serkan


mehmet

Alıntı yapılan: serkan - 25 Ekim 2022, 19:01:5537. satırda silinecek.
"goto" olmayınca sorun değil.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

mehmet

/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 25 Ekim 2022 Salı, 18:23
 */

// PIC12F675 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-Up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF      // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = ON       // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = ON          // Code Protection bit (Program Memory code protection is enabled)
#pragma config CPD = ON         // Data Code Protection bit (Data memory code protection is enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ  4000000

#define A1  GPIObits.GP1
#define A2  GPIObits.GP2
#define BTN GPIObits.GP3

/*
 * 
 */
void main(void)
{
    CMCON = 0x07;
    ANSEL = 0x00;
    GPIO = 0x00;
    
    TRISIObits.TRISIO1 = 0b0;
    TRISIObits.TRISIO2 = 0b0;
    TRISIObits.TRISIO3 = 0b1;

    while(1)
    {
        __delay_ms(200);

        if(BTN == 0b1)
        {
            __delay_ms(20); // debounce
            if(BTN == 0b1)
            {
                __delay_ms(200);
                A2 = 0b1;
                __delay_ms(10000);
            }
        }
        else
        {
            A2 = 0b0;
        }
        A1 = 0b0;
    }
}
//------------------------------------------------------------------------------

Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

ironeyes

Alıntı yapılan: mehmet - 25 Ekim 2022, 18:47:4335. satırı 0b00000000 olarak düzeltiniz.
59. satırı siliniz.
44. satırdan sonra debounce gecikmesi ve
şartı ilave ediniz.

MPLABX ile daha fazla yardım edebilirim.
GP3 pini mutlaka direnç ile şasede olsun.

debuence hariç dediklerinizi yaptım sorun çözülmedi.debuenceden kasıt nedir ben css c ile yazıyorum mplabx e hakim değilim.

Alıntı yapılan: mehmet - 26 Ekim 2022, 00:02:50
/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 25 Ekim 2022 Salı, 18:23
 */

// PIC12F675 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-Up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF      // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = ON       // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = ON          // Code Protection bit (Program Memory code protection is enabled)
#pragma config CPD = ON         // Data Code Protection bit (Data memory code protection is enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ  4000000

#define A1  GPIObits.GP1
#define A2  GPIObits.GP2
#define BTN GPIObits.GP3

/*
 * 
 */
void main(void)
{
    CMCON = 0x07;
    ANSEL = 0x00;
    GPIO = 0x00;
    
    TRISIObits.TRISIO1 = 0b0;
    TRISIObits.TRISIO2 = 0b0;
    TRISIObits.TRISIO3 = 0b1;

    while(1)
    {
        __delay_ms(200);

        if(BTN == 0b1)
        {
            __delay_ms(20); // debounce
            if(BTN == 0b1)
            {
                __delay_ms(200);
                A2 = 0b1;
                __delay_ms(10000);
            }
        }
        else
        {
            A2 = 0b0;
        }
        A1 = 0b0;
    }
}
//------------------------------------------------------------------------------



mplab kodu sanırım bunlar derleyici hata veriyor maalesef.

mehmet

MPLABX 'i yüklerseniz, paylaştığım kod
sorunsuz derlenir.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr