intterrupt kullanımı

kayimguney

Üye
Katılım
14 Nis 2008
Mesajlar
71
Puanları
1
Yaş
35
merhaba arkadaşlar microC ile bir kod yazıyorum kod çalışırken arka planda başka birşeyler daha yapılsın istiyorum bu da sanırım interruptla yapılabiliyor.. yazdığım bi fonksiyonu interrupta nasıl çağırabilirim yardımcı olabilir misinz?
 
Pic türü oyuncaklar aynı anda tek komut işleyebilir.Ancak TMR sayıcıları programdan bağımsız çalışabilirler.Gerektiğinde okuyabilirsin.17-18 ve ya yukarısı modeller de bazılarında donanımsal seri iletişim-enkoder sayıcı gibi modüller var.(Uart 16 ların bazılarındada var tabii)

İnterrupt , şartları oluştuğunda , işlenilen komutun bitirildiği anda gidilecek rutindir ve oraya ne yazdı isen o yapılır ve sonra o rutinden çıkmayı yazdı isen kaldığı yere döner ve oradan devam eder.
İnterruptun içerisine bir şeyler yazabilirsin veya include edersin.Sample dosyalarında bir şeyler olacaktı ama şu an kurulu değil.
Sorudan anladığım yeni başlıyorsun, illa demezsen micro c den CCS C ye dön.Sayısız örnek bulabilirsin ve Tr kaynaklar da var.
 
hayır yeni başlamıyorum bayaıdr uğraşıyorum sadece interrupta çok ihtiyacım olmamıştı.. interruptın kullanımıyla ilgili yardıma ihtiyacım var sadece.. hazır bi fonksiyonu interrupta çağırmak istiyorum o kadar..
 
musallim ' Alıntı:
...İnterruptun içerisine bir şeyler yazabilirsin veya include edersin...
Macronu isim.h ve ya isim.c ile kaydet (tercihan include klasörüne).
Kesmenin içerisinde #include <isim.h> ile çağır.
Dizilim farklı olabilir !
 
işte o dediğini yapamıyorum tam olarak.. interruptı aktif hale getiremedim.. elimdeki kaynakta kullanımını anlatmış ama çıkaramadım nasıl olacak..
Kod:
Interrupts
Interrupts can be easily handled by means of reserved word interrupt. mikroC implictly declares function interrupt which cannot be redeclared. Its prototype is:

void interrupt(void);For P18 low priorty interrupts reserved word is interrupt_low:

void interrupt_low(void);You are expected to write your own definition (function body) to handle interrupts in your application.

mikroC saves the following SFR on stack when entering interrupt and pops them back upon return:

PIC12 family: W, STATUS, FSR, PCLATH 
PIC16 family: W, STATUS, FSR, PCLATH 
PIC18 family: FSR (fast context is used to save WREG, STATUS, BSR) 
Use the #pragma disablecontexsaving to instruct the compiler not to automatically perform context-switching. This means that no regiser will be saved/restored by the compiler on entrance/exit from interrupt service routine. This enables the user to manually write code for saving registers upon entrance and to restore them before exit from interrupt.

P18 priority interrupts
Note: For the P18 family both low and high interrupts are supported. 

function with name interrupt will be linked as ISR (interrupt service routine) for high level interrupt 
function with name interrupt_low will be linked as ISR for low level interrupt_low 
If interrupt priority feature is to be used then the user should set the appropriate SFR bits to enable it. For more information refer to datasheet for specific device.

Function Calls from Interrupt
Calling functions from within the interrupt() routine is now possible. The compiler takes care about the registers being used, both in "interrupt" and in "main" thread, and performs "smart" context-switching between the two, saving only the registers that have been used in both threads.Check functions reentrancy.

Interrupt Examples
Here is a simple example of handling the interrupts from TMR0 (if no other interrupts are allowed):

void interrupt() {
 counter++;
 TMR0 = 96;
 INTCON = $20;
}//~

In case of multiple interrupts enabled, you need to test which of the interrupts occurred and then proceed with the appropriate code (interrupt handling):

void interrupt() {
 if (INTCON.TMR0IF) {
  counter++;
  TMR0 = 96;
  INTCON.TMR0F = 0;
 }
 else if (INTCON.RBIF) {
  counter++;
  TMR0 = 96;
  INTCON.RBIF = 0;
 }
}//
 
Problemi doğru tanımlayabilmek yarı yarıya çözmek demektir.
Ben algılayamadım demekki.İnterruptu kuramamak başka şey içerisinde kod çalıştıramamak başka şey.

Microc forumunda dolaşmak yararlı olacaktır.

Bir örnek yararlı olacaksa :

Kod:
/*
 * SIMPLE SERIAL FREQUENCY METER
 *
 * this program writes one time per second to the RS232 communication line,
 * the frequency of the input signal on the RB0 pin
 *
 * PIC16F84A
 * 16 Mhz crystal, HS clock
 *
 * PORTB.0, in : counter input
 * PORTB.1, out : RS232 tx
 * PORTB.2, in : RS232 rx
 *
 * Author : Bruno Gavand, november 2005
 * see more details on [url]www.micro-examples.com[/url]
 *
 */
/*
 * RAM variables
 */
unsigned long cntr ;     // number of RB0 transition
unsigned int  ovrflw ;    // number of timer0 overflows
unsigned char str[10] ;   // display result string
/*
 * constant strings
 */
const unsigned char welcome[] = "\r\rRS232 Frequency Meter Ready\rGo to [url]www.micro-examples.com[/url] for details\r" ;
const unsigned char unit[] = " Hz\r" ;
/*
 * write the s ram string to RS232
 */
void  Comm_Write(unsigned char *s)
    {
    while(*s)
        {
        Soft_Uart_Write(*s) ;
        s++ ;
        }
    }
/*
 * write the s constant string to RS232
 */
void  Comm_WriteConst(const unsigned char *s)
    {
    while(*s)
        {
        Soft_Uart_Write(*s) ;
        s++ ;
        }
    }
/*
 * convert the cnrt long value to string
 */
void  Long2str(void)
    {
    unsigned char i, j ;
    if(cntr == 0)
        {
        str[0] = '0' ;
        str[1] = 0 ;
        }
    else
        {
        str[0] = 0 ;
        i = 0 ;
        while(cntr > 0)
            {
            for(j = i + 1 ; j > 0 ; j--)
                {
                str[j] = str[j - 1] ;
                }
            str[0] = cntr % 10 ;
            str[0] += '0' ;
            i++ ;
            cntr /= 10 ;
            }
        }
    }
/*
 * interrupt routine called 4000000/256 times by seconds :
 * the timer TMR0 is increased each 4 clock cycles (quartz frequency is 16 Mhz),
 * and overflows when reseting from 255 to 0,
 * calling the interrupt procedure with bit T0IF set
 *
 * also called on each RBO transition, with bit INTF set
 */
void  interrupt(void)
    {
    if(INTCON.INTF)
        {
        /*
        * RB0 interrupt
        */
        cntr++ ;        // inc. transition counter
        INTCON.INTF = 0 ;   // clear interrupt flag to enable next call
        }
    else if(INTCON.T0IF)
        {
        /*
        * TIMER 0 overflow
        */
        ovrflw++ ;       // inc. overflow counter
        INTCON.T0IF = 0 ;   // clear interrupt flag to enable next call on overflow
        }
    }
/*
 * entry point
 */
main()
    {
    Soft_Uart_Init(PORTB, 1, 2, 38400, 0) ;  // RS232 on PORTB, bits 1 & 2, 38400 bauds
    Comm_WriteConst(welcome) ;       // write welcome message
    TRISB.F0 = 1 ;         // RB0 interrupt pin as input
    OPTION_REG = 0b11011000 ;   // no prescaler
    /*
    * main loop
    */
    for(;;)
        {
        cntr = 0 ;       // clear counters
        ovrflw = 0 ;
        INTCON = 0b10110000 ;     // T0IF, INTF and GIE enabled
        while(ovrflw < 15626) ;    // wait 1 second : 15626 = 16 000 000 / 4 / 256, rounded up
        INTCON.GIE = 0 ;        // stop all interrupts
        Long2Str() ;          // convert counter to string
        Comm_Write(str) ;       // write string
        Comm_WriteConst(unit) ;    // write unit
        }
    }
//
 
Alınma ama interruptsuz pic hiç bişeydir bence.. :) Saat yapman bile zor..

Yukarıda bahsedildiği gibi pic sadece tek komut işleyebilir.. Ancak sen kesmeleri açarak herhangi bi olay olduğunda programın başka bi yerdeki komutları işleyip tekrar geri dönmesini ve kaldığı yerden devam etmesini sağlayabilirsin..

Ayrıca kesmelerde W, STATUS ve PCLATH registerlerini birbirlerini bozmayacak şekilde kayıt yapılmalısın.. Mesela assemblyde SWAPF komutu status u etkilemez, bu komutla STATUS u yedekliyorsun.. Bu yedekleneceklerin listesini daha da uzatabilirsin ihtiyacına göre.. Assembly yazsan yazardım komutları, ama C biliyorum.. :(
 
kullandığım kodlamanın içinde assembly ekleyebiliyorum.. bana interrupt kullanımını anlatabilr msn? yani hangi kesme kullanılıo onu da bilmiorm ama ben şu şekilde bişi düşünüyorum.. benim bi main fonksiyonum var ve interruptım var.. ve birsürü de alt fonksiyon var.. bu alt fonksiyonları mainde ve interrupta kullanmayı planlıyorum.. yani temelde bakınca 2 fonksiyon gibi.. bilmiyorum anlatabildim mi.. anlamazsan eğer daha detaylı açıklarım..
 
Kayimguney:
kullandığım kodlamanın içinde assembly ekleyebiliyorum.. bana interrupt kullanımını anlatabilr msn? yani hangi kesme kullanılıo onu da bilmiorm ama ben şu şekilde bişi düşünüyorum.. benim bi main fonksiyonum var ve interruptım var.. ve birsürü de alt fonksiyon var.. bu alt fonksiyonları mainde ve interrupta kullanmayı planlıyorum.. yani temelde bakınca 2 fonksiyon gibi.. bilmiyorum anlatabildim mi.. anlamazsan eğer daha detaylı açıklarım..

Ben de daha önce hiç interrupta ihtiyaç duymamıştım ilk defa kullanıyorum ama interrupt ve timerı iyice araştırarak işe başladım. Benim de seninle aynı problemim var. İnterrupt alt yordamında bir fonksiyon çağırmak istiyorum. İnternette yeterli kaynak bulamadım ve Microc'nin teknik desteğine mail attım. Micro versiyon 8.2.0.0 kullanıyorum bu derleyicinizin interrupt yordamı içinde bir fonksiyon çağırma gibi bir imkanı var mı diye sordum ve aldığım cevaba dayanarak söylüyorum mainde o fonksiyonu kullanmamak kaydıyla çağırabiliyormuşuz. Fakat mainde kullanıyorsak da "mikroC PRO for PIC"'te yalnızca böyle bir imkan varmış (functions reentrancy diye geçiyor) ki o da fonksiyon parametre ve local değişken içermiyorsa ya da local değişkenlerin Rx alanında olması koşuluyla oluyormuş. (Bu kısmı ben de pek anlayamadım)

Benim önerim eğer mikroC PRO for PIC kullanmıyorsan, sırf interruptta kullanılacak şekilde bir fonksiyon yaratıp denemen, ki ben de öyle yapmaya çalıştım ama işe yaramadı, gözden kaçırdığım bir şey olabilir. Kodun başka yerleriyle ilgileniyorum şu anda. Eğer çözüm bulursam mutlaka paylaşırım. Umarım bu bilgi yardımcı olur :) Ayrıca interruptla ilgili bir sıkıntın varsa hala ona da yardımcı olmaya çalışabilirim.
 

Forum istatistikleri

Konular
128,840
Mesajlar
920,908
Kullanıcılar
450,935
Son üye
oqzknt

Yeni konular

Geri
Üst