Forum: Mikrocontroller und Digitale Elektronik PIC16F610 Timer0 Interrupt


von pico (Gast)


Lesenswert?

Hallo,
ich schreibe ein erstes Programm für den o.g. PIC. Diese kleine Programm 
soll den Pin RA1 togglen. Dies scheint nicht zu funktionieren, da der 
Pin dauerhaft high ist (gemessen).
Es ist kein Quarz angeschlossen (interner Oszillator wird verwendet). 
Verwendete IDE ist MPLAB X v3.55, Compiler ist XC8 v1.20.
1
// CONFIG
2
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
3
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
4
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
5
#pragma config MCLRE = ON       // MCLR Pin Function Select bit (MCLR pin function is MCLR)
6
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
7
#pragma config IOSCFS = 8MHZ    // Internal Oscillator Frequency Select bit (8 MHz)
8
#pragma config BOREN = OFF      // Brown-out Reset Selection bits (BOR Disabled)
9
10
// #pragma config statements should precede project file includes.
11
// Use project enums instead of #define for ON and OFF.
12
13
#include <xc.h>
14
15
16
void main(void)
17
{
18
  // Init Port A
19
  PORTA = 0x00;
20
  TRISA = 0x34;
21
  
22
  //init Timer0 
23
  OPTION_REGbits.T0CS=0; //TIMER MODE
24
  OPTION_REGbits.PSA=0b0; // enable prescaler
25
  OPTION_REGbits.PS=0b110;
26
  INTCONbits.T0IE = 1;
27
  PORTAbits.RA1 =1;
28
  ei();
29
  
30
  while(1)
31
  {
32
      
33
  }
34
  
35
}
36
37
void interrupt isr(void)
38
{
39
  if(INTCONbits.T0IF ==1)
40
  {
41
    INTCONbits.T0IF = 0;
42
    if(PORTAbits.RA1 == 0)
43
    {
44
      PORTAbits.RA1 = 1;
45
    }
46
    else
47
    {
48
      PORTAbits.RA1 = 0;
49
    }
50
  }
51
}

Da der Pin RA1 dauerhaft high ist, scheint die ISR nicht aufgerufen zu 
werden. Hat irgendjemand eine Idee, was mein Fehler sein könnte?

Vielen Dank!

von Jan (Gast)


Lesenswert?

Hallo,

Deine Ports sind noch Analog... Da kann nichts schalten.
Siehe Dabla Seite 33

Gruß
Jan

von Ingo L. (corrtexx)


Lesenswert?


von pico (Gast)


Lesenswert?

Vielen Dank euch beiden, das war es!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.