Manolo Envido
Newbie level 4
- Joined
- Oct 10, 2014
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Location
- Argentina
- Activity points
- 80
Hi everyone.
I’m having a problem with interrupts in a PIC18F14K50. IRS are not firing and I cannot find what I’m missing here. Interrupts are used for the Timer0 and recieving data from the UART.
The code was ported from a PIC16F877 and we are moving it to newer technology. I’m using MPLABX v2.10 with XC8 v1.31. Everything else seems to be working fine, even the UART transmition.
Sorry the commenst are in spanish, if you need I can translate them for you, but I think they are still readable.
Thanks for your help
I’m having a problem with interrupts in a PIC18F14K50. IRS are not firing and I cannot find what I’m missing here. Interrupts are used for the Timer0 and recieving data from the UART.
The code was ported from a PIC16F877 and we are moving it to newer technology. I’m using MPLABX v2.10 with XC8 v1.31. Everything else seems to be working fine, even the UART transmition.
Sorry the commenst are in spanish, if you need I can translate them for you, but I think they are still readable.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 void Timer_Init(void) { TMR0ON = 0; // Timer0 T08BIT = 0; // 8 Bits T0CS = 0; // Internal/External T0SE = 0; // Rising PSA = 0; // Timer 0 (1 - WDT ) TMR0 = 0; // Timer0 TMR0IE = TRUE; // Enable Timer0 Interrupt TMR0IF = FALSE; // Reset Start T0PS0 = 1; // Divisor 0b111 = 2^(7+1) = 256 T0PS1 = 1; T0PS2 = 1; PEIE = TRUE; // Habilita interrupciones de Perifericos GIE = TRUE; // Habilita interrupciones Globales }
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 void UART_Init(void) { PORTB = 0; // Limpia salidas SYNC = FALSE; // Modo asynchronous SPEN = TRUE; // Habilita RC7/RX y RC6/TX como pines del puerto serie DTRXP = FALSE; // No Invertir polaridad // Config Baud Rate - Pg. 192 ABDOVF = FALSE; // Auto-baud BRG16 = FALSE; // Baud Rate Generator 16 bits BRGH = FALSE; // Baud Rate Generator High SPBRGH = 0; SPBRG = 25; // 9600 Bauds // Recepcion Rx TRISB5 = ENTRADA; // RB5 -> RX ENTRADA RX9 = FALSE; // Sin 9no bit de Rx SENDB = FALSE; // Break Char CREN = TRUE; // Habilita la recepcion continua RCIDL = FALSE; // Rx idle flag RCIE = TRUE; // Habilita las interrupciones de Rx // Trasmicion Tx TRISB7 = SALIDA; // RB7/TX como salida TX9 = FALSE; // 9no bit de Tx CKTXP = FALSE; // Tx idle is HIGH TXEN = FALSE; // Purga la Tx TXEN = TRUE; // Habilita la Tx TXIE = FALSE; // No habilita las interrupciones de Tx // Interrupciones UART RCIF = FALSE; // Reset Rx pin flag RCIP = FALSE; // Not high priority PEIE = TRUE; // Habilita interrupciones de Perifericos GIE = TRUE; // Habilita interrupciones Globales UART_Clear_Errors(); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 void interrupt isr(void) { // UART Rx if (RCIF) { RCIF = FALSE; rx_buffer[in] = RCREG; in++; in %= BUFFER_SIZE; rx_empty = FALSE; } // Timer0 if (TMR0IF) { TMR0IF = FALSE; TestUART(); // [Debug] if (print_timeout) { print_timeout--; } } }
Thanks for your help