Hello There,

This piece of code is meant to flash a LED every second.

In my mind, and since the TMR1 is setup to overflow every 0.5 second, toggeling a BIT variable and checking when it is set should do the trick.

First, as long as the variable is not reset, the LED will do weird and never really go OFF.

Second, when I reset this variable (Flag = 0), it does kind of work, still not with a one second delay but 0.5 second instead.

What is the explanation please? What is wrong with my code?

Code:
' PIC 16F690

@ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF

OPTION_REG = %10000000 '
OSCCON     = %01100000 ' Internal oscillator 4MHz
ANSEL      = %00000000 ' analog inputs Channels 0 to 7
ANSELH     = %00000000 ' analog inputs Channels 8 to 11
INTCON     = %11000000 ' INTerrupts CONtrol; GIE=1, T0IE=1
T1CON      = %00110001 ' <5:4> prescaler 1:8, <1> Timer1 enabled

DEFINE OSC 4

Flag    VAR BIT
CAL_H   CON 11
CAL_L   CON 219 

MAIN:
    IF PIR1.0 THEN
        PIR1.0 = 0
        TOGGLE Flag
        TMR1H = CAL_H : TMR1L = CAL_L
    ENDIF
    
    IF Flag THEN
        Flag = 0
        TOGGLE PORTC.0
    ENDIF
        
    GOTO MAIN

END