Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem in pic16f877a interrupt(reset the microcontroller when INTCON = 0xC0)

Status
Not open for further replies.

deepa.malagi

New Member
Hello everybody,

I am using pic16f877a ic,

I am getting problem in interrupt(all peripheral interrupt).
I tried UART interrupt & timer1 interrupt
but there is same problem in these interrupt, i.e micro controller resting continually when I assign INTCON = 0xc0.

Please help me to sort out this problem,if possible give me example code for Timer1 imterrupt.
 
hi,
Post or Attach your full program.:)
 
Code:
unsigned int Timer_1_Reload = 62500;
void Timer_int(void)
{

    T1CON = 0x30;        // 0011 0000, 1:8 prescalar, disable timer-1
    TRISC = 0x00;
    TMR1H = (unsigned char)(Timer_1_Reload >> 8);
    TMR1L = (unsigned char)Timer_1_Reload;
    
    INTCON = 0xC0;              // Enable interrupt (bits GIE and PEIE)
    TMR1IF = 0;
    PIE1 |=    0x01;
    T1CON |= 0x01;

}    
    
void interrupt_isr(void)
{
    unsigned int Timer_1_Reload = 62500;
    if(PIR1 & TMR1IF)
    {
        //INTCON = 0xC0;
        PORTC = 0x01;
        TMR1H = (unsigned char)(Timer_1_Reload >> 8);
        TMR1L = (unsigned char)Timer_1_Reload;
        TMR1IF = 0;
    }
    PORTC |= 0x02;
}

This is my code please help me to sort out the problem.
 
Last edited by a moderator:
Please use code tags [ code] ....program... [ /code]

Where is your main() function ? As ericgibbs said we need to see the entire program.

We only have one interrupt vector so what it the purpose of void Timer_int(void); ?

As ericgibbs said we need to see the entire program!
 
Last edited:
I got your timer 1 interrupt working in MPLAB SIM.

First
void interrupt_isr(void)

needs to be
void interrupt isr(void)

Second
you need to turn on the interrupts outside the ISR for the ISR to be used
so putting
INTCON = 0xC0;
will not enable interrupts. Instead I used this line
Code:
//    Initialize_UART1();   /// removed this file for testing as it has redundant code
    PORTA = 0x01;
    Timer_int();
    INTCON = 0xC1;  //// added this
I do not care for
INTCON = 0xC1;
I would much rather see several lines like these bases on the bit name in the p16F877A.h file. That way everyone can see what is going on by looking at the code.
INTCONbits.TMR0IF = 1;
INTCONbits.GIE = 1;

Lastly use a __config line to set the fuses. That way you and everyone else know what they are without looking at you MPLAB project file.
Code:
#include <pic.h>
 __CONFIG(DEBUG_ON & FOSC_HS & WDTE_OFF & LVP_OFF );
#include "UART.h"
#include "TIMER.h"
Much of the code is still a mess. You need to take you time an look at the processor datasheet and examples. When you UNDERSTAND the code use the concepts and bits of code. Just copy and pasting does not cut it.
 

Attachments

  • display_board.zip
    6.1 KB · Views: 190
I tried this debug mode for 2 ,3 it times worked fine, but after that when I restart the Micro controller, it is not at all executing the main() function ,directly moving to the interrupt subroutine for any 1 time.
I tried the same program in simulation mode I am getting the error:

CORE-E0002: Stack under flow error occurred from instruction at 0x00001d

please help me.
 
You seem to be using timer1 but enable both timer1 and timer0 interrupts. Which compiler are you using?

Mike.
 
Your code is a mess. You need to either start over or go though and understand what every line does, know why you are setting or clearing each bit of the SFR's.

That sounds like a lot, but it is the nature of programming micro controllers.
 
I wrote separate code for timer interrupt, even in this also i am facing the same problem
its not executing the main function,(directly going to interrupt & then while(1) loop )

please find the code attached with this mail,

please help to sort out the problem.
 

Attachments

  • 16f877_timer_interrupt.zip
    21.2 KB · Views: 178
Your code works fine in the simulator. However, if(PIR1 & TMR1IF) should be if(TMR1IF). I'm not sure what the compiler would do anding a char with a bit.

Mike.
 
i tried this code in simulator, I am getting error
CORE-E0002: Stack under flow error occurred from instruction at 0x00001c

in which compiler u tried this?

please put break point in the main after the instruction T1CON = 0x30;
please see weather main function is executing.
 
I am using HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1 and I can single step all the way to main. The interrupt occurs every 24,332 cycles.

Mike.
 
It's customary to explain what the problem was so that anyone reading this in the future may be able to solve their problem.

Mike.
 
Hi,

My problem got solved.
The issue was with the version of Hi-Tech c compiler (version 9.60) that i was using.
Once i installed latest version 9.80 the problem got solved.

Thanks again for the timely help.

Thanks & regards,
Deepa.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top