Jump to content
Sign in to follow this  
marcob

Interupt Tmro And Rbo

Recommended Posts

HI,

Use mplab with “INCIRCUIT DEBUG " with a pic877 and compile whith boostc.

 

I have a interap that it is cyclical with TMR0.

And I want to count in input on RBO.

 

The problem is that when I qualify interap on TMR0 also the counter on RB0 it counts,

the program me seems corrected:

 

**************************************************************/

 

#include <system.h>

 

#include "lcd.h"

 

#pragma CLOCK_FREQ 20000000

 

//Define device config block

//#pragma DATA _CONFIG,_CP_OFF & _DEBUG_OFF & _CPD_OFF & _WRT_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

#pragma DATA _CONFIG,_CP_OFF & _DEBUG_ON & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

 

int int_1S; // flag interap 1 secondo

int flag_1S;

int val_enco,aaa;

 

// Main program entry

 

void main()

{

 

 

int_1S=100; //per ottenere 1 senondo in interap

flag_1S=0; //metto zero flag 1 secondo

 

val_enco,aaa=0; //azzero valore encoder

 

//Init ports

//A and B port initialization

adcon1=00001110b; // solo ra0 analogico il resto digitale

trise=00000100b; // output

trisb=00000011b; // output

trisd=00001111B; // d0-d3 input d4-d7 output

trisc=00011000b;

trisa=00000001b;

 

porta=0x00;

porte=0x00;

portb=0x00;

portd=0xff; // metto le uscite alte per la lettura della tastiera

portc=0x0;

 

init_LCD(); // inizializza LCD

 

 

// Interupt su tmro in overflow

 

clear_bit(intcon,GIE);

clear_bit(intcon,INTF);

clear_bit(intcon,T0IF);

clear_bit(intcon,RBIF);

clear_bit(intcon,PEIE); //-->

 

option_reg=00000111b; //config timer0 interrupt prescaler (f/4)/256 (51.2 uS)

// rbpu=0 intedg=0

set_bit(intcon,T0IE); //--> Abilita l'interrupt sul tmr0

set_bit(intcon,INTE); //--> Abilita l'interrupt sul RB0

// clear_bit(intcon,RBIE); //--> disAbilita l'interrupt sul portB (4..7)

 

set_bit(intcon,GIE); //--> Abilita global interrupt

 

while(1)

{

LCD_cmd(0x94+10);

if (flag_1S==1)

printf ("si");

else

printf ("no");

 

 

LCD_cmd(0x80+5);

Hex2Dec(val_enco);

 

LCD_cmd(0x80+10);

Hex2Dec(aaa);

 

}

 

}

 

 

 

 

 

/************************************************************/

/* Process any interrupts */

/************************************************************/

 

void interrupt( void )

{

 

 

if(T0IF){ //###### Flag int tmr0 ######

int_1S--;

if(int_1S ==0) //ogni secondo

{

if (flag_1S==1)

{

flag_1S=0;

int_1S=100; // ricarico il valore per 1 secondo

}

else

{

flag_1S=1;

int_1S=100; // ricarico il valore per 1 secondo

}

}

 

tmr0 = 60; //per ottenere 10 mS

clear_bit(intcon,T0IF); //Riabilita interrupt flag

}

 

if(INTF){ //###### Flag int RB0 ######

val_enco++;

clear_bit(intcon,INTF); //Riabilita interrupt flag

}

 

if(RBIF){ //###### Flag int RB4-7 ######

aaa++;

clear_bit(intcon,RBIF); //Riabilita interrupt flag

}

 

 

 

}

// End of Interrupt Service routine

 

what I am mistaking? :(

Share this post


Link to post
Share on other sites
HI,

Use mplab with “INCIRCUIT DEBUG " with a pic877 and compile whith boostc.

 

I have a interap that it is cyclical with TMR0.

And I want to count in input on RBO.

 

The problem is that when I qualify interap on TMR0 also the counter on RB0 it counts,

the program me seems corrected:

 

 

This might be a bit late, but if i am understanding correctly you are getting unwanted PortB interrupts durring your TimerZero interrupts.

 

This is because your not disabling all your interrupts or just the PortB interrupt when you enter into your TimerZero Interrupt. So what is happening is your getting another interrupt durring an existing interrupt.

 

If you move to the 18F series chips priority interrupts can help with issues like this, but in the 16F/C series you need to be aware of what you want to happen and what you expect to happen.

 

i hope that helps even if it is a bit late, and please excuse me if that is not your problem, i was having trouble figuring out your problem.

 

On a side note, this is a porting issue? PICLite and HI-Tech should exibit the same behaviour.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...