• AVR Freaks

Timer 0 Interrup on PIC18F87J11

New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/01/12 13:25:27
  • Location: 0
  • Status: offline
2020/01/16 00:01:33 (permalink)

Timer 0 Interrup on PIC18F87J11

I made a program which activate timer 0 interrupt using a pre-defined variabiles. Those variabiles (p1, p2) are defined in the function "conf()". And I trying to activate the interruption by using the RB0 button.

#include <xc.h>
#define _XTAL_FREQ 4000000
#define p1 0b10001000
#define p2 0b10101010

unsigned char counter=0;
void interrupt f1()
 if(TMR0IE && TMR0IF)

void conf()
  T0CON = T0CON|p1;

int main(){


It's ok like that or I need to change something? 

1 Reply Related Threads

    Super Member
    • Total Posts : 25493
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Timer 0 Interrup on PIC18F87J11 2020/01/17 14:54:23 (permalink)
    Some comments in your code would be very helpful.
    Otherwise anyone looking at this
    #define p1 0b10001000
    #define p2 0b10101010
    Has to go and refer to the datasheet to figure out what the hell you are trying to do.
    p2 is written to INTCON, so you are setting:
    Never, ever enable an interrupt that your ISR does not handle. That will make your code crash, continually running only the ISR whenver that interrupt request flag gets set.
    Please explain what you expect this code to do.
    It appears to me, when the RB0 pin is held low, it will very rapidly write to T0CON and INTCON over and over.
    (I have no idea why you are setting RBIE or INT0IF.)
    When RB0 is high, it rapidly clears all of the LATD port over and over.
    So, if you pull RB0 low, and hold it low, after 30 timer rollovers, it will raise the RD0-RD3 pins, so long as RB0 is still low.
    (If RB0 is high, they would be set very very briefly, but immediately get cleared by your non interrupt code)
    Also note:
    void interrupt f1()
    should be
    void interrupt f1(void)

    int main(){
    should be
    void main(void){


    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    Jump to:
    © 2020 APG vNext Commercial Version 4.5