Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4787

TMR1 & Button - long delay (1 min) before starting

$
0
0
Hi There,

I'm trying different little things to get familiar with the use of TMR1 as a timer (I want to use it as a time base).

Starting with "easy" little things, I'm trying to have my LED toggeling when the button is pressed.

It does work (immediatley) as long as I have not defined the T1CON and PIE1 registers like hereunder. If I uncomment both T1CON and PIE1 registers, the led will not toggle before (about) one minute has past.

Why is this please?

Code:

' ====== DEFINES ==================================================================================
DEFINE OSC 4

' ====== FUSES ====================================================================================
' PIC 16F690
@ __Config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF

' ====== REGISTERS ================================================================================
'            76543210
OPTION_REG = %10000000 ' PORT A&B Pull-Ups disabled (look WPUA & WPUB) INTEDG rising edge on A2
OSCCON    = %01100000 ' Internal RC set to 4Mhz - not to be used with XTal
ANSEL      = %00000000 ' Analog inputs Channels 0 to 7
ANSELH    = %00000000 ' Analog inputs Channels 8 to 11
ADCON0    = %00000000 ' A/D Module is OFF
CM1CON0    = %00000000 ' Comparator1 Module is OFF
CM2CON0    = %00000000 ' Comparator2 Module is OFF
INTCON    = %11000000 ' INTerrupts CONtrol: GIE is ON, PEIE is ON
'T1CON      = %00111001 ' Timer1 OSC enabled, Timer1 enabled, presc.1:8 (RA4/RA5!!)
'PIE1      = %00000001 ' Enable TMR1IF overflow flag
PORTA      = %00000000 ' Ports High/Low (0 to 5)
TRISA      = %00000100 ' Set Input/Output (0 to 5)
PORTB      = %00000000 ' Ports High/Low (4 to 7)
TRISB      = %00000000 ' Set Input/Output (4 to 7)
PORTC      = %00000000 ' Ports High/Low (0 to 7)
TRISC      = %00000000 ' Set Input/Output (0 to 7)

' ====== VARIABLES ================================================================================
LED    var PORTB.6
Btn    var PORTA.2
' ====== INITIALIZE ===============================================================================
PAUSE 1000 'circuit settle time

' ====== PROGRAM ==================================================================================
TEST:
    IF Btn = 0 THEN
        TOGGLE LED
        PAUSE 200
    ENDIF
GOTO TEST

Roger

Viewing all articles
Browse latest Browse all 4787

Trending Articles