Jump to content

Problems With Void Interrupt(void)

Recommended Posts



i have a main.c and two header files (initialization.h and function.h).

the summary is i integrate all my modules and turn them into function/process so that my main.c program will just call them. my function/process use timers. heres the problem: when i put the "void interrupt(void)" process in the function.h it compiles successfully but it doesn't work. but when i put "void interrupt(void)" process in the main.c it compiles error, saying



D:\SourceBoost\Samples\C\BoostC\esg05060211.c(9:6): error: Function 'interrupt' already has a body

D:\SourceBoost\boostc.pic16.exe esg05060211.c -t PIC16F877A

Exit code was 1.

Removing target: esg05060211.obj



here are my sample code:



#include <function.h>

//Target PIC16F877 configuration word

//Set clock frequency
#pragma CLOCK_FREQ	4000000

void interrupt()
//Handle timer0 interrupt
if(intcon & (1<<T0IF))
	/************************for RR_function************************/
	if(RRcounter == 49){	// already 0.05 second
		real_time++;		//same as 1/4 of big box
		RRcounter = 0;
	clear_bit( intcon, T0IF ); // clear timer 0 interrupt bit
	tmr0 = 0x00;

void main( void )
trisc = 0x00;
portc = 0x00;
portc.4 = 1;
	portc.3 = 1;



#include <initialization.h>

void ADC_init()
trisa.0 = 1;
adcon0 = 00000000b;		/*	Fosc/2, AN0, right justified*/
adcon1 = 10001110b;
clear_bit(pir1, 6);		//clear ADIF
clear_bit(pie1, 6);		//ADC interrupt disabled
set_bit(intcon, 6);		//set PEIE
set_bit(intcon, 7);		//set GIE

void ADC()
adcon0.0 = 1;
adcon0.2 = 1; 	//starts ADC
while(adcon0.2); // wait until conversion is done

void timer0_init()
/*---1:4 prescalar---*/
option_reg.2 = 0;
option_reg.1 = 0;
option_reg.0 = 1;
/* ------------------ */
option_reg.5 = 0;	// internal clk source
option_reg.3 = 0;	// prescalar assigned to timer0
//intcon.5 = 1;	// enables timer0 interrupt
tmr0 = 0x00;

void timer0_go(){
intcon.5 = 1;

void timer0_stop()
intcon.5 = 0;

void RR_function(void){

//unsigned long heart_rate = 0;
bit flagR1 = 0;
bit flagR2 = 0;
unsigned int rate = 0;


trisc = 0x00;
portc = 0x00;

MAKESHORT(ewan, adresl, adresh);

if(ewan > Nullplus){		
	first_frame = ewan;
	MAKESHORT(ewan, adresl, adresh);
	if(ewan >= first_frame){
		first_frame = ewan;
		goto ADC2;
	else if(ewan < first_frame){
		peak_temp = first_frame;
			if(flagR1 == 1){
				flagR2 = 1;
				portc.1 = flagR2;
				goto fin;																
			if(flagR1 == 0){
				flagR1 = 1;	
				portc.0 = flagR1;
				goto ADC;


goto ADC;

	unsigned int temp;
	temp = 300/real_time;
	rate = temp*4;
	//portc = rate;

	if(rate < 60){
		portc.7 = 1;
	if((rate >= 60) && (rate <= 100)){
		portc.6 = 1;
	if(rate > 100){
		portc.5 = 1;	



#include <system.h>

/***************R wave initialization***************/

unsigned short R_peak1 = 0x0256; // 	2.92
unsigned short R_peak2 = 0x01DB; // 	2.32
unsigned int RRcounter = 0;
unsigned int real_time = 0;


unsigned short Nullplus = 0x00A8;	//	820mV
unsigned short Nullminus = 0x006B;	//	520mV

unsigned short first_frame = 0x0000;	//	temporary first detection of a desired signal
unsigned short last_frame = 0x0000;	//	temporary last detection of a desired signal
unsigned short peak_temp = 0x0000;	//	temporary peak detected
unsigned short ewan = 0;


where should i put "void interrupt(void)"?


any comments/suggestions??




Link to post
Share on other sites

Picxie is a bit incorrect in this, having code in your headers is fine,

but you do have a problem with your headers:




Is miissing around both your headers.

Link to post
Share on other sites
Its not usual to put code in headers.

Picxie is a bit incorrect in this, having code in your headers is fine,

Hmm...it is possible to have code in your headers, but if you allocate anything in your headers, you have to require that only one source file includes that header (the inclusion guard alone won't cut it). So besides inline functions, Picxie is right on that it is very unusual to define code in your headers.

Link to post
Share on other sites

If you have functions with duplicate names and parameters, even if they are in different .c files

most compilers will complain. But i have had compilers that will not compile or link any headers

without the proper #define _HEADER_H_ #endif


i agree in decent code it is rare to have code in your headers

(unless your a Microchip library programmer, the best examples how not to program is by them)

except when activly developing a library.


Most people develope library by library during which most of the code is in the header, then

when everything is working all the functions and variables are moved into the .c.

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...