View previous topic :: View next topic |
Author |
Message |
randy.shaffer
Joined: 21 Mar 2018 Posts: 58
|
trouble enabling interrupts on 16F57 |
Posted: Wed Mar 12, 2025 4:43 pm |
|
|
I was trying to set up timer0 interrupts but got an error when enabling global interrupts:
*** Error 112 Line 7(1,1): Function used but not defined: ... enable_interrupts 272 SCR=438
even though the function (and GLOBAL) are defined in the header file.
Complier is 5v118
Code: | #include <16F57.h>
#fuses NOWDT XT
#use delay(XTAL = 4MHz)
void main()
{
setup_timer_0(T0_INTERNAL | T0_DIV_8); // clocked @ Fosc/4 = 1 MHz
enable_interrupts(GLOBAL); // enable all interrupts
set_timer0(0x82); // initialize timer for 1ms interrupts
while(TRUE);
} |
|
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9442 Location: Greensville,Ontario
|
|
Posted: Wed Mar 12, 2025 5:35 pm |
|
|
you've never enabled timer0 interrupt and there's no 'handler' ( code to execute... aka function ) to do 'something' when that interrupt happens.
'global' doesn't enable ALL interrupts. It only enables those that you've specifically enabled.
You can think of it as the 'main breaker' in the fuse panel, and the individual breakers control specific rooms( these would be the peripheral interrupt enables).
check some of the examples CCS supplies in the 'examples' subfolder..... |
|
 |
randy.shaffer
Joined: 21 Mar 2018 Posts: 58
|
|
Posted: Wed Mar 12, 2025 5:51 pm |
|
|
This was the original code:
Code: | #include <16F57.h>
#fuses NOWDT XT
#define ONE_MS 0x82
#use delay(XTAL = 4MHz)
void timer0_isr(void);
void main()
{
setup_timer_0(T0_INTERNAL | T0_DIV_8); // clocked @ Fosc/4 = 1 MHz
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL); // enable interrupts
set_timer0(ONE_MS); // initialize timer for 1ms interrupts
while(TRUE);
}
#INT_TIMER0
void timer0_isr(void)
{
clear_interrupt(INT_TIMER0);
set_timer0(ONE_MS); // load value for next 1ms interrupt
} |
The errors started with undefined identifier INT_TIMER0. I started whittling the code down to minimize the errors. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19761
|
|
Posted: Wed Mar 12, 2025 10:45 pm |
|
|
This I'm afraid is a 'read the data sheet' one.
This is a very old chip. Guess what?. It does not have an interrupt controller...
A lot of the very early PIC's did not. Though an 'F' chip, this was a redesign
of the C57, and shares it's features.
The full data sheet, is the 16F5x sheet.
The reason you can't enable interrupts, is there are none. There are no
instructions in this chip for this. It only has about 33 instructions. |
|
 |
|