18F26K42 TMR1 Interrupt troubles


Results 1 to 6 of 6

Threaded View

  1. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

    Default Re: 18F26K42 TMR1 Interrupt troubles

    your code would toggle led @32mS intervals , its a bit hard to see .
    I can't compile pbp3 for this chip but can say that these settings work in xc8

    Code:
    #CONFIG
        CONFIG FEXTOSC = OFF               
        CONFIG RSTOSC = HFINTOSC_64MHZ       
        CONFIG CLKOUTEN = OFF                
        CONFIG PR1WAY = OFF                    
        CONFIG CSWEN = ON                    
        CONFIG FCMEN = OFF                    
        CONFIG MCLRE = INTMCLR               
        CONFIG PWRTS = PWRT_OFF                
        CONFIG MVECEN = OFF                   
        CONFIG IVT1WAY = OFF                
        CONFIG LPBOREN = OFF               
        CONFIG BOREN = OFF                    
        CONFIG BORV = VBOR_245                
        CONFIG ZCD = OFF                    
        CONFIG PPS1WAY = OFF               
        CONFIG STVREN = OFF                    
        CONFIG DEBUG = OFF                  
        CONFIG XINST = OFF                    
        CONFIG WDTCPS = WDTCPS_31            
        CONFIG WDTE = OFF                   
        CONFIG WDTCWS = WDTCWS_7            
        CONFIG WDTCCS = LFINTOSC           
        CONFIG BBSIZE = BBSIZE_512            
        CONFIG BBEN = OFF                    
        CONFIG SAFEN = OFF                    
        CONFIG WRTAPP = OFF                    
        CONFIG WRTB = OFF                   
        CONFIG WRTC = OFF                    
        CONFIG WRTD = OFF                    
        CONFIG WRTSAF = OFF                    
        CONFIG LVP = OFF                    
        CONFIG CP = OFF                        
    #ENDCONFIG
      
    'Defines, Includes, and Constants-----------------------------------------------
    DEFINE OSC 64                                   ' Calibrate PBP to 64MHz clock
    OSCFRQ = 8                              ' Set system clock to 64MHz internal
    OSCCON1 = $60
    on interrupt goto INC_TICK
    'Direction----------------------------------------------------------------------
    TRISA.1 = 0
    'Alias---------------------------------------------------------------------------
    LED    VAR LATA.1
    'Variables----------------------------------------------------------------------
    'Initialize Registers----------------------------------------------------------------------
    Initilize:  
        ANSELA   = 0                      ' Set digital
        
         LED = 0
       
        INTCON0.7 = 1                                      'Enable global int
        T1CON = $35                                          'Prescale 1:8; enable the TMR1
       
        T1CLK = 1                                           'Clock Source Fosc/4
        
        
        PIR4.0 = 0                                             'Clear the Int flag
        PIE4.0 = 1                                             'Enable timer int
        
                                            'Start the timer 
    C0UNTER VAR BYTE   
       
    'Code---------------------------------------------------------------------------  
    Main:  
        pause 1 
        Goto Main
    '----- INTERRUPT CODE -------------------
    Disable
    INC_TICK:
             COUNTER=COUNTER+1
             IF COUNTER==31 THEN
             LED=!LED           ;TOGGLE LED ONCE PER SEC
             COUNTER=0
             ENDIF
             
             PIR4.0 = 0
             
             Resume
    enable
    Last edited by richard; - 8th March 2018 at 10:51.
    Warning I'm not a teacher

Similar Threads

  1. 12F683, TMR1 and ON INTERRUPT revisited
    By AvionicsMaster1 in forum PBP3
    Replies: 1
    Last Post: - 17th September 2013, 20:07
  2. Difficulty toggling LED with TMR1 overflow interrupt
    By jgjgjg in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th July 2012, 12:17
  3. How to set Tmr1 to interrupt every 5 seconds
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd December 2008, 04:51
  4. TMR1 100Hz Exactly Interrupt Routine
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 15th February 2007, 06:51
  5. TMR1 interrupt question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th February 2006, 04:02

Members who have read this thread : 2

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