CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

trouble enabling interrupts on 16F57

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
randy.shaffer



Joined: 21 Mar 2018
Posts: 58

View user's profile Send private message

trouble enabling interrupts on 16F57
PostPosted: Wed Mar 12, 2025 4:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 12, 2025 5:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 12, 2025 5:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 12, 2025 10:45 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group