Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MikroC pic18f14k50 Interrupt on Change (IoC)

Status
Not open for further replies.

cllunlu

Member level 4
Joined
Nov 21, 2006
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,900
Hello,

I try to use interrupt with pic18f14k50. (RA4 pin as IOC pin). But I cant find where I mistake. Anytime doesnt run part of ioc in interrupt routine. Same time I use timer interrupt for 1us.
I use internal oscillator 16Mhz.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
sbit LED0 at LATC4_bit;
sbit LED0_Direction at TRISC4_bit;
 
sbit LED1 at LATC3_bit;
sbit LED1_Direction at TRISC3_bit;
 
sbit DATA_IN at RA4_bit;
sbit DATA_IN_Direction at TRISA4_bit;
 
void Interrupt()
{
    if(send_it==0)
    {
        if (TMR0IF_bit)
        {
            TMR0L = 0xFC;
            TMR0IF_bit = 0;
            timer++;
            LED1=~LED1;
            if(timer==65536)
            {
               timer=0;
               //LED0=~LED0;
            }
        }
 
        if((RABIF_bit))
        {
              LED0=~LED0; //~LED0;
              RABIF_bit=0;
             if(DATA_IN)               // Yükselen kenar geldi mi?
             {
                  LED0=ON; //~LED0;
              }
         }
    }
}
 
void main() 
{
     init();
 
    TMR0IE_bit = 1;
     
     while(1)
     {}
}
 
void init()
{
    OSCCON=0b01110111;
    
    TRISA = 0x00;   TRISB = 0x00;    TRISC = 0x00;
 
    PORTA = 0x00;   PORTB = 0x00;    PORTC = 0x00;
 
    LATA = 0x00;    LATB = 0x00;     LATC = 0x00;
    
    LED0_Direction = OUTPUT;    LED1_Direction = OUTPUT;      
    
    DATA_IN_Direction = INPUT;
 
    PWM1_Init(125000);                    // Initialize PWM1 module at 125KHz
    PWM1_Set_Duty(127);
    PWM1_Start();                       // start PWM1
   
    T0CON      = 0xC8;
    TMR0L      = 0xFC;
 
    // Interrupt Settings 
    INTCON.RABIF = 0;     // Clear interrupt flag prior to enable
    INTCON.RABIE = 1;     // enable on change interrupts
    INTCON.GIE  = 1;     // enable Global interrupts
    IOCA4_bit=1;
    GIE_bit = 1;
 
    send_it=0;
}

 

I have notized that another interrupt on change pins are connected RA port. Just I cannot use RA4 and RA5 pin as interrupt on change. I use internal oscillator. These pins are osc-in and osc-out. Just I must to configure these pins. Anyone help?
 

I've not used that MCU but looking at the data sheet, the power-on-default for the PRI_SD bit in OSCCON2 is to have the oscillator drive circuit turned on. I suggest you turn it off.
Also, RA4 has analog capability and this needs to be switched to 'digital' mode with the ANSEL register. If not then it will always read as '0'.
With 'interrupt on change', you need to read the PORT to do 2 things: work out which pin has changed and also to reset the IOC detection (see Section 9.1 of the data sheet). If you don't read the the PORT then you will only get 1 interrupt.
Susan
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top