//************************************************************************************
//**  
//**  File name:     F:\RPM og Counter\05 - RPM og Counter\05 - RPM og Counter.c
//**  Generated by:  Flowcode v4.2.3.58
//**  Date:          Tuesday, March 16, 2010 13:39:01
//**  Licence:       Student
//**  Registered to: Keld Sørensen
//**  
//**  
//**     NOT FOR COMMERCIAL USE
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P16F628
#define MX_EE
#define MX_EE_TYPE1
#define MX_EE_SIZE 128
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 2
#define MX_UART_RX 1
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisb
#define MX_PWM_1 3

//Functions
#define MX_CLK_SPEED 20000000
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif

//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x2007, 0x3f0a
#endif
#ifdef HI_TECH_C
__CONFIG(0x3f0a);
#endif

//Internal functions
#include "C:\Programmer\Matrix Multimedia\Flowcode V4\FCD\internals.h"

//Macro function declarations
void FCM_UpdateDigit(char FCL_DIGIT, char FCL_VALUE);
void FCM_UpdateDisplay(short FCL_VALUE);
void FCM_CalculateDigits(short FCL_AVALUE);
void FCM_INTR_RB0();
void FCM_Initialiser();
void FCM_RPM();
void FCM_Counter();
void FCM_INTR_Nulstil();
void FCM_INTR_RPM();
void FCM_SetDigitsOff();


//Variable declarations
short FCV_INCOMMINGPULS;
char FCV_MODE;
short FCV_FRYSPULSANTAL;
short FCV_TELNEDTILNULSTILINIT;
short FCV_TELNEDTILNULSTIL;
char FCV_TMR0ENABLED;
char FCV_DIGIT1;
char FCV_FRYS;
char FCV_DIGIT2;
float FCV_FLOAT1;
char FCV_DIGIT3;
short FCV_DISPLAYTHIS;
char FCV_FLOAT2;
char FCV_DIGIT4;
char FCV_PULSPROMDR;
char FCV_FIRSTFRYS;
short FCV_RPMUPDATE;
char FCV_VISDIGITTID;
short FCV_RPMUPDATEINIT;


//Defines:

/**** Macro Substitutions ****
1 = Segment Port
0 = Common Port
128 = Pattern 0
242 = Pattern 1
72 = Pattern 2
96 = Pattern 3
50 = Pattern 4
36 = Pattern 5
4 = Pattern 6
240 = Pattern 7
0 = Pattern 8
48 = Pattern 9
255 = Pattern DP
1 = Common Mask
254 = Common Mask Inverted
0 = Segment Mask Inverted
0 = Common Anode Display Type
******************************/




//led7seg0: //Macro function declarations

void FCD_led7seg0_ShowDigit(char Value, char DecimalPoint);
void FCD_led7seg0_ClearDigit();
//Defines:

/**** Macro Substitutions ****
1 = Segment Port
0 = Common Port
128 = Pattern 0
242 = Pattern 1
72 = Pattern 2
96 = Pattern 3
50 = Pattern 4
36 = Pattern 5
4 = Pattern 6
240 = Pattern 7
0 = Pattern 8
48 = Pattern 9
255 = Pattern DP
2 = Common Mask
253 = Common Mask Inverted
0 = Segment Mask Inverted
0 = Common Anode Display Type
******************************/




//led7seg1: //Macro function declarations

void FCD_led7seg1_ShowDigit(char Value, char DecimalPoint);
void FCD_led7seg1_ClearDigit();
//Defines:

/**** Macro Substitutions ****
1 = Segment Port
0 = Common Port
128 = Pattern 0
242 = Pattern 1
72 = Pattern 2
96 = Pattern 3
50 = Pattern 4
36 = Pattern 5
4 = Pattern 6
240 = Pattern 7
0 = Pattern 8
48 = Pattern 9
255 = Pattern DP
4 = Common Mask
251 = Common Mask Inverted
0 = Segment Mask Inverted
0 = Common Anode Display Type
******************************/




//led7seg2: //Macro function declarations

void FCD_led7seg2_ShowDigit(char Value, char DecimalPoint);
void FCD_led7seg2_ClearDigit();
//Defines:

/**** Macro Substitutions ****
1 = Segment Port
0 = Common Port
128 = Pattern 0
242 = Pattern 1
72 = Pattern 2
96 = Pattern 3
50 = Pattern 4
36 = Pattern 5
4 = Pattern 6
240 = Pattern 7
0 = Pattern 8
48 = Pattern 9
255 = Pattern DP
8 = Common Mask
247 = Common Mask Inverted
0 = Segment Mask Inverted
0 = Common Anode Display Type
******************************/




//led7seg3: //Macro function declarations

void FCD_led7seg3_ShowDigit(char Value, char DecimalPoint);
void FCD_led7seg3_ClearDigit();
//Defines:

/**** Macro Substitutions ****
porta = Switch Port Register
trisa = Switch Data Direction Register
4 = Switch Pin
0 = Switch Polarity Control
0 = Switch Debounce Delay Value
******************************/




//SWITCH1: //Macro function declarations

char FCD_SWITCH1_ReadState();
void FCD_SWITCH1_WaitUntilHigh();
void FCD_SWITCH1_WaitUntilLow();
//Defines:

/**** Macro Substitutions ****
porta = Switch Port Register
trisa = Switch Data Direction Register
5 = Switch Pin
0 = Switch Polarity Control
0 = Switch Debounce Delay Value
******************************/




//SWITCH2: //Macro function declarations

char FCD_SWITCH2_ReadState();
void FCD_SWITCH2_WaitUntilHigh();
void FCD_SWITCH2_WaitUntilLow();



//led7seg0: //Macro implementations


void FCD_led7seg0_ShowDigit(char Value, char DecimalPoint)
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

	    //set pattern array for the display
	    #ifdef _BOOSTC
			rom char* cSegmentArray = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif
		#ifdef HI_TECH_C
			const char cSegmentArray[] = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif

		//get pattern for digit
		char cSegmentValue = cSegmentArray[Value % 10];
		if (DecimalPoint)
			cSegmentValue = cSegmentValue & 255;

		//set up ports
		MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & 254;
	    MX_7SEG1_SEGMENT_TRIS = (MX_7SEG1_SEGMENT_TRIS & 0) | 0x01;

		#define MX_7SEG_COM_ANODE_0

		//display the digit
	    #ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 1);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | ~cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 254);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}

void FCD_led7seg0_ClearDigit()
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

		#define MX_7SEG_COM_ANODE_0

	    //clear the digit
		#ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = 0xFF;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 254);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = 0x00;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 1);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}



//led7seg1: //Macro implementations


void FCD_led7seg1_ShowDigit(char Value, char DecimalPoint)
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

	    //set pattern array for the display
	    #ifdef _BOOSTC
			rom char* cSegmentArray = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif
		#ifdef HI_TECH_C
			const char cSegmentArray[] = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif

		//get pattern for digit
		char cSegmentValue = cSegmentArray[Value % 10];
		if (DecimalPoint)
			cSegmentValue = cSegmentValue & 255;

		//set up ports
		MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & 253;
	    MX_7SEG1_SEGMENT_TRIS = (MX_7SEG1_SEGMENT_TRIS & 0) | 0x01;

		#define MX_7SEG_COM_ANODE_0

		//display the digit
	    #ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 2);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | ~cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 253);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}

void FCD_led7seg1_ClearDigit()
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

		#define MX_7SEG_COM_ANODE_0

	    //clear the digit
		#ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = 0xFF;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 253);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = 0x00;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 2);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}



//led7seg2: //Macro implementations


void FCD_led7seg2_ShowDigit(char Value, char DecimalPoint)
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

	    //set pattern array for the display
	    #ifdef _BOOSTC
			rom char* cSegmentArray = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif
		#ifdef HI_TECH_C
			const char cSegmentArray[] = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif

		//get pattern for digit
		char cSegmentValue = cSegmentArray[Value % 10];
		if (DecimalPoint)
			cSegmentValue = cSegmentValue & 255;

		//set up ports
		MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & 251;
	    MX_7SEG1_SEGMENT_TRIS = (MX_7SEG1_SEGMENT_TRIS & 0) | 0x01;

		#define MX_7SEG_COM_ANODE_0

		//display the digit
	    #ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 4);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | ~cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 251);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}

void FCD_led7seg2_ClearDigit()
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

		#define MX_7SEG_COM_ANODE_0

	    //clear the digit
		#ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = 0xFF;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 251);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = 0x00;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 4);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}



//led7seg3: //Macro implementations


void FCD_led7seg3_ShowDigit(char Value, char DecimalPoint)
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

	    //set pattern array for the display
	    #ifdef _BOOSTC
			rom char* cSegmentArray = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif
		#ifdef HI_TECH_C
			const char cSegmentArray[] = {128, 242, 72, 96, 50, 36, 4, 240, 0, 48};
		#endif

		//get pattern for digit
		char cSegmentValue = cSegmentArray[Value % 10];
		if (DecimalPoint)
			cSegmentValue = cSegmentValue & 255;

		//set up ports
		MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & 247;
	    MX_7SEG1_SEGMENT_TRIS = (MX_7SEG1_SEGMENT_TRIS & 0) | 0x01;

		#define MX_7SEG_COM_ANODE_0

		//display the digit
	    #ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 8);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & 0) | ~cSegmentValue;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 247);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}

void FCD_led7seg3_ClearDigit()
{
	
		#define MX_7SEG_SEG_PORT_1
		#define MX_7SEG_COM_PORT_0

	    #ifdef MX_7SEG_SEG_PORT_0								//Segment Port Definitions
	      #define MX_7SEG1_SEGMENT_PORT  porta
	      #define MX_7SEG1_SEGMENT_TRIS  trisa
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_1
	      #define MX_7SEG1_SEGMENT_PORT  portb
	      #define MX_7SEG1_SEGMENT_TRIS  trisb
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_2
	      #define MX_7SEG1_SEGMENT_PORT  portc
	      #define MX_7SEG1_SEGMENT_TRIS  trisc
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_3
	      #define MX_7SEG1_SEGMENT_PORT  portd
	      #define MX_7SEG1_SEGMENT_TRIS  trisd
	    #endif

	    #ifdef MX_7SEG_SEG_PORT_4
	      #define MX_7SEG1_SEGMENT_PORT  porte
	      #define MX_7SEG1_SEGMENT_TRIS  trise
	    #endif

	    #ifdef MX_7SEG_COM_PORT_0								//Common Port Definitions
	      #define MX_7SEG1_COMMON_PORT   porta
	      #define MX_7SEG1_COMMON_TRIS   trisa
	    #endif

	    #ifdef MX_7SEG_COM_PORT_1
	      #define MX_7SEG1_COMMON_PORT   portb
	      #define MX_7SEG1_COMMON_TRIS   trisb
	    #endif

	    #ifdef MX_7SEG_COM_PORT_2
	      #define MX_7SEG1_COMMON_PORT   portc
	      #define MX_7SEG1_COMMON_TRIS   trisc
	    #endif

	    #ifdef MX_7SEG_COM_PORT_3
	      #define MX_7SEG1_COMMON_PORT   portd
	      #define MX_7SEG1_COMMON_TRIS   trisd
	    #endif

	    #ifdef MX_7SEG_COM_PORT_4
	      #define MX_7SEG1_COMMON_PORT   porte
	      #define MX_7SEG1_COMMON_TRIS   trise
	    #endif

		#define MX_7SEG_COM_ANODE_0

	    //clear the digit
		#ifdef MX_7SEG_COM_ANODE_1

			//common anode
			MX_7SEG1_SEGMENT_PORT = 0xFF;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & 247);

		#else

			//common cathode
			MX_7SEG1_SEGMENT_PORT = 0x00;
			MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | 8);

		#endif

		//undefine symbols
	    #undef MX_7SEG1_SEGMENT_PORT
	    #undef MX_7SEG1_SEGMENT_TRIS
	    #undef MX_7SEG1_COMMON_PORT
	    #undef MX_7SEG1_COMMON_TRIS
	    #undef MX_7SEG_SEG_PORT_1
		#undef MX_7SEG_COM_PORT_0
		#undef MX_7SEG_COM_ANODE_0

}



//SWITCH1: //Macro implementations


char FCD_SWITCH1_ReadState()
{
	
		char switchval;

		set_bit ( trisa, 4 );					//Convert pin to input
		delay_us(2);						//Allow input voltage to settle

		if (test_bit( porta, 4 ))				//Read state on input
			switchval = 1;
		else
			switchval = 0;

		if ( 0 == 1 )						//Active low polarity
		{
			if (switchval)					//Invert logic
				switchval = 0;
			else
				switchval = 1;
		}
		return (switchval);			//Return state of switch as least significant bit

}

void FCD_SWITCH1_WaitUntilHigh()
{
	
		set_bit ( trisa, 4 );						//Convert pin to input
		delay_us(2);							//Allow input voltage to settle

		if ( 0  == 0 )							//Active high polarity
		{
			while (test_bit( porta, 4 ) == 0);	//Wait for pin to go high
		}
		else									//Active low polarity
		{
			while (test_bit( porta, 4 ));			//Wait for pin to go low
		}
		if ( 0 )								//Timeout specified?
			Wdt_Delay_Ms(0);

}

void FCD_SWITCH1_WaitUntilLow()
{
	
		set_bit ( trisa, 4 );						//Convert pin to input
		delay_us(2);							//Allow input voltage to settle

		if ( 0 == 0 )							//Active high polarity
		{
			while (test_bit( porta, 4 ));			//Wait for pin to go low
		}
		else									//Active low polarity
		{
			while (test_bit( porta, 4 ) == 0);	//Wait for pin to go high
		}
		if ( 0 )								//Timeout specified?
			Wdt_Delay_Ms(0);

}



//SWITCH2: //Macro implementations


char FCD_SWITCH2_ReadState()
{
	
		char switchval;

		set_bit ( trisa, 5 );					//Convert pin to input
		delay_us(2);						//Allow input voltage to settle

		if (test_bit( porta, 5 ))				//Read state on input
			switchval = 1;
		else
			switchval = 0;

		if ( 0 == 1 )						//Active low polarity
		{
			if (switchval)					//Invert logic
				switchval = 0;
			else
				switchval = 1;
		}
		return (switchval);			//Return state of switch as least significant bit

}

void FCD_SWITCH2_WaitUntilHigh()
{
	
		set_bit ( trisa, 5 );						//Convert pin to input
		delay_us(2);							//Allow input voltage to settle

		if ( 0  == 0 )							//Active high polarity
		{
			while (test_bit( porta, 5 ) == 0);	//Wait for pin to go high
		}
		else									//Active low polarity
		{
			while (test_bit( porta, 5 ));			//Wait for pin to go low
		}
		if ( 0 )								//Timeout specified?
			Wdt_Delay_Ms(0);

}

void FCD_SWITCH2_WaitUntilLow()
{
	
		set_bit ( trisa, 5 );						//Convert pin to input
		delay_us(2);							//Allow input voltage to settle

		if ( 0 == 0 )							//Active high polarity
		{
			while (test_bit( porta, 5 ));			//Wait for pin to go low
		}
		else									//Active low polarity
		{
			while (test_bit( porta, 5 ) == 0);	//Wait for pin to go high
		}
		if ( 0 )								//Timeout specified?
			Wdt_Delay_Ms(0);

}

//Macro implementations

void FCM_UpdateDigit(char FCL_DIGIT, char FCL_VALUE)
{
	
	//Hvilket ciffer
	//Switch: UpdateDigit.Digit?
	switch (FCL_DIGIT)
	{
		case 1:
		{
			//Call Component Macro
			//Call Component Macro: led7seg(0)::ShowDigit(UpdateDigit.Value, 0)
			FCD_led7seg0_ShowDigit(FCL_VALUE, 0);


			//Output
			//Output: 1 -> PORT A
			trisa = trisa & 0xf0;
			porta = (porta & 0xf0) | (1 & 0x0f);


			break;
		}

		case 2:
		{
			//Call Component Macro
			//Call Component Macro: led7seg(1)::ShowDigit(UpdateDigit.Value, 0)
			FCD_led7seg1_ShowDigit(FCL_VALUE, 0);


			//Output
			//Output: 2 -> PORT A
			trisa = trisa & 0xf0;
			porta = (porta & 0xf0) | (2 & 0x0f);


			break;
		}

		case 3:
		{
			//Call Component Macro
			//Call Component Macro: led7seg(2)::ShowDigit(UpdateDigit.Value, 0)
			FCD_led7seg2_ShowDigit(FCL_VALUE, 0);


			//Output
			//Output: 4 -> PORT A
			trisa = trisa & 0xf0;
			porta = (porta & 0xf0) | (4 & 0x0f);


			break;
		}

		case 4:
		{
			//Call Component Macro
			//Call Component Macro: led7seg(3)::ShowDigit(UpdateDigit.Value, 0)
			FCD_led7seg3_ShowDigit(FCL_VALUE, 0);


			//Output
			//Output: 8 -> PORT A
			trisa = trisa & 0xf0;
			porta = (porta & 0xf0) | (8 & 0x0f);


			break;
		}

	}


	//Delay
	//Delay: VisDigitTid ms
	delay_ms(FCV_VISDIGITTID);


}

void FCM_UpdateDisplay(short FCL_VALUE)
{
	
	//Beregn cifrene
	//Call Macro: CalculateDigits(UpdateDisplay.Value)
	FCM_CalculateDigits(FCL_VALUE);


	//Vis 1. ciffer
	//Call Macro: UpdateDigit(1, Digit1)
	FCM_UpdateDigit(1, FCV_DIGIT1);


	//Vis 2. ciffer
	//Call Macro: UpdateDigit(2, Digit2)
	FCM_UpdateDigit(2, FCV_DIGIT2);


	//Vis 3. ciffer
	//Call Macro: UpdateDigit(3, Digit3)
	FCM_UpdateDigit(3, FCV_DIGIT3);


	//Vis 4. ciffer
	//Call Macro: UpdateDigit(4, Digit4)
	FCM_UpdateDigit(4, FCV_DIGIT4);


}

void FCM_CalculateDigits(short FCL_AVALUE)
{
	
	//Beregn de enkelte cifre
	//Calculation:
	//  Digit1 = CalculateDigits.Avalue MOD 10
	FCV_DIGIT1 = FCL_AVALUE % 10;
	

	//
	//Calculation:
	//  Digit2 = (CalculateDigits.Avalue MOD 100)/10
	FCV_DIGIT2 = (FCL_AVALUE % 100)/10;
	

	//
	//Calculation:
	//  Digit3 = (CalculateDigits.Avalue MOD 1000)/100
	FCV_DIGIT3 = (FCL_AVALUE % 1000)/100;
	

	//
	//Calculation:
	//  Digit4 = CalculateDigits.Avalue/1000
	FCV_DIGIT4 = FCL_AVALUE/1000;
	

}

void FCM_INTR_RB0()
{
	
	//Optælling
	//Calculation:
	//  InCommingPuls = InCommingPuls+1
	FCV_INCOMMINGPULS = FCV_INCOMMINGPULS+1;
	

}

void FCM_Initialiser()
{
	
	//Konstanter
	//Calculation:
	//  RPMUpdateInit = 50
	//  VisDigitTid = 1
	//  PulsPrOmdr = 1
	//  TelNedTilNulstilInit = 100
	FCV_RPMUPDATEINIT = 50;
	FCV_VISDIGITTID = 1;
	FCV_PULSPROMDR = 1;
	FCV_TELNEDTILNULSTILINIT = 100;
	

	//Nulstil variable
	//Calculation:
	//  DisplayThis = 0
	//  InCommingPuls = 0
	FCV_DISPLAYTHIS = 0;
	FCV_INCOMMINGPULS = 0;
	

	//Call Macro
	//Call Macro: SetDigitsOff
	FCM_SetDigitsOff();


	//Start optælling af indkommende pulser
	//Interrupt: Enable RB0INT
	st_bit(option_reg,INTEDG);
	st_bit(intcon,GIE);
	st_bit(intcon, INTE);


}

void FCM_RPM()
{
	
	//Interrupt
	//Interrupt: Enable TMR0
	cr_bit(option_reg,T0CS);
	st_bit(option_reg,T0SE);
	option_reg = (option_reg & 0xF0) | 0x07;
	st_bit(intcon,GIE);
	st_bit(intcon, T0IE);


	//Decision
	//Decision: RPMUpdate<=0?
	if (FCV_RPMUPDATE<=0)
	{
		//Calculation
		//Calculation:
		//  RPMUpdate = RPMUpdateInit
		//  DisplayThis = InCommingPuls/PulsPrOmdr*60/(13*RPMUpdate)
		//  InCommingPuls = 0
		FCV_RPMUPDATE = FCV_RPMUPDATEINIT;
		FCV_DISPLAYTHIS = FCV_INCOMMINGPULS/FCV_PULSPROMDR*60/(13*FCV_RPMUPDATE);
		FCV_INCOMMINGPULS = 0;
		

	}


}

void FCM_Counter()
{
	
	//Aflæs FRYS-knappen
	//Call Component Macro: Frys=SWITCH(2)::ReadState
	FCV_FRYS = FCD_SWITCH2_ReadState();


	//Er FRYS trykket ned ?
	//Decision: Frys=1?
	if (FCV_FRYS==1)
	{
		//Er det første gang ?
		//Decision: FirstFrys=1?
		if (FCV_FIRSTFRYS==1)
		{
			//Start nedtælling til nulstil
			//Interrupt: Enable TMR0
			cr_bit(option_reg,T0CS);
			st_bit(option_reg,T0SE);
			option_reg = (option_reg & 0xF0) | 0x07;
			st_bit(intcon,GIE);
			st_bit(intcon, T0IE);


			//Calculation
			//Calculation:
			//  FirstFrys = 0
			FCV_FIRSTFRYS = 0;
			

			//Fastlås tallet
			//Calculation:
			//  FrysPulsAntal = InCommingPuls
			FCV_FRYSPULSANTAL = FCV_INCOMMINGPULS;
			

		} else {
			//Skal der nulstilles
			//Decision: TelNedTilNulstil<=0?
			if (FCV_TELNEDTILNULSTIL<=0)
			{
				//Stop nulstil intr
				//Interrupt: Disable TMR0
				cr_bit(intcon, T0IE);


				//Stop tælling af indkommende pulser
				//Interrupt: Disable RB0INT
				cr_bit(intcon, INTE);


				//Nulstil variable
				//Calculation:
				//  DisplayThis = 0
				//  InCommingPuls = 0
				FCV_DISPLAYTHIS = 0;
				FCV_INCOMMINGPULS = 0;
				

				//Call Macro
				//Call Macro: SetDigitsOff
				FCM_SetDigitsOff();


				//Vent på at FRYS slippes
				//Call Component Macro: SWITCH(2)::WaitUntilLow
				FCD_SWITCH2_WaitUntilLow();


				//Start telling af indkommernde pulser
				//Interrupt: Enable RB0INT
				st_bit(option_reg,INTEDG);
				st_bit(intcon,GIE);
				st_bit(intcon, INTE);


				//Goto Connection Point
				//Goto Connection Point: [A]: A
				goto FCC_Counter_A;


			}


		}


		//Calculation
		//Calculation:
		//  DisplayThis = FrysPulsAntal
		FCV_DISPLAYTHIS = FCV_FRYSPULSANTAL;
		

	} else {
		//Interrupt
		//Interrupt: Disable TMR0
		cr_bit(intcon, T0IE);


		//Calculation
		//Calculation:
		//  FirstFrys = 1
		FCV_FIRSTFRYS = 1;
		

		//Calculation
		//Calculation:
		//  TelNedTilNulstil = TelNedTilNulstilInit
		FCV_TELNEDTILNULSTIL = FCV_TELNEDTILNULSTILINIT;
		

		//Connection Point
		//Connection Point: [A]: A
FCC_Counter_A:
;


		//Calculation
		//Calculation:
		//  DisplayThis = InCommingPuls
		FCV_DISPLAYTHIS = FCV_INCOMMINGPULS;
		

	}


}

void FCM_INTR_Nulstil()
{
	
	//Nedtælling til nulstil
	//Calculation:
	//  TelNedTilNulstil = TelNedTilNulstil-1
	FCV_TELNEDTILNULSTIL = FCV_TELNEDTILNULSTIL-1;
	

}

void FCM_INTR_RPM()
{
	
	//Calculation
	//Calculation:
	//  RPMUpdate = RPMUpdate-1
	FCV_RPMUPDATE = FCV_RPMUPDATE-1;
	

}

void FCM_SetDigitsOff()
{
	
	//Nulstil cifrene
	//Call Component Macro: led7seg(0)::ClearDigit
	FCD_led7seg0_ClearDigit();


	//
	//Call Component Macro: led7seg(1)::ClearDigit
	FCD_led7seg1_ClearDigit();


	//
	//Call Component Macro: led7seg(2)::ClearDigit
	FCD_led7seg2_ClearDigit();


	//
	//Call Component Macro: led7seg(3)::ClearDigit
	FCD_led7seg3_ClearDigit();


}

void main()
{
	
	//Initialisation
	cmcon = 0x07;


	//Interrupt initialisation code
	option_reg = 0xC0;


	//Call Macro
	//Call Macro: Initialiser
	FCM_Initialiser();


	//Loop
	//Loop: While 1
	while (1)
	{
		//Call Component Macro
		//Call Component Macro: Mode=SWITCH(1)::ReadState
		FCV_MODE = FCD_SWITCH1_ReadState();


		//Tæller eller RPM
		//Decision: Mode=1?
		if (FCV_MODE==1)
		{
			//RPM
			//Call Macro: RPM
			FCM_RPM();


		} else {
			//Counter
			//Call Macro: Counter
			FCM_Counter();


		}


		//UpdateDisplay
		//Call Macro: UpdateDisplay(DisplayThis)
		FCM_UpdateDisplay(FCV_DISPLAYTHIS);


	}


	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
	//Handler code for [RB0INT]
	if (ts_bit(intcon, INTF) && ts_bit(intcon, INTE))
	{
		FCM_INTR_RB0();
		cr_bit(intcon, INTF);
	}


	//Handler code for [TMR0]
	if (ts_bit(intcon, T0IF) && ts_bit(intcon, T0IE))
	{
		FCM_INTR_RPM();
		cr_bit(intcon, T0IF);
	}


	//Handler code for [RB0INT]
	if (ts_bit(intcon, INTF) && ts_bit(intcon, INTE))
	{
		FCM_INTR_RB0();
		cr_bit(intcon, INTF);
	}


	//Handler code for [TMR0]
	if (ts_bit(intcon, T0IF) && ts_bit(intcon, T0IE))
	{
		FCM_INTR_Nulstil();
		cr_bit(intcon, T0IF);
	}


}



