PIC16F877A - Timer0 won't interrupt


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10

    Default PIC16F877A - Timer0 won't interrupt

    Hello all,

    I've been struggling with a, for a not-picbasic-newbie (which I am! ), simple problem. I'm trying to let a LED blink on the overflow rate of timer0. Unfortunately I wasn't very succesfull.

    When I run the following code (I know the LED won't blink with this, but that's step 2)

    Code:
    define loader_used 1  
    define osc 20        
    
    led var portc.1            ;LED is connected on PortC.1
    
    wsave var   byte $20 system
    ssave var   byte bank0 system
    psave var   byte bank0 system
    
    Goto main
    
    define INTHAND tmroverflow
    
    asm
    tmroverflow movwf	wsave
                swapf	STATUS, W
                clrf	STATUS
                movwf	ssave              ;Interrupt
                movf	PCLATH, W          ;Routine
                movwf	psave              ;with Save function
                                           
                bsf     _led               ;Put on LED  
                
                movf	psave, W
                movwf	PCLATH
                swapf	ssave, W
                movwf	STATUS
                swapf	wsave, F
                swapf	wsave, W
                
                bcf     intcon,2           ;Clear Interrupt Flag
                
                retfie
    ENDASM
    
    main:
       INTCON = %10100000                  ;GIE enabled, T0IE enabled
       OPTION_REG = %00000101              ;Prescaler on TMR0 rate 1:32
       goto loop
       
    loop:
       goto loop                           ;Wait here for interrupt
    When I run it in debug mode, the compiler goes insane and gives me mismatched address errors after the timer didn't respond for some time (the watchdog timer is off, so it isn't him who's complaining )
    I think that my mistake is in the INTCON and/or the OPTION_REG, but experimenting with this values didn't helped me further neither.
    The "save" function is O.K asfar as I can see, since it's straight out of the manual!!

    All it need to do for step 1 is to light the LED...

    So if someone sees the problem right away, and I'm sure there will be many, please help this desperate newbie! I will be very gratefull!

    Cheers,

    William

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I don't see anything for a TRISC.1 = 0

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    define loader_used 1  
    define osc 20        
    
    led var portc.1            ;LED is connected on PortC.1
    ledcnt var word
    
    wsave var   byte $20 system
    ssave var   byte bank0 system
    psave var   byte bank0 system
    
    Goto main
    
    define INTHAND tmroverflow
    
    asm
    tmroverflow movwf	wsave
                swapf	STATUS, W
                clrf	STATUS
                movwf	ssave              ;Interrupt
                movf	PCLATH, W          ;Routine
                movwf	psave              ;with Save function
                                           
                inc          _ledcnt            ;increment the counter
                
                movf	psave, W
                movwf	PCLATH
                swapf	ssave, W
                movwf	STATUS
                swapf	wsave, F
                swapf	wsave, W
                
                bcf     intcon,2           ;Clear Interrupt Flag
                
                retfie
    ENDASM
    
    main:
       INTCON = %10100000                  ;GIE enabled, T0IE enabled
       OPTION_REG = %00000101              ;Prescaler on TMR0 rate 1:32
       Output LED
       
    loop:
       led = ledcnt.7                     ;make the led follow bit 7 of ledcounter
       goto loop                           ;Wait here for interrupt
    A couple of changes. If you don't see the LED blink, turn up the prescaler and/or use a slower oscillator for test. At least you should see it work.

  4. #4
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Typo or I missed that instruction

    Quote Originally Posted by skimask View Post
    [code]


    incf _ledcnt ;increment the counter

    Hi,

    Skimask I think it should be incf and is a simple typo.
    Regards

    Sougata

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata View Post
    Hi,

    Skimask I think it should be incf and is a simple typo.
    Yep, should be, and is......then again, it is Friday the 13th....maybe my keyboard is playing em no skcirt

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Interrupts and the MSC Debugger don't get along very well together.

    You must DISABLE debugging in any interrupt routines.
    Code:
    DISABLE DEBUG
    asm
    tmroverflow movwf	wsave
        ...
        ...
                retfie
    ENDASM
    ENABLE DEBUG
    For an 877, you should use $70 for the wsave address.

    OPTION_REG = %00000101 sets the prescaler to 1:64. (comment says 32)

    and, like skimask said ... set the LED's pin to output.
    DT

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Also a working example on MELABs website
    http://www.melabs.com/resources/samples/pbp/asmint.bas
    (maybe you got your start for yours there? I did not check if they are similar)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. 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
  2. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  3. Ping Darrel Taylor - Timer0 Instant Interrupt
    By JEC in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2007, 11:20
  4. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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