12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The basic interrupt routine you have worked with
    Code:
        DISABLE
        TLOOP:
        'DO SOMETHING
        INTCON.2=0
        RESUME
        ENABLE
    SOMETHING...
    I = I + 1
    IF ??? THEN
    ???
    RESET COUNTER
    ENDIF

    Tick Tock...
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Code:
    DISABLE 
    TLOOP:
    IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0 IF I<=100 GOTO MAIN IF I =100 GOTO TOG
     tog:TOGGLE GPIO.2
     RESUME: ENABLE
    That's what I was trying to fit in.

    Blimmey, it's nearly Friday already

    Am I close-ish.

    Dave

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Close-ish...

    IF INTCON.2=1
    is not needed in the interrupt routine, that is what send the code there in the first place.

    The rest might work.
    Does it??
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Mmmm.

    I was trying to use then reset IF INTCON.2=1 to increment count on 'I' the VAR.

    Code:
    IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0
    I'll sleep on it (I hope it doesn't keep me awake thinking).

    Dave

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Something...
    I = I + 1
    if ??? Then
    ???
    I = 0 'reset counter
    endif
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default

    IF INTCON.2=1
    is not needed in the interrupt routine, that is what send the code there in the first place.
    Correct. But remember that if/when you start adding more interrupt sources you need to determine which one it was that tripped so checking the interrupt flag is probably good practice. But as have been said, it's not strictly needed in this case.

    You seem to have a GOTO Main inside the ISR - you can do that but it is probably not a good idea as it will restart from the beginning of the program and not where it got interrupted. This MAY not be a problem in THIS particular program but can cause some interesting results so - try not to do that.

    Have a look at this:
    Code:
    DISABLE 
    TLOOP:
    IF INTCON.2 = 1 THEN    'TMR0 Interrupt?
       I = I + 1            'Increment counter
       IF I = 100 THEN      'Has it reached 100?
          TOGGLE GPIO.2     'If so, toggle LED...
          I = 0             '...and reset counter
       ENDIF
       INTCON.2 = 0            'Reset interrupt flag
    ENDIF
    RESUME                  'back to work.
    ENABLE
    /Henrik.

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Well once again I've learned a lot of things, thanks as ever.

    In the UK there's a famous comedy sketch where a musician says "I was playing all the right notes
    but not necessarily in the right order".

    I was a little (ok a lot) like that in this last exercise. I had written down I = 0 to reset the counter, I knew
    I had to do that which is something and I'd figured I = I + 1 to add to / increment the counter, so not all bad.

    Henrik highlighted within the program:
    Code:
     INTCON.2 = 1 THEN   'TMR0 Interrupt?
    I guess that's because as mackrackit pointed out to me that for the program to be there the INTERRUPT
    must have already occured?

    Code:
    ANSEL   = %00000000      'Disable analog select so ports work as digital i/o
     CMCON0 = %00000111      'Disable analog comparators
     TRISIO = %11111110      'TRISIO.0 set as OUTPUT
     GPIO   = %00000000      'All bits set LOW
     INTCON.5 = 1            'ENABLE TMR0
     OPTION_REG = %10000101  '16BIT 1:64 PRESCALE
     
    
     ON INTERRUPT GOTO TLOOP  'ON INTERRUPT GOTO the INTERRUPT handler LABEL 'TLOOP'
                                  
     i var byte               'Set I as a VARIABLE BYTE
    
    Main: 
     
    Not_pressed:
    PAUSE 25                            'Leave 25mili_sec for a button press to occur.
    if GPIO.5 = 1 THEN GOTO Not_pressed 'Keep waiting for +0v button press on GPIO.5
    IF GPIO.5 = 0  THEN goto LED        'Button has been pressed move to LABEL LED:
    LED:
    TOGGLE GPIO.0                       'Change state of GPIO.0 pin
    GOTO Not_pressed                    'Start again
     
     DISABLE                            'Disable INTERRUPT in handler
     TLOOP:
     IF INTCON.2 = 1 THEN   'TMR0 Interrupt?
       I = I + 1            'Increment counter
       IF I = 100 THEN      'Has it reached 100?
          TOGGLE GPIO.2     'If so, toggle LED...
          I = 0             '...and reset counter
       ENDIF
       INTCON.2 = 0         'Reset interrupt flag
    ENDIF
    RESUME:ENABLE           'ENABLE INTERRUPT in handler start prog again
    10/10 for you guys.

    Dave (not clever just persistent).
    Last edited by LEDave; - 26th March 2010 at 21:02.

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