PIC loop olmayınca kararsız çalışıyor

Başlatan baran123, 04 Ekim 2016, 23:44:29

baran123

Demin bir kodu denedim oldukça basit.
#include <xc.h> 

// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF       // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
#pragma config STVREN = OFF     // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

#define _XTAL_FREQ  8000000

#define LED LATAbits.LATA0

void main(void) 
{
    OSCCON = 0x70;
    OSCTUNE = 0x00;
    while (!OSCSTATbits.HFIOFR);
    
    for (char c = 0; c < 100; c++)
        __delay_ms(1);
    
    ANSELA = 0;
    TRISA = 0;
    LATA = 0;
    WPUA = 0;
    
    for (char c = 0; c < 100; c++)
        __delay_ms(1);
    
    LED = 1;
}


LED 'in yanması gerekirken süreli blink oluyor.Fakat oradaki delay komutunu kaldırınca program düzeliyor. Yada LED = 1; den sonra for(;;) {} yazmak da sorunu çözüyor. Bunun sebebi nedir ? ASM çıktısını inceledim. En alttaki goto 0x2 neden yazılmış anlamadım.
PIC12F1822 + XC8 kullanıyorum.
!void main(void) 
!{
!    OSCCON = 0x70;
0x7C1: MOVLW 0x70
0x7C2: MOVLB 0x1
0x7C3: MOVWF OSCCON
!    OSCTUNE = 0x00;
0x7C4: CLRF T1CON
!    while (!OSCSTATbits.HFIOFR);
0x7C5: BTFSS TMR2, 0x4
0x7C6: GOTO 0x7C5
!    
!    for (char c = 0; c < 100; c++)
0x7C7: CLRF c
0x7C8: MOVLW 0x64
0x7C9: SUBWF c, W
0x7CA: BTFSC STATUS, 0x0
0x7CB: GOTO 0x7DD
0x7D5: MOVLW 0x1
0x7D6: MOVWF __pcstackCOMMON
0x7D7: MOVF __pcstackCOMMON, W
0x7D8: ADDWF c, F
0x7D9: MOVLW 0x64
0x7DA: SUBWF c, W
0x7DB: BTFSS STATUS, 0x0
0x7DC: GOTO 0x7CC
!        __delay_ms(1);
0x7CC: MOVLW 0x3
0x7CD: MOVWF 0x71
0x7CE: MOVLW 0x97
0x7CF: MOVWF __pcstackCOMMON
0x7D0: DECFSZ __pcstackCOMMON, F
0x7D1: GOTO 0x7D0
0x7D2: DECFSZ 0x71, F
0x7D3: GOTO 0x7D0
0x7D4: BRA 0x7D5
!    
!    ANSELA = 0;
0x7DD: MOVLB 0x3
0x7DE: CLRF ANSELA
!    TRISA = 0;
0x7DF: MOVLB 0x1
0x7E0: CLRF TRISA
!    LATA = 0;
0x7E1: MOVLB 0x2
0x7E2: CLRF LATA
!    WPUA = 0;
0x7E3: MOVLB 0x4
0x7E4: CLRF WPUA
!    
!    for (char c = 0; c < 100; c++)
0x7E5: CLRF c
0x7E6: MOVLW 0x64
0x7E7: SUBWF c, W
0x7E8: BTFSC STATUS, 0x0
0x7E9: GOTO 0x7FB
0x7F3: MOVLW 0x1
0x7F4: MOVWF __pcstackCOMMON
0x7F5: MOVF __pcstackCOMMON, W
0x7F6: ADDWF c, F
0x7F7: MOVLW 0x64
0x7F8: SUBWF c, W
0x7F9: BTFSS STATUS, 0x0
0x7FA: GOTO 0x7EA
!        __delay_ms(1);
0x7EA: MOVLW 0x3
0x7EB: MOVWF 0x71
0x7EC: MOVLW 0x97
0x7ED: MOVWF __pcstackCOMMON
0x7EE: DECFSZ __pcstackCOMMON, F
0x7EF: GOTO 0x7EE
0x7F0: DECFSZ 0x71, F
0x7F1: GOTO 0x7EE
0x7F2: BRA 0x7F3
!    
!    LED = 1;
0x7FB: MOVLB 0x2
0x7FC: BSF LATA, 0x0
!}
0x7FD: GOTO 0x2

RaMu

Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

baran123

Tamamen aklımdan çıkmış hocam.
Çok teşekkür ederim.
Özet : Programı boşta bırakmıyoruz. Mutlaka bir döngüye sokup bir işle meşgul ediyoruz. :)

eeburakdemir

Teşekkür ederiz bilgiler için çok faydalı oldu @RaMu @baran123
Asla pes etme...