cllunlu
Member level 4
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.
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; }