I'm trying to start with just getting one timer to work and do the usual "Flash an LED", or actually toggle between 2 LED's so I can tell where in the timing sequence it is. With what I have below, LED2 is on at startup and then it switches to LED1 and never toggles again. I think I have something wrong in my setup but don't know what. Once I get this working I would like to add the TMR1 (TimerB).
Any help is appreciated.
Thank you,
Hylan
Here's the code:
Code:'**************************************************************** '* Name : TimerTest.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 12/9/2012 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** #config __CONFIG _CONFIG1H, _OSCS_OFF_1H & _OSC_XT_1H __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_27_2L & _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H __CONFIG _CONFIG3H, _CCP2MUX_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L #endconfig '************************************************************** 'Interrupt code added 12-9-12 INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? ;INT_Handler RX_INT, _serialin, PBP, no ;INT_Handler INT_INT, _ToggleLED1, PBP, yes INT_Handler TMR0_INT, _TimerA, PBP, yes ;INT_Handler TMR1_INT, _TimerB, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T0CON = %10010010 ; T0 = 16-bit, Prescaler 8 ;@ INT_ENABLE RX_INT ; enable external (INT) interrupts ;@ INT_ENABLE INT_INT ; enable external (INT) interrupts @ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts ;@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts CLEAR ' Clear all variables to 0 LED1 VAR PortC.5 ' Output 1 LED2 VAR PortC.4 IN1 VAR PortE.0 ' Input 1 Counter var byte ' Keeps count of seconds PortA = %00100000 ' PortA All Off PortB = %00000000 ' PortB All Off PortC = %00000000 ' PortC All Off PortD = %00000000 ' PortD All Off PortE = %00000000 ' PortE All Off PortF = %00000000 ' PortF All Off PortG = %00000000 ' PortG All Off TRISA = %00011001 ' Inputs = 1, Outputs = 0 RA(7-6) NA TRISB = %11111111 ' Inputs = 1, Outputs = 0 TRISC = %10000010 ' Inputs = 1, Outputs = 0 TRISD = %11111111 ' Inputs = 1, Outputs = 0 TRISE = %11111111 ' Inputs = 1, Outputs = 0 TRISF = %11111111 ' Inputs = 1, Outputs = 0 TRISG = %00000000 ' Inputs = 1, Outputs = 0 RG(7-5) NA ADCON0 = %00000001 ' A/D Enabled, Channel 0 (AN0) ADCON1 = %00001110 ' AN0 Analog Input (Rest Digital I/O) ADCON2.7 = 1 ' Right Justify 10 Bit Word CMCON = %00000111 ' Both Comparators Disabled INTCON2.7 = 0 ' Turn ON PortB Pull-Ups T1CON = %00110100 ' 1:8 Prescale, T1OSCEN Off (524.288mS) GOSUB ResetTime ; Reset Time to 0d-00:00:00.00 GOSUB StartTimer ; Start the Elapsed Timer Main: pause 200 if (Counter > 0) and (Counter < 10) then LED1 = 1 LED2 = 0 else LED1 = 0 LED2 = 1 endif goto Main TimerA: if SecondsChanged = 1 then SecondsChanged = 0 Counter = Counter + 1 If Counter = 20 then Counter = 0 endif endif @ INT_RETURN




Bookmarks