//************************************************************************************
//**  
//**  File name:     C:\Flowcode_Testing\ProgRC5_1.c
//**  Generated by:  Flowcode v4.3.7.63
//**  Date:          Wednesday, January 05, 2011 18:07:33
//**  Licence:       Professional
//**  Registered to: Martin
//**  
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P18F4455
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_BCB
#define MX_SPI_SDI 0
#define MX_SPI_SDO 7
#define MX_SPI_SCK 1
#define MX_UART
#define MX_UART_C
#define MX_UART_TX 6
#define MX_UART_RX 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_B
#define MX_I2C_SDA 0
#define MX_I2C_SCL 1
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 2
#define MX_PWM_TRIS2 trisc
#define MX_PWM_2 1
#define MX_PWM_TRIS2a trisb
#define MX_PWM_2a 3
#define MX_USB_TYPE1

//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic18.h>
#endif

//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x300000, 0x20
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300001, 0xcc
#endif
#ifdef _HI_TECH_C
__CONFIG(1, 0xcc20);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300002, 0x1f
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300003, 0x1e
#endif
#ifdef _HI_TECH_C
__CONFIG(2, 0x1e1f);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300004, 0xff
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300005, 0x83
#endif
#ifdef _HI_TECH_C
__CONFIG(3, 0x83ff);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300006, 0x80
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300007, 0xff
#endif
#ifdef _HI_TECH_C
__CONFIG(4, 0xff80);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300008, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300009, 0xc0
#endif
#ifdef _HI_TECH_C
__CONFIG(5, 0xc00f);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000a, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000b, 0xe0
#endif
#ifdef _HI_TECH_C
__CONFIG(6, 0xe00f);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000c, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000d, 0x40
#endif
#ifdef _HI_TECH_C
__CONFIG(7, 0x400f);
#endif

//Internal functions
#include "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h"

//Macro function declarations
void FCM_RC5_Send();
void FCM_Learn();


//Variable declarations
char FCV_LEARN;
char FCV_ADDR[10];
char FCV_KEYVAL;
char FCV_MODE;
char FCV_TX;
char FCV_TOGGLE;
char FCV_CMD[10];
char FCV_HASH;


//Defines:

/**** Macro Substitutions ****
my value = Timer preload value
 = Timer count register
 = Timer interrupt flag register
 = Timer interrupt flag bit number
 = Timer count enable / prescaler register
 = Timer count enable value
 = Interrupt pin edge control register
 = Interrupt pin edge control bit
 = Interrupt port register
 = Interrupt tris register
%k = Interrupt bit
%l = Interrupt enable register
%m = Interrupt enable bit
%n = Interrupt flag register
%o = Interrupt flag bit
%p = Signal inversion control
%q = Maximum allowable pulse width
%r = Minimum allowable pulse width
%s = Threshold between short and long pulses
%t = Transmit pin tris
%u = Transmit pin port
%v = Transmit pin bit
%w = PWM functionality enable
%x = PWM period
%y = PWM Prescaler
%z = PWM channel
******************************/

//common defines
#define MX_RC5_TIMER_PRELOAD	85			//Auto added to timer count
#define MX_RC5_TIMER_REGISTER	tmr0l			//Timer count register
#define MX_RC5_TIMER_TOUTREG	intcon
#define MX_RC5_TIMER_TOUTBIT	TMR0IF
#define MX_RC5_TIMER_ENREG		intcon
#define MX_RC5_TIMER_ENVAL		0x05			//Prescaler for timer
#define MX_RC5_INT_EDGEREG		intcon2
#define MX_RC5_INT_EDGEBIT		INTEDG0
#define MX_RC5_INT_PORT			portb
#define MX_RC5_INT_TRIS			trisb
#define MX_RC5_INT_PIN			0
#define MX_RC5_INT_ENREG		intcon
#define MX_RC5_INT_ENBIT		INT0IE
#define MX_RC5_INT_FLAGREG		intcon
#define MX_RC5_INT_FLAGBIT		INT0IF
#define MX_RC5_SIGNAL_INVERT	1
#define MX_RC5_UPPER_WIDTH		255				//2222us Approx - Must be over 1778us
#define MX_RC5_LOWER_WIDTH		119				//444us Approx - Must be under 889us
#define MX_RC5_CUTOFF_WIDTH		187				//1334us Approx - Must be around 1333us
#define MX_RC5_TX_TRIS			trisb
#define MX_RC5_TX_PORT			portb
#define MX_RC5_TX_PIN			7
#define MX_RC5_PWM				1
#define MX_RC5_PWM_PERIOD		33
#define MX_RC5_PWM_SCALER		5
#define MX_RC5_PWM_CHANNEL		1

//RC5 Defines
#define E0	0
#define M1	1
#define S1	2
#define M0	3
#define S0	4

//global variables
char rc5_state = E0;
char rc5_count = 0;
char rc5_command = 0;
char rc5_address = 0;
char rc5_update = 0;
char rc5_toggle	= 0;
char rc5_out_command = 0;
char rc5_out_address = 0;
char rc5_out_toggle = 0;
unsigned int rc5_packet = 0;




//Custom(0): //Macro function declarations

void FCD_Custom0_RC5_Initialise_States();
void FCD_Custom0_RC5_Signal_Edge();
void FCD_Custom0_RC5_RX_Enable();
void FCD_Custom0_RC5_RX_Disable();
char FCD_Custom0_RC5_CheckRX();
char FCD_Custom0_RC5_Collect_Data(char selection);
void FCD_Custom0_RC5_TX_Enable();
void FCD_Custom0_RC5_TX_Disable();
void FCD_Custom0_RC5_TX_Packet(char command, char address, char toggle);
//Defines:

/**** Macro Substitutions ****
{'1','4','7','*','2','5','8','0','3','6','9','#'} = Key List (Numbers)
{1,4,7,10,2,5,8,0,3,6,9,11} = Key List (Characters)
trisd = Row Data Direction Register
portd = Row Port Register
3 = Number Of Columns
4 = Number Of Rows
trisd = Column Data Direction Register
portd = Column Port Register
1 = Column 1 mask
2 = Column 2 mask
4 = Column 3 mask
16 = Column 4 mask
16 = Row 1 mask
32 = Row 2 mask
64 = Row 3 mask
128 = Row 4 mask
******************************/

#define MX_RC5_TIMER_PRELOAD	85			//Auto added to timer count
#define MX_RC5_TIMER_REGISTER	tmr0			//Timer count register
#define MX_RC5_TIMER_TOUTREG	intcon
#define MX_RC5_TIMER_TOUTBIT	TMR0IF
#define MX_RC5_TIMER_ENREG		option_reg
#define MX_RC5_TIMER_ENVAL		0x05			//Prescaler for timer
#define MX_RC5_INT_EDGEREG		option_reg
#define MX_RC5_INT_EDGEBIT		INTEDG
#define MX_RC5_INT_PORT			portb
#define MX_RC5_INT_TRIS			trisb
#define MX_RC5_INT_PIN			0
#define MX_RC5_INT_ENREG		intcon
#define MX_RC5_INT_ENBIT		INTE
#define MX_RC5_INT_FLAGREG		intcon
#define MX_RC5_INT_FLAGBIT		INTF
#define MX_RC5_SIGNAL_INVERT	1
#define MX_RC5_UPPER_WIDTH		255				//2222us Approx - Must be over 1778us
#define MX_RC5_LOWER_WIDTH		119				//444us Approx - Must be under 889us
#define MX_RC5_CUTOFF_WIDTH		187				//1334us Approx - Must be around 1333us
#define MX_RC5_TX_TRIS			trisb
#define MX_RC5_TX_PORT			portb
#define MX_RC5_TX_PIN			7
#define MX_RC5_PWM				1
#define MX_RC5_PWM_PERIOD		33
#define MX_RC5_PWM_SCALER		5
#define MX_RC5_PWM_CHANNEL		1



//KeyPad(0): //Macro function declarations

char FCD_KeyPad0_GetKeypadNumber();
char FCD_KeyPad0_GetKeypadAscii();
//Defines:

/**** Macro Substitutions ****
portc = D1 Port
trisc = D1 Data Direction
portc = D2 Port
trisc = D2 Data Direction
portc = D3 Port
trisc = D3 Data Direction
portc = D4 Port
trisc = D4 Data Direction
portc = RS Port
trisc = RS Data Direction
portc = E Port
trisc = E Data Direction
0 = Data 1_Pin
1 = Data 2 Pin
2 = Data 3 Pin
3 = Data 4 Pin
4 = RS Pin
5 = Enable Pin
LCD_5964980 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/

	//component connections
	#define LCD_5964980_PORT0    portc
	#define LCD_5964980_TRIS0    trisc
	#define LCD_5964980_PORT1    portc
	#define LCD_5964980_TRIS1    trisc
	#define LCD_5964980_PORT2    portc
	#define LCD_5964980_TRIS2    trisc
	#define LCD_5964980_PORT3    portc
	#define LCD_5964980_TRIS3    trisc
	#define LCD_5964980_PORT4    portc
	#define LCD_5964980_TRIS4    trisc
	#define LCD_5964980_PORT5    portc
	#define LCD_5964980_TRIS5    trisc
	#define LCD_5964980_BIT0    	0
	#define LCD_5964980_BIT1    	1
	#define LCD_5964980_BIT2    	2
	#define LCD_5964980_BIT3    	3
	#define LCD_5964980_RS      	4
	#define LCD_5964980_E       	5
	#define LCD_5964980_ROWCNT	2
	#define LCD_5964980_COLCNT	16

	#ifdef _BOOSTC
	  #define LCD_5964980_DELAY   delay_10us(10)
	#endif
	#ifdef _C2C_
	  #define LCD_5964980_DELAY   delay_us(100)
	#endif
	#ifdef HI_TECH_C
	  #define LCD_5964980_DELAY   __delay_us(120)
	#endif
	#ifndef LCD_5964980_DELAY
	  #define LCD_5964980_DELAY   delay_us(100)
	#endif




//LCDDisplay(0): //Macro function declarations

void FCD_LCDDisplay0_RawSend(char in, char mask);
void FCD_LCDDisplay0_Start();
void FCD_LCDDisplay0_Clear();
void FCD_LCDDisplay0_PrintASCII(char Character);
void FCD_LCDDisplay0_Command(char in);
void FCD_LCDDisplay0_Cursor(char x, char y);
void FCD_LCDDisplay0_PrintNumber(short Number);
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String);
void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions);
void FCD_LCDDisplay0_ClearLine(char Line);
void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7);



//Custom(0): //Macro implementations


void FCD_Custom0_RC5_Initialise_States()
{
	
		rc5_state = E0;
		rc5_count = 0;
		MX_RC5_INT_EDGEREG.MX_RC5_INT_EDGEBIT = 0;

}

void FCD_Custom0_RC5_Signal_Edge()
{
	
		char rc5_timeout;
		char rc5_pulsewidth;
		char rc5_pulselevel;
		char rc5_transerror;

		//Store timer value and reset back to initial value
		rc5_pulsewidth = MX_RC5_TIMER_REGISTER;
		MX_RC5_TIMER_REGISTER = MX_RC5_TIMER_PRELOAD;

		//Check the timeout flag?
		rc5_timeout = MX_RC5_TIMER_TOUTREG.MX_RC5_TIMER_TOUTBIT;
		MX_RC5_TIMER_TOUTREG.MX_RC5_TIMER_TOUTBIT = 0;

		//If the timer has timed out
		if(rc5_timeout)
		{
			FCD_Custom0_RC5_Initialise_States();
		}

		//Read the state of the incoming signal
		if(MX_RC5_INT_PORT.MX_RC5_INT_PIN)
			rc5_pulselevel = 1;
		else
			rc5_pulselevel = 0;

		#if (MX_RC5_SIGNAL_INVERT == 1)
			//If the receiver hardware is inverting the signal then we need to re-invert
			rc5_pulselevel = 1 - rc5_pulselevel;
		#endif

		//Swap interrupt edge
		if (MX_RC5_INT_EDGEREG.MX_RC5_INT_EDGEBIT)
			MX_RC5_INT_EDGEREG.MX_RC5_INT_EDGEBIT = 0;
		else
			MX_RC5_INT_EDGEREG.MX_RC5_INT_EDGEBIT = 1;

		//First edge?
		if(rc5_count == 0)
		{
			//Valid first edge?
			if(rc5_pulselevel == 1)
			{
				rc5_state = M1;
			}
			else
			{
				FCD_Custom0_RC5_Initialise_States();
			}
		}
		else
		{
			//Valid pulse width?
			if((rc5_pulsewidth >= MX_RC5_LOWER_WIDTH) && (rc5_pulsewidth <= MX_RC5_UPPER_WIDTH))
			{
				//Default error
				rc5_transerror = 1;

				//Long Pulse?
				if (rc5_pulsewidth > MX_RC5_CUTOFF_WIDTH)
				{
					//High level?
					if(rc5_pulselevel)
					{
						//Current state M0?
						if(rc5_state == M0)
						{
							rc5_state = M1;
							rc5_transerror = 0;
						}
					}
					else
					{
						//Current state M1?
						if(rc5_state == M1)
						{
							rc5_state = M0;
							rc5_transerror = 0;
						}
					}
				}
				else
				{
					//High Level?
					if(rc5_pulselevel)
					{
						//Current state M0?
						if(rc5_state == M0)
						{
							rc5_state = S0;
							rc5_transerror = 0;
						}

						//Current state S1?
						if(rc5_state == S1)
						{
							rc5_state = M1;
							rc5_transerror = 0;
						}
					}
					else
					{
						//Current state M1?
						if(rc5_state == M1)
						{
							rc5_state = S1;
							rc5_transerror = 0;
						}

						//Current state S0?
						if(rc5_state == S0)
						{
							rc5_state = M0;
							rc5_transerror = 0;
						}
					}
				}

				//State transition error
				if (rc5_transerror)
				{
					FCD_Custom0_RC5_Initialise_States();
				}
			}
			else
			{
				FCD_Custom0_RC5_Initialise_States();
			}
		}

		//Data bit?
		if (( rc5_state == M0 ) || ( rc5_state == M1 ))
		{
			//New packet?
			if (rc5_count == 0)
			{
				rc5_packet = 0;
			}

			//Shift data
			rc5_packet = rc5_packet << 1;

			//Bit = 1?
			if (rc5_state == M1)
			{
				rc5_packet = rc5_packet | 0x01;
			}

			//Increment data count
			rc5_count = rc5_count + 1;

			//Reception complete?
			if (rc5_count == 14)
			{
				//Start bits correct?
				if ((rc5_packet & 0x3000) == 0x3000)
				{
					//Unpack the data
					rc5_command = rc5_packet & 0x3F;
					rc5_address = (rc5_packet & 0x7c0) >> 6;
					rc5_toggle = (rc5_packet & 0x800) >> 11;

					//Signal update
					rc5_update = 1;

				}
				FCD_Custom0_RC5_Initialise_States();
			}
		}

}

void FCD_Custom0_RC5_RX_Enable()
{
	
		FCD_Custom0_RC5_Initialise_States();
		MX_RC5_INT_TRIS.MX_RC5_INT_PIN = 1;								//Convert I/O INT pin to Input
		MX_RC5_INT_ENREG.MX_RC5_INT_ENBIT = 1;							//Enable INT Interrupt
		MX_RC5_TIMER_ENREG = MX_RC5_TIMER_ENVAL;						//Start the timer running
		st_bit(intcon,GIE);												//Enable global interrupts

}

void FCD_Custom0_RC5_RX_Disable()
{
	
		FCD_Custom0_RC5_Initialise_States();
		MX_RC5_INT_ENREG.MX_RC5_INT_ENBIT = 0;

}

char FCD_Custom0_RC5_CheckRX()
{
	
		//New data available?
		if (rc5_update)
		{
			//Repeat if updated during the read sequence
			while (rc5_update)
			{
				rc5_update = 0;
				rc5_out_command = rc5_command;
				rc5_out_address = rc5_address;
				rc5_out_toggle = rc5_toggle;
			}
			return(1);
		}
		else
		{
			return(0);
		}

}

char FCD_Custom0_RC5_Collect_Data(char selection)
{
	
		//Command - 0
		if (selection == 0)
		{
			return rc5_out_command;
		}

		//Address - 1
		if (selection == 1)
		{
			return rc5_out_address;
		}

		//toggle - 2
		if (selection == 2)
		{
			return rc5_out_toggle;
		}

		//Invalid selection value
		return 0;

}

void FCD_Custom0_RC5_TX_Enable()
{
	
		//Setup PWM
	//	#if (MX_RC5_PWM == 1)
	//
	//		#ifdef MX_PWM
	//
	//			pr2 = MX_RC5_PWM_PERIOD;
	//			t2con = MX_RC5_PWM_SCALER;
	//
	//			if (MX_RC5_PWM_CHANNEL == 1)
	//			{
	//				#if (MX_PWM_CNT >= 1)
	//					ccp1con = 0x0C;
	//				#endif
	//			}
	//			else
	//			{
	//				#if (MX_PWM_CNT >= 2)
	//					ccp2con = 0x0C;
	//				#endif
	//			}
	//
	//		#endif
	//
	//	#endif

		//Configure I/O
		MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;
		MX_RC5_TX_TRIS.MX_RC5_TX_PIN = 0;

}

void FCD_Custom0_RC5_TX_Disable()
{
	
		//Disable PWM
	//	#if (MX_RC5_PWM == 1)
	//
	//		#ifdef MX_PWM
	//
	//			if (MX_RC5_PWM_CHANNEL == 1)
	//			{
	//				#if (MX_PWM_CNT >= 1)
	//					ccp1con = 0x00;
	//				#endif
	//			}
	//			else
	//			{
	//				#if (MX_PWM_CNT >= 2)
	//					ccp2con = 0x00;
	//				#endif
	//			}
	//
	//		#endif
	//
	//	#endif

		//Configure I/O
		MX_RC5_TX_TRIS.MX_RC5_TX_PIN = 1;

}

void FCD_Custom0_RC5_TX_Packet(char command, char address, char toggle)
{
	
		unsigned int packet = 0;
		char loop_bit, loop_pwm;

		//Add command to packet
		packet = command & 0x3F;

		//Add address to packet
		packet = packet | ((address & 0x1F) << 6);

		//Add toggle bit to packet
		if (toggle)
			packet = packet | 0x800;

		//Add start bits to packet
		packet = packet | 0x3000;

		//Stream out the RC5 packet
		for (loop_bit = 0; loop_bit < 14; loop_bit++)
		{
			if (packet & 0x2000)
			{
				//Clear Port Pin
				MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;

				//Bit delay - 888us
				delay_10us(80);
				delay_us(8);

				//Set Port Pin
				for(loop_pwm = 0; loop_pwm < 32; loop_pwm++)
				{
					MX_RC5_TX_PORT.MX_RC5_TX_PIN = 1;
					delay_us(13);
					MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;
					delay_us(14);
				}
			}
			else
			{
				//Set Port Pin
				for(loop_pwm = 0; loop_pwm < 32; loop_pwm++)
				{
					MX_RC5_TX_PORT.MX_RC5_TX_PIN = 1;
					delay_us(13);
					MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;
					delay_us(14);
				}

				//Clear Port Pin
				MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;

				//Bit delay - 888us
				delay_10us(80);
				delay_us(8);
			}

			//Shift to next bit in packet
			packet = packet << 1;
		}

		//Clear Port Pin
		MX_RC5_TX_PORT.MX_RC5_TX_PIN = 0;

}



//KeyPad(0): //Macro implementations


char FCD_KeyPad0_GetKeypadNumber()
{
		//get matrices for rows and columns
		#if (3 == 1)
			#define KPAD_COL_MTX {1}
			#define KPAD_COL_MASK (1)
		#endif
		#if (3 == 2)
			#define KPAD_COL_MTX {1,2}
			#define KPAD_COL_MASK (1|2)
		#endif
		#if (3 == 3)
			#define KPAD_COL_MTX {1,2,4}
			#define KPAD_COL_MASK (1|2|4)
		#endif
		#if (3 == 4)
			#define KPAD_COL_MTX {1,2,4,16}
			#define KPAD_COL_MASK (1|2|4|16)
		#endif
		#if (4 == 1)
			#define KPAD_ROW_MTX {16}
			#define KPAD_ROW_MASK (16)
		#endif
		#if (4 == 2)
			#define KPAD_ROW_MTX {16,32}
			#define KPAD_ROW_MASK (16|32)
		#endif
		#if (4 == 3)
			#define KPAD_ROW_MTX {16,32,64}
			#define KPAD_ROW_MASK (16|32|64)
		#endif
		#if (4 == 4)
			#define KPAD_ROW_MTX {16,32,64,128}
			#define KPAD_ROW_MASK (16|32|64|128)
		#endif

		#ifndef KPAD_COL_MTX
	  		#ifdef _BOOSTC
	  			#pragma error "Keypad error: column count is not 1-4"
	  		#endif
	  		#ifdef HI_TECH_C
	  			#error Keypad error: column count is not 1-4
			#endif
		#endif
		#ifndef KPAD_ROW_MTX
	  		#ifdef _BOOSTC
	  			#pragma error "Keypad error: row count is not 1-4"
	  		#endif
	  		#ifdef HI_TECH_C
	  			#error Keypad error: row count is not 1-4
			#endif
		#endif

		//store keys and pin connections into a constant array
		#ifdef _BOOSTC
			rom char* mtxKeysAsNumbers = {1,4,7,10,2,5,8,0,3,6,9,11};
			rom char* mtxCols = KPAD_COL_MTX;
			rom char* mtxRows = KPAD_ROW_MTX;
		#endif
		#ifdef HI_TECH_C
			const char mtxKeysAsNumbers[] = {1,4,7,10,2,5,8,0,3,6,9,11};
			const char mtxCols[] = KPAD_COL_MTX;
			const char mtxRows[] = KPAD_ROW_MTX;
		#endif

		//set up i/o of port (rows = inputs, columns = outputs)
		trisd = (trisd | KPAD_ROW_MASK);
		trisd = (trisd & ~KPAD_COL_MASK);		//BR

		char iCol;
		char iRow;
		char c_ip;
		for (iCol=0; iCol<3; iCol++)
		{
			//output the appropriate column high
			portd = mtxCols[iCol];

			//delay
			delay_us(10);

			//read the port
			c_ip = portd;

			//check for a hit
			for (iRow=0; iRow<4; iRow++)
			{
				if ((c_ip & mtxRows[iRow]) != 0)
				{
					//found it!
					goto found_key;
				}
			}
		}

		//if it gets here, it has not been found...
		return (255);

	  found_key:
		return (mtxKeysAsNumbers[(iCol*4) + iRow]);

	  #undef KPAD_COL_MTX
	  #undef KPAD_ROW_MTX
	  #undef KPAD_COL_MASK
	  #undef KPAD_ROW_MASK

}

char FCD_KeyPad0_GetKeypadAscii()
{
		//get matrices for rows and columns
		#if (3 == 1)
			#define KPAD_COL_MTX {1}
			#define KPAD_COL_MASK (1)
		#endif
		#if (3 == 2)
			#define KPAD_COL_MTX {1,2}
			#define KPAD_COL_MASK (1|2)
		#endif
		#if (3 == 3)
			#define KPAD_COL_MTX {1,2,4}
			#define KPAD_COL_MASK (1|2|4)
		#endif
		#if (3 == 4)
			#define KPAD_COL_MTX {1,2,4,16}
			#define KPAD_COL_MASK (1|2|4|16)
		#endif
		#if (4 == 1)
			#define KPAD_ROW_MTX {16}
			#define KPAD_ROW_MASK (16)
		#endif
		#if (4 == 2)
			#define KPAD_ROW_MTX {16,32}
			#define KPAD_ROW_MASK (16|32)
		#endif
		#if (4 == 3)
			#define KPAD_ROW_MTX {16,32,64}
			#define KPAD_ROW_MASK (16|32|64)
		#endif
		#if (4 == 4)
			#define KPAD_ROW_MTX {16,32,64,128}
			#define KPAD_ROW_MASK (16|32|64|128)
		#endif

		#ifndef KPAD_COL_MTX
	  		#ifdef _BOOSTC
	  			#pragma error "Keypad error: column count is not 1-4"
	  		#endif
	  		#ifdef HI_TECH_C
	  			#error Keypad error: column count is not 1-4
			#endif
		#endif
		#ifndef KPAD_ROW_MTX
	  		#ifdef _BOOSTC
	  			#pragma error "Keypad error: row count is not 1-4"
	  		#endif
	  		#ifdef HI_TECH_C
	  			#error Keypad error: row count is not 1-4
			#endif
		#endif

		//store keys and pin connections into a constant array
		#ifdef _BOOSTC
			rom char* mtxKeysAsChars = {'1','4','7','*','2','5','8','0','3','6','9','#'};
			rom char* mtxCols = KPAD_COL_MTX;
			rom char* mtxRows = KPAD_ROW_MTX;
		#endif
		#ifdef HI_TECH_C
			const char mtxKeysAsChars[] = {'1','4','7','*','2','5','8','0','3','6','9','#'};
			const char mtxCols[] = KPAD_COL_MTX;
			const char mtxRows[] = KPAD_ROW_MTX;
		#endif

		//set up i/o of port (rows = inputs, columns = outputs)
		trisd = (trisd | KPAD_ROW_MASK);
		trisd = (trisd & ~KPAD_COL_MASK);

		char iCol;
		char iRow;
		char c_ip;
		for (iCol=0; iCol<3; iCol++)
		{
			//output the appropriate column high
			portd = mtxCols[iCol];

			//delay
			delay_us(10);

			//read the port
			c_ip = portd;

			//check for a hit
			for (iRow=0; iRow<4; iRow++)
			{
				if ((c_ip & mtxRows[iRow]) != 0)
				{
					//found it!
					goto found_key;
				}
			}
		}

		//if it gets here, it has not been found...
		return (255);

	  found_key:
		return (mtxKeysAsChars[(iCol*4) + iRow]);

	  #undef KPAD_COL_MTX
	  #undef KPAD_ROW_MTX
	  #undef KPAD_COL_MASK
	  #undef KPAD_ROW_MASK

}



//LCDDisplay(0): //Macro implementations


void FCD_LCDDisplay0_RawSend(char in, char mask)
{
		unsigned char pt;

		clear_bit(LCD_5964980_PORT0, LCD_5964980_BIT0);
		clear_bit(LCD_5964980_PORT1, LCD_5964980_BIT1);
		clear_bit(LCD_5964980_PORT2, LCD_5964980_BIT2);
		clear_bit(LCD_5964980_PORT3, LCD_5964980_BIT3);
		clear_bit(LCD_5964980_PORT4, LCD_5964980_RS);
		clear_bit(LCD_5964980_PORT5, LCD_5964980_E);
		pt = ((in >> 4) & 0x0f);
		if (pt & 0x01)
		    set_bit(LCD_5964980_PORT0, LCD_5964980_BIT0);
		if (pt & 0x02)
		    set_bit(LCD_5964980_PORT1, LCD_5964980_BIT1);
		if (pt & 0x04)
		    set_bit(LCD_5964980_PORT2, LCD_5964980_BIT2);
		if (pt & 0x08)
		    set_bit(LCD_5964980_PORT3, LCD_5964980_BIT3);
		if (mask)
		    set_bit(LCD_5964980_PORT4, LCD_5964980_RS);
		LCD_5964980_DELAY;
		set_bit (LCD_5964980_PORT5, LCD_5964980_E);
		LCD_5964980_DELAY;
		clear_bit (LCD_5964980_PORT5, LCD_5964980_E);
		pt = (in & 0x0f);
		LCD_5964980_DELAY;
		clear_bit(LCD_5964980_PORT0, LCD_5964980_BIT0);
		clear_bit(LCD_5964980_PORT1, LCD_5964980_BIT1);
		clear_bit(LCD_5964980_PORT2, LCD_5964980_BIT2);
		clear_bit(LCD_5964980_PORT3, LCD_5964980_BIT3);
		clear_bit(LCD_5964980_PORT4, LCD_5964980_RS);
		clear_bit(LCD_5964980_PORT5, LCD_5964980_E);
		if (pt & 0x01)
		    set_bit(LCD_5964980_PORT0, LCD_5964980_BIT0);
		if (pt & 0x02)
		    set_bit(LCD_5964980_PORT1, LCD_5964980_BIT1);
		if (pt & 0x04)
		    set_bit(LCD_5964980_PORT2, LCD_5964980_BIT2);
		if (pt & 0x08)
		    set_bit(LCD_5964980_PORT3, LCD_5964980_BIT3);
		if (mask)
		    set_bit(LCD_5964980_PORT4, LCD_5964980_RS);
		LCD_5964980_DELAY;
		set_bit (LCD_5964980_PORT5, LCD_5964980_E);
		LCD_5964980_DELAY;
		clear_bit (LCD_5964980_PORT5, LCD_5964980_E);
		LCD_5964980_DELAY;
}

void FCD_LCDDisplay0_Start()
{
	
		clear_bit(LCD_5964980_TRIS0, LCD_5964980_BIT0);
		clear_bit(LCD_5964980_TRIS1, LCD_5964980_BIT1);
		clear_bit(LCD_5964980_TRIS2, LCD_5964980_BIT2);
		clear_bit(LCD_5964980_TRIS3, LCD_5964980_BIT3);
		clear_bit(LCD_5964980_TRIS4, LCD_5964980_RS);
		clear_bit(LCD_5964980_TRIS5, LCD_5964980_E);

		Wdt_Delay_Ms(12);

		FCD_LCDDisplay0_RawSend(0x33, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x33, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x32, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x2c, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x06, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x0c, 0);
		Wdt_Delay_Ms(2);

		//clear the display
		FCD_LCDDisplay0_RawSend(0x01, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x02, 0);
		Wdt_Delay_Ms(2);

}

void FCD_LCDDisplay0_Clear()
{
	
		FCD_LCDDisplay0_RawSend(0x01, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay0_RawSend(0x02, 0);
		Wdt_Delay_Ms(2);

}

void FCD_LCDDisplay0_PrintASCII(char Character)
{
	
		FCD_LCDDisplay0_RawSend(Character, 0x10);

}

void FCD_LCDDisplay0_Command(char in)
{
	
		FCD_LCDDisplay0_RawSend(in, 0);
		Wdt_Delay_Ms(2);

}

void FCD_LCDDisplay0_Cursor(char x, char y)
{
	
	  #if (LCD_5964980_ROWCNT == 1)
	    y=0x80;
	  #endif

	  #if (LCD_5964980_ROWCNT == 2)
		if (y==0)
			y=0x80;
		else
			y=0xc0;
	  #endif

	  #if (LCD_5964980_ROWCNT == 4)
		if (y==0)
			y=0x80;
		else if (y==1)
			y=0xc0;

		#if (LCD_5964980_COLCNT == 16)
			else if (y==2)
				y=0x90;
			else
				y=0xd0;
		#endif

		#if (LCD_5964980_COLCNT == 20)
			else if (y==2)
				y=0x94;
			else
				y=0xd4;
		#endif
	  #endif

		FCD_LCDDisplay0_RawSend(y+x, 0);
		Wdt_Delay_Ms(2);

}

void FCD_LCDDisplay0_PrintNumber(short Number)
{
	
		short tmp_int;
		char tmp_byte;
		if (Number < 0)
		{
			FCD_LCDDisplay0_RawSend('-', 0x10);
			Number = 0 - Number;
		}

		tmp_int = Number;
		if (Number >= 10000)
		{
			tmp_byte = tmp_int / 10000;
			FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);

			while (tmp_byte > 0)
			{
				tmp_int = tmp_int - 10000;
				tmp_byte--;
			}
		}
		if (Number >= 1000)
		{
			tmp_byte = tmp_int / 1000;
			FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);

			while (tmp_byte > 0)
			{
				tmp_int = tmp_int - 1000;
				tmp_byte--;
			}
		}
		if (Number >= 100)
		{
			tmp_byte = tmp_int / 100;
			FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);

			while (tmp_byte > 0)
			{
				tmp_int = tmp_int - 100;
				tmp_byte--;
			}
		}
		if (Number >= 10)
		{
			tmp_byte = tmp_int / 10;
			FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);

			while (tmp_byte > 0)
			{
				tmp_int = tmp_int - 10;
				tmp_byte--;
			}
		}
		FCD_LCDDisplay0_RawSend('0' + tmp_int, 0x10);

}

void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String)
{
	
		char idx = 0;

		for (idx=0; idx<MSZ_String; idx++)
		{
			#ifdef _BOOSTC
				if (String[idx] == 0)
				{
					break;
				}
				FCD_LCDDisplay0_RawSend(String[idx], 0x10);
			#endif

			#ifdef HI_TECH_C
				if (*String == 0)
				{
					break;
				}
				FCD_LCDDisplay0_RawSend(*String, 0x10);
				String++;
			#endif
		}

}

void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions)
{
	
		char cmd = 0;
		char count;

		//Choose the direction
		switch (Direction)
		{
			case 0:
			case 'l':
			case 'L':

				cmd = 0x18;
				break;

			case 1:
			case 'r':
			case 'R':

				cmd = 0x1C;
				break;

			default:
				break;
		}

		//If direction accepted then scroll the specified amount
		if (cmd)
		{
			for (count = 0; count < Num_Positions; count++)
				FCD_LCDDisplay0_Command(cmd);
		}

}

void FCD_LCDDisplay0_ClearLine(char Line)
{
	
		char count;
		char rowcount;

		//Define number of columns per line
		#if (LCD_5964980_ROWCNT == 1)
			rowcount=80;
		#endif

		#if (LCD_5964980_ROWCNT == 2)
			rowcount=40;
		#endif

		#if (LCD_5964980_ROWCNT == 4)
			#if (LCD_5964980_COLCNT == 16)
				rowcount=16;
			#endif
			#if (LCD_5964980_COLCNT == 20)
				rowcount=20;
			#endif
		#endif

		//Start at beginning of the line
		FCD_LCDDisplay0_Cursor (0, Line);

		//Send out spaces to clear line
		for (count = 0; count < rowcount; count++)
			FCD_LCDDisplay0_RawSend(' ', 0x10);

		//Move back to the beginning of the line.
		FCD_LCDDisplay0_Cursor (0, Line);

}

void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7)
{
	   //set CGRAM address
	   FCD_LCDDisplay0_RawSend(64 + (nIdx << 3), 0);
	   delay_ms(2);

	   //write CGRAM data
	   FCD_LCDDisplay0_RawSend(d0, 0x10);
	   FCD_LCDDisplay0_RawSend(d1, 0x10);
	   FCD_LCDDisplay0_RawSend(d2, 0x10);
	   FCD_LCDDisplay0_RawSend(d3, 0x10);
	   FCD_LCDDisplay0_RawSend(d4, 0x10);
	   FCD_LCDDisplay0_RawSend(d5, 0x10);
	   FCD_LCDDisplay0_RawSend(d6, 0x10);
	   FCD_LCDDisplay0_RawSend(d7, 0x10);

	   //Clear the display
	   FCD_LCDDisplay0_RawSend(0x01, 0);
	   delay_ms(2);
	   FCD_LCDDisplay0_RawSend(0x02, 0);
	   delay_ms(2);
}

//Macro implementations

void FCM_RC5_Send()
{
	
	//Local variable definitions
	char FCL_ADDR;
	char FCL_CMD;

	//Call Component Macro
	//Call Component Macro: Custom(0)::RC5_TX_Enable
	FCD_Custom0_RC5_TX_Enable();


	//Calculation
	//Calculation:
	//  RC5_Send.addr = addr[keyVal]
	//  RC5_Send.cmd = cmd[keyVal]
	FCL_ADDR = FCV_ADDR[FCV_KEYVAL];
	FCL_CMD = FCV_CMD[FCV_KEYVAL];
	

	//Call Component Macro
	//Call Component Macro: Custom(0)::RC5_TX_Packet(RC5_Send.cmd, RC5_Send.addr, toggle)
	FCD_Custom0_RC5_TX_Packet(FCL_CMD, FCL_ADDR, FCV_TOGGLE);


	//Call Component Macro
	//Call Component Macro: Custom(0)::RC5_TX_Disable
	FCD_Custom0_RC5_TX_Disable();


}

void FCM_Learn()
{
	
	//Local variable definitions
	char FCL_RX;
	char FCL_CMD;
	char FCL_ADDR;
	char FCL_EXIT;
	char FCL_PROGKEY;

	//Call Component Macro
	//Call Component Macro: Custom(0)::RC5_RX_Enable
	FCD_Custom0_RC5_RX_Enable();


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
	FCD_LCDDisplay0_Cursor(0, 1);


	//Calculation
	//Calculation:
	//  Learn.ProgKey = 255
	//  Learn.exit = 0
	FCL_PROGKEY = 255;
	FCL_EXIT = 0;
	

	//Loop
	//Loop: While Learn.exit
	while (1)
	{
		//Call Component Macro
		//Call Component Macro: keyVal=KeyPad(0)::GetKeypadNumber
		FCV_KEYVAL = FCD_KeyPad0_GetKeypadNumber();


		//Decision
		//Decision: keyVal <> 255?
		if (FCV_KEYVAL != 255)
		{
			//Decision
			//Decision: keyVal < 10?
			if (FCV_KEYVAL < 10)
			{
				//Calculation
				//Calculation:
				//  Learn.ProgKey = keyVal
				FCL_PROGKEY = FCV_KEYVAL;
				

				//Clear pending data
				//Call Component Macro: Learn.rx=Custom(0)::RC5_CheckRX
				FCL_RX = FCD_Custom0_RC5_CheckRX();


				//Call Component Macro
				//Call Component Macro: LCDDisplay(0)::Cursor(6, 0)
				FCD_LCDDisplay0_Cursor(6, 0);


				//Call Component Macro
				//Call Component Macro: LCDDisplay(0)::PrintNumber(keyVal)
				FCD_LCDDisplay0_PrintNumber(FCV_KEYVAL);


			} else {
				//Decision
				//Decision: keyVal = 11?
				if (FCV_KEYVAL == 11)
				{
					//Calculation
					//Calculation:
					//  Learn.exit = 1
					FCL_EXIT = 1;
					

				}


			}


		}


		//Decision
		//Decision: Learn.ProgKey < 10?
		if (FCL_PROGKEY < 10)
		{
			//Call Component Macro
			//Call Component Macro: Learn.rx=Custom(0)::RC5_CheckRX
			FCL_RX = FCD_Custom0_RC5_CheckRX();


			//Decision
			//Decision: Learn.rx?
			if (FCL_RX)
			{
				//Call Component Macro
				//Call Component Macro: Learn.cmd=Custom(0)::RC5_Collect_Data(0)
				FCL_CMD = FCD_Custom0_RC5_Collect_Data(0);


				//Call Component Macro
				//Call Component Macro: Learn.addr=Custom(0)::RC5_Collect_Data(1)
				FCL_ADDR = FCD_Custom0_RC5_Collect_Data(1);


				//Calculation
				//Calculation:
				//  addr[Learn.ProgKey] = Learn.addr
				//  cmd[Learn.ProgKey] = Learn.cmd
				FCV_ADDR[FCL_PROGKEY] = FCL_ADDR;
				FCV_CMD[FCL_PROGKEY] = FCL_CMD;
				

				//Calculation
				//Calculation:
				//  Learn.exit = 1
				FCL_EXIT = 1;
				

			}


		}


		if ((FCL_EXIT) != 0) break;
	}


}

void main()
{
	
	//Initialisation
	adcon1 = 0x0F;
	ucfg = 0x08;
cr_bit(pie2, USBIE);

	intcon.GIE = 1;

	//Interrupt initialisation code
	


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Start
	FCD_LCDDisplay0_Start();


	//Output
	//Output: 1 -> B2
	trisb = trisb & 0xfb;
	if (1)
		portb = (portb & 0xfb) | 0x04;
	else
		portb = portb & 0xfb;


	//Modes
	//Calculation:
	//  TX = 0
	//  HASH = 1
	//  LEARN = 2
	FCV_TX = 0;
	FCV_HASH = 1;
	FCV_LEARN = 2;
	

	//Calculation
	//Calculation:
	//  addr[0] = 0
	//  addr[1] = 0
	//  addr[2] = 0
	//  addr[3] = 0
	//  addr[4] = 0
	//  addr[5] = 0
	//  addr[6] = 0
	//  addr[7] = 0
	//  addr[8] = 0
	//  addr[9] = 0
	FCV_ADDR[0] = 0;
	FCV_ADDR[1] = 0;
	FCV_ADDR[2] = 0;
	FCV_ADDR[3] = 0;
	FCV_ADDR[4] = 0;
	FCV_ADDR[5] = 0;
	FCV_ADDR[6] = 0;
	FCV_ADDR[7] = 0;
	FCV_ADDR[8] = 0;
	FCV_ADDR[9] = 0;
	

	//Calculation
	//Calculation:
	//  cmd[0] = 0
	//  cmd[1] = 1
	//  cmd[2] = 2
	//  cmd[3] = 3
	//  cmd[4] = 4
	//  cmd[5] = 5
	//  cmd[6] = 6
	//  cmd[7] = 7
	//  cmd[8] = 8
	//  cmd[9] = 9
	FCV_CMD[0] = 0;
	FCV_CMD[1] = 1;
	FCV_CMD[2] = 2;
	FCV_CMD[3] = 3;
	FCV_CMD[4] = 4;
	FCV_CMD[5] = 5;
	FCV_CMD[6] = 6;
	FCV_CMD[7] = 7;
	FCV_CMD[8] = 8;
	FCV_CMD[9] = 9;
	

	//Calculation
	//Calculation:
	//  mode = TX
	FCV_MODE = FCV_TX;
	

	//Calculation
	//Calculation:
	//  toggle = 0
	FCV_TOGGLE = 0;
	

	//Loop
	//Loop: While 1
	while (1)
	{
		//Loop
		//Loop: While keyVal = 255
		while (1)
		{
			//Call Component Macro
			//Call Component Macro: keyVal=KeyPad(0)::GetKeypadNumber
			FCV_KEYVAL = FCD_KeyPad0_GetKeypadNumber();


			if ((FCV_KEYVAL == 255) == 0) break;
		}


		//Switch
		//Switch: keyVal?
		switch (FCV_KEYVAL)
		{
			case 10:
			{
				//Decision
				//Decision: mode = HASH?
				if (FCV_MODE == FCV_HASH)
				{
					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::Clear
					FCD_LCDDisplay0_Clear();


					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::PrintASCII("Learn")
					FCD_LCDDisplay0_PrintASCII('L');
					FCD_LCDDisplay0_PrintASCII('e');
					FCD_LCDDisplay0_PrintASCII('a');
					FCD_LCDDisplay0_PrintASCII('r');
					FCD_LCDDisplay0_PrintASCII('n');


					//Calculation
					//Calculation:
					//  mode = LEARN
					FCV_MODE = FCV_LEARN;
					

					//Call Macro
					//Call Macro: Learn
					FCM_Learn();


					//Calculation
					//Calculation:
					//  mode = TX
					FCV_MODE = FCV_TX;
					

					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::Clear
					FCD_LCDDisplay0_Clear();


				}


				break;
			}

			case 11:
			{
				//Decision
				//Decision: mode = TX?
				if (FCV_MODE == FCV_TX)
				{
					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::PrintASCII("#")
					FCD_LCDDisplay0_PrintASCII('#');


					//Calculation
					//Calculation:
					//  mode = HASH
					FCV_MODE = FCV_HASH;
					

				} else {
					//Calculation
					//Calculation:
					//  mode = TX
					FCV_MODE = FCV_TX;
					

					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::Clear
					FCD_LCDDisplay0_Clear();


				}


				break;
			}

			default:
			{
				//Decision
				//Decision: keyVal < 10?
				if (FCV_KEYVAL < 10)
				{
					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::PrintASCII("Transmit")
					FCD_LCDDisplay0_PrintASCII('T');
					FCD_LCDDisplay0_PrintASCII('r');
					FCD_LCDDisplay0_PrintASCII('a');
					FCD_LCDDisplay0_PrintASCII('n');
					FCD_LCDDisplay0_PrintASCII('s');
					FCD_LCDDisplay0_PrintASCII('m');
					FCD_LCDDisplay0_PrintASCII('i');
					FCD_LCDDisplay0_PrintASCII('t');


					//Calculation
					//Calculation:
					//  mode = TX
					FCV_MODE = FCV_TX;
					

					//Call Macro
					//Call Macro: RC5_Send
					FCM_RC5_Send();


					//Delay
					//Delay: 100 ms
					delay_ms(100);


					//Call Component Macro
					//Call Component Macro: LCDDisplay(0)::Clear
					FCD_LCDDisplay0_Clear();


				}


			}
		}


		//Loop
		//Loop: While keyVal = 255
		while (1)
		{
			//Call Component Macro
			//Call Component Macro: keyVal=KeyPad(0)::GetKeypadNumber
			FCV_KEYVAL = FCD_KeyPad0_GetKeypadNumber();


			if ((FCV_KEYVAL == 255) != 0) break;
		}


		//Calculation
		//Calculation:
		//  toggle = 1 - toggle
		FCV_TOGGLE = 1 - FCV_TOGGLE;
		

	}


	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
	
	//Is the RC5 receive interrupt enabled and is the interrupt flag set?
	if ((MX_RC5_INT_ENREG.MX_RC5_INT_ENBIT) && (MX_RC5_INT_FLAGREG.MX_RC5_INT_FLAGBIT))
	{
		//Process signal edge
		FCD_Custom0_RC5_Signal_Edge();

		//Clear interrupt
		MX_RC5_INT_FLAGREG.MX_RC5_INT_FLAGBIT = 0;
	}


}



