PIC18F4620 TMR1 furcsa

Moczik Gabor pm at progzmaster.hu
Thu May 24 23:59:36 CEST 2007


Hi!

Lassan fel napja ezzel a procival kinlodok...
Furan viselkedik a TMR1 (is :-) )
Boot utan felkonfiguralom, de par masodpercig nem jon megszakitas, utana 
rendesen megy.

A kod ide vago reszei:

#define TMR1_PRELOAD    19456     /* 50Hz @ 18.432MHz PRESCALE=2 */

#define TMR1_PRELOAD_L  (TMR1_PRELOAD&0x00FF)
#define TMR1_PRELOAD_H  (TMR1_PRELOAD/256)

volatile unsigned char sec10_postscaler=5;
volatile unsigned long ticks;

static void interrupt low_priority isr_lo(void)
{
     if (TMR1IF && TMR1IE) {
         TMR1IF=0;
         TMR1H=TMR1_PRELOAD_H;
         TMR1L=TMR1_PRELOAD_L;
         sec10_postscaler--;
         if (sec10_postscaler==0) {
             sec10_postscaler=5;
             ticks++;
         }
     }
}

void main(void)
{
	
     // configure TMR1
     T1CON=0b10010001;             // 16 bit, int. clock, prescale=2
     TMR1H=TMR1_PRELOAD_H;
     TMR1L=TMR1_PRELOAD_L;

     // configure interrupts
     IPEN=1;      // enable priority
     PEIE=1;      // enable low priority interrupts

     TMR1IE=1;    // enable TMR1 int (50Hz, timing functions)
     TMR1IP=0;    // low priority

     GIE=1;

     for(;;) {
         lcd_goto(0);
         printf("Ticks: %d",ticks);
     }
}

---------------------------
Tizedmasodpercenkent lepteti a "ticks" valtozot, de az elejen par 
masodpercig 0-t mutat, utana elindul.

Egyebkent 18F452-n ugyanez a kod jol mukodik...

-- 
((( Móczik Gábor  )))--((( pm -> @ -> progzmaster -> . -> hu  )))
((( Skype: moczik )))--((( Website: http://www.progzmaster.hu )))



More information about the Elektro mailing list