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.

[SOLVED] PIC16f886 Timer0 based interrupt not working

Status
Not open for further replies.

ragav4456

Full Member level 4
Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Visit site
Activity points
2,568
Hi

I need PIC16f886 timer based 1 min interrupt occur program.

I tried in hitech c compiler, its not working. 4Mhz osc
Code:
#include<htc.h>

__CONFIG(0x20A1);
__CONFIG(0X0700);

unsigned int ivalue=0,Display=0;

void main()
{

    TRISA=0x03;
    PORTA=0x00;
    TRISC=0x07;
    TRISB=0x00;
    PORTB=0x00;
    PORTC=0b00000000;

    T1OSCEN=0;
    ANSEL=0x03;
    ANSELH=0x00;

    OSCCON= 0b01101101;
    OSCTUNE= 0x00;

    GIE=1;
    PEIE=1;
    T0IE=1;
    T0CS=0;
    T0SE=0;
    PSA=0;      // Prescaler assign for Timer0
    PS2=1,PS1=1,PS0=1;
//    OPTION=0X86;
    TMR0=0;
    PIE1=0;
    PIE2=0;

    C1ON=0;     //Comparator1 off
    C2ON=0;     //Comparator2 off
    SSPEN = 0;  //Disable SPI n I2C
  
    while(1)
    {
        PORTB=~PORTB;
        if(ivalue=30)
        {
            RA4=1;
        }
    }
}

void interrupt_isr()
{
    if(T0IF)
    {
        T0IF=0;
        ivalue++;
    }
}
 

Where is timer0 reloaded in ISR ?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void interrupt_isr()
{
    if(T0IF)
    {
    if(++ivalue == 30)
        {
            RA4 = 1;
        }
 
        T0IF=0;
        TMR0H = x;
    TMR0L = y;
    }
}

 

you can not create 1 min of timer count but u can count timer interrupt for 1 minute.
means
generate 100ms timer count and count for 10 times and after that use this event.

Code:
// timer interrupt after 100 ms 
interrupt void isr()
{
count++;
if(count==10)
{
//use this space for interrupt of 1 minute.
}
}
 

Thanks to all,

@ milan.rajik, x and y means?

- - - Updated - - -

Code Not working, what is the reason?
 

Post the code you have modifed so far so we can see what you are currently working with.

Is it possible for you to use Timer 1 instead of Timer 0? Timer 1 is better for creating longer delays.

Brian.
 

x and y are timer0 reload values. This is mikroC code. Modify it to your Compiler.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Timer0, 4MHz Fosc
//Prescaler 1:256; TMR0 Preload = 61; Actual Interrupt Time : 49.92 ms
 
//Place/Copy this part in declaration section
void InitTimer0(){
  OPTION_REG = 0x87;
  TMR0 = 61;
  INTCON = 0xA0;
}
 
void Interrupt(){
  if (TMR0IF_bit){
     if(counter == 20)PORTA.F4 = 1;
    //Enter your code here
    TMR0IF_bit = 0;
    TMR0 = 61;
  }
}

 

Rectify the problem, Problem is declaration of interrupt loop.
void interrupt_isr()
 

The code I posted was mikroC PRO PIC code. I mentioned to modify it to your Compiler.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top