Page 1 of 1

Customizing TMR1

Posted: Tue Feb 03, 2026 11:37 am
by samtin
Hello everyone,
I tried to make a custom TMR1 for PIC16F877A and visualize the signals on pin A0 on the oscilloscope, but it doesn't compile.
Can anyone help me? I'm using Flowcode 10.

Re: Customizing TMR1

Posted: Tue Feb 03, 2026 11:51 am
by Steve-Matrix
It looks like the capitalisation for the registers is wrong. For example, use "INTCONbits.PEIE = 1;"

See the Wiki entry here:
https://www.flowcode.co.uk/wiki/index.p ... -_PICmicro

NOTE: it looks like the images on that page are out of date, but the text itself seems to be correct. I will replace the images to avoid confusion.

Re: Customizing TMR1

Posted: Tue Feb 03, 2026 12:11 pm
by samtin
Thank you very much, it worked.

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 9:58 am
by samtin
Hello everyone,
I didn't get any signals on pin A0. Can anyone help me?
What is the mechanism of the custom code?
T1CON is the register where I select the prescale bits, but where are the postscale bits selected?
What is the register for setting the final value?

Here I found the custom code:
https://www.flowcode.co.uk/wiki/index.p ... -_PICmicro

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 10:33 am
by Steve-Matrix
There is a "Timer 1" interrupt for that device in Flowcode. Would using that be better or do you specifically need a custom version?

The Custom Interrupt feature is a more advanced feature that requires a knowledge of C code and the registers in the chip and so it's often much easier to make do with the inbuilt interrupts if they have the functionality you require.

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 11:09 am
by samtin
The existing code does not generate any signal on pin A0.
Why? The oscilloscope is connected to pin A0.

Enable code:
T1CON = 0x79; // Start timer with Internal clock source, prescaler = 1:8
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts
PIE1bits.TMR1IE = 1; // Enable Timer 1 interrupts

Disable code:
PIE1bits.TMR1IE = 0; // Disable Timer 1 interrupts

Handler code:
if (PIR1 & (1 << TMR1IF)) // Check to see if the interrupt flag is set
{
FCM_%n(); // Call Flowcode Macro
PIR1bits.TMR1IF= 0; // Clear interrupt flag
}

Do I need to add more code to the existing one?

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 11:16 am
by samtin
I am really interested in custom timing and I am trying
to observe how it works, but unfortunately it does not work.

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 12:09 pm
by Steve-Matrix
Ok, I understand. I suggest then you try using the inbuilt Timer 1 interrupt and look at the C code that is generated. For example, the following shows the custom code and the inbuilt code and from that you should be able to see how it works.

The datasheet for the chip should also have a lot of useful information about the settings required for T1CON.

Re: Customizing TMR1

Posted: Wed Feb 04, 2026 4:09 pm
by BenR
Hello,

Your custom interrupt code looks ok to me.

Have you tried a one second flasher test to confirm the basic setup is ok and the chip is running?
https://www.flowcode.co.uk/wiki/index.p ... ED_flasher

Your current setup suggests an external 19.6608MHz crystal is that correct?