Jump to content
Sign in to follow this  
scud21

Problems With Void Interrupt(void)

Recommended Posts

hi

 

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

 

failure

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

Done

 

here are my sample code:

 

main.c

#include <function.h>

//Target PIC16F877 configuration word
#pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _XT_OSC & _CP_OFF

//Set clock frequency
#pragma CLOCK_FREQ	4000000

void interrupt()
{
//Handle timer0 interrupt
if(intcon & (1<<T0IF))
{
	/************************for RR_function************************/
	RRcounter++;
	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;
RR_function();
while(1)
	portc.3 = 1;
}

 

function.h

#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;


ADC_init();

trisc = 0x00;
portc = 0x00;

ADC:
ADC();
MAKESHORT(ewan, adresl, adresh);

if(ewan > Nullplus){		
	first_frame = ewan;
	ADC2:
	ADC();
	MAKESHORT(ewan, adresl, adresh);
	if(ewan >= first_frame){
		first_frame = ewan;
		goto ADC2;
	}
	else if(ewan < first_frame){
		peak_temp = first_frame;
		if((peak_temp<=R_peak1)&&(peak_temp>=R_peak2)){
			if(flagR1 == 1){
				timer0_stop();
				flagR2 = 1;
				portc.1 = flagR2;
				goto fin;																
			}
			if(flagR1 == 0){
				flagR1 = 1;	
				portc.0 = flagR1;
				timer0_init();
				timer0_go();
				delay_ms(20);
				goto ADC;
			}	

		}		
	}
}

goto ADC;

fin:
delay_s(1);
while(1){
	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;	
	}
}
}

 

initialization.h

#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??

 

regards,

scud

Share this post


Link to post
Share on other sites

Its not usual to put code in headers.

I bet if you took all that code out of the .h files and put it in .c files your problem will disappear

Share this post


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:

 

#ifndef _INITIALIZATION_H_
#define _INITIALIZATION_H_
   .
   .
   .
   code
   .
   .
   .
#endif

 

Is miissing around both your headers.

Share this post


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.

Share this post


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.

Share this post


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.

Guest
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.

Loading...
Sign in to follow this  

×
×
  • Create New...