PIC18F reagiert bei ext. INT1 nicht

Gast #956146
Lesenswert?

1
/*Header*/
2
#ifdef USE_PIC18F4685
3
  #define __PICF4685
4
#else
5
  #define __PICF4680
6
#endif
7

8
/*Includes*/
9
#include "p18f4685.h"    //definition for PIC18F
10
#include "CAN18XX8.h"    //definition for CAN
11
#include "main.h"      //global Defines
12
#include "delays.h"      //delay library
13
#include "em4095.h"      //RFID
14

15

16

17

18

19
/**************************************************************/
20
/*        Function: High priority interrupt routine    */
21
/**************************************************************/
22

23
#pragma code
24
#pragma interrupt InterruptHandlerHigh
25

26
void InterruptHandlerHigh ()
27
{
28
  if(IRQ_INT1_FLAG)
29
  {
30
    IRQ_INT1_FLAG = CLEAR;        //clear ext. interrupt 1 flag
31
  }
32
    if(TMR0_OVERFLOW_FLAG)          //check for TMR0 overflow
33
    {                                   
34
      TMR0_OVERFLOW_FLAG = CLEAR;
35
      
36
    }
37
}
38

39
/**************************************************************/
40
/*        Function: High priority interrupt Vector    */
41
/**************************************************************/
42

43
#pragma code InterruptVectorHigh = 0x08
44
void
45
InterruptVectorHigh (void)
46
{
47
  _asm
48
    goto InterruptHandlerHigh     //jump to interrupt routine
49
  _endasm
50
}
51

52
/**************************************************************/
53
/*          Function: PIC Initializing          */
54
/**************************************************************/
55
void PIC_Init(void)
56
{
57
  /*Port init*/
58
  TRISB = 0b11001011;        // Port-B definition: RB7=in / RB6=in / RB5=out / RB4=out / CANRX=in / CANTX=out / RB1=in / RB0=in
59
  TRISA = 0b11111111;       // Bit 0 to 6 are not used
60

61
  /*interrupt init*/
62
  IRQ_PRIORITY = ENABLE;
63
  //IRQ_GLOBAL_LOWPRIO = DISABLE;
64
  //IRQ_GLOBAL_HIGHPRIO = 1;  // only high priority IRQ
65
  IRQ_TMR0 = ENABLE;
66
  IRQ_INT0 = DISABLE;
67
  IRQ_PORTB_CHANGE = DISABLE;
68
  IRQ_INT1_EDGE_SELECT = RISING;
69
  IRQ_INT1_PRIORITY = HIGH;
70
  IRQ_INT1 = ENABLE;
71
  IRQ_INT1_FLAG = CLEAR;
72
  IRQ_TMR0_PRIORITY = HIGH;
73

74
  INTCONbits.GIE = 1;
75
  INTCONbits.PEIE = 0;
76
  
77
  /*Timer 0 init*/
78
  TMR0_CLK_SOURCE_SELECT = 0;    // Internal instruction cycle clock (CLKO)
79
  TMR0_PRESCALER_notACTIV = 0;  // Timer0 clock input comes from prescaler output. Prescaler activated
80
  TMR0_PRESCALER_T0PS0 = 1;
81
  TMR0_PRESCALER_T0PS1 = 0;
82
  TMR0_PRESCALER_T0PS2 = 0;    // Set prescaler value 1:4 -> TIMER clock = 0.1us
83
  TMR0_OVERFLOW_FLAG = CLEAR;
84
  TMR0_8BIT = ENABLE;
85
  
86
  TMR0 = DISABLE;          // Enable TIMER 0
87

88
}
89

90

91
/**************************************************************/
92
/*          Function: CAN Initializing          */
93
/**************************************************************/
94
void CAN_Init(void)
95
{
96
  /*Sets Baudrate of 125KB and goes back to normal mode*/
97
  CANInitialize(SJW_125K,BRP_125K,PHSEG1_125K,PHSEG2_125K,PROPSEG_125K, CAN_CONFIG_ALL_VALID_MSG);
98

99
  CANSetOperationMode(CAN_OP_MODE_CONFIG);            // Set CAN module into configuration mode       
100
  RXB0CONbits.RXBODBEN = ENABLE;                  // Double receive buffer if RXBuffer 0 full -> Message in RXBuffer 1
101
  CIOCONbits.ENDRHI = ENABLE;                   // CAN Tx PIN will drive VDD when recessive      
102
  CANSetOperationMode(CAN_OP_MODE_NORMAL);             // Set CAN module into normal mode
103
}
104

105
/**************************************************************/
106
/*          Function: MAIN                 */
107
/**************************************************************/
108
void main(void){
109
  /*temporary definition  */
110
  BYTE MessageData[8];
111
  BYTE DataLen = 8;
112
  unsigned long ID = 0x11;
113
  MessageData[0]=0x08;
114
  MessageData[1]=0x80;
115
  MessageData[2]=0x11;
116
  MessageData[3]=0x01;
117
  MessageData[4]=0x02;
118
  MessageData[5]=0x04;
119
  MessageData[6]=0x12;
120
  MessageData[7]=0x14;
121
  
122

123

124
  /*Initializing of the moduls: CAN, RF and PIC*/
125
  RF_Init();
126
  CAN_Init();
127
  PIC_Init();
128

129
  while(1)
130
    {  
131
    
132

133
    CANSendMessage(ID, MessageData, DataLen, CAN_TX_PRIORITY_0 & CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME);
134
  
135
    Delay10KTCYx(255);
136
    }  
137

138
}

Der PIC18F4685 will den externen INT1 nicht auslösen.
Meiner Meinung nach habe ich alle Register gesetzt. Wenn ich den Timer0 
aktiviere springt er nach dem overflow schön an seinen Platz, aber 
jedoch nicht der INT1.
Das anliegende Signal ist ein TTL Ausgang von einem anderen IC. Die 
Flanken sind also relativ steil 0V-5V.
-Global Interrupt Flag ist gesetzt.
-INT1 aktivert

Er reagiert weder auf rising noch auf falling edges.
Woran könnte dies liegen? Die Suchfunktion hat mich leider nicht weiter 
gebracht.

Danke schonmal.
Grüsse
Rödu
Gast #956508
Lesenswert?

ich werde nicht ganz schlüssig, was bei meinem PIC vor sich geht.
Wenn ich in den CONFIG Bits auf "configured as analog input on reset" 
instelle kann ich den PORTB konfigueren (inputs, outputs, Pegel,....).
Gehe ich nun auf "configured as digital I/O on reset", was eigentlich 
auch richtig wäre, reagiert der PORTB nicht mehr auf meine Befehle. Ich 
kann sie nicht mehr HIGH und LOW schalten.
TRISB sollte korrekt eingestellt sein. Keine Ahnung wo das hakt, hier.
Gast #956877
Lesenswert?

Ich habe das Gefühl, dass mit den Config Bits etwas nicht ordnungsgemäss 
abläuft.
Wenn ich nun die Config-Bits des PICs in den Code nehme, meldet er immer 
den Fehler, dass sie zweimal definiert sind.
Im Programm Code ist aber nichts zu sehen, ausser der Teil im 
Header-File.

Wo verstecken sich beim MPLab die Config-files für einen PIC18F noch?
Ich möchte sie nicht im MPlab definieren, sondern im Code.

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