C18 Timer0 Initalisierung PIC18F97J60

OP #3659960
Lesenswert?

Hallo Zusammen,

ich ärgere mich gerade mit dem Timer 0 herum.

Ziel ist es ein kleines Betriebssystem aufzusetzen das jede Millisekunde 
einen Impuls liefert. Dieses Puls sol innerhalb des Programmes zu allen 
möglichen Zeitfunktionen verwendet werden. Mein Programm blinkt schon 
allerdings nicht mit den Zeiten die ich berechnet habe. Kennt jemand 
diese Eigenheit des PIC?

PIC18F97J60
25MHz
Prescaler 1:2
Timer Resolution 16 Bit
TMR0 = 0xF3CB


1
OpenTimer0( TIMER_INT_OFF & T0_16BIT & T0_SOURCE_INT & T0_PS_1_2 );
2
TMR0H = 0xF3;
3
TMR0L = 0xCB;
4

5
  if (INTCONbits.TMR0IF = 1) 
6
  {
7
     uint_zhl++;
8
  }
9

10

11
 if (uint_zhl == 1 && PORTB == 0x00)
12
 {
13
  //printf("%.4u", uint_zhl);
14
  //printf("\r\n");
15
  PORTB = 0xFF;
16
  uint_zhl = 0;
17
 }
18
 
19

20
      
21
 if (uint_zhl == 0 && PORTB == 0xFF)
22
 {
23
  //printf("%.4u", uint_zhl);
24
  //printf("\r\n");
25
  PORTB = 0x00;
26
  uint_zhl = 0;
27
}

Danke und Gruß
OP #3659969
Lesenswert?

Hier wäre mal der gesamte code
1
/************************************************************************/
2
// Microcontroller-Konfiguration
3
/************************************************************************/
4
#pragma  config  XINST = OFF      // do not use extended instructions
5
#pragma  config  STVR = OFF      // stack overflow off
6
#pragma  config  WDT = OFF      // HW Disabled - SW Controlled
7
#pragma  config  CP0 = OFF        // code protection block 0
8
#pragma  config  FCMEN = OFF         // Fail-Safe Clock Monitor disabled
9
#pragma  config  IESO = OFF          // 2 speed startup
10
#pragma  config  FOSC2 = ON      // primary oscillator by default
11
#pragma  config  FOSC = HS          // HS oscillator
12
#pragma  config  WDTPS = 1         // WDT off, so who cares
13
#pragma  config  WAIT = OFF        // Ext Mem buss - don't care
14
#pragma  config  BW = 8        // Ext Mem buss - don't care
15
#pragma  config  MODE = MM        // Ext Mem bus disabled
16
#pragma  config  EASHFT = OFF      // Ext Mem buss - don't care
17
#pragma  config  ETHLED = OFF        // RA0, RA1 are IO, not ethernet LED
18
#pragma  config  ECCPMX = OFF    // ?
19
#pragma  config  CCP2MX = OFF    // ?
20
/************************************************************************/
21

22

23
/************************************************************************/
24
// Include-Dateien
25
/************************************************************************/
26
#include <P18F97J60.h>      
27
#include <stdio.h>      
28
#include <delays.h>
29
#include <timers.h>
30
/************************************************************************/
31

32

33
/************************************************************************/
34
// sonstige Deklarationen
35
/************************************************************************/
36
#define True      1
37
#define False      0  
38
/************************************************************************/
39

40
/************************************************************************/
41
// Hauptprogramm
42
/************************************************************************/
43

44

45
void main(void)
46
{
47
  unsigned int uint_zhl;
48
  
49
  //PORTA, PORTH, und PORTF sind Analog-Ports
50

51
  TRISB = 0x00;           // PORTB initalisieren    
52
    PORTB = 0X00;          
53
    
54
    TRISC= 0b01011000;           // PORTC initalisieren
55
    PORTC= 0b01011000;
56
    
57
    TRISD = 0x00;          // PORTD initalisieren
58
  PORTD = 0x00;          
59
  
60
    TRISE = 0x00;          // PORTE initalisieren
61
  PORTE = 0x00;  
62

63
    TRISG = 0x00;          // PORTG initalisieren DIP-Schalter
64
  PORTG = 0x00;
65
  
66
  TRISJ = 0x00;          // PORTJ initalisieren DIP-Schalter
67
  PORTJ = 0x00;  
68
  
69

70
OpenTimer0( TIMER_INT_OFF & T0_16BIT & T0_SOURCE_INT & T0_PS_1_2 );
71
TMR0H = 0xF3;
72
TMR0L = 0xCB;
73
  
74
//*****************************************************************************
75
// Start der Hauptprogramm-Schleife 
76
//*****************************************************************************  
77
 
78
 while(1)                    // Ganzes Programm ist Endlosschleife
79
 {     
80

81
          
82
  if (INTCONbits.TMR0IF = 1) 
83
  {
84
     uint_zhl++;
85
  }
86

87

88
 if (uint_zhl == 1 && PORTB == 0x00)
89
 {
90
  //printf("%.4u", uint_zhl);
91
  //printf("\r\n");
92
  PORTB = 0xFF;
93
  uint_zhl = 0;
94
 }
95
 
96

97
      
98
 if (uint_zhl == 0 && PORTB == 0xFF)
99
 {
100
  //printf("%.4u", uint_zhl);
101
  //printf("\r\n");
102
  PORTB = 0x00;
103
  uint_zhl = 0;
104
}     
105

106
            
107
 }
108
//*****************************************************************************    
109
 }  // Ende des Hauptprogramm
110
//*****************************************************************************

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren