Troubles getting timers to work with PIC18F24K40

Thread Starter

geekoftheweek

Joined Oct 6, 2013
898
It seems I'm missing something. I know the program is running since if I use a couple bytes to make a counter in the program loop I can make the led blink. It just seems that either the timers are not working for some reason or it's not setting the interrupt flags for whatever reason. I also tried using timer 1 with no luck either. It should blink the led a number of times, then pause, then repeat. It works perfect on every other PIC I've used it with.

Code:
include "global-defines.inc"

#define __MAIN_ASM__
include "main.inc"
include "i2c-slave.inc"
include "app-functions.inc"

; ---------------------------------------------------------------------------------------------------------------------------------------	

     config FEXTOSC = OFF                       ;External Oscillator not enabled
     config RSTOSC = HFINTOSC_64MHZ             ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
     config CLKOUTEN = OFF                      ;CLKOUT function is disabled
     config CSWEN = OFF                         ;The NOSC and NDIV bits cannot be changed by user software
     config FCMEN = OFF                          ;Fail-Safe Clock Monitor enabled
     config WDTE = OFF                          ;WDT Disabled
     config MCLRE = INTMCLR      ;If LVP = 0, MCLR pin function is port defined function; If LVP =1, RE3 pin fuction is MCLR
     config LVP = OFF            ;Single-Supply ICSP disabled
     config CP = OFF             ;Block 0 (000800-001FFFh) not code-protected
     config CPD = OFF            ;Data EEPROM not code-protected
     config WRT0 = OFF           ;Block 0 (000800-001FFFh) not write-protected
     config WRT1 = OFF           ;Block 1 (002000-003FFFh) not write-protected
     config WRTC = ON            ;Configuration registers (300000-3000FFh) write-protected
     config WRTB = OFF           ;Boot Block (000000-0007FFh) not write-protected
     config WRTD = OFF           ;Data EEPROM not write-protected
     config EBTR0 = OFF          ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
     config EBTR1 = OFF          ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
     config EBTRB = OFF          ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks


; ---------------------------------------------------------------------------------------------------------------------------------------	

boot   code
    
; ---------------------------------------------------------------------------------------------------------------------------------------
	
    goto __start
    dw 0
    dw 0
    
__interrupts
    movff STATUS, status_temp
    movwf w_temp
    
_interrupts_end    
    movf w_temp, w
    movff status_temp, STATUS
    retfie
    
; ---------------------------------------------------------------------------------------------------------------------------------------

__start

    clrf sys_flags
    clrf sys_error
    clrf app_flags
    clrf app_error
    
; switch banks for SFR not in access memory
    movlb 0x0f
    
; set ADC pins to digital
    clrf ANSELA, b
    clrf ANSELB, b
    clrf ANSELC, b
    bsf ODCONA, 0, b
    
; set up led
    bcf STATUS_LED_TRIS
    bsf STATUS_LED_LATCH
    turnStatusLedOn
    
; set up status led initial values
    movlfa 1, status_led_code
    movff status_led_code, status_led_count
    
; set up timer 0 for status led
    movlfa b'00011111', T0CON0
    bsf T0CON1, T0CS1
    bsf T0CON0, T0EN
  
    ;call __i2c_slave_init      

; ---------------------------------------------------------------------------------------------------------------------------------------

__main__loop
    
    
; test to see if blink status led
    btfsc PIR0, TMR0IF, b
    call __timer0_isr

; check for i2c traffic
    ;call __i2c_slave_poll
    
    goto __main__loop
    
; ---------------------------------------------------------------------------------------------------------------------------------------	

__timer0_isr
    bcf PIR0, TMR0IF, b
    
; figure out if led is on or not
    btfss STATUS_LED_LATCH
    bra _timer0_isr_led_is_on

_timer0_isr_led_is_off
; firgure out if counting dead space
    btfsc status_led_count, 7
    bra _timer0_isr_led_is_off_counting_dead_space
    
    dcfsnz status_led_count, F
    bra _timer0_isr_led_is_off_hit_zero
    turnStatusLedOn
    return
    
_timer0_isr_led_is_off_hit_zero    
    movlfa STATUS_LED_DEAD_COUNT, status_led_count
    bsf status_led_count, 7
    return
    
_timer0_isr_led_is_off_counting_dead_space    
    decf status_led_count, F
    movlw 0x7f
    andwf status_led_count, W
    bz _timer0_isr_led_is_off_counting_dead_space_hit_zero
    return
    
_timer0_isr_led_is_off_counting_dead_space_hit_zero    
    movff status_led_code, status_led_count
    turnStatusLedOn
    return
    
_timer0_isr_led_is_on    
    turnStatusLedOff
    return
    
; ---------------------------------------------------------------------------------------------------------------------------------------	
    
    
; ---------------------------------------------------------------------------------------------------------------------------------------	    

    end

; ---------------------------------------------------------------------------------------------------------------------------------------
 
Top