Ynt: 12F1822 clock ayarı(XC8)

Başlatan baran123, 02 Temmuz 2015, 00:56:13

baran123

OSCCON ayarladım ama alakasız bir yerde hata yapıyorum sanırım.LED proteusda A0 a bağlı ve sürekli yanıyor

main.c
/* 
 * File:   main.c
 * Author: Baran EKREM
 * Created on 02 Temmuz 2015 Perşembe, 00:00
 */
#include <stdio.h>
#include <stdlib.h>
#include "main.h"

#define Led PORTAbits.AN0 

void MCU_Init(void);
void Delay_ms(unsigned int second);

int main(int argc, char** argv) {

    MCU_Init();
    
    while(1) {
        Led = 1;
        Delay_ms(500);
        Led = 0;
        Delay_ms(500);
    }
    return (EXIT_SUCCESS); // return 0
}

void MCU_Init(void)
{
    OSCCON = 0x11110010;
            
    TRISA = 0x00;  
    LATA = 0x00;    // All Pins Set to low
    ANSELA = 0x00;  // Set all pin as Digital output
}

void Delay_ms(unsigned int second)
{
    unsigned int i;
    for(i=0; i < second; i++)
        __delay_ms(1);
}


main.h
/* 
 * File:   main.h
 * Author: Baran EKREM
 * Created on 02 Temmuz 2015 Perşembe, 00:01
 */
#ifndef MAIN_H
#define	MAIN_H

#include <xc.h>

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

// 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 = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#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 = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

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

#define _XTAL_FREQ 8000000

#endif


mesaj birleştirme:: 02 Temmuz 2015, 00:57:52

Amaç 4(pll )*8(internal) = 32MHz yapmak  8)

RaMu

Proteus da kodda yazdıklarının geçerli olacağını hiç sanmıyorum,
pice çift tıklayıp
frequency kısmına ne yazdıysan her halükarda o geçerlidir,
henüz istisna ile karşılaşmadım.

Gerçek devrede denesen daha doğru olur.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

baran123

Hocam o kısmı yaptım. 32MHz göre ayarladığım için 32 denedim olmadı.Kristal değerini  kullanıyordum oda olmadı.

RaMu

void Delay_ms(unsigned int second);

unsigned int xc8 de unsigned int8 olarak kabul ediliyordur muhtemelen,
en yüksek 255 alabilir,
Delay_ms(500);
dediğinde problem olur.
Gibi bir durum olabilir.
Delay_ms(250);
ile dene.
Olursa delay fonksiyonunu düzelt.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

baran123

Hocam evet orayi 250 ile denedim fakat yine olmadi.Yarin board uzerinde deneyecegim

semihel

main.h kısmını 32Mhz ayarladıktan sonra ana program içerisine OSCCON=0b11110000; ve OSCSTAT=0b01011001; ve OSCTUNE= 0b00000000; ekledikten sonra deneyebilir misin.
genelde ccs c kullanıyorum ama istediğm osc ayarları bazen sapıtınca asm de kod eklerim. ana programda bunları göremeyınce belki bundan olabilir. Kolay gelsin

iyildirim

1822 nin biraderi 1840 kullanırken aynı sorun çıkmıştı. Sigorta ayarlarından yapamamıştım. En sonunda sadece clock switch ing yapıp PLL yi sonradan aktif edince  32Mhz çalıştırabilmiştim.
Daha önce konusu açılmıştı.  32 Mhz için XC8 örneği de paylaşmıştım.

RaMu

@iyildirim  isisde çalıştırkende aynı problem oluyor muydu yoksa
gerçek devrede mi problem oluyordu?
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

mehmet

//Ön ayar seçenekleri
// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
...
#pragma config PLLEN = OFF       // PLL Disable (4x PLL disabled)
...
#define _XTAL_FREQ 32000000L


//main fonksiyonu en başına eklenmeli
    OSCCONbits.IRCF = 0b1110;
    OSCCONbits.SPLLEN = 0b1;
    __delay_ms(1000);
    while (!OSCSTATbits.PLLR);
    while (!OSCSTATbits.HFIOFR);
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

baran123

#9
@mehmet hocam çok teşekkür ederim şimdi oldu. while ile registerlar hazır olana kadar orada beklıyoruz dimi ?

mesaj birleştirme:: 02 Temmuz 2015, 20:42:04

Unutmadan XC8 değişken tipleri ! http://ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf

mesaj birleştirme:: 02 Temmuz 2015, 20:42:14

sayfa : 143

baran123

Bu pic de nasıl SPI kullanabilirim ?
#include <plib/spi.h> eklediğimde bu dosya içerisindeki #include <pconfig.h> de hata veriyor.Sanırım 12F leri desteklemiyor ?

iyildirim

Alıntı yapılan: RaMu - 02 Temmuz 2015, 16:06:13
@iyildirim  isisde çalıştırkende aynı problem oluyor muydu yoksa
gerçek devrede mi problem oluyordu?
Hocam hiç isis kullanmıyorum.

mehmet

Alıntı yapılan: Baran Ekrem - 02 Temmuz 2015, 20:24:13
@mehmet hocam çok teşekkür ederim şimdi oldu. while ile registerlar hazır olana kadar orada beklıyoruz dimi ?
Birincisi pll açılması, ikincisi de 32MHz oturması olarak biliyorum...
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr