How to set interrupt for Timer 0


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    70

    Default How to set interrupt for Timer 0

    Now have problem with time 0 set interrupt every 34 us

    Here is my code ,that is correct or not

    Main:
    Trisb = %11111111
    Trisa = %00000000

    'DECLARE SYMBOLS
    Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
    Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
    Symbol GIE = INTCON.7 ' Global Interrupt Enable
    Symbol PS0 = OPTION_REG.0 ' Prescaler Rate Select
    Symbol PS1 = OPTION_REG.1 ' Prescaler Rate Select
    Symbol PS2 = OPTION_REG.2 ' Prescaler Rate Select
    Symbol PSA = OPTION_REG.3 ' Prescaler Assignment
    Symbol TOCS = OPTION_REG.5

    'SET REGISTERS

    'Below is the prescaler setting you chose....
    '---------------------------------------------------------
    PS0 = 0
    PS1 = 0
    PS2 = 0
    PSA = 1
    '---------------------------------------------------------
    TOCS = 0 'set the clock source for internal oscillator
    T0IF = 0 'clear the interrupt flag
    T0IE = 1 'enable tmr0 interrupt
    GIE = 1 'enable Global interrupts
    'Below is the offset setting you chose....
    TMR0 = 223
    'START PROGRAM
    On Interrupt goto Int
    Strobe = 1 'strobe off
    latch = 1 'lactch off
    clock = 1 'CLOCK OFF ACTIVE HIGH

    Sin3 = 0
    Sin2 = 0
    SIN1 = 0
    Loop:
    nap 7
    goto loop

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's not the whole thing you posted right?

    It miss the most intereting part...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    after i start debug with IDC the code will run and stop at line TMR0 = 223
    and still there Now i don't know why ...
    Norrmally after we run should run untill sub " loop " and replace there untill TMR0 was over full and then jump to "INT:" sub right

    Pls advise too.....

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    NAP uses SLEEP which stops the clock, which stops the timer.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Red face

    DOH! Seems i miss that line
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    So , I did change to used ..
    '--------------
    While 1

    wend

    '--------------

    But still same problem found, Who did have sample of time interrupt TMR0 pls share for me too

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  4. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts