//************************************************************************************
//**  
//**  File name:     E:\My Documents\HAZTECH SYSTEMS\matrixmultimedia\software_component_library\menus\multilevel_menu3.c
//**  Generated by:  Flowcode v4.3.7.63
//**  Date:          Tuesday, July 06, 2010 22:47:26
//**  Licence:       Professional
//**  Registered to: pete smart
//**  
//**  
//**  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_MIAC
#define MX_USB_TYPE1

//Functions
#define MX_CLK_SPEED 48000000
#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, 0xe
#endif
#ifdef _HI_TECH_C
__CONFIG(1, 0xe20);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300002, 0x3e
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300003, 0x1e
#endif
#ifdef _HI_TECH_C
__CONFIG(2, 0x1e3e);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300004, 0x0
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300005, 0x81
#endif
#ifdef _HI_TECH_C
__CONFIG(3, 0x8100);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300006, 0x81
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300007, 0x0
#endif
#ifdef _HI_TECH_C
__CONFIG(4, 0x81);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300008, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x300009, 0x80
#endif
#ifdef _HI_TECH_C
__CONFIG(5, 0x800f);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000a, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000b, 0xa0
#endif
#ifdef _HI_TECH_C
__CONFIG(6, 0xa00f);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000c, 0xf
#endif
#ifdef _HI_TECH_C
//__CONFIG(, );
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000d, 0x0
#endif
#ifdef _HI_TECH_C
__CONFIG(7, 0xf);
#endif

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

//Macro function declarations
void FCM_get_key_front_panel();
void FCM_display_menu_structure();
void FCM_page_up();
void FCM_page_down();
void FCM_page_left();
void FCM_page_right();
void FCM_Home_page();
void FCM_write_sub_display();
void FCM_sub_menu();
void FCM_write_display();


//Variable declarations
#define FCSZ_COMPANY_NAME 16
#define FCSZ_PRODUCT_VERSION 5
#define FCSZ_PRODUCT_NAME 16
char FCV_KEY_PRESSED;
char FCV_PAGE_H_PLANE;
char FCV_COMPANY_NAME[FCSZ_COMPANY_NAME];
char FCV_PAGE_RIGHT;
char FCV_PRODUCT_VERSION[FCSZ_PRODUCT_VERSION];
char FCV_MAX_MENU_V_DEPTH;
char FCV_LAST_KEY_PRESSED;
char FCV_PAGE_V_PLANE;
char FCV_PAGE_UP;
char FCV_MAX_MENU_H_DEPTH;
char FCV_PRODUCT_NAME[FCSZ_PRODUCT_NAME];


//Defines:

/**** Macro Substitutions ****
portd = LCD Port register
trisd = LCD Data Direction register
5 = D1 Pin
4 = D2 Pin
3 = D3 Pin
0 = D4 Pin
1 = RS Pin
6 = E Pin
 = Unused
4 = LCD Row Count
******************************/

//Component connections
#define LCD_PORT   portd
#define LCD_TRIS    trisd
#define LCD_BIT0    5
#define LCD_BIT1    4
#define LCD_BIT2    3
#define LCD_BIT3    0
#define LCD_RS      1
#define LCD_E       6

#define LCD_DELAY   delay_10us(10)




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

char FCD_MIAC0_InputDIGITAL(char InputID);
char FCD_MIAC0_InputANALOG(char InputID);
char FCD_MIAC0_GetKeypad();
void FCD_MIAC0_RelayON(char RelayID);
void FCD_MIAC0_RelayOFF(char RelayID);
void FCD_MIAC0_OutputON(char TransID);
void FCD_MIAC0_OutputOFF(char TransID);
void FCD_MIAC0_DisplayStart();
void FCD_MIAC0_DisplayClear();
void FCD_MIAC0_DisplayCursor(char x, char y);
void FCD_MIAC0_PrintASCII(char Character);
void FCD_MIAC0_PrintNumber(short Number);
void FCD_MIAC0_PrintString(char* String, char MSZ_String);
void FCD_MIAC0_DisplayCommand(char in);
void FCD_MIAC0_LCD_RawSend(char nIn, char nMask);
short FCD_MIAC0_InputANALOG_10Bit(char InputID);



//MIAC(0): //Macro implementations


char FCD_MIAC0_InputDIGITAL(char InputID)
{
	
		char RetVal = 255;

		if(InputID && (InputID < 9))
		{
			switch(InputID)
			{
				case(1):	trisa |= 0x01;
							RetVal = ((porta & 0x01) == 0x01);
							break;
				case(2):	trisa |= 0x02;
							RetVal = ((porta & 0x02) == 0x02);
							break;
				case(3):	trisa |= 0x04;
							RetVal = ((porta & 0x04) == 0x04);
							break;
				case(4):	trisa |= 0x08;
							RetVal = ((porta & 0x08) == 0x08);
							break;
				case(5):	trise |= 0x01;
							RetVal = ((porte & 0x01) == 0x01);
							break;
				case(6):	trise |= 0x02;
							RetVal = ((porte & 0x02) == 0x02);
							break;
				case(7):	trise |= 0x04;
							RetVal = ((porte & 0x04) == 0x04);
							break;
				case(8):	trisb |= 0x04;
							RetVal = ((portb & 0x04) == 0x04);
							break;
			}
		}
		return(RetVal);

}

char FCD_MIAC0_InputANALOG(char InputID)
{
	
		#define MX_ADC_SAMP_TIME 40

		//set up ADC conversion
		char old_tris, cnt, tris_mask, chan_id;

		if(InputID && (InputID < 9))
		{
			chan_id = InputID;
			if (InputID >= 5) chan_id++;

			adcon2 = 0x03;
			adcon1 = 15 - chan_id;

			//store old tris value, and set the i/o pin as an input
			switch (InputID)
			{
				case(1):	old_tris = trisa;
							trisa |= 0x01;
							break;
				case(2):	old_tris = trisa;
							trisa |= 0x02;
							break;
				case(3):	old_tris = trisa;
							trisa |= 0x04;
							break;
				case(4):	old_tris = trisa;
							trisa |= 0x08;
							break;
				case(5):	old_tris = trise;
							trise |= 0x01;
							break;
				case(6):	old_tris = trise;
							trise |= 0x02;
							break;
				case(7):	old_tris = trise;
							trise |= 0x04;
							break;
				case(8):	old_tris = trisb;
							trisb |= 0x04;
							break;
			}

			//turn ADC on
			adcon0 = 0x01 | ((chan_id - 1) << 2);

			//wait the acquisition time
			cnt = 0;
			while (cnt < MX_ADC_SAMP_TIME) cnt++;

			//begin conversion and wait until it has finished
			adcon0 = adcon0 | 0x02;
			while (adcon0 & 0x02);

			//restore old tris value, and reset adc registers
			if(InputID == 8)
			{
				trisb = old_tris;
			}
			else
			{
				if(InputID < 5)
				{
					trisa = old_tris;
				}
				else
				{
					trise = old_tris;
				}
			}
			adcon1 = 0x0f;
			adcon0 = 0x00;
		}

		return(adresh);

}

char FCD_MIAC0_GetKeypad()
{
	
		//get matrices for rows and columns
		char kpad_col_select = 0x08;
		char kpad_col_mask = 0x38;
		char kpad_row_mask = 0x07;
		char trisd_temp = trisd;
		char iCol;
		char iRow;
		char c_ip;

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

		for (iCol=0; iCol<3; iCol++)
		{
			//output the appropriate column low
			portd = (latd | kpad_col_mask) & ~(kpad_col_select);

			//delay
			delay_10us(2);

			//read the port
			c_ip = portd;

			//check for a hit
			for (iRow=0; iRow<3; iRow++)
			{
				if ((c_ip & 0x01) == 0)
				{
					//found it!
					goto found_key;
				}
				c_ip >>= 1;
			}
			kpad_col_select <<= 1;
		}

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

	  found_key:
		trisd = trisd_temp;
		return (iCol * 3 + iRow);

}

void FCD_MIAC0_RelayON(char RelayID)
{
	
		if(RelayID && (RelayID < 5))
			clear_bit(trisb, RelayID + 3);
			set_bit(portb, RelayID + 3);

}

void FCD_MIAC0_RelayOFF(char RelayID)
{
	
		if(RelayID && (RelayID < 5))
			clear_bit(trisb, RelayID + 3);
			clear_bit(portb, RelayID + 3);

}

void FCD_MIAC0_OutputON(char TransID)
{
	
		if(TransID && (TransID < 5))
		{
			switch(TransID)
			{
				case(1):	trisc &= ~0x04;
							portc |= 0x04;
							break;
				case(2):	trisc &= ~0x01;
							portc |= 0x01;
							break;
				case(3):	trisc &= ~0x02;
							portc |= 0x02;
							break;
				case(4):	trisc &= ~0x40;
							portc |= 0x40;
							break;
			}
		}

}

void FCD_MIAC0_OutputOFF(char TransID)
{
	
		if(TransID && (TransID < 5))
		{
			switch(TransID)
			{
				case(1):	trisc &= ~0x04;
							portc &= ~0x04;
							break;
				case(2):	trisc &= ~0x01;
							portc &= ~0x01;
							break;
				case(3):	trisc &= ~0x02;
							portc &= ~0x02;
							break;
				case(4):	trisc &= ~0x40;
							portc &= ~0x40;
							break;
			}
		}

}

void FCD_MIAC0_DisplayStart()
{
	
		clear_bit(LCD_TRIS, LCD_BIT0);
		clear_bit(LCD_TRIS, LCD_BIT1);
		clear_bit(LCD_TRIS, LCD_BIT2);
		clear_bit(LCD_TRIS, LCD_BIT3);
		clear_bit(LCD_TRIS, LCD_RS);
		clear_bit(LCD_TRIS, LCD_E);

		delay_ms(12);

		FCD_MIAC0_LCD_RawSend(0x33, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x33, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x32, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x2c, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x06, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x0c, 0);
		delay_ms(2);

		//clear the display
		FCD_MIAC0_LCD_RawSend(0x01, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x02, 0);
		delay_ms(2);

}

void FCD_MIAC0_DisplayClear()
{
	
		FCD_MIAC0_LCD_RawSend(0x01, 0);
		delay_ms(2);
		FCD_MIAC0_LCD_RawSend(0x02, 0);
		delay_ms(2);

}

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

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

	  #if (4 == 4)
		if (y==0)
			y=0x80;
		else if (y==1)
			y=0xc0;
		else if (y==2)
			y=0x90;
		else
			y=0xd0;
	  #endif

		FCD_MIAC0_LCD_RawSend(y+x, 0);
		delay_ms(2);

}

void FCD_MIAC0_PrintASCII(char Character)
{
	
		FCD_MIAC0_LCD_RawSend(Character, 0x10);

}

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

		tmp_int = Number;
		if (Number >= 10000)
		{
			tmp_byte = tmp_int / 10000;
			FCD_MIAC0_LCD_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_MIAC0_LCD_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_MIAC0_LCD_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_MIAC0_LCD_RawSend('0' + tmp_byte, 0x10);

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

}

void FCD_MIAC0_PrintString(char* String, char MSZ_String)
{
	
		char idx;
		for (idx=0; idx<MSZ_String; idx++)
		{
			if (String[idx]==0)
			{
				break;
			}
			FCD_MIAC0_LCD_RawSend(String[idx], 0x10);
		}

}

void FCD_MIAC0_DisplayCommand(char in)
{
	
		FCD_MIAC0_LCD_RawSend(in, 0);
		delay_ms(2);

}

void FCD_MIAC0_LCD_RawSend(char nIn, char nMask)
{
		unsigned char pt;
		unsigned char outVal;
		outVal = LCD_PORT;
		clear_bit(outVal, LCD_BIT0);
		clear_bit(outVal, LCD_BIT1);
		clear_bit(outVal, LCD_BIT2);
		clear_bit(outVal, LCD_BIT3);
		clear_bit(outVal, LCD_RS);
		clear_bit(outVal, LCD_E);
		pt = ((nIn >> 4) & 0x0f);
		if (pt & 0x01)
		    set_bit(outVal, LCD_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_RS);
		LCD_PORT = outVal;
		LCD_DELAY;
		set_bit (LCD_PORT, LCD_E);
		LCD_DELAY;
		clear_bit (LCD_PORT, LCD_E);
		pt = (nIn & 0x0f);
		LCD_DELAY;
		outVal = LCD_PORT;
		clear_bit(outVal, LCD_BIT0);
		clear_bit(outVal, LCD_BIT1);
		clear_bit(outVal, LCD_BIT2);
		clear_bit(outVal, LCD_BIT3);
		clear_bit(outVal, LCD_RS);
		clear_bit(outVal, LCD_E);
		if (pt & 0x01)
		    set_bit(outVal, LCD_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_RS);
		LCD_PORT = outVal;
		LCD_DELAY;
		set_bit (LCD_PORT, LCD_E);
		LCD_DELAY;
		clear_bit (LCD_PORT, LCD_E);
		LCD_DELAY;
}

short FCD_MIAC0_InputANALOG_10Bit(char InputID)
{
	
		short result;

		result = FCD_MIAC0_InputANALOG(InputID);
		result = result << 2;
		result = result | (adresl >> 6);

		return(result);

}

//Macro implementations

void FCM_get_key_front_panel()
{
	//front panel key sense
	
	//Local variable definitions
	char FCL_KEY_PRESSED;

	//Get_front_panel_key_value
	//Call Component Macro: key_pressed=MIAC(0)::GetKeypad
	FCV_KEY_PRESSED = FCD_MIAC0_GetKeypad();


	//Decision
	//Decision: key_pressed=255?
	if (FCV_KEY_PRESSED==255)
	{
	} else {
		//Delay
		//Delay: 100 ms
		delay_ms(100);


		//store_last_key_pressed
		//Calculation:
		//  last_key_pressed = key_pressed
		FCV_LAST_KEY_PRESSED = FCV_KEY_PRESSED;
		

		//jump to display menu
		//Call Macro: display_menu_structure
		FCM_display_menu_structure();


	}


}

void FCM_display_menu_structure()
{
	
	//Menu_function _select
	//Switch: last_key_pressed?
	switch (FCV_LAST_KEY_PRESSED)
	{
		case 1:
		{
			//Call Macro
			//Call Macro: page_left
			FCM_page_left();


			//Call Macro
			//Call Macro: write_sub_display
			FCM_write_sub_display();


			//Call Macro
			//Call Macro: sub_menu
			FCM_sub_menu();


			break;
		}

		case 3:
		{
			//Call Macro
			//Call Macro: page_down
			FCM_page_down();


			//Call Macro
			//Call Macro: write_sub_display
			FCM_write_sub_display();


			//Call Macro
			//Call Macro: sub_menu
			FCM_sub_menu();


			break;
		}

		case 5:
		{
			//Call Macro
			//Call Macro: page_up
			FCM_page_up();


			//Call Macro
			//Call Macro: write_sub_display
			FCM_write_sub_display();


			//Call Macro
			//Call Macro: sub_menu
			FCM_sub_menu();


			break;
		}

		case 7:
		{
			//Call Macro
			//Call Macro: page_right
			FCM_page_right();


			//Call Macro
			//Call Macro: write_sub_display
			FCM_write_sub_display();


			//Call Macro
			//Call Macro: sub_menu
			FCM_sub_menu();


			break;
		}

		case 8:
		{
			//Call Macro
			//Call Macro: write_display
			FCM_write_display();


			break;
		}

		case 6:
		{
			//Call Macro
			//Call Macro: Home_page
			FCM_Home_page();


			break;
		}

		case 4:
		{
			break;
		}

		case 0:
		{
			break;
		}

		case 2:
		{
			break;
		}

	}


	//Comment:
	//Write menu names


}

void FCM_page_up()
{
	
	//Comment:
	//Page Up


	//Top of Menu ?
	//Decision: page_V_plane < = 1?
	if (FCV_PAGE_V_PLANE < == 1)
	{
		//roll around to max
		//Calculation:
		//  page_V_plane = Max_menu_V_depth
		FCV_PAGE_V_PLANE = FCV_MAX_MENU_V_DEPTH;
		

	} else {
		//page_up
		//Calculation:
		//  page_V_plane = page_V_plane - 1
		FCV_PAGE_V_PLANE = FCV_PAGE_V_PLANE - 1;
		

	}


	//Calculation
	//Calculation:
	//  page_H_plane = 0
	FCV_PAGE_H_PLANE = 0;
	

}

void FCM_page_down()
{
	
	//Comment:
	//page down


	//bottom of Menu ?
	//Decision: page_V_plane  >= Max_menu_V_depth?
	if (FCV_PAGE_V_PLANE  >= FCV_MAX_MENU_V_DEPTH)
	{
		//reset to page 1
		//Calculation:
		//  page_V_plane = 1
		FCV_PAGE_V_PLANE = 1;
		

	} else {
		//page_down
		//Calculation:
		//  page_V_plane = page_V_plane + 1
		FCV_PAGE_V_PLANE = FCV_PAGE_V_PLANE + 1;
		

	}


	//Calculation
	//Calculation:
	//  page_H_plane = 0
	FCV_PAGE_H_PLANE = 0;
	

}

void FCM_page_left()
{
	
	//maximum left of Menu ?
	//Decision: page_H_plane < = 0?
	if (FCV_PAGE_H_PLANE < == 0)
	{
		//roll around to max
		//Calculation:
		//  page_H_plane = Max_menu_H_depth
		FCV_PAGE_H_PLANE = FCV_MAX_MENU_H_DEPTH;
		

	} else {
		//page_left
		//Calculation:
		//  page_H_plane = page_H_plane - 1
		FCV_PAGE_H_PLANE = FCV_PAGE_H_PLANE - 1;
		

	}


}

void FCM_page_right()
{
	
	//maximum right  of Menu ?
	//Decision: page_H_plane  >= Max_menu_H_depth?
	if (FCV_PAGE_H_PLANE  >= FCV_MAX_MENU_H_DEPTH)
	{
		//reset to page 1
		//Calculation:
		//  page_H_plane = 0
		FCV_PAGE_H_PLANE = 0;
		

	} else {
		//page_right
		//Calculation:
		//  page_H_plane = page_H_plane + 1
		FCV_PAGE_H_PLANE = FCV_PAGE_H_PLANE + 1;
		

	}


}

void FCM_Home_page()
{
	
	//reset_to_home_ page
	//Calculation:
	//  page_V_plane = 0
	//  page_H_plane = 0
	FCV_PAGE_V_PLANE = 0;
	FCV_PAGE_H_PLANE = 0;
	

	//return_key
	//Call Component Macro: MIAC(0)::DisplayClear
	FCD_MIAC0_DisplayClear();


	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayCursor(0, 0)
	FCD_MIAC0_DisplayCursor(0, 0);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString(company_name)
	FCD_MIAC0_PrintString(FCV_COMPANY_NAME,FCSZ_COMPANY_NAME);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayCursor(5, 1)
	FCD_MIAC0_DisplayCursor(5, 1);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString(product_name)
	FCD_MIAC0_PrintString(FCV_PRODUCT_NAME,FCSZ_PRODUCT_NAME);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayCursor(6, 2)
	FCD_MIAC0_DisplayCursor(6, 2);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString(product_version)
	FCD_MIAC0_PrintString(FCV_PRODUCT_VERSION,FCSZ_PRODUCT_VERSION);


}

void FCM_write_sub_display()
{
	
	//
	//Call Component Macro: MIAC(0)::DisplayClear
	FCD_MIAC0_DisplayClear();


	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayCursor(0, 0)
	FCD_MIAC0_DisplayCursor(0, 0);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintNumber(page_V_plane)
	FCD_MIAC0_PrintNumber(FCV_PAGE_V_PLANE);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString(".")
	FCD_MIAC0_PrintString(".",1);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintNumber(page_H_plane)
	FCD_MIAC0_PrintNumber(FCV_PAGE_H_PLANE);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString(" ")
	FCD_MIAC0_PrintString(" ",1);


}

void FCM_sub_menu()
{
	
	//Switch
	//Switch: page_V_plane?
	switch (FCV_PAGE_V_PLANE)
	{
		case 1:
		{
			//Call Component Macro
			//Call Component Macro: MIAC(0)::PrintString("Test Level")
			FCD_MIAC0_PrintString("Test Level",10);


			//Switch
			//Switch: page_H_plane?
			switch (FCV_PAGE_H_PLANE)
			{
				case 1:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 2:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 3:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 4:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 5:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 0:
				{
					//Calculation
					//Calculation:
					//  key_pressed = 0
					FCV_KEY_PRESSED = 0;
					

					break;
				}

			}


			break;
		}

		case 2:
		{
			//Call Component Macro
			//Call Component Macro: MIAC(0)::PrintString("Inputs")
			FCD_MIAC0_PrintString("Inputs",6);


			//Switch
			//Switch: page_H_plane?
			switch (FCV_PAGE_H_PLANE)
			{
				case 1:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 2:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 3:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 4:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 5:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 0:
				{
					break;
				}

			}


			break;
		}

		case 3:
		{
			//Call Component Macro
			//Call Component Macro: MIAC(0)::PrintString("Outputs")
			FCD_MIAC0_PrintString("Outputs",7);


			//Switch
			//Switch: page_H_plane?
			switch (FCV_PAGE_H_PLANE)
			{
				case 1:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 2:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 3:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 4:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 5:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 0:
				{
					break;
				}

			}


			break;
		}

		case 4:
		{
			//Engine menu
			//Call Component Macro: MIAC(0)::PrintString("Engine")
			FCD_MIAC0_PrintString("Engine",6);


			//Switch
			//Switch: page_H_plane?
			switch (FCV_PAGE_H_PLANE)
			{
				case 1:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 2:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 3:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 4:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 5:
				{
					//Call Component Macro
					//Call Component Macro: MIAC(0)::DisplayCursor(0, 1)
					FCD_MIAC0_DisplayCursor(0, 1);


					//Call Component Macro
					//Call Component Macro: MIAC(0)::PrintString("Test Level")
					FCD_MIAC0_PrintString("Test Level",10);


					break;
				}

				case 0:
				{
					break;
				}

			}


			break;
		}

		case 5:
		{
			break;
		}

		case 6:
		{
			break;
		}

		case 7:
		{
			break;
		}

		case 8:
		{
			break;
		}

		case 0:
		{
			break;
		}

	}


}

void FCM_write_display()
{
	
	//
	//Call Component Macro: MIAC(0)::DisplayClear
	FCD_MIAC0_DisplayClear();


	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayCursor(0, 0)
	FCD_MIAC0_DisplayCursor(0, 0);


	//Call Component Macro
	//Call Component Macro: MIAC(0)::PrintString("Diagnostic Menus ")
	FCD_MIAC0_PrintString("Diagnostic Menus ",17);


}

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


	//Interrupt initialisation code
	


	//preset variables
	//Calculation:
	//  Max_menu_H_depth = 5
	//  Max_menu_V_depth = 5
	FCV_MAX_MENU_H_DEPTH = 5;
	FCV_MAX_MENU_V_DEPTH = 5;
	

	//Names Table
	//String Manipulation:
	//  company_name = "HAZTECH SYSTEMS"
	//  product_version = "v3.0"
	//  product_name = "HAMPAC"
	FCI_CONCATENATE("HAZTECH SYSTEMS",15,"",0,FCV_COMPANY_NAME,FCSZ_COMPANY_NAME);
	FCI_CONCATENATE("v3.0",4,"",0,FCV_PRODUCT_VERSION,FCSZ_PRODUCT_VERSION);
	FCI_CONCATENATE("HAMPAC",6,"",0,FCV_PRODUCT_NAME,FCSZ_PRODUCT_NAME);
	

	//Call Component Macro
	//Call Component Macro: MIAC(0)::DisplayStart
	FCD_MIAC0_DisplayStart();


	//Call Macro
	//Call Macro: Home_page
	FCM_Home_page();


	//Loop
	//Loop: While 1
	while (1)
	{
		//Call Macro
		//Call Macro: get_key_front_panel
		FCM_get_key_front_panel();


	}


	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}



