//************************************************************************************
//**  
//**  File name:     \\NASHJJAKL\Jordy Kleian\Documenten\Flowcode Projects\Projecten\Power Supply Rev.2\uC Display\Display.c
//**  Title:         
//**  Description:   
//**  
//**  Generated by:  Flowcode v5.5.2.1
//**  Date:          Saturday, June 08, 2013 16:54:31
//**  Licence:       Professional
//**  Registered to: Jordy Kleian
//**  Licence key:   H8NNFC
//**  
//**  
//**  http://www.matrixmultimedia.com
//**  
//************************************************************************************


#define MX_PIC

#define MX_USES_UINT8 1
#define MX_USES_SINT16 1
#define MX_USES_CHAR 2
#define MX_USES_FLOAT 1
#define MX_USES_SINT32 0
#define MX_USES_BOOL 1
#define MX_USES_UINT16 1
#define MX_USES_UINT32 0
//Defines voor de microcontroller
#define P18F6722
#define FC_CAL_PIC
#define MX_ADC
#define MX_ADC_TYPE_12
#define MX_ADC_BITS_10
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 1024
#define MX_SPI_1
#define MX_SPI_1_MISO_PORT portc
#define MX_SPI_1_MISO_TRIS trisc
#define MX_SPI_1_MISO_PIN 4
#define MX_SPI_1_MOSI_PORT portc
#define MX_SPI_1_MOSI_TRIS trisc
#define MX_SPI_1_MOSI_PIN 5
#define MX_SPI_1_CLK_PORT portc
#define MX_SPI_1_CLK_TRIS trisc
#define MX_SPI_1_CLK_PIN 3
#define MX_SPI_1_SS_PORT portf
#define MX_SPI_1_SS_TRIS trisf
#define MX_SPI_1_SS_PIN 7
#define MX_SPI_2
#define MX_SPI_2_MISO_PORT portd
#define MX_SPI_2_MISO_TRIS trisd
#define MX_SPI_2_MISO_PIN 5
#define MX_SPI_2_MOSI_PORT portd
#define MX_SPI_2_MOSI_TRIS trisd
#define MX_SPI_2_MOSI_PIN 4
#define MX_SPI_2_CLK_PORT portd
#define MX_SPI_2_CLK_TRIS trisd
#define MX_SPI_2_CLK_PIN 6
#define MX_SPI_2_SS_PORT portd
#define MX_SPI_2_SS_TRIS trisd
#define MX_SPI_2_SS_PIN 7
#define MX_UART_1
#define MX_UART_1_TX_PORT portc
#define MX_UART_1_TX_TRIS trisc
#define MX_UART_1_TX_PIN 6
#define MX_UART_1_RX_PORT portc
#define MX_UART_1_RX_TRIS trisc
#define MX_UART_1_RX_PIN 7
#define MX_UART_2
#define MX_UART_2_TX_PORT portg
#define MX_UART_2_TX_TRIS trisg
#define MX_UART_2_TX_PIN 1
#define MX_UART_2_RX_PORT portg
#define MX_UART_2_RX_TRIS trisg
#define MX_UART_2_RX_PIN 2
#define MX_I2C
#define MX_MI2C
#define MX_I2C_1
#define MX_I2C_1_SDA_PORT portc
#define MX_I2C_1_SDA_TRIS trisc
#define MX_I2C_1_SDA_PIN 4
#define MX_I2C_1_SCL_PORT portc
#define MX_I2C_1_SCL_TRIS trisc
#define MX_I2C_1_SCL_PIN 3
#define MX_I2C_2
#define MX_I2C_2_SDA_PORT portd
#define MX_I2C_2_SDA_TRIS trisd
#define MX_I2C_2_SDA_PIN 5
#define MX_I2C_2_SCL_PORT portd
#define MX_I2C_2_SCL_TRIS trisd
#define MX_I2C_2_SCL_PIN 6
#define MX_PWM
#define MX_PWM_CNT 5
#define MX_PWM_PSCA1
#define MX_PWM_PSCA4
#define MX_PWM_PSCA16
#define MX_PWM_1_PORT portc
#define MX_PWM_1_TRIS trisc
#define MX_PWM_1_PIN 2
#define MX_PWM_2_PORT portc
#define MX_PWM_2_TRIS trisc
#define MX_PWM_2_PIN 1
#define MX_PWM_2_PORT_A porte
#define MX_PWM_2_TRIS_A trise
#define MX_PWM_2_PIN_A 7
#define MX_PWM_3_PORT portg
#define MX_PWM_3_TRIS trisg
#define MX_PWM_3_PIN 0
#define MX_PWM_4_PORT portg
#define MX_PWM_4_TRIS trisg
#define MX_PWM_4_PIN 3
#define MX_PWM_5_PORT portg
#define MX_PWM_5_TRIS trisg
#define MX_PWM_5_PIN 4

//Functies
#define MX_CLK_SPEED 20000000
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic18.h>
#endif

//Configuratiegegevens
#ifdef _BOOSTC
#pragma DATA 0x300000, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300001, 0x2
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300002, 0x19
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300003, 0x1e
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300004, 0x3
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300005, 0x81
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300006, 0xa0
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300007, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300008, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300009, 0xc0
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000a, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000b, 0xe0
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000c, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000d, 0x40
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif

//Interne functies
#include "C:\Program Files (x86)\Flowcode\v5\FCD\internals.c"

//Macro functie declaraties
void FCM_DrawHomescreen1();
void FCM_DATA_RS232();
void FCM_Check_RS232();
void FCM_VoltageReg_5VEN();
void FCM_BUS_Voltage();
void FCM_VREG_5V();
void FCM_CURRENT_5V();
void FCM_VREG_33V();
void FCM_VREG_MENU();


//Variable declaraties
#define FCSZ_VREG_SET_VOLT 20
#define FCSZ_VREG_SET_CURR 20
#define FCSZ_VREG_SET_TOT 20
#define FCSZ_VREG_SET 20
#define FCSZ_VREG_SET_UNIT 20
#define FCSZ_RS232_DATA_RX_STR 20
#define FCSZ_VREG_SET_TENS 20
#define FCSZ_BUS_VOLT_STR 4
#define FCSZ_VARVREG_SET 20
#define FCV_DISABLE (1)
#define FCV_ENABLE (0)
#define FCV_TRUE (1)
#define FCV_FALSE (0)
MX_UINT8 FCV_CURR_DISP;
MX_CHAR FCV_VREG_SET_VOLT[FCSZ_VREG_SET_VOLT];
MX_CHAR FCV_VREG_SET_CURR[FCSZ_VREG_SET_CURR];
MX_FLOAT FCV_COMP_STRINF;
MX_CHAR FCV_VREG_SET_TOT[FCSZ_VREG_SET_TOT];
MX_CHAR FCV_VREG_SET[FCSZ_VREG_SET];
MX_CHAR FCV_VREG_SET_UNIT[FCSZ_VREG_SET_UNIT];
MX_UINT16 FCV_RS232_DATA_RX;
MX_CHAR FCV_RS232_DATA_RX_STR[FCSZ_RS232_DATA_RX_STR];
MX_FLOAT FCV_BUS_VOLT_FLT;
MX_UINT8 FCV_VOLT_DISP;
MX_CHAR FCV_VREG_SET_TENS[FCSZ_VREG_SET_TENS];
MX_UINT8 FCV_VOLTAGEREG_5V;
MX_CHAR FCV_BUS_VOLT_STR[FCSZ_BUS_VOLT_STR];
MX_UINT8 FCV_VOLTAGEREG_33V;
MX_UINT8 FCV_VOLTAGEREG_5VEN;
MX_SINT16 FCV_ADC_BUSVOLT;
MX_UINT16 FCV_RS232_DATA_RX_OLD;
MX_CHAR FCV_VARVREG_SET[FCSZ_VARVREG_SET];




//Custom(0): //Defines:
//Error Reading Code For 128x64 gLCD Flowcode Component::DefinesCode



//Custom(0): //Macro functie declaraties

void FCD_Custom0_GetDefines();
void FCD_Custom0_LCD_Init();
void FCD_Custom0_LCD_Clear();
void FCD_Custom0_LCD_PlotPixel(char x, char y, char colour);
void FCD_Custom0_LCD_Draw_Line(char x, char y, char x2, char y2, char colour);
void FCD_Custom0_LCD_Draw_Rect(char x, char y, char width, char height, char colour);
void FCD_Custom0_LCD_Print_String(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour);
void FCD_Custom0_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent, char Colour);
void FCD_Custom0_LCD_Invert_Rect(char x, char y, char width, char height);


//RS232(0): //Defines:

/**** Macro Substitutions ****
a = Unique Reference
b = Uart Channel		(0-software / 1-4 hardware)
c = tx pin
d = tx port
e = rx pin
f = rx port
g = flow control		(0-Off / 1-On)
h = cts pin
i = cts port
j = rts pin
k = rts port
l = baud rate
m = data bits			(7/8/9) (7 only supported in software modes)
n = return type		(0-byte / 1-MX_UINT16)
o = echo enable		(0-Off / 1-On)
******************************/

//Definitions for RS232 UART slot allocation
#ifndef	MX_UART_REF1
	#define MX_UART_REF1
	#define RS232_2_MX_UART_UREF			1
	#define MX_UART_CHANNEL_1		1
	#define MX_UART_TX_PIN_1		0
	#define MX_UART_TX_PORT_1		porta
	#define MX_UART_TX_TRIS_1		trisa
	#define MX_UART_RX_PIN_1		0
	#define MX_UART_RX_PORT_1		porta
	#define MX_UART_RX_TRIS_1		trisa
	#define MX_UART_FLOWEN_1		0
	#define MX_UART_CTS_PIN_1		4
	#define MX_UART_CTS_PORT_1		portc
	#define MX_UART_CTS_TRIS_1		trisc
	#define MX_UART_RTS_PIN_1		0
	#define MX_UART_RTS_PORT_1		portc
	#define MX_UART_RTS_TRIS_1		trisc
	#define MX_UART_BAUD_1			19200
	#define MX_UART_DBITS_1			9
	#define MX_UART_RETURN_1		1
	#define MX_UART_ECHO_1			0
	#define MX_UART_INT_1			0
#else
 #ifndef	MX_UART_REF2
	#define MX_UART_REF2
	#define RS232_2_MX_UART_UREF			2
	#define MX_UART_CHANNEL_2		1
	#define MX_UART_TX_PIN_2		0
	#define MX_UART_TX_PORT_2		porta
	#define MX_UART_TX_TRIS_2		trisa
	#define MX_UART_RX_PIN_2		0
	#define MX_UART_RX_PORT_2		porta
	#define MX_UART_RX_TRIS_2		trisa
	#define MX_UART_FLOWEN_2		0
	#define MX_UART_CTS_PIN_2		4
	#define MX_UART_CTS_PORT_2		portc
	#define MX_UART_CTS_TRIS_2		trisc
	#define MX_UART_RTS_PIN_2		0
	#define MX_UART_RTS_PORT_2		portc
	#define MX_UART_RTS_TRIS_2		trisc
	#define MX_UART_BAUD_2			19200
	#define MX_UART_DBITS_2			9
	#define MX_UART_RETURN_2		1
	#define MX_UART_ECHO_2			0
	#define MX_UART_INT_2			0
 #else
  #ifndef	MX_UART_REF3
	#define MX_UART_REF3
	#define RS232_2_MX_UART_UREF			3
	#define MX_UART_CHANNEL_3		1
	#define MX_UART_TX_PIN_3		0
	#define MX_UART_TX_PORT_3		porta
	#define MX_UART_TX_TRIS_3		trisa
	#define MX_UART_RX_PIN_3		0
	#define MX_UART_RX_PORT_3		porta
	#define MX_UART_RX_TRIS_3		trisa
	#define MX_UART_FLOWEN_3		0
	#define MX_UART_CTS_PIN_3		4
	#define MX_UART_CTS_PORT_3		portc
	#define MX_UART_CTS_TRIS_3		trisc
	#define MX_UART_RTS_PIN_3		0
	#define MX_UART_RTS_PORT_3		portc
	#define MX_UART_RTS_TRIS_3		trisc
	#define MX_UART_BAUD_3			19200
	#define MX_UART_DBITS_3			9
	#define MX_UART_RETURN_3		1
	#define MX_UART_ECHO_3			0
	#define MX_UART_INT_3			0
  #else
   #ifndef	MX_UART_REF4
	#define MX_UART_REF4
	#define RS232_2_MX_UART_UREF			4
	#define MX_UART_CHANNEL_4		1
	#define MX_UART_TX_PIN_4		0
	#define MX_UART_TX_PORT_4		porta
	#define MX_UART_TX_TRIS_4		trisa
	#define MX_UART_RX_PIN_4		0
	#define MX_UART_RX_PORT_4		porta
	#define MX_UART_RX_TRIS_4		trisa
	#define MX_UART_FLOWEN_4		0
	#define MX_UART_CTS_PIN_4		4
	#define MX_UART_CTS_PORT_4		portc
	#define MX_UART_CTS_TRIS_4		trisc
	#define MX_UART_RTS_PIN_4		0
	#define MX_UART_RTS_PORT_4		portc
	#define MX_UART_RTS_TRIS_4		trisc
	#define MX_UART_BAUD_4			19200
	#define MX_UART_DBITS_4			9
	#define MX_UART_RETURN_4		1
	#define MX_UART_ECHO_4			0
	#define MX_UART_INT_4			0
   #endif
  #endif
 #endif
#endif

#define RS232_2_UART_Init		CAL_APPEND(FC_CAL_UART_Init_, RS232_2_MX_UART_UREF)
#define RS232_2_UART_Send		CAL_APPEND(FC_CAL_UART_Send_, RS232_2_MX_UART_UREF)
#define RS232_2_UART_Receive		CAL_APPEND(FC_CAL_UART_Receive_, RS232_2_MX_UART_UREF)
#define RS232_2_UART_Update_Baud CAL_APPEND(FC_CAL_UART_Update_Baud_, RS232_2_MX_UART_UREF)

extern void RS232_2_UART_Init();
extern void RS232_2_UART_Send(MX_UINT16 nChar);
extern MX_SINT16 RS232_2_UART_Receive(MX_UINT8 nTimeout);
extern void RS232_2_UART_Update_Baud(MX_UINT8 newbaud);




//RS232(0): //Macro functie declaraties

void FCD_RS2320_SendRS232Char(MX_SINT16 nChar);
void FCD_RS2320_SendRS232String(MX_STRING String, MX_UINT8 MSZ_String);
MX_SINT16 FCD_RS2320_ReceiveRS232Char(MX_UINT8 nTimeout);
void FCD_RS2320_ReceiveRS232String(MX_CHAR* FCR_RETVAL, MX_UINT8 FCR_RETVAL_SIZE, MX_UINT8 nTimeout, MX_UINT8 NumBytes);
void FCD_RS2320_ChangeHWBaud(MX_UINT8 newbaud);


//ADC(0): //Defines:

/**** Macro Substitutions ****
a = Unique Reference
b = Which ADC Channel
c = Acquisition time
d = Conversion Speed
e = VRef+ Option
f = VRef Voltage x 0.01V
******************************/

//Common Defines

#define ADC_3_MX_ADC_CHANNEL	4
#define ADC_3_MX_ADC_ACTIME	40
#define ADC_3_MX_ADC_CONVSP	3
#define ADC_3_MX_ADC_VREFOP	0
#define ADC_3_MX_ADC_VREFVOL	500

#ifndef MX_ADC_CHANNEL_4
 #define MX_ADC_CHANNEL_4			//Inform CAL ADC channel 4 is now in use.
#endif

#ifndef MX_ADC_REF					//Inform CAL ADC peripheral is now in use
 #define MX_ADC_REF
#endif

extern void FC_CAL_Enable_ADC (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge);
extern MX_UINT16 FC_CAL_Sample_ADC (MX_UINT8 Sample_Mode);
extern void FC_CAL_Disable_ADC (void);




//ADC(0): //Macro functie declaraties

void FCD_ADC0_SampleADC();
MX_UINT8 FCD_ADC0_ReadAsByte();
MX_UINT16 FCD_ADC0_ReadAsInt();
MX_FLOAT FCD_ADC0_ReadAsVoltage();
void FCD_ADC0_ReadAsString(MX_CHAR* FCR_RETVAL, MX_UINT8 FCR_RETVAL_SIZE);
void FCD_ADC0_ADC_RAW_Configure_Channel();
MX_UINT8 FCD_ADC0_ADC_RAW_Sample_Channel_Byte();
MX_UINT16 FCD_ADC0_ADC_RAW_Sample_Channel_Int();
MX_UINT8 FCD_ADC0_ADC_RAW_Average_Channel_Byte(MX_UINT8 NumSamples, MX_UINT8 DelayUs);
MX_UINT16 FCD_ADC0_ADC_RAW_Average_Channel_Int(MX_UINT8 NumSamples, MX_UINT8 DelayUs);
void FCD_ADC0_ADC_RAW_Disable_Channel();


//Custom2(0): //Defines:
//Error Reading Code For 128x64 gLCD Flowcode Component::DefinesCode



//Custom2(0): //Macro functie declaraties

void FCD_Custom20_GetDefines();
void FCD_Custom20_LCD_Init();
void FCD_Custom20_LCD_Clear();
void FCD_Custom20_LCD_PlotPixel(char x, char y, char colour);
void FCD_Custom20_LCD_Draw_Line(char x, char y, char x2, char y2, char colour);
void FCD_Custom20_LCD_Draw_Rect(char x, char y, char width, char height, char colour);
void FCD_Custom20_LCD_Print_String(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour);
void FCD_Custom20_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent, char Colour);
void FCD_Custom20_LCD_Invert_Rect(char x, char y, char width, char height);



//Custom(0): //Macro implementaties


void FCD_Custom0_GetDefines()
{
	
	}  //Dummy end of function to allow defines to be added correctly

	#include <string.h>

	//Common defines
	#define MX_DATA_PORT 		portf //
	#define MX_DATA_TRIS		trisf //
	#define MX_CONTROL_PORT		porta //
	#define MX_CONTROL_TRIS		trisa //
	#define MX_CS1			    3     //
	#define MX_CS2			    4     //
	#define MX_DAT_INST		    0     //
	#define MX_ENABLE		    2     //
	#define MX_READ_WRITE		1     //


	//Static defines
	#define MX_CHIP1			0x00
	#define MX_CHIP2			0x01
	#define MX_LCD_ON			0x3F
	#define MX_LCD_OFF			0x3E
	#define MX_LCD_SET_ADD		0x40
	#define MX_LCD_SET_PAGE		0xB8
	#define MX_LCD_DISP_START	0xC0
	#define MX_BLACK			0xFF
	#define MX_WHITE			0x00


	//ASCII Pixel data
	rom char* ASCII1 = {0x00 , 0x00 , 0x00 , 0x00 , 0x00,       // space // 32  - 43
						0x00 , 0x06 , 0x5F , 0x06 , 0x00,       // !
						0x07 , 0x03 , 0x00 , 0x07 , 0x03,       // ''
						0x24 , 0x7E , 0x24 , 0x7E , 0x24,       // #
						0x24 , 0x2B , 0x6A , 0x12 , 0x00,       // $
						0x63 , 0x13 , 0x08 , 0x64 , 0x63,       // %
						0x36 , 0x49 , 0x56 , 0x20 , 0x50,       // &
						0x00 , 0x07 , 0x03 , 0x00 , 0x00,       // '
						0x00 , 0x3E , 0x41 , 0x00 , 0x00,       // (
						0x00 , 0x41 , 0x3E , 0x00 , 0x00,       // )
						0x08 , 0x3E , 0x1C , 0x3E , 0x08,       // *
						0x08 , 0x08 , 0x3E , 0x08 , 0x08};      // +
	rom char* ASCII2 = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00,       // , // 44 - 55
						0x08 , 0x08 , 0x08 , 0x08 , 0x08,       // -
						0x00 , 0x60 , 0x60 , 0x00 , 0x00,       // .
						0x20 , 0x10 , 0x08 , 0x04 , 0x02,       // /
						0x3E , 0x51 , 0x49 , 0x45 , 0x3E,       // 0
						0x00 , 0x42 , 0x7F , 0x40 , 0x00,       // 1
						0x62 , 0x51 , 0x49 , 0x49 , 0x46,       // 2
						0x22 , 0x49 , 0x49 , 0x49 , 0x36,       // 3
						0x18 , 0x14 , 0x12 , 0x7F , 0x10,       // 4
						0x2F , 0x49 , 0x49 , 0x49 , 0x31,       // 5
						0x3C , 0x4A , 0x49 , 0x49 , 0x30,       // 6
						0x01 , 0x71 , 0x09 , 0x05 , 0x03};      // 7
	rom char* ASCII3 = {0x36 , 0x49 , 0x49 , 0x49 , 0x36,       // 8 // 56 - 67
						0x06 , 0x49 , 0x49 , 0x29 , 0x1E,       // 9
						0x00 , 0x6C , 0x6C , 0x00 , 0x00,       // :
						0x00 , 0xEC , 0x6C , 0x00 , 0x00,       // ;
						0x08 , 0x14 , 0x22 , 0x41 , 0x00,       // <
						0x24 , 0x24 , 0x24 , 0x24 , 0x24,       // =
						0x00 , 0x41 , 0x22 , 0x14 , 0x08,       // >
						0x02 , 0x01 , 0x59 , 0x09 , 0x06,       // ?
						0x3E , 0x41 , 0x5D , 0x55 , 0x1E,       // @
						0x7E , 0x09 , 0x09 , 0x09 , 0x7E,       // A
						0x7F , 0x49 , 0x49 , 0x49 , 0x36,       // B
						0x3E , 0x41 , 0x41 , 0x41 , 0x22};      // C
	rom char* ASCII4 = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E,       // D // 68 - 79
						0x7F , 0x49 , 0x49 , 0x49 , 0x41,       // E
						0x7F , 0x09 , 0x09 , 0x09 , 0x01,       // F
						0x3E , 0x41 , 0x49 , 0x49 , 0x7A,       // G
						0x7F , 0x08 , 0x08 , 0x08 , 0x7F,       // H
						0x00 , 0x41 , 0x7F , 0x41 , 0x00,       // I
						0x30 , 0x40 , 0x40 , 0x40 , 0x3F,       // J
						0x7F , 0x08 , 0x14 , 0x22 , 0x41,       // K
						0x7F , 0x40 , 0x40 , 0x40 , 0x40,       // L
						0x7F , 0x02 , 0x04 , 0x02 , 0x7F,       // M
						0x7F , 0x02 , 0x04 , 0x08 , 0x7F,       // N
						0x3E , 0x41 , 0x41 , 0x41 , 0x3E};      // O
	rom char* ASCII5 = {0x7F , 0x09 , 0x09 , 0x09 , 0x06,       // P // 80 - 91
						0x3E , 0x41 , 0x51 , 0x21 , 0x5E,       // Q
						0x7F , 0x09 , 0x09 , 0x19 , 0x66,       // R
						0x26 , 0x49 , 0x49 , 0x49 , 0x32,       // S
						0x01 , 0x01 , 0x7F , 0x01 , 0x01,       // T
						0x3F , 0x40 , 0x40 , 0x40 , 0x3F,       // U
						0x1F , 0x20 , 0x40 , 0x20 , 0x1F,       // V
						0x3F , 0x40 , 0x3C , 0x40 , 0x3F,       // W
						0x63 , 0x14 , 0x08 , 0x14 , 0x63,       // X
						0x07 , 0x08 , 0x70 , 0x08 , 0x07,       // Y
						0x71 , 0x49 , 0x45 , 0x43 , 0x00,       // Z
						0x00 , 0x7F , 0x41 , 0x41 , 0x00};      // [
	rom char* ASCII6 = {0x02 , 0x04 , 0x08 , 0x10 , 0x20,       // \ // 92 - 103
						0x00 , 0x41 , 0x41 , 0x7F , 0x00,       // ]
						0x04 , 0x02 , 0x01 , 0x02 , 0x04,       // ^
						0x80 , 0x80 , 0x80 , 0x80 , 0x80,       // _
						0x00 , 0x03 , 0x07 , 0x00 , 0x00,       // `
						0x20 , 0x54 , 0x54 , 0x54 , 0x78,       // a
						0x7F , 0x44 , 0x44 , 0x44 , 0x38,       // b
						0x38 , 0x44 , 0x44 , 0x44 , 0x28,       // c
						0x38 , 0x44 , 0x44 , 0x44 , 0x7F,       // d
						0x38 , 0x54 , 0x54 , 0x54 , 0x18,       // e
						0x08 , 0x7E , 0x09 , 0x09 , 0x00,       // f
						0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C};      // g
	rom char* ASCII7 = {0x7F , 0x04 , 0x04 , 0x78 , 0x00,       // h // 104 - 115
						0x00 , 0x00 , 0x7D , 0x00 , 0x00,       // i
						0x40 , 0x80 , 0x84 , 0x7D , 0x00,       // j
						0x7F , 0x10 , 0x28 , 0x44 , 0x00,       // k
						0x00 , 0x00 , 0x7F , 0x40 , 0x00,       // l
						0x7C , 0x04 , 0x18 , 0x04 , 0x78,       // m
						0x7C , 0x04 , 0x04 , 0x78 , 0x00,       // n
						0x38 , 0x44 , 0x44 , 0x44 , 0x38,       // o
						0xFC , 0x44 , 0x44 , 0x44 , 0x38,       // p
						0x38 , 0x44 , 0x44 , 0x44 , 0xFC,       // q
						0x44 , 0x78 , 0x44 , 0x04 , 0x08,       // r
						0x08 , 0x54 , 0x54 , 0x54 , 0x20};      // s
	rom char* ASCII8 = {0x04 , 0x3E , 0x44 , 0x24 , 0x00,       // t // 116 - 126
						0x3C , 0x40 , 0x20 , 0x7C , 0x00,       // u
						0x1C , 0x20 , 0x40 , 0x20 , 0x1C,       // v
						0x3C , 0x60 , 0x30 , 0x60 , 0x3C,       // w
						0x6C , 0x10 , 0x10 , 0x6C , 0x00,       // x
						0x9C , 0xA0 , 0x60 , 0x3C , 0x00,       // y
						0x64 , 0x54 , 0x54 , 0x4C , 0x00,       // z
						0x08 , 0x3E , 0x41 , 0x41 , 0x00,       // {
						0x00 , 0x00 , 0x7F , 0x00 , 0x00,       // |
						0x00 , 0x41 , 0x41 , 0x3E , 0x08,       // }
						0x02 , 0x01 , 0x02 , 0x01 , 0x00};      // ~


	//Global Variables
	char mx_page;
	char mx_currentx;
	char mx_currenty;


	//Internal Prototypes
	void MX_LCD_Enable (void);
	void MX_Write_Command(char cmd, char chip);
	void GotoXY(char x, char y);
	void MX_WriteData(char data);
	char MX_ReadData(void);


	//Internal Functions
	void MX_LCD_Enable (void)
	{
		set_bit(MX_CONTROL_PORT, MX_ENABLE);
		//delay_10us(1);								//Min delay 450ns
		nop();
		nop();
		nop();
		nop();
		nop();

		clear_bit(MX_CONTROL_PORT, MX_ENABLE);
		//delay_10us(1);								//Min delay 1.5us
		nop();
		nop();
		nop();
		nop();
		nop();
	}


	void MX_Write_Command(char cmd, char chip)
	{
		if(chip == MX_CHIP1)						//Select Chip 1
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}
		else if(chip == MX_CHIP2)					//Select Chip 2
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);	//Write Command
		clear_bit(MX_CONTROL_PORT, MX_DAT_INST);	//Instruction code
		MX_DATA_TRIS = 0x00;						//Configure data port as output
		MX_DATA_PORT = cmd;
		MX_LCD_Enable();
		MX_DATA_PORT = 0x00;
	}


	void MX_GotoXY(char x, char y)
	{
		char chip = MX_CHIP1;
		char cmd;

		if(x > 127) x = 0;							//Ensure that coordinates are legal
		if(y > 63)  y = 0;

		mx_currentx = x;
		mx_currenty = y;
		mx_page = y / 8;

		if(x >= 64) 								//Select the right chip
		{
			x = x - 64;
			chip = MX_CHIP2;
		}

		cmd = MX_LCD_SET_PAGE | mx_page;			//Set y address on both chips
		MX_Write_Command(cmd, MX_CHIP1);
		MX_Write_Command(cmd, MX_CHIP2);

		cmd = MX_LCD_SET_ADD | x;					//Set x address on active chip
		MX_Write_Command(cmd, chip);
	}



	void MX_WriteData(char data)
	{
		char displayData, yOffset, cmdPort;

		if(mx_currentx >= 128)
			return;

		if(mx_currentx < 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);			//Select chip 1
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}

		else if(mx_currentx >= 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);			//Select chip 2
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}

		if(mx_currentx == 64)							//Chip 2 X Address = 0
			MX_Write_Command(MX_LCD_SET_ADD, MX_CHIP2);

		set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to write data
		MX_DATA_TRIS = 0x00;							//Configure data port to Output
		yOffset = mx_currenty % 8;

		if(yOffset != 0) 								//First page?
		{
			cmdPort = MX_CONTROL_PORT;					//Save command port
			displayData = MX_ReadData();
			MX_CONTROL_PORT = cmdPort;					//Restore command port
			MX_DATA_TRIS = 0x00;						//Data port is output
			displayData = displayData | (data << yOffset);
			MX_DATA_PORT = displayData;					//Write data
			MX_LCD_Enable();							//Enable

			// second page
			MX_GotoXY(mx_currentx, (mx_currenty + 8));
			displayData = MX_ReadData();
			MX_CONTROL_PORT = cmdPort;					//Restore command port
			MX_DATA_TRIS = 0x00;						//Data port is output
			displayData = displayData | (data >> (8-yOffset));
			MX_DATA_PORT = displayData;					//Write data
			MX_LCD_Enable();							//Enable
			MX_GotoXY(mx_currentx + 1, (mx_currenty - 8));
		}
		else
		{
			MX_DATA_PORT = data;						//Write data
			MX_LCD_Enable();							//Enable
			mx_currentx = mx_currentx + 1;
		}
		MX_DATA_PORT = 0x00;
	}


	char MX_ReadData(void)
	{
		char data, i;

		MX_DATA_PORT = 0x00;
		MX_DATA_TRIS = 0xFF;							//Data port is input
		set_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to read data
		set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data

		if(mx_currentx < 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);			//Select chip 1
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}

		else if(mx_currentx >= 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);			//Select chip 2
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}

		set_bit(MX_CONTROL_PORT, MX_ENABLE);			//Set the enable bit
		for (i=0; i<3; i++);
		clear_bit(MX_CONTROL_PORT, MX_ENABLE);			//Clear the enable bit
		for (i=0; i<8; i++);							//Min 1.5us delay
		set_bit(MX_CONTROL_PORT, MX_ENABLE);			//Set the enable bit
		for (i=0; i<15; i++);							//Min 450ns delay

		data = MX_DATA_PORT;							//Read Data
		clear_bit(MX_CONTROL_PORT, MX_ENABLE);			//Clear the enable bit
		MX_DATA_TRIS = 0x00;							//Configure port as output
		MX_GotoXY(mx_currentx, mx_currenty);
		return data;
	}


	// Dummy function to close the defines section off
	void CUSTOM_Dummy_Function();
	void CUSTOM_Dummy_Function()
	{

}

void FCD_Custom0_LCD_Init()
{
	
		mx_currentx = 0;
		mx_currenty = 0;
		mx_page = 0;

		MX_DATA_TRIS = 0x00;								//Convert data port to output
		MX_DATA_PORT = 0x00;

		clear_bit(MX_CONTROL_TRIS, MX_ENABLE);				//Convert control pins to output
		clear_bit(MX_CONTROL_TRIS, MX_DAT_INST);
		clear_bit(MX_CONTROL_TRIS, MX_CS1);
		clear_bit(MX_CONTROL_TRIS, MX_CS2);
		clear_bit(MX_CONTROL_TRIS, MX_READ_WRITE);

		set_bit(MX_CONTROL_PORT, MX_ENABLE);
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);			//Write Command
		clear_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Instruction code
		set_bit(MX_CONTROL_PORT, MX_CS1);					//Select Chip 1
		clear_bit(MX_CONTROL_PORT, MX_CS2);

		MX_Write_Command(MX_LCD_ON, MX_CHIP1);				//Switch on LCD controller chips
		MX_Write_Command(MX_LCD_ON, MX_CHIP2);

		MX_Write_Command(MX_LCD_DISP_START, MX_CHIP1);		//Configure the display start address
		MX_Write_Command(MX_LCD_DISP_START, MX_CHIP2);

		FCD_Custom0_LCD_Clear();
		MX_GotoXY(0,0);

}

void FCD_Custom0_LCD_Clear()
{
		FCD_Custom0_LCD_Draw_Rect(0, 0, 127, 63, MX_WHITE);
}

void FCD_Custom0_LCD_PlotPixel(char x, char y, char colour)
{
		char data, mod_y;

		mod_y = y%8;
		MX_GotoXY(x, y - mod_y);
		data = MX_ReadData();							//Read 8 pixels from display
		if (colour)
			data = data | (0x01 << mod_y);				//Set Pixel
		else
			data = data & (~(0x01 << mod_y));			//Clear Pixel
		MX_WriteData(data);
}

void FCD_Custom0_LCD_Draw_Line(char x, char y, char x2, char y2, char colour)
{
		int C1, M1;
		signed int D1 = 0;
		signed int Pixelx = x2 - x;    //number of X-pixels;
		signed int Pixely = y2 - y;    //Number of Y-pixels
		signed char Xinc = 1;
		signed char Yinc = 1;

		if (Pixelx < 0)        //If negative X direction
		{
			Xinc = -1;
			Pixelx = Pixelx * -1;
		}
		if (Pixely < 0)        //If negative Y direction
		{
			Yinc = -1;
			Pixely = Pixely * -1;
		}
		if (Pixely <= Pixelx)
		{
			C1 = 2 * Pixelx;
			M1 = 2 * Pixely;
			while (x != x2)
			{
				FCD_Custom0_LCD_PlotPixel(x, y, colour);    //ForePlot line
				x = x + Xinc;
				D1 = D1 + M1;
				if (D1 > Pixelx)
				{
					y = y + Yinc;
					D1 = D1 - C1;
				}
			}
		}
		else
		{
			C1 = 2 * Pixely;
			M1 = 2 * Pixelx;
			while (y != y2)
			{
				FCD_Custom0_LCD_PlotPixel(x, y, colour);    //ForePlot Line
				y = y + Yinc;
				D1 = D1 + M1;
				if (D1 > Pixely)
				{
					x = x + Xinc;
					D1 = D1 - C1;
				}
			}
			FCD_Custom0_LCD_PlotPixel(x, y, colour);
		}
}

void FCD_Custom0_LCD_Draw_Rect(char x, char y, char width, char height, char colour)
{
		char mask, pageOffset, h, i, data;

		if(colour)
			colour = 255;

		height = height + 1;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;

		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
			h = (8 - pageOffset);

		mask = mask << pageOffset;

		MX_GotoXY(x, y);

		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			if(colour)
				data = data | mask;
			else
				data = data & (~mask);

			MX_WriteData(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
				MX_WriteData(colour);
		}

		if(h < height)
		{
			mask = ~(0xFF << (height - h));
			MX_GotoXY(x, (y + 8));

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();

				if(colour)
					data = data | mask;
				else
					data = data & (~mask);

				MX_WriteData(data);
			}
		}
}

void FCD_Custom0_LCD_Print_String(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour)
{
	    char xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
	    char Fontwidth = 1;                //First we assume small font
	    char Fontheight = 1;
		char inv_colour = 1;

	    char temp[6];
	    temp[5] = 0x00;                        //Spacing Line

		if (Colour)
			inv_colour = 0;

	    if (Font == 1)                     	//Double Height Sizes //Double Width
	    {
	        Fontwidth = 2;
	    }
	    if (Font == 2)                         //Double Height and Width Sizes
	    {
	        Fontwidth = 2;
	        Fontheight = 2;
	    }
	    if (Font == 3)                         //Double Height Sizes
	    {
	        Fontheight = 2;
	    }

	    xcount = 0;
	    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
	    {
	        if (String[i] == 0)
	        	return;
	        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

	        for (count = 0; count < 5; count++)        //Use correct buffer location
	        {
	            if (pos_Str < 12)
	            {
	                temp[count]=ASCII1[(pos_Str*5)+count];
	            }
	            else if (pos_Str < 24)
	            {
	                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
	            }
	            else if (pos_Str < 36)
	            {
	                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
	            }
	            else if (pos_Str < 48)
	            {
	                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
	            }
	            else if (pos_Str < 60)
	            {
	                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
	            }
	            else if (pos_Str < 72)
	            {
	                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
	            }
	            else if (pos_Str < 84)
	            {
	                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
	            }
	            else if (pos_Str < 95)
	            {
	                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
	            }
	        }
	        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
	        {
	            for (width=0;width<Fontwidth;width++)
	            {
	                ycount = 0;
	                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
	                {
	                    for (height=0;height<Fontheight;height++)
	                    {
	                        if (test_bit(temp[xpix],ypix))
	                        {
	                            FCD_Custom0_LCD_PlotPixel(X + xcount, Y + ycount, Colour);
	                        }
	                        else if (Transparent == 0)
	                        {
	                            FCD_Custom0_LCD_PlotPixel(X+xcount, Y+ycount, inv_colour);
	                        }
	                        ycount++;
	                    }
	                }
	                xcount++;
	            }
	        }
	    }
}

void FCD_Custom0_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent, char Colour)
{
		char string_length;

		if (Number < -10000	)
			string_length = 6;

		else if(Number > 10000 || Number < -1000)
			string_length = 5;

		else if(Number > 1000 || Number < -100)
			string_length = 4;

		else if(Number > 100 || Number < -10)
			string_length = 3;

		else if(Number > 10 || Number < -1)
			string_length = 2;

		else
			string_length = 1;

		char temp_str[6];

		FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
		FCD_Custom0_LCD_Print_String(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
}

void FCD_Custom0_LCD_Invert_Rect(char x, char y, char width, char height)
{
		char mask, pageOffset, h, i, data, tmpData;
		height++;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;
		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
		{
			h = 8 - pageOffset;
		}
		mask = mask << pageOffset;

		MX_GotoXY(x, y);
		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			tmpData = ~data;
			data = (tmpData & mask) | (data & ~mask);
			MX_WriteData(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();
				MX_WriteData(~data);
			}
		}

		if(h < height)
		{
			mask = ~(0xFF << (height-h));
			MX_GotoXY(x, y+8);

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();
				tmpData = ~data;
				data = (tmpData & mask) | (data & ~mask);
				MX_WriteData(data);
			}
		}
}



//RS232(0): //Macro implementaties


void FCD_RS2320_SendRS232Char(MX_SINT16 nChar)
{
	
		RS232_2_UART_Send ( nChar);

}

void FCD_RS2320_SendRS232String(MX_STRING String, MX_UINT8 MSZ_String)
{
	
		MX_UINT8 idx;
		for(idx = 0; idx < MSZ_String; idx++)
		{
			if (String[idx] == 0)
				break;
			else RS232_2_UART_Send ( String[idx] );
		}

}

MX_SINT16 FCD_RS2320_ReceiveRS232Char(MX_UINT8 nTimeout)
{
	
		return ( RS232_2_UART_Receive ( nTimeout) );

}

void FCD_RS2320_ReceiveRS232String(MX_CHAR* FCR_RETVAL, MX_UINT8 FCR_RETVAL_SIZE, MX_UINT8 nTimeout, MX_UINT8 NumBytes)
{
	
		MX_UINT8 idx;
		MX_SINT16 RS232_TO = 255;
		MX_SINT16 in;

		if ( 1 != 0 )
			RS232_TO = 256;

		if (NumBytes > FCR_RETVAL_SIZE)
			NumBytes = FCR_RETVAL_SIZE;

		for (idx = 0; idx < NumBytes; idx++)
		{
			in = RS232_2_UART_Receive ( nTimeout);
			if(in < RS232_TO)
				FCR_RETVAL[idx] = in & 0xFF;
			else
				break;
		}

		if (idx < FCR_RETVAL_SIZE)
			FCR_RETVAL[idx] = 0;

}

void FCD_RS2320_ChangeHWBaud(MX_UINT8 newbaud)
{
	
		RS232_2_UART_Update_Baud (newbaud);

}



//ADC(0): //Macro implementaties


void FCD_ADC0_SampleADC()
{
	
	    //unused

}

MX_UINT8 FCD_ADC0_ReadAsByte()
{
	
		MX_UINT8 retVal;

		//Configure & Enable ADC Channel
		FC_CAL_Enable_ADC ( ADC_3_MX_ADC_CHANNEL , ADC_3_MX_ADC_CONVSP , ADC_3_MX_ADC_VREFOP , ADC_3_MX_ADC_ACTIME );

		retVal = FC_CAL_Sample_ADC( 0 );				//Perform Sample - Return as byte

		FC_CAL_Disable_ADC ();

		return (retVal);

}

MX_UINT16 FCD_ADC0_ReadAsInt()
{
	
		MX_UINT16 retVal;

		//Configure & Enable ADC Channel
		FC_CAL_Enable_ADC ( ADC_3_MX_ADC_CHANNEL , ADC_3_MX_ADC_CONVSP , ADC_3_MX_ADC_VREFOP , ADC_3_MX_ADC_ACTIME );

		retVal = FC_CAL_Sample_ADC( 1 );				//Perform Sample - Return as MX_UINT16

		FC_CAL_Disable_ADC ();

		return (retVal);

}

MX_FLOAT FCD_ADC0_ReadAsVoltage()
{
	
		MX_UINT16 iSample;
		MX_FLOAT fSample, fVoltage, fVperDiv;

		//Configure & Enable ADC Channel
		FC_CAL_Enable_ADC ( ADC_3_MX_ADC_CHANNEL , ADC_3_MX_ADC_CONVSP , ADC_3_MX_ADC_VREFOP , ADC_3_MX_ADC_ACTIME );

	  #ifdef MX_ADC_BITS_8
		iSample = FC_CAL_Sample_ADC( 0 );								//Perform Sample - Return as byte
	  #else
		iSample = FC_CAL_Sample_ADC( 1 );								//Perform Sample - Return as MX_UINT16
	  #endif

	  	FC_CAL_Disable_ADC ();											//Switch off ADC peripheral
		fVoltage = flt_fromi( ADC_3_MX_ADC_VREFVOL );						//Convert reference voltage count to floating point (0 - 500 x 10mV)
		fVoltage = flt_mul(fVoltage, 0.01);								//Convert reference voltage count to actual voltage (0 - 5)

	  #ifdef MX_ADC_BITS_8
		fVperDiv = flt_mul(fVoltage, 0.00390625);						//Convert actual voltage to voltage per division (VRef / 256)
	  #endif
	  #ifdef MX_ADC_BITS_10
		fVperDiv = flt_mul(fVoltage, 0.000976);							//Convert actual voltage to voltage per division (VRef / 1024)
	  #endif
	  #ifdef MX_ADC_BITS_12
		fVperDiv = flt_mul(fVoltage, 0.00024414);						//Convert actual voltage to voltage per division (VRef / 4096)
	  #endif

		fSample = flt_fromi(iSample);									//Convert to floating point variable
		fVoltage = flt_mul(fSample, fVperDiv);							//Calculate floating point voltage

		return (fVoltage);

}

void FCD_ADC0_ReadAsString(MX_CHAR* FCR_RETVAL, MX_UINT8 FCR_RETVAL_SIZE)
{
	
		MX_FLOAT fVoltage;

		fVoltage = FCD_ADC0_ReadAsVoltage();
		FCI_FLOAT_TO_STRING(fVoltage, 2, FCR_RETVAL, FCR_RETVAL_SIZE);	//Convert to String

}

void FCD_ADC0_ADC_RAW_Configure_Channel()
{
	
		//Configure & Enable ADC Channel
		FC_CAL_Enable_ADC ( ADC_3_MX_ADC_CHANNEL , ADC_3_MX_ADC_CONVSP , ADC_3_MX_ADC_VREFOP , ADC_3_MX_ADC_ACTIME );

}

MX_UINT8 FCD_ADC0_ADC_RAW_Sample_Channel_Byte()
{
	
		return FC_CAL_Sample_ADC( 0 );									//Perform Sample - Return as byte

}

MX_UINT16 FCD_ADC0_ADC_RAW_Sample_Channel_Int()
{
	
		return FC_CAL_Sample_ADC( 1 );									//Perform Sample - Return as MX_UINT16

}

MX_UINT8 FCD_ADC0_ADC_RAW_Average_Channel_Byte(MX_UINT8 NumSamples, MX_UINT8 DelayUs)
{
	
		MX_UINT32 average = 0;
		MX_UINT8 count;

		for (count=0; count<NumSamples; count++)
		{
			average = average + FC_CAL_Sample_ADC( 0 );					//Perform Sample - Return as byte - add to average

			if (DelayUs)
				delay_us(DelayUs);										//If delay is not 0 then pause between samples
		}
		average = average / count;

		return (average & 0xFF);										//Return average as byte

}

MX_UINT16 FCD_ADC0_ADC_RAW_Average_Channel_Int(MX_UINT8 NumSamples, MX_UINT8 DelayUs)
{
	
		MX_UINT32 average = 0;
		MX_UINT8 count;

		for (count=0; count<NumSamples; count++)
		{
			average = average + FC_CAL_Sample_ADC( 1 );					//Perform Sample - Return as MX_UINT16 - add to average

			if (DelayUs)
				delay_us(DelayUs);										//If delay is not 0 then pause between samples
		}
		average = average / count;

		return (average & 0x1FFF);										//Return average as MX_SINT16

}

void FCD_ADC0_ADC_RAW_Disable_Channel()
{
	
		FC_CAL_Disable_ADC ();											//Disable ADC Channel

}



//Custom2(0): //Macro implementaties


void FCD_Custom20_GetDefines()
{
	
	}  //Dummy end of function to allow defines to be added correctly

	#include <string.h>

	/* -----
	  Change the 'unique' value for each in the custom code for each addition
	  Wrap MX_UNIQUE around each static non-unique name:
	    void MX_UNIQUE(GotoXY)(char x, char y)
	    .....
	    MX_UNIQUE(GotoXY)(57, 21);
	  Etc...
	----- */
	#undef MX_LCD_INSTANCE
	#define MX_LCD_INSTANCE 1
	#define MX_UNIQUE(name) MXU_##MX_LCD_INSTANCE_##name


	// Remove any previous defines
	#undef MX_DATA_PORT
	#undef MX_DATA_TRIS
	#undef MX_CONTROL_PORT
	#undef MX_CONTROL_TRIS
	#undef MX_CS1
	#undef MX_CS2
	#undef MX_DAT_INST
	#undef MX_ENABLE
	#undef MX_READ_WRITE

	//Common defines
	#define MX_DATA_PORT 	    portf	
	#define MX_DATA_TRIS	    trisf	
	#define MX_CONTROL_PORT		porta   
	#define MX_CONTROL_TRIS		trisa   
	#define MX_CS1			    3       
	#define MX_CS2			    4       
	#define MX_DAT_INST		    0       
	#define MX_ENABLE		    2       
	#define MX_READ_WRITE		1       


	//Static defines
	#ifndef MX_LCD_INITIALISED // Only do this once
	#define MX_LCD_INITIALISED

	#define MX_CHIP1			0x00
	#define MX_CHIP2			0x01
	#define MX_LCD_ON			0x3F
	#define MX_LCD_OFF			0x3E
	#define MX_LCD_SET_ADD		0x40
	#define MX_LCD_SET_PAGE		0xB8
	#define MX_LCD_DISP_START	0xC0
	#define MX_BLACK			0xFF
	#define MX_WHITE			0x00


	//ASCII Pixel data
	 #ifndef MX_FCD_CUSTOMCMPNT
	   #define MX_FCD_CUSTOMCMPNT
	rom char* ASCII1 = {0x00 , 0x00 , 0x00 , 0x00 , 0x00,       // space // 32  - 43
						0x00 , 0x06 , 0x5F , 0x06 , 0x00,       // !
						0x07 , 0x03 , 0x00 , 0x07 , 0x03,       // ''
						0x24 , 0x7E , 0x24 , 0x7E , 0x24,       // #
						0x24 , 0x2B , 0x6A , 0x12 , 0x00,       // $
						0x63 , 0x13 , 0x08 , 0x64 , 0x63,       // %
						0x36 , 0x49 , 0x56 , 0x20 , 0x50,       // &
						0x00 , 0x07 , 0x03 , 0x00 , 0x00,       // '
						0x00 , 0x3E , 0x41 , 0x00 , 0x00,       // (
						0x00 , 0x41 , 0x3E , 0x00 , 0x00,       // )
						0x08 , 0x3E , 0x1C , 0x3E , 0x08,       // *
						0x08 , 0x08 , 0x3E , 0x08 , 0x08};      // +
	rom char* ASCII2 = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00,       // , // 44 - 55
						0x08 , 0x08 , 0x08 , 0x08 , 0x08,       // -
						0x00 , 0x60 , 0x60 , 0x00 , 0x00,       // .
						0x20 , 0x10 , 0x08 , 0x04 , 0x02,       // /
						0x3E , 0x51 , 0x49 , 0x45 , 0x3E,       // 0
						0x00 , 0x42 , 0x7F , 0x40 , 0x00,       // 1
						0x62 , 0x51 , 0x49 , 0x49 , 0x46,       // 2
						0x22 , 0x49 , 0x49 , 0x49 , 0x36,       // 3
						0x18 , 0x14 , 0x12 , 0x7F , 0x10,       // 4
						0x2F , 0x49 , 0x49 , 0x49 , 0x31,       // 5
						0x3C , 0x4A , 0x49 , 0x49 , 0x30,       // 6
						0x01 , 0x71 , 0x09 , 0x05 , 0x03};      // 7
	rom char* ASCII3 = {0x36 , 0x49 , 0x49 , 0x49 , 0x36,       // 8 // 56 - 67
						0x06 , 0x49 , 0x49 , 0x29 , 0x1E,       // 9
						0x00 , 0x6C , 0x6C , 0x00 , 0x00,       // :
						0x00 , 0xEC , 0x6C , 0x00 , 0x00,       // ;
						0x08 , 0x14 , 0x22 , 0x41 , 0x00,       // <
						0x24 , 0x24 , 0x24 , 0x24 , 0x24,       // =
						0x00 , 0x41 , 0x22 , 0x14 , 0x08,       // >
						0x02 , 0x01 , 0x59 , 0x09 , 0x06,       // ?
						0x3E , 0x41 , 0x5D , 0x55 , 0x1E,       // @
						0x7E , 0x09 , 0x09 , 0x09 , 0x7E,       // A
						0x7F , 0x49 , 0x49 , 0x49 , 0x36,       // B
						0x3E , 0x41 , 0x41 , 0x41 , 0x22};      // C
	rom char* ASCII4 = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E,       // D // 68 - 79
						0x7F , 0x49 , 0x49 , 0x49 , 0x41,       // E
						0x7F , 0x09 , 0x09 , 0x09 , 0x01,       // F
						0x3E , 0x41 , 0x49 , 0x49 , 0x7A,       // G
						0x7F , 0x08 , 0x08 , 0x08 , 0x7F,       // H
						0x00 , 0x41 , 0x7F , 0x41 , 0x00,       // I
						0x30 , 0x40 , 0x40 , 0x40 , 0x3F,       // J
						0x7F , 0x08 , 0x14 , 0x22 , 0x41,       // K
						0x7F , 0x40 , 0x40 , 0x40 , 0x40,       // L
						0x7F , 0x02 , 0x04 , 0x02 , 0x7F,       // M
						0x7F , 0x02 , 0x04 , 0x08 , 0x7F,       // N
						0x3E , 0x41 , 0x41 , 0x41 , 0x3E};      // O
	rom char* ASCII5 = {0x7F , 0x09 , 0x09 , 0x09 , 0x06,       // P // 80 - 91
						0x3E , 0x41 , 0x51 , 0x21 , 0x5E,       // Q
						0x7F , 0x09 , 0x09 , 0x19 , 0x66,       // R
						0x26 , 0x49 , 0x49 , 0x49 , 0x32,       // S
						0x01 , 0x01 , 0x7F , 0x01 , 0x01,       // T
						0x3F , 0x40 , 0x40 , 0x40 , 0x3F,       // U
						0x1F , 0x20 , 0x40 , 0x20 , 0x1F,       // V
						0x3F , 0x40 , 0x3C , 0x40 , 0x3F,       // W
						0x63 , 0x14 , 0x08 , 0x14 , 0x63,       // X
						0x07 , 0x08 , 0x70 , 0x08 , 0x07,       // Y
						0x71 , 0x49 , 0x45 , 0x43 , 0x00,       // Z
						0x00 , 0x7F , 0x41 , 0x41 , 0x00};      // [
	rom char* ASCII6 = {0x02 , 0x04 , 0x08 , 0x10 , 0x20,       // \ // 92 - 103
						0x00 , 0x41 , 0x41 , 0x7F , 0x00,       // ]
						0x04 , 0x02 , 0x01 , 0x02 , 0x04,       // ^
						0x80 , 0x80 , 0x80 , 0x80 , 0x80,       // _
						0x00 , 0x03 , 0x07 , 0x00 , 0x00,       // `
						0x20 , 0x54 , 0x54 , 0x54 , 0x78,       // a
						0x7F , 0x44 , 0x44 , 0x44 , 0x38,       // b
						0x38 , 0x44 , 0x44 , 0x44 , 0x28,       // c
						0x38 , 0x44 , 0x44 , 0x44 , 0x7F,       // d
						0x38 , 0x54 , 0x54 , 0x54 , 0x18,       // e
						0x08 , 0x7E , 0x09 , 0x09 , 0x00,       // f
						0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C};      // g
	rom char* ASCII7 = {0x7F , 0x04 , 0x04 , 0x78 , 0x00,       // h // 104 - 115
						0x00 , 0x00 , 0x7D , 0x00 , 0x00,       // i
						0x40 , 0x80 , 0x84 , 0x7D , 0x00,       // j
						0x7F , 0x10 , 0x28 , 0x44 , 0x00,       // k
						0x00 , 0x00 , 0x7F , 0x40 , 0x00,       // l
						0x7C , 0x04 , 0x18 , 0x04 , 0x78,       // m
						0x7C , 0x04 , 0x04 , 0x78 , 0x00,       // n
						0x38 , 0x44 , 0x44 , 0x44 , 0x38,       // o
						0xFC , 0x44 , 0x44 , 0x44 , 0x38,       // p
						0x38 , 0x44 , 0x44 , 0x44 , 0xFC,       // q
						0x44 , 0x78 , 0x44 , 0x04 , 0x08,       // r
						0x08 , 0x54 , 0x54 , 0x54 , 0x20};      // s
	rom char* ASCII8 = {0x04 , 0x3E , 0x44 , 0x24 , 0x00,       // t // 116 - 126
						0x3C , 0x40 , 0x20 , 0x7C , 0x00,       // u
						0x1C , 0x20 , 0x40 , 0x20 , 0x1C,       // v
						0x3C , 0x60 , 0x30 , 0x60 , 0x3C,       // w
						0x6C , 0x10 , 0x10 , 0x6C , 0x00,       // x
						0x9C , 0xA0 , 0x60 , 0x3C , 0x00,       // y
						0x64 , 0x54 , 0x54 , 0x4C , 0x00,       // z
						0x08 , 0x3E , 0x41 , 0x41 , 0x00,       // {
						0x00 , 0x00 , 0x7F , 0x00 , 0x00,       // |
						0x00 , 0x41 , 0x41 , 0x3E , 0x08,       // }
						0x02 , 0x01 , 0x02 , 0x01 , 0x00};      // ~

	#endif // #ifndef MX_LCD_INITIALISED // Only do this once

	//Global Variables
	char MX_UNIQUE(page);
	char MX_UNIQUE(currentx);
	char MX_UNIQUE(currenty);

	//Internal Prototypes
	void MX_UNIQUE(LCD_Enable)(void);
	void MX_UNIQUE(Write_Command)(char cmd, char chip);
	void MX_UNIQUE(GotoXY)(char x, char y);
	void MX_UNIQUE(WriteData)(char data);
	char MX_UNIQUE(ReadData)(void);


	//Internal Functions
	void MX_LCD_Enable (void)
	{
		set_bit(MX_CONTROL_PORT, MX_ENABLE);
		//delay_10us(1);								//Min delay 450ns
		nop();
		nop();
		nop();
		nop();
		nop();

		clear_bit(MX_CONTROL_PORT, MX_ENABLE);
		//delay_10us(1);								//Min delay 1.5us
		nop();
		nop();
		nop();
		nop();
		nop();
	}


	void MX_Write_Command(char cmd, char chip)
	{
		if(chip == MX_CHIP1)						//Select Chip 1
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}
		else if(chip == MX_CHIP2)					//Select Chip 2
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);	//Write Command
		clear_bit(MX_CONTROL_PORT, MX_DAT_INST);	//Instruction code
		MX_DATA_TRIS = 0x00;						//Configure data port as output
		MX_DATA_PORT = cmd;
		MX_LCD_Enable();
		MX_DATA_PORT = 0x00;
	}


	void MX_GotoXY(char x, char y)
	{
		char chip = MX_CHIP1;
		char cmd;

		if(x > 127) x = 0;							//Ensure that coordinates are legal
		if(y > 63)  y = 0;

		mx_currentx = x;
		mx_currenty = y;
		mx_page = y / 8;

		if(x >= 64) 								//Select the right chip
		{
			x = x - 64;
			chip = MX_CHIP2;
		}

		cmd = MX_LCD_SET_PAGE | mx_page;			//Set y address on both chips
		MX_Write_Command(cmd, MX_CHIP1);
		MX_Write_Command(cmd, MX_CHIP2);

		cmd = MX_LCD_SET_ADD | x;					//Set x address on active chip
		MX_Write_Command(cmd, chip);
	}



	void MX_WriteData(char data)
	{
		char displayData, yOffset, cmdPort;

		if(mx_currentx >= 128)
			return;

		if(mx_currentx < 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);			//Select chip 1
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}

		else if(mx_currentx >= 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);			//Select chip 2
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}

		if(mx_currentx == 64)							//Chip 2 X Address = 0
			MX_Write_Command(MX_LCD_SET_ADD, MX_CHIP2);

		set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to write data
		MX_DATA_TRIS = 0x00;							//Configure data port to Output
		yOffset = mx_currenty % 8;

		if(yOffset != 0) 								//First page?
		{
			cmdPort = MX_CONTROL_PORT;					//Save command port
			displayData = MX_ReadData();
			MX_CONTROL_PORT = cmdPort;					//Restore command port
			MX_DATA_TRIS = 0x00;						//Data port is output
			displayData = displayData | (data << yOffset);
			MX_DATA_PORT = displayData;					//Write data
			MX_LCD_Enable();							//Enable

			// second page
			MX_GotoXY(mx_currentx, (mx_currenty + 8));
			displayData = MX_ReadData();
			MX_CONTROL_PORT = cmdPort;					//Restore command port
			MX_DATA_TRIS = 0x00;						//Data port is output
			displayData = displayData | (data >> (8-yOffset));
			MX_DATA_PORT = displayData;					//Write data
			MX_LCD_Enable();							//Enable
			MX_GotoXY(mx_currentx + 1, (mx_currenty - 8));
		}
		else
		{
			MX_DATA_PORT = data;						//Write data
			MX_LCD_Enable();							//Enable
			mx_currentx = mx_currentx + 1;
		}
		MX_DATA_PORT = 0x00;
	}


	char MX_ReadData(void)
	{
		char data, i;

		MX_DATA_PORT = 0x00;
		MX_DATA_TRIS = 0xFF;							//Data port is input
		set_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to read data
		set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data

		if(mx_currentx < 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS2);			//Select chip 1
			set_bit(MX_CONTROL_PORT, MX_CS1);
		}

		else if(mx_currentx >= 64)
		{
			clear_bit(MX_CONTROL_PORT, MX_CS1);			//Select chip 2
			set_bit(MX_CONTROL_PORT, MX_CS2);
		}

		set_bit(MX_CONTROL_PORT, MX_ENABLE);			//Set the enable bit
		for (i=0; i<3; i++);
		clear_bit(MX_CONTROL_PORT, MX_ENABLE);			//Clear the enable bit
		for (i=0; i<8; i++);							//Min 1.5us delay
		set_bit(MX_CONTROL_PORT, MX_ENABLE);			//Set the enable bit
		for (i=0; i<15; i++);							//Min 450ns delay

		data = MX_DATA_PORT;							//Read Data
		clear_bit(MX_CONTROL_PORT, MX_ENABLE);			//Clear the enable bit
		MX_DATA_TRIS = 0x00;							//Configure port as output
		MX_GotoXY(mx_currentx, mx_currenty);
		return data;
	}


	// Dummy function to close the defines section off
	void CUSTOM_Dummy_Function();
	void CUSTOM_Dummy_Function()
	{

}

void FCD_Custom20_LCD_Init()
{
	
		mx_currentx = 0;
		mx_currenty = 0;
		mx_page = 0;

		MX_DATA_TRIS = 0x00;								//Convert data port to output
		MX_DATA_PORT = 0x00;

		clear_bit(MX_CONTROL_TRIS, MX_ENABLE);				//Convert control pins to output
		clear_bit(MX_CONTROL_TRIS, MX_DAT_INST);
		clear_bit(MX_CONTROL_TRIS, MX_CS1);
		clear_bit(MX_CONTROL_TRIS, MX_CS2);
		clear_bit(MX_CONTROL_TRIS, MX_READ_WRITE);

		set_bit(MX_CONTROL_PORT, MX_ENABLE);
		clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);			//Write Command
		clear_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Instruction code
		set_bit(MX_CONTROL_PORT, MX_CS1);					//Select Chip 1
		clear_bit(MX_CONTROL_PORT, MX_CS2);

		MX_Write_Command(MX_LCD_ON, MX_CHIP1);				//Switch on LCD controller chips
		MX_Write_Command(MX_LCD_ON, MX_CHIP2);

		MX_Write_Command(MX_LCD_DISP_START, MX_CHIP1);		//Configure the display start address
		MX_Write_Command(MX_LCD_DISP_START, MX_CHIP2);

		FCD_Custom20_LCD_Clear();
		MX_GotoXY(0,0);

}

void FCD_Custom20_LCD_Clear()
{
		FCD_Custom20_LCD_Draw_Rect(0, 0, 127, 63, MX_WHITE);
}

void FCD_Custom20_LCD_PlotPixel(char x, char y, char colour)
{
		char data, mod_y;

		mod_y = y%8;
		MX_GotoXY(x, y - mod_y);
		data = MX_ReadData();							//Read 8 pixels from display
		if (colour)
			data = data | (0x01 << mod_y);				//Set Pixel
		else
			data = data & (~(0x01 << mod_y));			//Clear Pixel
		MX_WriteData(data);
}

void FCD_Custom20_LCD_Draw_Line(char x, char y, char x2, char y2, char colour)
{
		int C1, M1;
		signed int D1 = 0;
		signed int Pixelx = x2 - x;    //number of X-pixels;
		signed int Pixely = y2 - y;    //Number of Y-pixels
		signed char Xinc = 1;
		signed char Yinc = 1;

		if (Pixelx < 0)        //If negative X direction
		{
			Xinc = -1;
			Pixelx = Pixelx * -1;
		}
		if (Pixely < 0)        //If negative Y direction
		{
			Yinc = -1;
			Pixely = Pixely * -1;
		}
		if (Pixely <= Pixelx)
		{
			C1 = 2 * Pixelx;
			M1 = 2 * Pixely;
			while (x != x2)
			{
				FCD_Custom20_LCD_PlotPixel(x, y, colour);    //ForePlot line
				x = x + Xinc;
				D1 = D1 + M1;
				if (D1 > Pixelx)
				{
					y = y + Yinc;
					D1 = D1 - C1;
				}
			}
		}
		else
		{
			C1 = 2 * Pixely;
			M1 = 2 * Pixelx;
			while (y != y2)
			{
				FCD_Custom20_LCD_PlotPixel(x, y, colour);    //ForePlot Line
				y = y + Yinc;
				D1 = D1 + M1;
				if (D1 > Pixely)
				{
					x = x + Xinc;
					D1 = D1 - C1;
				}
			}
			FCD_Custom20_LCD_PlotPixel(x, y, colour);
		}
}

void FCD_Custom20_LCD_Draw_Rect(char x, char y, char width, char height, char colour)
{
		char mask, pageOffset, h, i, data;

		if(colour)
			colour = 255;

		height = height + 1;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;

		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
			h = (8 - pageOffset);

		mask = mask << pageOffset;

		MX_GotoXY(x, y);

		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			if(colour)
				data = data | mask;
			else
				data = data & (~mask);

			MX_WriteData(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
				MX_WriteData(colour);
		}

		if(h < height)
		{
			mask = ~(0xFF << (height - h));
			MX_GotoXY(x, (y + 8));

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();

				if(colour)
					data = data | mask;
				else
					data = data & (~mask);

				MX_WriteData(data);
			}
		}
}

void FCD_Custom20_LCD_Print_String(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour)
{
	    char xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
	    char Fontwidth = 1;                //First we assume small font
	    char Fontheight = 1;
		char inv_colour = 1;

	    char temp[6];
	    temp[5] = 0x00;                        //Spacing Line

		if (Colour)
			inv_colour = 0;

	    if (Font == 1)                     	//Double Height Sizes //Double Width
	    {
	        Fontwidth = 2;
	    }
	    if (Font == 2)                         //Double Height and Width Sizes
	    {
	        Fontwidth = 2;
	        Fontheight = 2;
	    }
	    if (Font == 3)                         //Double Height Sizes
	    {
	        Fontheight = 2;
	    }

	    xcount = 0;
	    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
	    {
	        if (String[i] == 0)
	        	return;
	        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

	        for (count = 0; count < 5; count++)        //Use correct buffer location
	        {
	            if (pos_Str < 12)
	            {
	                temp[count]=ASCII1[(pos_Str*5)+count];
	            }
	            else if (pos_Str < 24)
	            {
	                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
	            }
	            else if (pos_Str < 36)
	            {
	                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
	            }
	            else if (pos_Str < 48)
	            {
	                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
	            }
	            else if (pos_Str < 60)
	            {
	                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
	            }
	            else if (pos_Str < 72)
	            {
	                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
	            }
	            else if (pos_Str < 84)
	            {
	                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
	            }
	            else if (pos_Str < 95)
	            {
	                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
	            }
	        }
	        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
	        {
	            for (width=0;width<Fontwidth;width++)
	            {
	                ycount = 0;
	                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
	                {
	                    for (height=0;height<Fontheight;height++)
	                    {
	                        if (test_bit(temp[xpix],ypix))
	                        {
	                            FCD_Custom20_LCD_PlotPixel(X + xcount, Y + ycount, Colour);
	                        }
	                        else if (Transparent == 0)
	                        {
	                            FCD_Custom20_LCD_PlotPixel(X+xcount, Y+ycount, inv_colour);
	                        }
	                        ycount++;
	                    }
	                }
	                xcount++;
	            }
	        }
	    }
}

void FCD_Custom20_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent, char Colour)
{
		char string_length;

		if (Number < -10000	)
			string_length = 6;

		else if(Number > 10000 || Number < -1000)
			string_length = 5;

		else if(Number > 1000 || Number < -100)
			string_length = 4;

		else if(Number > 100 || Number < -10)
			string_length = 3;

		else if(Number > 10 || Number < -1)
			string_length = 2;

		else
			string_length = 1;

		char temp_str[6];

		FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
		FCD_Custom20_LCD_Print_String(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
}

void FCD_Custom20_LCD_Invert_Rect(char x, char y, char width, char height)
{
		char mask, pageOffset, h, i, data, tmpData;
		height++;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;
		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
		{
			h = 8 - pageOffset;
		}
		mask = mask << pageOffset;

		MX_GotoXY(x, y);
		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			tmpData = ~data;
			data = (tmpData & mask) | (data & ~mask);
			MX_WriteData(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();
				MX_WriteData(~data);
			}
		}

		if(h < height)
		{
			mask = ~(0xFF << (height-h));
			MX_GotoXY(x, y+8);

			for(i=0; i<=width; i++)
			{
				data = MX_ReadData();
				tmpData = ~data;
				data = (tmpData & mask) | (data & ~mask);
				MX_WriteData(data);
			}
		}
}

#include "C:\Program Files (x86)\Flowcode\v5\CAL\includes.c"

//Macro implementaties


void FCM_DrawHomescreen1()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Init()
	FCD_Custom0_LCD_Init();

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Init()
	FCD_Custom20_LCD_Init();

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

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Clear()
	FCD_Custom0_LCD_Clear();

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("Working", 0, 0, 0, 0, 1)
	FCD_Custom20_LCD_Print_String("Working", 7, 0, 0, 0, 0, 1);

	//Commentaar:
	//Draw Outline Frame

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(0, 0, 127, 63, 1)
	FCD_Custom0_LCD_Draw_Rect(0, 0, 127, 63, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(1, 1, 125, 61, 0)
	FCD_Custom0_LCD_Draw_Rect(1, 1, 125, 61, 0);

	//Commentaar:
	//Draw Vertical Line Middle Screen

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(63, 0, 63, 11, 1)
	FCD_Custom0_LCD_Draw_Line(63, 0, 63, 11, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(63, 22, 63, 63, 1)
	FCD_Custom0_LCD_Draw_Line(63, 22, 63, 63, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(0, 12, 127, 12, 1)
	FCD_Custom0_LCD_Draw_Line(0, 12, 127, 12, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(0, 22, 127, 22, 1)
	FCD_Custom0_LCD_Draw_Line(0, 22, 127, 22, 1);

	//Commentaar:
	//Draw Text

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(1, 1, 61, 10, 0)
	FCD_Custom0_LCD_Draw_Rect(1, 1, 61, 10, 0);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("Enabled", 11, 3, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("Enabled", 7, 11, 3, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(65, 1, 62, 10, 0)
	FCD_Custom0_LCD_Draw_Rect(65, 1, 62, 10, 0);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("Enabled", 74, 3, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("Enabled", 7, 74, 3, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("BUSV:", 38, 14, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("BUSV:", 5, 38, 14, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00V", 3, 25, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00V", 5, 3, 25, 2, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00A", 3, 45, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00A", 5, 3, 45, 2, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00V", 66, 25, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00V", 5, 66, 25, 2, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00A", 66, 45, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00A", 5, 66, 45, 2, 0, 1);

}


void FCM_DATA_RS232()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: RS232_Data_RX=ReceiveRS232Char(40)
	FCV_RS232_DATA_RX = FCD_RS2320_ReceiveRS232Char(40);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: RS232_Data_RX_Str=ReceiveRS232String(20, 20)
	FCD_RS2320_ReceiveRS232String(FCV_RS232_DATA_RX_STR,FCSZ_RS232_DATA_RX_STR, 20, 20);

}


void FCM_Check_RS232()
{

	//Lus
	//Lus: While 1
	while (1)
	{

		//Decision
		//Decision: RS232_Data_RX = 100?
		if (FCV_RS232_DATA_RX == 100)
		{

			//Component Macro Aanroepen
			//Component Macro Aanroepen: SendRS232Char(101)
			FCD_RS2320_SendRS232Char(101);

			//Spring naar Connection Point
			//Spring naar Connection Point: [A]: A
			goto FCC_Check_RS232_A;

		// } else {

		}


	}

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

}


void FCM_VoltageReg_5VEN()
{

	//Decision
	//Decision: VoltageReg_5V = 1?
	if (FCV_VOLTAGEREG_5V == 1)
	{

		//Decision
		//Decision: VoltageReg_5VEN = 1?
		if (FCV_VOLTAGEREG_5VEN == 1)
		{

			//Component Macro Aanroepen
			//Component Macro Aanroepen: LCD_Draw_Rect(1, 1, 61, 10, 1)
			FCD_Custom0_LCD_Draw_Rect(1, 1, 61, 10, 1);

			//Calculation
			//Calculation:
			//  VoltageReg_5VEN = 0
			FCV_VOLTAGEREG_5VEN = 0;

		// } else {

		}

		//Component Macro Aanroepen
		//Component Macro Aanroepen: LCD_Print_String("Enabled", 11, 3, 0, 0, 0)
		FCD_Custom0_LCD_Print_String("Enabled", 7, 11, 3, 0, 0, 0);

	} else {

		//Decision
		//Decision: VoltageReg_5VEN = 0?
		if (FCV_VOLTAGEREG_5VEN == 0)
		{

			//Component Macro Aanroepen
			//Component Macro Aanroepen: LCD_Draw_Rect(1, 1, 61, 10, 0)
			FCD_Custom0_LCD_Draw_Rect(1, 1, 61, 10, 0);

			//Calculation
			//Calculation:
			//  VoltageReg_5VEN = 1
			FCV_VOLTAGEREG_5VEN = 1;

		// } else {

		}

		//Component Macro Aanroepen
		//Component Macro Aanroepen: LCD_Print_String("Enabled", 11, 3, 0, 0, 1)
		FCD_Custom0_LCD_Print_String("Enabled", 7, 11, 3, 0, 0, 1);

	}

}


void FCM_BUS_Voltage()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: ADC_RAW_Configure_Channel()
	FCD_ADC0_ADC_RAW_Configure_Channel();

	//Component Macro Aanroepen
	//Component Macro Aanroepen: ADC_BUSVOLT=ReadAsInt()
	FCV_ADC_BUSVOLT = FCD_ADC0_ReadAsInt();

	//Calculation
	//Calculation:
	//  BUS_VOLT_FLT = ((4.94 / 1023) * ADC_BUSVOLT) * 64.75
	//  BUS_VOLT_Str = FloatToString$ (BUS_VOLT_FLT)
	FCV_BUS_VOLT_FLT = flt_mul((flt_mul((flt_div(4.94, 1023)), flt_fromi(FCV_ADC_BUSVOLT))), 64.75);
	FCI_FLOAT_TO_STRING(FCV_BUS_VOLT_FLT, 6, FCV_BUS_VOLT_STR,FCSZ_BUS_VOLT_STR);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String(BUS_VOLT_Str, 68, 14, 0, 0, 1)
	FCD_Custom0_LCD_Print_String(FCV_BUS_VOLT_STR, FCSZ_BUS_VOLT_STR, 68, 14, 0, 0, 1);

}


void FCM_VREG_5V()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String(RS232_Data_RX_Str, 3, 25, 2, 0, 1)
	FCD_Custom0_LCD_Print_String(FCV_RS232_DATA_RX_STR, FCSZ_RS232_DATA_RX_STR, 3, 25, 2, 0, 1);

	//Calculation
	//Calculation:
	//  Comp_StrINF = StringToFloat$ (RS232_Data_RX_Str)
	FCV_COMP_STRINF = FCI_STRING_TO_FLOAT(FCV_RS232_DATA_RX_STR, FCSZ_RS232_DATA_RX_STR);

	//Decision
	//Decision: Comp_StrINF > 4.9?
	if (flt_gt(FCV_COMP_STRINF, 4.9))
	{

		//Calculation
		//Calculation:
		//  VoltageReg_5V = 1
		FCV_VOLTAGEREG_5V = 1;

	} else {

		//Calculation
		//Calculation:
		//  VoltageReg_5V = 0
		FCV_VOLTAGEREG_5V = 0;

	}

}


void FCM_CURRENT_5V()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String(RS232_Data_RX_Str, 3, 45, 2, 0, 1)
	FCD_Custom0_LCD_Print_String(FCV_RS232_DATA_RX_STR, FCSZ_RS232_DATA_RX_STR, 3, 45, 2, 0, 1);

}


void FCM_VREG_33V()
{

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String(RS232_Data_RX_Str, 66, 25, 2, 0, 1)
	FCD_Custom0_LCD_Print_String(FCV_RS232_DATA_RX_STR, FCSZ_RS232_DATA_RX_STR, 66, 25, 2, 0, 1);

	//Calculation
	//Calculation:
	//  Comp_StrINF = StringToFloat$ (RS232_Data_RX_Str)
	FCV_COMP_STRINF = FCI_STRING_TO_FLOAT(FCV_RS232_DATA_RX_STR, FCSZ_RS232_DATA_RX_STR);

	//Decision
	//Decision: Comp_StrINF > 3.0?
	if (flt_gt(FCV_COMP_STRINF, 3.0))
	{

		//Calculation
		//Calculation:
		//  VoltageReg_33V = 1
		FCV_VOLTAGEREG_33V = 1;

	} else {

		//Calculation
		//Calculation:
		//  VoltageReg_33V = 0
		FCV_VOLTAGEREG_33V = 0;

	}

}


void FCM_VREG_MENU()
{

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

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Clear()
	FCD_Custom0_LCD_Clear();

	//Commentaar:
	//Draw Outline Frame

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(0, 0, 127, 63, 1)
	FCD_Custom0_LCD_Draw_Rect(0, 0, 127, 63, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Rect(1, 1, 125, 61, 0)
	FCD_Custom0_LCD_Draw_Rect(1, 1, 125, 61, 0);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("Setup", 47, 2, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("Setup", 5, 47, 2, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("Variable Voltage", 15, 12, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("Variable Voltage", 16, 15, 12, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(0, 20, 127, 20, 1)
	FCD_Custom0_LCD_Draw_Line(0, 20, 127, 20, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(0, 30, 127, 30, 1)
	FCD_Custom0_LCD_Draw_Line(0, 30, 127, 30, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("M1", 12, 22, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("M1", 2, 12, 22, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(32, 20, 32, 30, 1)
	FCD_Custom0_LCD_Draw_Line(32, 20, 32, 30, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("M2", 44, 22, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("M2", 2, 44, 22, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(63, 20, 63, 30, 1)
	FCD_Custom0_LCD_Draw_Line(63, 20, 63, 30, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("M3", 76, 22, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("M3", 2, 76, 22, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(96, 20, 96, 30, 1)
	FCD_Custom0_LCD_Draw_Line(96, 20, 96, 30, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("M4", 108, 22, 0, 0, 1)
	FCD_Custom0_LCD_Print_String("M4", 2, 108, 22, 0, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Draw_Line(63, 30, 63, 63, 1)
	FCD_Custom0_LCD_Draw_Line(63, 30, 63, 63, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00V", 3, 40, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00V", 5, 3, 40, 2, 0, 1);

	//Component Macro Aanroepen
	//Component Macro Aanroepen: LCD_Print_String("0.00A", 67, 40, 2, 0, 1)
	FCD_Custom0_LCD_Print_String("0.00A", 5, 67, 40, 2, 0, 1);

	//Lus
	//Lus: While 1
	while (1)
	{

		//Lus
		//Lus: While 1
		while (1)
		{

			//Decision
			//Decision: RS232_Data_RX = 501?
			if (FCV_RS232_DATA_RX == 501)
			{

				//Component Macro Aanroepen
				//Component Macro Aanroepen: LCD_Invert_Rect(1, 21, 30, 8)
				FCD_Custom0_LCD_Invert_Rect(1, 21, 30, 8);

				//Component Macro Aanroepen
				//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
				FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

			} else {

				//Decision
				//Decision: RS232_Data_RX = 502?
				if (FCV_RS232_DATA_RX == 502)
				{

					//Component Macro Aanroepen
					//Component Macro Aanroepen: LCD_Invert_Rect(33, 21, 29, 8)
					FCD_Custom0_LCD_Invert_Rect(33, 21, 29, 8);

					//Component Macro Aanroepen
					//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
					FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

				} else {

					//Decision
					//Decision: RS232_Data_RX = 503?
					if (FCV_RS232_DATA_RX == 503)
					{

						//Component Macro Aanroepen
						//Component Macro Aanroepen: LCD_Invert_Rect(64, 21, 31, 8)
						FCD_Custom0_LCD_Invert_Rect(64, 21, 31, 8);

						//Component Macro Aanroepen
						//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
						FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

					} else {

						//Decision
						//Decision: RS232_Data_RX = 504?
						if (FCV_RS232_DATA_RX == 504)
						{

							//Component Macro Aanroepen
							//Component Macro Aanroepen: LCD_Invert_Rect(97, 21, 29, 8)
							FCD_Custom0_LCD_Invert_Rect(97, 21, 29, 8);

							//Component Macro Aanroepen
							//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
							FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

						} else {

							//Decision
							//Decision: RS232_Data_RX = 505?
							if (FCV_RS232_DATA_RX == 505)
							{

								//Calculation
								//Calculation:
								//  VOLT_DISP = 1
								//  CURR_DISP = 0
								FCV_VOLT_DISP = 1;
								FCV_CURR_DISP = 0;

								//Component Macro Aanroepen
								//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
								FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

							} else {

								//Decision
								//Decision: RS232_Data_RX = 506?
								if (FCV_RS232_DATA_RX == 506)
								{

									//Calculation
									//Calculation:
									//  VOLT_DISP = 0
									//  CURR_DISP = 1
									FCV_VOLT_DISP = 0;
									FCV_CURR_DISP = 1;

									//Component Macro Aanroepen
									//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 67, 40, 2, 0, 1)
									FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 67, 40, 2, 0, 1);

								} else {

									//Decision
									//Decision: RS232_Data_RX = 507?
									if (FCV_RS232_DATA_RX == 507)
									{

										//Spring naar Connection Point
										//Spring naar Connection Point: [A]: A
										goto FCC_VREG_MENU_A;

									// } else {

									}

								}

							}

							//Decision
							//Decision: RS232_Data_RX < 9?
							if (FCV_RS232_DATA_RX < 9)
							{

								//Calculation
								//Calculation:
								//  VREG_SET = ToString$ (RS232_Data_RX)
								//  VREG_SET_TOT = "00." + VREG_SET + "V"
								FCI_TOSTRING(FCV_RS232_DATA_RX, FCV_VREG_SET,FCSZ_VREG_SET);
								FCI_SHEAD("00.",3, FCV_VREG_SET,FCSZ_VREG_SET, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, "V",1, FCV_VREG_SET_TOT,FCSZ_VREG_SET_TOT);

							} else {

								//Calculation
								//Calculation:
								//  VREG_SET = ToString$ (RS232_Data_RX)
								//  VREG_SET_TENS = Left$ (VREG_SET,1)
								//  VREG_SET_UNIT = Right$ (VREG_SET,1)
								//  VREG_SET_TOT = "0" + VREG_SET_TENS + "." + VREG_SET_UNIT + "V"
								FCI_TOSTRING(FCV_RS232_DATA_RX, FCV_VREG_SET,FCSZ_VREG_SET);
								FCI_LEFTSTRING(FCV_VREG_SET, FCSZ_VREG_SET, 1, FCV_VREG_SET_TENS,FCSZ_VREG_SET_TENS);
								FCI_RIGHTSTRING(FCV_VREG_SET, FCSZ_VREG_SET, 1, FCV_VREG_SET_UNIT,FCSZ_VREG_SET_UNIT);
								FCI_SHEAD("0",1, FCV_VREG_SET_TENS,FCSZ_VREG_SET_TENS, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, ".",1, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, FCV_VREG_SET_UNIT,FCSZ_VREG_SET_UNIT, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, "V",1, FCV_VREG_SET_TOT,FCSZ_VREG_SET_TOT);

							}

							//Decision
							//Decision: RS232_Data_RX > 99?
							if (FCV_RS232_DATA_RX > 99)
							{

								//Calculation
								//Calculation:
								//  VREG_SET = ToString$ (RS232_Data_RX)
								//  VREG_SET_TENS = Left$ (VREG_SET,2)
								//  VREG_SET_UNIT = Right$ (VREG_SET,1)
								//  VREG_SET_TOT = VREG_SET_TENS + "." + VREG_SET_UNIT + "V"
								FCI_TOSTRING(FCV_RS232_DATA_RX, FCV_VREG_SET,FCSZ_VREG_SET);
								FCI_LEFTSTRING(FCV_VREG_SET, FCSZ_VREG_SET, 2, FCV_VREG_SET_TENS,FCSZ_VREG_SET_TENS);
								FCI_RIGHTSTRING(FCV_VREG_SET, FCSZ_VREG_SET, 1, FCV_VREG_SET_UNIT,FCSZ_VREG_SET_UNIT);
								FCI_SHEAD(FCV_VREG_SET_TENS,FCSZ_VREG_SET_TENS, ".",1, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, FCV_VREG_SET_UNIT,FCSZ_VREG_SET_UNIT, FCI_TMP_STR,20);
								FCI_SHEAD(FCI_TMP_STR,20, "V",1, FCV_VREG_SET_TOT,FCSZ_VREG_SET_TOT);

							// } else {

							}

							//Decision
							//Decision: VOLT_DISP = 1?
							if (FCV_VOLT_DISP == 1)
							{

								//Component Macro Aanroepen
								//Component Macro Aanroepen: LCD_Print_String("***", 23, 31, 0, 0, 1)
								FCD_Custom0_LCD_Print_String("***", 3, 23, 31, 0, 0, 1);

								//Component Macro Aanroepen
								//Component Macro Aanroepen: LCD_Print_String("   ", 90, 31, 0, 0, 1)
								FCD_Custom0_LCD_Print_String("   ", 3, 90, 31, 0, 0, 1);

								//Component Macro Aanroepen
								//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 3, 40, 2, 0, 1)
								FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 3, 40, 2, 0, 1);

							} else {

								//Decision
								//Decision: CURR_DISP = 1?
								if (FCV_CURR_DISP == 1)
								{

									//Component Macro Aanroepen
									//Component Macro Aanroepen: LCD_Print_String("   ", 23, 31, 0, 0, 1)
									FCD_Custom0_LCD_Print_String("   ", 3, 23, 31, 0, 0, 1);

									//Component Macro Aanroepen
									//Component Macro Aanroepen: LCD_Print_String("***", 90, 31, 0, 0, 1)
									FCD_Custom0_LCD_Print_String("***", 3, 90, 31, 0, 0, 1);

									//Component Macro Aanroepen
									//Component Macro Aanroepen: LCD_Print_String(VREG_SET_TOT, 67, 40, 2, 0, 1)
									FCD_Custom0_LCD_Print_String(FCV_VREG_SET_TOT, FCSZ_VREG_SET_TOT, 67, 40, 2, 0, 1);

								// } else {

								}

							}

						}

					}

				}

			}


		}


	}

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

	//Calculation
	//Calculation:
	//  RS232_Data_RX = 0
	FCV_RS232_DATA_RX = 0;

	//Call Macro
	//Call Macro: DrawHomescreen1()
	FCM_DrawHomescreen1();

}


void main()
{
	//Initialisatie
	adcon1 = 0x0F;

	
		RS232_2_UART_Init( );		//Call initialise function


	//Interrupt-initialisatiecode
	


	//Interrupt
	//Interrupt: Enable RXINT
	st_bit(intcon, GIE);
	st_bit(intcon, PEIE);
	st_bit(pie1, RC1IE);

	//Call Macro
	//Call Macro: DrawHomescreen1()
	FCM_DrawHomescreen1();

	//Calculation
	//Calculation:
	//  VOLT_DISP = 1
	//  CURR_DISP = 0
	FCV_VOLT_DISP = 1;
	FCV_CURR_DISP = 0;

	//Lus
	//Lus: While 1
	while (1)
	{

		//Commentaar:
		//Left-Halfe Display

		//Call Macro
		//Call Macro: VoltageReg_5VEN()
		FCM_VoltageReg_5VEN();

		//Call Macro
		//Call Macro: BUS_Voltage()
		FCM_BUS_Voltage();

		//Schakelaar 
		//Schakelaar : RS232_Data_RX?
		switch (FCV_RS232_DATA_RX)
		{
			case 1:
			{
				//Call Macro
				//Call Macro: VREG_5V()
				FCM_VREG_5V();

				break;
			}
			case 2:
			{
				//Call Macro
				//Call Macro: CURRENT_5V()
				FCM_CURRENT_5V();

				break;
			}
			case 3:
			{
				//Call Macro
				//Call Macro: VREG_33V()
				FCM_VREG_33V();

				break;
			}
			case 4:
			{
				break;
			}
			case 5:
			{
				break;
			}
			// default:

		}

		//Schakelaar 
		//Schakelaar : RS232_Data_RX?
		switch (FCV_RS232_DATA_RX)
		{
			case 10:
			{
				//Call Macro
				//Call Macro: VREG_MENU()
				FCM_VREG_MENU();

				break;
			}
			case 11:
			{
				break;
			}
			case 12:
			{
				break;
			}
			case 13:
			{
				break;
			}
			case 14:
			{
				break;
			}
			case 15:
			{
				break;
			}
			// default:

		}


	}

	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
	//Handler code for [RXINT]
	#ifndef MX_INTHANDLER_pir1_RC1IF
	#define MX_INTHANDLER_pir1_RC1IF
	if (ts_bit(pir1, RC1IF) && ts_bit(pie1, RC1IE))
	{
		#ifdef USE_FLOWCODE_ICD
			extern char ICD_Interrupt_Enable = 1;
		#endif
		FCM_DATA_RS232();
		cr_bit(pir1, RC1IF);
		#ifdef USE_FLOWCODE_ICD
			extern char ICD_Interrupt_Enable = 0;
		#endif	
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <DATA_RS232> may never get called."
	#endif

}



