FLOWCODE da FCFX uzantı nedir?

Başlatan Epsilon, 25 Ekim 2019, 19:21:45

Epsilon

Araştırdığım bir konuda program flowcode ile yazılmış.
Elimde hex ve fcfx uzantılı 2 dosya var fcfx uzantıdan kaynak kodlara ulaşılabilirmiyiz?

M.Salim GÜLLÜCE

#1
Alıntı yapılan: Epsilon - 25 Ekim 2019, 19:21:45Araştırdığım bir konuda program flowcode ile yazılmış.
Elimde hex ve fcfx uzantılı 2 dosya var fcfx uzantıdan kaynak kodlara ulaşılabilirmiyiz?
Yanılmıyorsam fcfx V5 ten sonraki versiyonlar için flowcode un oluşturduğu dosya.
V5 te fcf diye oluşturuyordu.
Eğer flowcode 7 veya 8 kuruluysa bilgisayarınızda açık kaynak kodu olarak kullanabilmeniz lazım.
Kurulu değilse o şansınız yok.
Kaldıki Flowcode kendi kütüphanelerini kullandığından sadece orada derlemek zorundasınız.
Derlendiğinde C çıktısınıda oluşturur ama pek işinize yaramaz.
Lakin genede program main alanını C dosyada görme şansına sahip olursunuz.
Aşağıdaki örnekteki gibi.

//************************************************************************************
//**  
//**  File name:     C:\Users\Dede\Documents\FlowCode\Dede\1 LED On-Off\1 LED On-Off.c
//**  Title:         
//**  Description:   
//**  
//**  Generated by:  Flowcode v5.5.2.1
//**  Date:          Thursday, October 31, 2019 23:11:39
//**  Licence:       Professional
//**  Registered to: xyz
//**  Licence key:   WUK7B9
//**  
//**  
//**  http://www.matrixmultimedia.com
//**  
//************************************************************************************


#define MX_PIC

#define MX_USES_UINT8 1
#define MX_USES_SINT16 0
#define MX_USES_CHAR 0
#define MX_USES_FLOAT 0
#define MX_USES_SINT32 0
#define MX_USES_BOOL 1
#define MX_USES_UINT16 0
#define MX_USES_UINT32 0
//Mikrodenetleyici için tan?mlamalar
#define P16F628A
#define FC_CAL_PIC
#define MX_EE
#define MX_EE_SIZE 128
#define MX_UART_1
#define MX_UART_1_TX_PORT portb
#define MX_UART_1_TX_TRIS trisb
#define MX_UART_1_TX_PIN 2
#define MX_UART_1_RX_PORT portb
#define MX_UART_1_RX_TRIS trisb
#define MX_UART_1_RX_PIN 1
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_PSCA1
#define MX_PWM_PSCA4
#define MX_PWM_PSCA16
#define MX_PWM_1_PORT portb
#define MX_PWM_1_TRIS trisb
#define MX_PWM_1_PIN 3

//Fonksiyonlar
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif

//Dosya yap?land?rmas?

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

//Makro fonksiyon bildirileri


//De?i?ken bildirileri
#define FCV_TRUE (1)
#define FCV_FALSE (0)



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

//Makro uygulamas?



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


	//Interrupt initialization code
	option_reg = 0xC0;


	//Döngü
	//Döngü: ?ken 1
	while (1)
	{

		//Ç?kt?  
		//Ç?kt?  : 1 -> A0
		trisa = trisa & 0xFE;
		if ((1))
			porta = (porta & 0xFE) | 0x01;
		else
			porta = porta & 0xFE;

		//Gecikme   
		//Gecikme   : 1 s
		delay_s(1);

		//Ç?kt?  
		//Ç?kt?  : 0 -> A0
		trisa = trisa & 0xFE;
		if ((0))
			porta = (porta & 0xFE) | 0x01;
		else
			porta = porta & 0xFE;

		//Gecikme   
		//Gecikme   : 1 s
		delay_s(1);


	}

	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}
Oysa hepi topu code bu kadarcık bişey.
yukarıdaki bi çuval koda karşılık fcf dosyasını açtığınızda bunu görürsünüz.


Epsilon

Yani kaynak koda ulaşılamıyor.Gerçi kodlar karmaşık şeyler değildir ama olsaydı iyi olurdu.


M.Salim GÜLLÜCE

Alıntı yapılan: Epsilon - 31 Ekim 2019, 23:58:51Yani kaynak koda ulaşılamıyor.Gerçi kodlar karmaşık şeyler değildir ama olsaydı iyi olurdu.


Ama FCF nin kendisi kaynakki..
Sadece derleyicisini kurmanız gerek

Epsilon


M.Salim GÜLLÜCE

#5
C kod dökümanı şöyle
//************************************************************************************
//**  
//**  Source name:   C:\Users\Dede\Documents\FlowCode V8\Accu_Activator_Elektor_V2.fcfx
//**  Title:         
//**  Description:   
//**  Device:        PIC.16F.16F1847
//**  
//**  Generated by:  Flowcode v8.0.0.6
//**  Date:          Saturday, November 02, 2019 21:40:30
//**  Users:         1
//**  Registered to: 
//**  License key: *****
//**  
//**  http://www.matrixtsl.com
//**  
//************************************************************************************


#define MX_PIC

#define MX_CAL_PIC

#define MX_CLK_SPEED 16000000

#define FCP_NULL Unconnected_Port


#include <xc.h>
#include <math.h>
//Chip Configuration Settings
__PROG_CONFIG(0x1, 0x9A4);
__PROG_CONFIG(0x2, 0x1CFF);

/*========================================================================*\
   Use :Include the type definitions
\*========================================================================*/
#include "C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\internals.c"





/*========================================================================*\
   Use :panel
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define FCVsz_STRTEMP 5
#define FCV_FALSE (0)
#define FCV_TRUE (1)
MX_GLOBAL MX_UINT8 FCV_HB0;
MX_GLOBAL MX_UINT16 FCV_VACC_HIGH;
MX_GLOBAL MX_FLOAT FCV_FV0;
MX_GLOBAL MX_UINT8 FCV_TAQUISITION_USEC;
MX_GLOBAL MX_UINT8 FCV_II;
MX_GLOBAL MX_FLOAT FCV_FR_INTERNAL;
MX_GLOBAL MX_UINT8 FCV_LB3;
MX_GLOBAL MX_UINT8 FCV_LB2;
MX_GLOBAL MX_UINT8 FCV_LB1;
MX_GLOBAL MX_UINT16 FCV_V0_MIN;
MX_GLOBAL MX_UINT8 FCV_LED_NUMBER;
MX_GLOBAL MX_UINT8 FCV_TIMER0_COUNTER;
MX_GLOBAL MX_UINT8 FCV_LB0;
MX_GLOBAL MX_UINT16 FCV_VACC_LOW;
MX_GLOBAL MX_FLOAT FCV_TEMP_FLOAT;
MX_GLOBAL MX_FLOAT FCV_CURRENT;
MX_GLOBAL MX_UINT8 FCV_TDELAY_USEC;
MX_GLOBAL MX_UINT8 FCV_WAIT_SECONDS;
MX_GLOBAL MX_UINT8 FCV_CALCULATIONS_WITHOUT_ERROR;
MX_GLOBAL MX_FLOAT FCV_FVSHUNT_TOPSIDE;
MX_GLOBAL MX_UINT8 FCV_TEMP;
MX_GLOBAL MX_FLOAT FCV_FVSHUNT_BOTTOMSIDE;
MX_GLOBAL MX_FLOAT FCV_FV0_MIN;
MX_GLOBAL MX_UINT16 FCV_VLEAD_LOW;
MX_GLOBAL MX_UINT16 FCV_TEMP_Z;
MX_GLOBAL MX_UINT8 FCV_STATUSA5;
MX_GLOBAL MX_UINT8 FCV_RSHUNT_MOHM;
MX_GLOBAL MX_CHAR FCV_STRTEMP[FCVsz_STRTEMP];
MX_GLOBAL MX_UINT8 FCV_CHANGE_SECONDS;
MX_GLOBAL MX_UINT8 FCV_VOLTAGE_PART;
MX_GLOBAL MX_FLOAT FCV_RSHUNT;
MX_GLOBAL MX_UINT16 FCV_VLEAD_HIGH;
MX_GLOBAL MX_UINT8 FCV_ERRORNUMBER;
MX_GLOBAL MX_UINT8 FCV_SECONDS;
MX_GLOBAL MX_FLOAT FCV_CURRENT_MAX;
MX_GLOBAL MX_UINT8 FCV_ACTUAL_LED_NUMBER;
MX_GLOBAL MX_UINT8 FCV_PULSESENT;
MX_GLOBAL MX_UINT8 FCV_HB3;
MX_GLOBAL MX_UINT8 FCV_HB2;
MX_GLOBAL MX_UINT16 FCV_ADC_READING;
MX_GLOBAL MX_UINT8 FCV_LED_NUMBER_PREVIOUS;
MX_GLOBAL MX_FLOAT FCV_FV_TERMINAL;
MX_GLOBAL MX_UINT8 FCV_HB1;

void FCM_FloatTo4Char(MX_FLOAT FCL_FLOATTOPRINT);
void FCM_Test_Voltage_V0();
void FCM_Timer0_Interrupt();
void FCM_Dead_end();
MX_UINT8 FCM_TriState_Input_ports_B(MX_UINT8 FCL_B_PORT_NUMBER);
void FCM_Init();
MX_UINT16 FCM_Voltage_to_ADC(MX_FLOAT FCL_FV_IN);
MX_FLOAT FCM_ADC_to_Voltage(MX_UINT8 FCL_HIGH_BYTE, MX_UINT8 FCL_LOW_BYTE);
void FCM_TriState_Output_Ports_A(MX_UINT8 FCL_LED_NUM);
MX_UINT8 FCM_Current_and_Internal_resistance();
void FCM_ADC_AN1();

/*========================================================================*\
   Use :fcdhelper
       :Variable declarations
       :Macro function declarations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define ADC_3_MX_ADC_ACTIME 10
#define MX_ADC_REF 
#define ADC_3_MX_ADC_VREFVOL 500
#define MX_ADC_CHANNEL_1 
#define MX_ADC_TYPE_23 
#define ADC_3_MX_ADC_VREFOP 0
#define ADC_3_MX_ADC_CONVSP 5
#define MX_ADC_BITS_10 
#define ADC_3_MX_ADC_CHANNEL 1

#define FCV_0aae3_cal_adc__FALSE (0)
#define FCV_0aae3_cal_adc__TRUE (1)

void FC_CAL_ADC_Disable();
void FC_CAL_ADC_Enable(MX_UINT8 FCL_CHANNEL, MX_UINT8 FCL_CONV_SPEED, MX_UINT8 FCL_VREF, MX_UINT8 FCL_T_CHARGE);
MX_UINT16 FC_CAL_ADC_Sample(MX_UINT8 FCL_SAMPLE_MODE);

/*========================================================================*\
   Use :fcdhelper
       :Variable declarations
       :Macro function declarations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define ADC_2_MX_ADC_ACTIME 10
#define MX_ADC_REF 
#define ADC_2_MX_ADC_VREFVOL 500
#define MX_ADC_CHANNEL_0 
#define MX_ADC_TYPE_23 
#define ADC_2_MX_ADC_VREFOP 0
#define ADC_2_MX_ADC_CONVSP 5
#define MX_ADC_BITS_10 
#define ADC_2_MX_ADC_CHANNEL 0

#define FCV_0aae2_cal_adc__FALSE (0)
#define FCV_0aae2_cal_adc__TRUE (1)

void FC_CAL_ADC_Disable();
void FC_CAL_ADC_Enable(MX_UINT8 FCL_CHANNEL, MX_UINT8 FCL_CONV_SPEED, MX_UINT8 FCL_VREF, MX_UINT8 FCL_T_CHARGE);
MX_UINT16 FC_CAL_ADC_Sample(MX_UINT8 FCL_SAMPLE_MODE);

/*========================================================================*\
   Use :fcdhelper
       :Variable declarations
       :Macro function declarations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define ADC_1_MX_ADC_ACTIME 10
#define MX_ADC_REF 
#define ADC_1_MX_ADC_VREFVOL 500
#define MX_ADC_CHANNEL_6 
#define MX_ADC_TYPE_23 
#define ADC_1_MX_ADC_VREFOP 0
#define ADC_1_MX_ADC_CONVSP 5
#define MX_ADC_BITS_10 
#define ADC_1_MX_ADC_CHANNEL 6

#define FCV_0aae1_cal_adc__FALSE (0)
#define FCV_0aae1_cal_adc__TRUE (1)

void FC_CAL_ADC_Disable();
void FC_CAL_ADC_Enable(MX_UINT8 FCL_CHANNEL, MX_UINT8 FCL_CONV_SPEED, MX_UINT8 FCL_VREF, MX_UINT8 FCL_T_CHARGE);
MX_UINT16 FC_CAL_ADC_Sample(MX_UINT8 FCL_SAMPLE_MODE);

/*========================================================================*\
   Use :ctrl_lcd
       :Variable declarations
       :Macro function declarations
\*========================================================================*/

/*========================================================================*\
   Use :LCD
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
void FCD_04071_LCD__Clear();
void FCD_04071_LCD__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT);
void FCD_04071_LCD__PrintAscii(MX_UINT8 FCL_CHARACTER);
void FCD_04071_LCD__PrintNumber(MX_SINT16 FCL_NUMBER);
void FCD_04071_LCD__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7);
void FCD_04071_LCD__ClearLine(MX_UINT8 FCL_LINE);
void FCD_04071_LCD__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y);
void FCD_04071_LCD__Command(MX_UINT8 FCL_INSTRUCTION);
void FCD_04071_LCD__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT);
void FCD_04071_LCD__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION);
void FCD_04071_LCD__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE);
void FCD_04071_LCD__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER);
void FCD_04071_LCD__Start();

/*========================================================================*\
   Use :lcd_eb005
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
void FCD_0ad31_lcd_eb005__Clear();
void FCD_0ad31_lcd_eb005__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT);
void FCD_0ad31_lcd_eb005__PrintAscii(MX_UINT8 FCL_CHARACTER);
void FCD_0ad31_lcd_eb005__PrintNumber(MX_SINT16 FCL_NUMBER);
void FCD_0ad31_lcd_eb005__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7);
void FCD_0ad31_lcd_eb005__ClearLine(MX_UINT8 FCL_LINE);
void FCD_0ad31_lcd_eb005__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y);
void FCD_0ad31_lcd_eb005__Command(MX_UINT8 FCL_INSTRUCTION);
void FCD_0ad31_lcd_eb005__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT);
void FCD_0ad31_lcd_eb005__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION);
void FCD_0ad31_lcd_eb005__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE);
void FCD_0ad31_lcd_eb005__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER);
void FCD_0ad31_lcd_eb005__Start();

/*========================================================================*\
   Use :Include the chip adaption layer
\*========================================================================*/
#include "C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\includes.c"


/*========================================================================*\
   Use :fcdhelper
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :fcdhelper
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :fcdhelper
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :ctrl_lcd
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :LCD
       :Macro implementations
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Clears the entire contents of the display.
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Clear()
{




	FCD_04071_LCD__RawSend(0x01, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x02, 0);

	FCI_DELAYBYTE_MS(2);

}

/*=----------------------------------------------------------------------=*\
   Use :Breaks down a string of text and sends it to the LCD via the private RawSend(byte, mask) macro
       :
       :Parameters for macro PrintString:
       :  Text[20] : Enter the text or variable to print to the LCD
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT)
{
	//Local variable definitions
	MX_UINT8 FCL_IDX = (0x0);
	MX_UINT8 FCL_COUNT;


	FCL_COUNT = FCI_GETLENGTH(FCL_TEXT, FCLsz_TEXT);

	while (FCL_IDX < FCL_COUNT)
	{

		#if (0) // 0 > 0

		//Code has been optimised out by the pre-processor
		#else


			FCD_04071_LCD__RawSend(FCL_TEXT[FCL_IDX], 0x10);

		#endif

		FCL_IDX = FCL_IDX + 1;


	}


}

/*=----------------------------------------------------------------------=*\
   Use :Takes the ascii value for a character and prints the character
       :
       :Parameters for macro PrintAscii:
       :  character : Holds an ascii value.
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintAscii(MX_UINT8 FCL_CHARACTER)
{

	FCD_04071_LCD__RawSend(FCL_CHARACTER, 0x10);



}

/*=----------------------------------------------------------------------=*\
   Use :Based on v5 macro, will allow you to print a number. This is limited to a signed-INT, -32768 to 32767
       :
       :Parameters for macro PrintNumber:
       :  Number : Enter the number or variable to print to the LCD
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintNumber(MX_SINT16 FCL_NUMBER)
{
	//Local variable definitions
#define FCLsz_S 10
	MX_CHAR FCL_S[FCLsz_S];


	FCI_TOSTRING(FCL_NUMBER, FCL_S,10);

	FCD_04071_LCD__PrintString(FCL_S, FCLsz_S);

	//Local variable definitions
#undef FCLsz_S
}

/*=----------------------------------------------------------------------=*\
   Use :Modifies the internal memory of the LCD to allow for up to 8 customised characters to be created and stored in the device memory
       :
       :Parameters for macro RAMWrite:
       :  Index : Values 0 to 7
       :  d0 : MX_UINT8
       :  d1 : MX_UINT8
       :  d2 : MX_UINT8
       :  d3 : MX_UINT8
       :  d4 : MX_UINT8
       :  d5 : MX_UINT8
       :  d6 : MX_UINT8
       :  d7 : MX_UINT8
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7)
{

	FCD_04071_LCD__RawSend(64 + (FCL_INDEX << 3), 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(FCL_D0, 0x10);

	FCD_04071_LCD__RawSend(FCL_D1, 0x10);

	FCD_04071_LCD__RawSend(FCL_D2, 0x10);

	FCD_04071_LCD__RawSend(FCL_D3, 0x10);

	FCD_04071_LCD__RawSend(FCL_D4, 0x10);

	FCD_04071_LCD__RawSend(FCL_D5, 0x10);

	FCD_04071_LCD__RawSend(FCL_D6, 0x10);

	FCD_04071_LCD__RawSend(FCL_D7, 0x10);

	FCD_04071_LCD__Clear();

}

/*=----------------------------------------------------------------------=*\
   Use :Clears a single line on the display and then moves the cursor to the start of the line to allow you to start populating the line with data.
       :
       :Parameters for macro ClearLine:
       :  Line : The line to clear, zero being the first (top) line of the display
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__ClearLine(MX_UINT8 FCL_LINE)
{
	//Local variable definitions
	MX_UINT8 FCL_X;


	if (FCL_LINE < 2)
	{

		FCD_04071_LCD__Cursor(0, FCL_LINE);

		FCL_X = 0;

		while (FCL_X < 16)
		{


			FCD_04071_LCD__RawSend(' ', 0x10);

			FCL_X = FCL_X + 1;


		}

		FCD_04071_LCD__Cursor(0, FCL_LINE);

	// } else {

	}

}

/*=----------------------------------------------------------------------=*\
   Use :Moves the cursor on the LCD Display
       :
       :Parameters for macro Cursor:
       :  x : Set the cursor position in the X plane, 0 is the left most cell
       :  y : Set the cursor position in the Y plane, 0 is the top most cell
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y)
{



	#if (0) // 2 == 1

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	#if (1) // 2 == 2

		if (FCL_Y == 0)
		{

			FCL_Y = 0x80;

		} else {

			FCL_Y = 0xC0;

		}

	// #else

	//Code has been optimised out by the pre-processor
	#endif

	#if (0) // 2 == 4

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	FCD_04071_LCD__RawSend(FCL_Y + FCL_X, 0);

	FCI_DELAYBYTE_MS(2);

}

/*=----------------------------------------------------------------------=*\
   Use :Use this method/macro to send a specific command to the LCD. Refer to the Matrix Multimedia EB006 datasheet for a list of supported instructions. For Non-Matrix LCD's refer to the manufacturers datasheet.
       :
       :Parameters for macro Command:
       :  instruction : Send a defined command to the LCD Screen. See datasheet for supported commands.
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Command(MX_UINT8 FCL_INSTRUCTION)
{

	FCD_04071_LCD__RawSend(FCL_INSTRUCTION, 0);

	FCI_DELAYBYTE_MS(2);

}

/*=----------------------------------------------------------------------=*\
   Use :Will allow you to print a number up to 32-bits with signed or unsigned formatting.

       :Signed = -2147483648 to 2147483647

       :Unsigned = 0 to 4294967295
       :
       :Parameters for macro PrintFormattedNumber:
       :  Number : Enter the number or variable to print to the LCD
       :  Format : 0=Signed, 1=Unsigned
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT)
{
	//Local variable definitions
#define FCLsz_S 15
	MX_CHAR FCL_S[FCLsz_S];


	if (FCL_FORMAT == 1)
	{

		FCI_UTOS32(FCL_NUMBER, FCL_S,15);

	} else {

		FCI_ITOS32((MX_SINT32)(FCL_NUMBER), FCL_S,15);

	}

	FCD_04071_LCD__PrintString(FCL_S, FCLsz_S);

	//Local variable definitions
#undef FCLsz_S
}

/*=----------------------------------------------------------------------=*\
   Use :Scrolls the display left or right by a number of given positions.
       :
       :Parameters for macro ScrollDisplay:
       :  Position : Holds the number of positions to shift the display
       :  Direction : 0 = left, 1 = right
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION)
{
	//Local variable definitions
	MX_UINT8 FCL_CMD = (0x0);


	FCL_CMD = 0;

	if (FCL_DIRECTION == 0)
	{

		FCL_CMD = 0x18;


	} else {

		FCL_CMD = 0x1C;


	}

	if (FCL_CMD != 0 && FCL_POSITION != 0)
	{

		while (FCL_POSITION != 0)
		{

			FCD_04071_LCD__RawSend(FCL_CMD, 0);

			FCL_POSITION = FCL_POSITION - 1;


		}

	// } else {

	}

}

/*=----------------------------------------------------------------------=*\
   Use :Sends data to the LCD display
       :
       :Parameters for macro RawSend:
       :  data : The data byte to send to the LCD
       :  type : A boolean to indicate command type: true to write data, false to write a command
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE)
{
	//Local variable definitions
	MX_UINT8 FCL_NIBBLE;


	//Comment:
	//Output upper nibble of the byte

	#if (1) // 0 == 0

		SET_PORT_PIN(A, 3, 0);
		SET_PORT_PIN(B, 6, 0);
		SET_PORT_PIN(B, 0, 0);
		SET_PORT_PIN(B, 1, 0);
		SET_PORT_PIN(B, 2, 0);
		SET_PORT_PIN(A, 4, 0);

		#if (0)

		//Code has been optimised out by the pre-processor
		// #else

		#endif

		FCL_NIBBLE = (FCL_DATA >> 4);
		SET_PORT_PIN(A, 3, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 6, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 0, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 1, (FCL_NIBBLE & 0x01));

	// #else

	//Code has been optimised out by the pre-processor
	#endif

	//Comment:
	//Output byte to pins

	#if (0) // 0 == 1

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	//Comment:
	//Output byte to port

	#if (0) // 0 == 2

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	if (FCL_TYPE)
	{

		SET_PORT_PIN(B, 2, 1);

	// } else {

	}

	FCI_DELAYBYTE_US(100);

	//Comment:
	//Set Enable high, pause then set low

	//to acknowledge the data has been 
	//submitted.

	SET_PORT_PIN(A, 4, 1);

	FCI_DELAYBYTE_US(100);

	SET_PORT_PIN(A, 4, 0);

	FCI_DELAYBYTE_US(100);

	#if (1) // 0 == 0

		SET_PORT_PIN(A, 3, 0);
		SET_PORT_PIN(B, 6, 0);
		SET_PORT_PIN(B, 0, 0);
		SET_PORT_PIN(B, 1, 0);
		SET_PORT_PIN(B, 2, 0);

		FCL_NIBBLE = (FCL_DATA & 0xf);
		SET_PORT_PIN(A, 3, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 6, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 0, (FCL_NIBBLE & 0x01));
		FCL_NIBBLE = FCL_NIBBLE >> 1;
		SET_PORT_PIN(B, 1, (FCL_NIBBLE & 0x01));

		if (FCL_TYPE)
		{

			SET_PORT_PIN(B, 2, 1);

		// } else {

		}

		FCI_DELAYBYTE_US(100);

		SET_PORT_PIN(A, 4, 1);

		FCI_DELAYBYTE_US(100);

		SET_PORT_PIN(A, 4, 0);

		FCI_DELAYBYTE_US(100);

	// #else

	//Code has been optimised out by the pre-processor
	#endif

}

/*=----------------------------------------------------------------------=*\
   Use :Assigns a remap character allowing the PrintString function to automatically swap between pre-defined characters. 

       :The characters can be custom (in the range 0-9) or can point to an existing character in the LCD character map.
       :
       :Parameters for macro RemapCharacter:
       :  RemapIdx : Remap Index, Range: 0 to (Remap Characters - 1)
       :  SearchCharacter : Character to look for a replace
       :  ReplacementCharacter : New character value to use in place of the search character.
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER)
{

	#if (0) // 0 > 0

	//Code has been optimised out by the pre-processor
	// #else

	#endif

}

/*=----------------------------------------------------------------------=*\
   Use :Startup routine required by the hardware device.

       :Automatically clears the display after initialising.
\*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Start()
{




	#if (1) // 0 == 0

		SET_PORT_PIN(A, 3, 0);
		SET_PORT_PIN(B, 6, 0);
		SET_PORT_PIN(B, 0, 0);
		SET_PORT_PIN(B, 1, 0);
		SET_PORT_PIN(B, 2, 0);
		SET_PORT_PIN(A, 4, 0);

	// #else

	//Code has been optimised out by the pre-processor
	#endif

	#if (0) // 0 == 1

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	#if (0) // 0 == 2

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	#if (0)

	//Code has been optimised out by the pre-processor
	// #else

	#endif

	FCI_DELAYBYTE_MS(12);

	FCD_04071_LCD__RawSend(0x33, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x33, 0);

	FCI_DELAYBYTE_MS(2);

	#if (0) // 0 > 0

	//Code has been optimised out by the pre-processor
	#else

		FCD_04071_LCD__RawSend(0x32, 0);

		FCI_DELAYBYTE_MS(2);

		FCD_04071_LCD__RawSend(0x2c, 0);

	#endif

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x06, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x0c, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x01, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__RawSend(0x02, 0);

	FCI_DELAYBYTE_MS(2);

	FCD_04071_LCD__Clear();

	#if (0) // 0 > 0

	//Code has been optimised out by the pre-processor
	// #else

	#endif

}


/*========================================================================*\
   Use :lcd_eb005
       :Macro implementations
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Clears the entire contents of the display.
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__Clear()
{

	FCD_04071_LCD__Clear();

}

/*=----------------------------------------------------------------------=*\
   Use :Breaks down a string of text and sends it to the LCD via the private RawSend(byte, mask) macro
       :
       :Parameters for macro PrintString:
       :  Text[20] : Enter the text or variable to print to the LCD
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT)
{

	FCD_04071_LCD__PrintString(FCL_TEXT, FCLsz_TEXT);

}

/*=----------------------------------------------------------------------=*\
   Use :Takes the ascii value for a character and prints the character
       :
       :Parameters for macro PrintAscii:
       :  character : Holds an ascii value.
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__PrintAscii(MX_UINT8 FCL_CHARACTER)
{

	FCD_04071_LCD__PrintAscii(FCL_CHARACTER);

}

/*=----------------------------------------------------------------------=*\
   Use :Based on v5 macro, will allow you to print a number. This is limited to a signed-INT, -32768 to 32767
       :
       :Parameters for macro PrintNumber:
       :  Number : Enter the number or variable to print to the LCD
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__PrintNumber(MX_SINT16 FCL_NUMBER)
{

	FCD_04071_LCD__PrintNumber(FCL_NUMBER);

}

/*=----------------------------------------------------------------------=*\
   Use :Modifies the internal memory of the LCD to allow for up to 8 customised characters to be created and stored in the device memory
       :
       :Parameters for macro RAMWrite:
       :  Index : Values 0 to 7
       :  d0 : MX_UINT8
       :  d1 : MX_UINT8
       :  d2 : MX_UINT8
       :  d3 : MX_UINT8
       :  d4 : MX_UINT8
       :  d5 : MX_UINT8
       :  d6 : MX_UINT8
       :  d7 : MX_UINT8
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7)
{

	FCD_04071_LCD__RAMWrite(FCL_INDEX, FCL_D0, FCL_D1, FCL_D2, FCL_D3, FCL_D4, FCL_D5, FCL_D6, FCL_D7);

}

/*=----------------------------------------------------------------------=*\
   Use :Clears a single line on the display and then moves the cursor to the start of the line to allow you to start populating the line with data.
       :
       :Parameters for macro ClearLine:
       :  Line : The line to clear, zero being the first (top) line of the display
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__ClearLine(MX_UINT8 FCL_LINE)
{

	FCD_04071_LCD__ClearLine(FCL_LINE);

}

/*=----------------------------------------------------------------------=*\
   Use :Moves the cursor on the LCD Display
       :
       :Parameters for macro Cursor:
       :  x : Set the cursor position in the X plane, 0 is the left most cell
       :  y : Set the cursor position in the Y plane, 0 is the top most cell
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y)
{

	FCD_04071_LCD__Cursor(FCL_X, FCL_Y);

}

/*=----------------------------------------------------------------------=*\
   Use :Use this method/macro to send a specific command to the LCD. Refer to the Matrix Multimedia EB006 datasheet for a list of supported instructions. For Non-Matrix LCD's refer to the manufacturers datasheet.
       :
       :Parameters for macro Command:
       :  instruction : Send a defined command to the LCD Screen. See datasheet for supported commands.
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__Command(MX_UINT8 FCL_INSTRUCTION)
{

	FCD_04071_LCD__Command(FCL_INSTRUCTION);

}

/*=----------------------------------------------------------------------=*\
   Use :Will allow you to print a number up to 32-bits with signed or unsigned formatting.

       :Signed = -2147483648 to 2147483647

       :Unsigned = 0 to 4294967295
       :
       :Parameters for macro PrintFormattedNumber:
       :  Number : Enter the number or variable to print to the LCD
       :  Format : 0=Signed, 1=Unsigned
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT)
{

	FCD_04071_LCD__PrintFormattedNumber(FCL_NUMBER, FCL_FORMAT);

}

/*=----------------------------------------------------------------------=*\
   Use :Scrolls the display left or right by a number of given positions.
       :
       :Parameters for macro ScrollDisplay:
       :  Position : Holds the number of positions to shift the display
       :  Direction : 0 = left, 1 = right
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION)
{

	FCD_04071_LCD__ScrollDisplay(FCL_POSITION, FCL_DIRECTION);

}

/*=----------------------------------------------------------------------=*\
   Use :Sends data to the LCD display
       :
       :Parameters for macro RawSend:
       :  data : The data byte to send to the LCD
       :  type : A boolean to indicate command type: true to write data, false to write a command
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE)
{

	FCD_04071_LCD__RawSend(FCL_DATA, FCL_TYPE);

}

/*=----------------------------------------------------------------------=*\
   Use :Assigns a remap character allowing the PrintString function to automatically swap between pre-defined characters. 

       :The characters can be custom (in the range 0-9) or can point to an existing character in the LCD character map.
       :
       :Parameters for macro RemapCharacter:
       :  RemapIdx : Remap Index, Range: 0 to (Remap Characters - 1)
       :  SearchCharacter : Character to look for a replace
       :  ReplacementCharacter : New character value to use in place of the search character.
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER)
{

	FCD_04071_LCD__RemapCharacter(FCL_REMAPIDX, FCL_SEARCHCHARACTER, FCL_REPLACEMENTCHARACTER);

}

/*=----------------------------------------------------------------------=*\
   Use :Startup routine required by the hardware device.

       :Automatically clears the display after initialising.
\*=----------------------------------------------------------------------=*/
void FCD_0ad31_lcd_eb005__Start()
{

	FCD_04071_LCD__Start();

}


/*========================================================================*\
   Use :panel
       :Macro implementations
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Parameters for macro FloatTo4Char:
       :  FloatToPrint : MX_FLOAT
\*=----------------------------------------------------------------------=*/
void FCM_FloatTo4Char(MX_FLOAT FCL_FLOATTOPRINT)
{

	//Comment:
	//Transforms floating point variable into string with 4 digits

	// Name: Beslissing, Type: Decision: .FloatToPrint < 10000?
	if (flt_lt(FCL_FLOATTOPRINT, 10000))
	{

		// Name: Converse floating point to string, Type: Calculation:
		// Name: Converse floating point to string, Type:  StrTemp = FloatToString$ (.FloatToPrint)
		FCI_FLOAT_TO_STRING(FCL_FLOATTOPRINT, FCV_PRECISION, FCV_STRTEMP, FCVsz_STRTEMP);

		// Name: The first 4 characters, Type: Calculation:
		// Name: The first 4 characters, Type:  StrTemp = Left$ (StrTemp,4)
		FCI_LEFTSTRING(FCV_STRTEMP, FCVsz_STRTEMP, 4, FCV_STRTEMP,5);

	} else {

		// Name: Set string to max value, Type: Calculation:
		// Name: Set string to max value, Type:  StrTemp = "9999"
		FCI_SCOPY("9999",5, FCV_STRTEMP,FCVsz_STRTEMP);

	}

}

/*=----------------------------------------------------------------------=*\
   Use :
\*=----------------------------------------------------------------------=*/
void FCM_Test_Voltage_V0()
{

	//Comment:
	//Test V0 > V0_min and
	//Test V_ADC >1019 (out of range)

	// Name: Save LED#, Type: Calculation:
	// Name: Save LED#, Type:  LED_Number_Previous = LED_Number
	FCV_LED_NUMBER_PREVIOUS = FCV_LED_NUMBER;

	// Name: Reset Voltage, Type: Calculation:
	// Name: Reset Voltage, Type:  ADC_reading = 0
	FCV_ADC_READING = 0;

	// Name: Disable Timer0 , Type: Interrupt: Disable TMR0
	cr_bit(INTCON, TMR0IE);

	//Comment:
	//Test V0 is present? 
	//And is V0 not to high (out of range)?

	//Comment:
	//ADC  (AN0....AN11)
	//Register ADCON1 for PIC16F1847:
	//bit7:   ADFM=1 with the 2 bits of ADRESH right justified
	//bit6-4: ADCS =5 for Fosc/16 conversion clock
	//bit3:   x
	//bit2:   ADNREF= 0 with Vref- = Vss
	//bit1-0: ADPREF= 0 with Vref+ = Vdd
	//Resulting into:
	//ADCON1= 0xD0

	// Name: Set register ADCON1 (V0) for all ADC's, Type: C Code:
	adcon1= 0xD0;

	// Name: Set ports A0, A1 and B7 (ADC's) as analog input ports , Type: C Code:
	trisa=trisa | 0x03;  // set ports A0 and A1 as input
	trisb=trisb | 0x80;  // set B7 as input
	ansela = 0x03;       // set ports A0 and A1 as analog ports
	anselb = 0x80;       // set B7 as analog input

	// Name: Reset temp counter, Type: Calculation:
	// Name: Reset temp counter, Type:  Temp = 0
	// Name: Reset temp counter, Type:  LED_Number = 4 // green
	FCV_TEMP = 0;
	FCV_LED_NUMBER = 4;

	// Name: Until Vt >= minimum allowed voltage, Type: Loop: While ADC_reading >= V0_min
	while (!(FCV_ADC_READING >= FCV_V0_MIN))
	{

		// Name: Not the first time, Type: Decision: Temp > 0?
		if (FCV_TEMP > 0)
		{

			// Name: Flicker green LED  on/off, Type: Calculation:
			// Name: Flicker green LED  on/off, Type:  LED_Number = 4 - LED_Number
			FCV_LED_NUMBER = 4 - FCV_LED_NUMBER;

			// Name: Show green LED, Type: Call Macro: TriState_Output_Ports_A(LED_Number)
			FCM_TriState_Output_Ports_A(FCV_LED_NUMBER);

			// Name: Vertraging, Type: Delay: 400 ms
			FCI_DELAYINT_MS(400);

		// } else {

		}

		// Name: second loop, Type: Decision: Temp = 1?
		if (FCV_TEMP == 1)
		{

			//Comment:
			//Condition will be met only once
			//to prevent LCD flickering

			// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
			FCD_0ad31_lcd_eb005__Clear();

			// Name: show text, Type: Call Component Macro: lcd_eb005::PrintString("Waiting for")
			FCD_0ad31_lcd_eb005__PrintString("Waiting for", 12);

			// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
			FCD_0ad31_lcd_eb005__Cursor(0, 1);

			// Name: show text, Type: Call Component Macro: lcd_eb005::PrintString("Voltage >= ")
			FCD_0ad31_lcd_eb005__PrintString("Voltage >= ", 12);

			// Name: Floating to string, Type: Call Macro: FloatTo4Char(FV0_min)
			FCM_FloatTo4Char(FCV_FV0_MIN);

			// Name: show text, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
			FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

			// Name: show text, Type: Call Component Macro: lcd_eb005::PrintString("V")
			FCD_0ad31_lcd_eb005__PrintString("V", 2);

		// } else {

		}

		// Name: Read ACD AN1 (V0), Type: Call Macro: ADC_AN1()
		FCM_ADC_AN1();

		// Name: Voltage out of range (within 0.5%)?, Type: Decision: ADC_reading > 1019?
		if (FCV_ADC_READING > 1019)
		{

			// Name: Change maximum voltage into string, Type: Calculation:
			// Name: Change maximum voltage into string, Type:  Temp = 5 * Voltage_Part
			// Name: Change maximum voltage into string, Type:  Temp_Float = int2float (temp)
			FCV_TEMP = 5 * FCV_VOLTAGE_PART;
			FCV_TEMP_FLOAT = flt_fromi(FCV_TEMP);

			// Name: Output string, Type: Call Macro: FloatTo4Char(Temp_Float)
			FCM_FloatTo4Char(FCV_TEMP_FLOAT);

			// Name: High voltage error#, Type: Calculation:
			// Name: High voltage error#, Type:  ErrorNumber = 2
			FCV_ERRORNUMBER = 2;

			// Name: DEAD END , Type: Call Macro: Dead_end()
			FCM_Dead_end();

		// } else {

		}

		// Name: Increase temp counter, Type: Calculation:
		// Name: Increase temp counter, Type:  Temp = Temp + 1
		FCV_TEMP = FCV_TEMP + 1;

		// Name: Prevent overflow, Type: Decision: Temp = 255?
		if (FCV_TEMP == 255)
		{

			//Comment:
			//Temp=1 is reserved for the LCD output only

			// Name: Reset to 1, Type: Calculation:
			// Name: Reset to 1, Type:  Temp = 2
			FCV_TEMP = 2;

		// } else {

		}


	}

	//Comment:
	//If V was less then Vo_min for a while, 
	//it is possible that at certain moment
	//V becomes larger compared to V0_min. 
	//In that case V can change a little bit (unstable)
	//due to the fact that the contacts has not been set.
	//Therefor we test for stable input voltages.

	// Name: waited for input?, Type: Decision: Temp > 1?
	if (FCV_TEMP > 1)
	{

		//Comment:
		//Assumed is that after 1 seconds the input voltage is stable.

		// Name: Vertraging, Type: Delay: 1 s
		FCI_DELAYBYTE_S(1);

	// } else {

	}

	// Name: (Re)start Timer0 at 61 Hz, Type: Interrupt: Enable TMR0
	cr_bit(OPTION_REG,T0CS);
	st_bit(OPTION_REG,T0SE);
	OPTION_REG = (OPTION_REG & 0xF0) | 0x07;
	st_bit(INTCON,GIE);
	st_bit(INTCON, TMR0IE);

	// Name: set previous LED, Type: Call Macro: TriState_Output_Ports_A(LED_Number_Previous)
	FCM_TriState_Output_Ports_A(FCV_LED_NUMBER_PREVIOUS);

}

/*=----------------------------------------------------------------------=*\
   Use :
\*=----------------------------------------------------------------------=*/
void FCM_Timer0_Interrupt()
{

	//Comment:
	//61 Hz timer, used as count down counter

	// Name: counter=0, Type: Decision: Timer0_Counter = 0?
	if (FCV_TIMER0_COUNTER == 0)
	{

		// Name: Reset counter en decrease seconds, Type: Calculation:
		// Name: Reset counter en decrease seconds, Type:  Timer0_Counter = 61 // 61 Hz timer0
		// Name: Reset counter en decrease seconds, Type:  Seconds = Seconds - 1
		// Name: Reset counter en decrease seconds, Type:  Change_seconds = 1
		FCV_TIMER0_COUNTER = 61;
		FCV_SECONDS = FCV_SECONDS - 1;
		FCV_CHANGE_SECONDS = 1;

	} else {

		// Name: decrease counter, Type: Calculation:
		// Name: decrease counter, Type:  Timer0_Counter = Timer0_Counter - 1
		FCV_TIMER0_COUNTER = FCV_TIMER0_COUNTER - 1;

	}

}

/*=----------------------------------------------------------------------=*\
   Use :
\*=----------------------------------------------------------------------=*/
void FCM_Dead_end()
{

	//Comment:
	//DEAD END 
	//With errornumber 1 or 2 a real dead end.
	//Errornumber=3 only a warning
	//Remark: Low voltage/current will be checked in Test_Voltage_V0  and not in dead_end.
	//Error#=0 default value.

	// Name: Reset gate MOSFET, Type: Output: 0 -> B3
	SET_PORT_PIN(B,3,(0));

	//Comment:
	//For safety 2 times reset of the gate

	// Name: Reset gate MOSFET, Type: Output: 0 -> B3
	SET_PORT_PIN(B,3,(0));

	//Comment:
	//Disabling comparator on A2 (NTC) has been removed 
	//Not used anymore

	// Name: Stop Timer0 Interrupts, Type: Interrupt: Disable TMR0
	cr_bit(INTCON, TMR0IE);

	//Comment:
	//Start LCD has been added here, incase there is directly
	//at the startup an comparator interrupt, before passing
	//the first LCD START in the Init macro.

	// Name: Start LCD, Type: Call Component Macro: lcd_eb005::Start()
	FCD_0ad31_lcd_eb005__Start();

	// Name: Vertraging, Type: Delay: 100 ms
	FCI_DELAYBYTE_MS(100);

	// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
	FCD_0ad31_lcd_eb005__Clear();

	// Name: Special cases, Type: Switch: ErrorNumber?
	switch (FCV_ERRORNUMBER)
	{
		case 1:
		{
			//Comment:
			//High current dead end

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("Current > 250")
			FCD_0ad31_lcd_eb005__PrintString("Current > 250", 14);

			// Name: Set paramters, Type: Calculation:
			// Name: Set paramters, Type:  LED_Number = 2 // red
			// Name: Set paramters, Type:  temp_Z = 100 // msec  fast flickering
			FCV_LED_NUMBER = 2;
			FCV_TEMP_Z = 100;

			break;
		}
		case 2:
		{
			//Comment:
			//High Voltage dead end

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("Voltage > ")
			FCD_0ad31_lcd_eb005__PrintString("Voltage > ", 11);

			// Name: Show maximum voltage of the range, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
			FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

			// Name: Set paramters, Type: Calculation:
			// Name: Set paramters, Type:  LED_Number = 3 // orange
			// Name: Set paramters, Type:  temp_Z = 100 // msec  fast flickering
			FCV_LED_NUMBER = 3;
			FCV_TEMP_Z = 100;

			break;
		}
		case 3:
		{
			//Comment:
			//Possible open circuit

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("Probably open")
			FCD_0ad31_lcd_eb005__PrintString("Probably open", 14);

			// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
			FCD_0ad31_lcd_eb005__Cursor(0, 1);

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("circuit")
			FCD_0ad31_lcd_eb005__PrintString("circuit", 8);

			// Name: Set paramters, Type: Calculation:
			// Name: Set paramters, Type:  LED_Number = 4 // green
			// Name: Set paramters, Type:  // flickering rate will be 1 seconds in the main macro
			FCV_LED_NUMBER = 4;

			break;
		}
		// default:

	}

	// Name: Vertraging, Type: Delay: 1 s
	FCI_DELAYBYTE_S(1);

	// Name: Error# 1, 2, Type: Decision: (ErrorNumber = 1) OR (ErrorNumber = 2)?
	if ((FCV_ERRORNUMBER == 1) | (FCV_ERRORNUMBER == 2))
	{

		// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
		FCD_0ad31_lcd_eb005__Cursor(0, 1);

		// Name: show text, Type: Call Component Macro: lcd_eb005::PrintString("------RESTART-----")
		FCD_0ad31_lcd_eb005__PrintString("------RESTART-----", 19);

	} else {

		//Comment:
		//Skip DEAD END
		//Warning only

	}

	// Name: Endless loop for error# 1 and 2, Type: Loop: While (ErrorNumber = 0) OR (ErrorNumber > 2)
	while (1)
	{

		//Comment:
		//LED#:
		//0= all off
		//1= blue
		//2= red
		//3= orange
		//4= green

		// Name: Show LED, Type: Call Macro: TriState_Output_Ports_A(LED_Number)
		FCM_TriState_Output_Ports_A(FCV_LED_NUMBER);

		// Name: Vertraging, Type: Delay: Temp_Z ms
		FCI_DELAYINT_MS(FCV_TEMP_Z);

		// Name: LEDs off, Type: Call Macro: TriState_Output_Ports_A(0)
		FCM_TriState_Output_Ports_A(0);

		// Name: Vertraging, Type: Delay: Temp_Z ms
		FCI_DELAYINT_MS(FCV_TEMP_Z);


		if (((FCV_ERRORNUMBER == 0) | (FCV_ERRORNUMBER > 2)) != 0) break;
	}

	// Name: Vertraging, Type: Delay: 300 ms
	FCI_DELAYINT_MS(300);

	// Name: Enable Timer0 on 61 Hz, Type: Interrupt: Enable TMR0
	cr_bit(OPTION_REG,T0CS);
	st_bit(OPTION_REG,T0SE);
	OPTION_REG = (OPTION_REG & 0xF0) | 0x07;
	st_bit(INTCON,GIE);
	st_bit(INTCON, TMR0IE);

	// Name: Reset error# to default value, Type: Calculation:
	// Name: Reset error# to default value, Type:  ErrorNumber = 0
	FCV_ERRORNUMBER = 0;

}

/*=----------------------------------------------------------------------=*\
   Use :Parameters for macro TriState_Input_ports_B:
       :  B_Port_Number : MX_UINT8
       :
       :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCM_TriState_Input_ports_B(MX_UINT8 FCL_B_PORT_NUMBER)
{
	//Local variable definitions
	MX_UINT8 FCL_IN_LOW;
	MX_UINT8 FCL_IN_HIGH;
	MX_UINT8 FCR_RETVAL;


	//Comment:
	//Read the status of portB i with i=0...7.

	//Comment:
	//WARNING!!!!!!
	//Requirements for the port is equal for output-ports.
	//That means there should always an applicale resistance between the port
	//and Vss or Vdd. (recommended 10k).
	//This input may NEVER be used on B3

	// Name: B3 not allowed, Type: Decision: .B_Port_Number <> 3?
	if (FCL_B_PORT_NUMBER != 3)
	{

		//Comment:
		//Get and Set:
		//   Type: M= Mask methode
		//   Port: B
		//   Mask:  (1<<Port#)
		//   Shift: Port#
		//Set only:
		//   Source: 0x00 (low) or 0xFF (high)

		// Name: Set Output-Port Bi to low (0), Type: C Code:
		FCP_SET(M,B,(1<<FCL_B_PORT_NUMBER),FCL_B_PORT_NUMBER,(0x00));

		//Comment:
		//Small delay is necessary to 'power' the output
		//If to small the next ready of the input can be 
		//found to be not correct

		// Name: Vertraging, Type: Delay: 10 us
		FCI_DELAYBYTE_US(10);

		// Name: Get status Port Bi, Type: C Code:
		FCL_IN_LOW=FCP_GET(M,B,(1<<FCL_B_PORT_NUMBER),FCL_B_PORT_NUMBER);

		// Name: Set Output-Port Bi to high (1), Type: C Code:
		FCP_SET(M,B,(1<<FCL_B_PORT_NUMBER),FCL_B_PORT_NUMBER,(0xFF));

		// Name: Vertraging, Type: Delay: 10 us
		FCI_DELAYBYTE_US(10);

		// Name: Get status Port Bi, Type: C Code:
		FCL_IN_HIGH=FCP_GET(M,B,(1<<FCL_B_PORT_NUMBER),FCL_B_PORT_NUMBER);

		//Comment:
		//Return 0=low, 1=open or 2=high for the 
		//B-port B_Port_Number

		// Name: Calculate status Bi (0=low,1=open, 2= high), Type: Calculation:
		// Name: Calculate status Bi (0=low,1=open, 2= high), Type:  .Return = .IN_low + .IN_high
		FCR_RETVAL = FCL_IN_LOW + FCL_IN_HIGH;

	} else {

		// Name: Software error# , Type: Calculation:
		// Name: Software error# , Type:  ErrorNumber = 0
		FCV_ERRORNUMBER = 0;

		// Name: Stop input on B3, Type: Call Macro: Dead_end()
		FCM_Dead_end();

	}

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :
\*=----------------------------------------------------------------------=*/
void FCM_Init()
{

	//Comment:
	//B3 is output to MOSFET gate which activates the SHUNT.
	//DO NOT USE this port for other reasons!

	//Comment:
	//Tristate Input on B6 is not used. 
	//Open for future extensions.
	//But for safety reasons connect 10K in serie to B6

	//Comment:
	//STEPS:
	//1. Reset B3 
	//5. Prepare comparator on A2. This checks high temperature of the shunt
	//   and start NTC temperature control
	//2. Set default values
	//3. Start Timer0 at 61 Hz, as countdown counter between pulses
	//4. Start blicking LEDs showing progress of the program
	//6. Show LCD with start text
	//7. Read status input B4 (shunt resistance) and B5 (Division Voltages)
	//   and in case B5 low: A5 input low will change 
	//   the shunt activation each 10 seconds
	//8. Set ADC start settings

	//Comment:
	//1. Reset B3 

	// Name: Prevent Shunt on. Set B3  low!, Type: Output: 0 -> B3
	SET_PORT_PIN(B,3,(0));

	//Comment:
	//5.Comparator on A2 has been removed to detect the NTC temperature
	//Error_number was 9 (not used anymore)

	// Name: Prevent Shunt on. Set B3  low! (for safety a second time), Type: Output: 0 -> B3
	SET_PORT_PIN(B,3,(0));

	//Comment:
	//2. Set default values

	// Name: Set default values, Type: Calculation:
	// Name: Set default values, Type:  FVshunt_bottomside = 0.0
	// Name: Set default values, Type:  FVshunt_topside = 0.0
	// Name: Set default values, Type:  Tdelay_usec = 10
	// Name: Set default values, Type:  // Tc = 1.4 usec with 10k external load
	// Name: Set default values, Type:  // Tc = 8.2 usec with 100k extrenal load
	// Name: Set default values, Type:  Taquisition_usec = 11 // = 2 + Tc + 0.05 (T-25 oC) usec
	// Name: Set default values, Type:  ErrorNumber = 0 // default value
	// Name: Set default values, Type:  Seconds = 30 // default start time of the count down counter
	// Name: Set default values, Type:  Timer0_counter = 1 // must >0
	// Name: Set default values, Type:  Wait_seconds = 30 // activate shunt each 30 seconds
	// Name: Set default values, Type:  Rshunt_mOhm = 50 // 50 mOhm shunt
	// Name: Set default values, Type:  Current_max = 250 // Amp. Max pulse current 280A for diode SR1203/4 and 250A for MOSFET IRFB7828
	// Name: Set default values, Type:  //Remark: Set max. current also in Dead_end macro
	// Name: Set default values, Type:  FV0_min = 0.2 // volt. Lowest voltage allowed
	FCV_FVSHUNT_BOTTOMSIDE = 0.0;
	FCV_FVSHUNT_TOPSIDE = 0.0;
	FCV_TDELAY_USEC = 10;
	FCV_TAQUISITION_USEC = 11;
	FCV_ERRORNUMBER = 0;
	FCV_SECONDS = 30;
	FCV_TIMER0_COUNTER = 1;
	FCV_WAIT_SECONDS = 30;
	FCV_RSHUNT_MOHM = 50;
	FCV_CURRENT_MAX = 250;
	FCV_FV0_MIN = 0.2;

	// Name: Start LCD, Type: Call Component Macro: lcd_eb005::Start()
	FCD_0ad31_lcd_eb005__Start();

	//Comment:
	//During setup this will shows the scrollings LEDs each second

	//Comment:
	//3. Start Timer0 at 61 Hz, as countdown counter between pulses

	// Name: Interrupt, Type: Interrupt: Enable TMR0
	cr_bit(OPTION_REG,T0CS);
	st_bit(OPTION_REG,T0SE);
	OPTION_REG = (OPTION_REG & 0xF0) | 0x07;
	st_bit(INTCON,GIE);
	st_bit(INTCON, TMR0IE);

	//Comment:
	//4. Start red LEDs showing progress of the program

	// Name: Show red LED, Type: Call Macro: TriState_Output_Ports_A(2)
	FCM_TriState_Output_Ports_A(2);

	//Comment:
	//6. Show LCD with start text

	// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
	FCD_0ad31_lcd_eb005__Clear();

	// Name: print text, Type: Call Component Macro: lcd_eb005::PrintString(" E L E K T O R ")
	FCD_0ad31_lcd_eb005__PrintString(" E L E K T O R ", 16);

	// Name: Vertraging, Type: Delay: 1 s
	FCI_DELAYBYTE_S(1);

	// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
	FCD_0ad31_lcd_eb005__Clear();

	// Name: print text, Type: Call Component Macro: lcd_eb005::PrintString("Internal")
	FCD_0ad31_lcd_eb005__PrintString("Internal", 9);

	// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
	FCD_0ad31_lcd_eb005__Cursor(0, 1);

	//Comment:
	//Version #

	// Name: print text, Type: Call Component Macro: lcd_eb005::PrintString("resistance V2")
	FCD_0ad31_lcd_eb005__PrintString("resistance V2", 14);

	// Name: Vertraging, Type: Delay: 2 s
	FCI_DELAYBYTE_S(2);

	// Name: Show orange LED, Type: Call Macro: TriState_Output_Ports_A(3)
	FCM_TriState_Output_Ports_A(3);

	//Comment:
	//Tristate input:
	//-Set output 0, 
	//-read input status, 
	//-set output 1, 
	//-read input status
	//The sum status will be:
	//0 is B3=0            Rshunt=50 mOhm
	//1 if B3 undefined    Rshunt= 100 mOhm
	//2 if B3=1            Rshunt= 220 mOhm

	// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
	FCD_0ad31_lcd_eb005__Clear();

	//Comment:
	//7. Read status input B4 (shunt resistance), B5 (Voltage ratios) and A5 (Offtime)

	//Comment:
	//Input for different shunts has been removed 
	//and replaced by default value of 50 mOhm

	// Name: Calculate Rshunt in Ohm's, Type: Calculation:
	// Name: Calculate Rshunt in Ohm's, Type:  Rshunt = int2float (Rshunt_mOhm)
	// Name: Calculate Rshunt in Ohm's, Type:  Rshunt = fdiv (Rshunt,1000.0)
	FCV_RSHUNT = flt_fromi(FCV_RSHUNT_MOHM);
	FCV_RSHUNT = flt_div(FCV_RSHUNT, 1000.0);

	// Name: Get tri-state status B5 (Conn5B) Vratio, Type: Call Macro: Temp=TriState_Input_ports_B(5)
	FCV_TEMP = FCM_TriState_Input_ports_B(5);

	// Name: B5 low (Conn5B) Ratio valtage Vin/Vout, Type: Switch: Temp?
	switch (FCV_TEMP)
	{
		case 1:
		{
			//Comment:
			//B5 open

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("0.2 / 5.5-30V")
			FCD_0ad31_lcd_eb005__PrintString("0.2 / 5.5-30V", 14);

			// Name: Vadc= V/6, Type: Calculation:
			// Name: Vadc= V/6, Type:  Voltage_Part = 6
			FCV_VOLTAGE_PART = 6;

			//Comment:
			//Green, Orange and Red LED's:
			//24V Lead accumulators (6 cells) have in good conditions
			//a voltage of 25-25.8 Volt
			//low condition between 23.8-25 Volt
			//bad condition below 23.8 Volt
			//Vhigh= 25V 
			//Vlow= 23.8 V 
			//24V accumulators will never get a voltage > 30 Volt
			//Vmax = 30V 

			// Name: Set values accumulator , Type: Calculation:
			// Name: Set values accumulator , Type:  FVshunt_bottomside = 23.8 // temp variable for Vlow
			// Name: Set values accumulator , Type:  FVshunt_topside = 25.0 // temp variable for Vhigh
			FCV_FVSHUNT_BOTTOMSIDE = 23.8;
			FCV_FVSHUNT_TOPSIDE = 25.0;

			break;
		}
		case 2:
		{
			//Comment:
			//B5 high

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString(" 0.2-10V")
			FCD_0ad31_lcd_eb005__PrintString(" 0.2-10V", 9);

			// Name: Vadc= V/2, Type: Calculation:
			// Name: Vadc= V/2, Type:  Voltage_Part = 2
			FCV_VOLTAGE_PART = 2;

			//Comment:
			//Green, Orange and Red LED's:
			//Lead accumulators (3 cells) have in good conditions
			//a voltage of 6.25-6.45 Volt
			//low condition between 5.95-6.25 Volt
			//bad condition below <5.95 Volt
			//Vhigh= 6.25V 
			//Vlow= 5.95V 
			//6V accumulators will never get a voltage > 7.5 Volt
			//Vmax = 7.5V 

			// Name: Set values accumulator , Type: Calculation:
			// Name: Set values accumulator , Type:  FVshunt_bottomside = 5.95 // temp variable for Vlow
			// Name: Set values accumulator , Type:  FVshunt_topside = 6.25 // temp variable for Vhigh
			FCV_FVSHUNT_BOTTOMSIDE = 5.95;
			FCV_FVSHUNT_TOPSIDE = 6.25;

			break;
		}
		default:
		{
			//Comment:
			//B5 low

			// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("0.2 / 5.5-20V")
			FCD_0ad31_lcd_eb005__PrintString("0.2 / 5.5-20V", 14);

			// Name: Vadc= V/4, Type: Calculation:
			// Name: Vadc= V/4, Type:  Voltage_Part = 4
			FCV_VOLTAGE_PART = 4;

			//Comment:
			//Green, Orange and Red LED's:
			//Lead accumulators (12 cells) have in good conditions
			//a voltage of 12.5-12.9 Volt
			//low condition between 11.9-12.5 Volt
			//bad condition below 11.9 Volt
			//Vhigh= 12.5V 
			//Vlow= 11.9V 
			//12V accumulators will never get a voltage > 15 Volt
			//Vmax = 15V 

			// Name: Set values accumulator , Type: Calculation:
			// Name: Set values accumulator , Type:  FVshunt_bottomside = 11.9 // temp variable for Vlow
			// Name: Set values accumulator , Type:  FVshunt_topside = 12.5 // temp variable for Vhigh
			FCV_FVSHUNT_BOTTOMSIDE = 11.9;
			FCV_FVSHUNT_TOPSIDE = 12.5;

		}
	}

	//Comment:
	//Offtime on A5
	//High/Open: 30 sec
	//Low: 10 sec.

	// Name: Get status A5 (Conn5C) Offtime, Type: Input: A5 -> StatusA5
	FCV_STATUSA5 = GET_PORT_PIN(A,5);

	// Name: Input A5 high (Conn5C)?, Type: Decision: StatusA5 = 1?
	if (FCV_STATUSA5 == 1)
	{

		//Comment:
		//Default 30 seconds offtime

	} else {

		// Name: (Re)set shunt activation frequency, Type: Calculation:
		// Name: (Re)set shunt activation frequency, Type:  Wait_seconds = 10 // activate shunt each 10 seconds
		FCV_WAIT_SECONDS = 10;

	}

	// Name: Change Voltage FV0_min into V0_min ADC units, Type: Call Macro: V0_min=Voltage_to_ADC(FV0_min)
	FCV_V0_MIN = FCM_Voltage_to_ADC(FCV_FV0_MIN);

	// Name: Change Voltage FVshunt_bottomside into Vacc_low with ADC units, Type: Call Macro: Vacc_low=Voltage_to_ADC(FVshunt_bottomside)
	FCV_VACC_LOW = FCM_Voltage_to_ADC(FCV_FVSHUNT_BOTTOMSIDE);

	// Name: Change Voltage FVshunt_topside into Vacc_high with ADC units, Type: Call Macro: Vacc_high=Voltage_to_ADC(FVshunt_topside)
	FCV_VACC_HIGH = FCM_Voltage_to_ADC(FCV_FVSHUNT_TOPSIDE);

	// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
	FCD_0ad31_lcd_eb005__Cursor(0, 1);

	// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("Rshunt = ")
	FCD_0ad31_lcd_eb005__PrintString("Rshunt = ", 10);

	// Name: Show Rshunt, Type: Call Component Macro: lcd_eb005::PrintNumber(Rshunt_mOhm)
	FCD_0ad31_lcd_eb005__PrintNumber(FCV_RSHUNT_MOHM);

	// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString(" m")
	FCD_0ad31_lcd_eb005__PrintString(" m", 3);

	// Name: Print greek omega for Ohm, Type: Call Component Macro: lcd_eb005::PrintAscii(0xF4)
	FCD_0ad31_lcd_eb005__PrintAscii(0xF4);

	// Name: Vertraging, Type: Delay: 2 s
	FCI_DELAYBYTE_S(2);

	// Name: Show green LED, Type: Call Macro: TriState_Output_Ports_A(4)
	FCM_TriState_Output_Ports_A(4);

	// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
	FCD_0ad31_lcd_eb005__Clear();

	// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString("Offtime ")
	FCD_0ad31_lcd_eb005__PrintString("Offtime ", 9);

	// Name: Show number, Type: Call Component Macro: lcd_eb005::PrintNumber(Wait_seconds)
	FCD_0ad31_lcd_eb005__PrintNumber(FCV_WAIT_SECONDS);

	// Name: Show text, Type: Call Component Macro: lcd_eb005::PrintString(" sec")
	FCD_0ad31_lcd_eb005__PrintString(" sec", 5);

	// Name: Vertraging, Type: Delay: 2 s
	FCI_DELAYBYTE_S(2);

	// Name: All LEDs off, Type: Call Macro: TriState_Output_Ports_A(0)
	FCM_TriState_Output_Ports_A(0);

	//Comment:
	//8. Set ADC start settings

	//Comment:
	//ADC  (AN0....AN11)
	//Register ADCON1 for PIC16F1847:
	//bit7:   ADFM=1 with the 2 bits of ADRESH right justified
	//bit6-4: ADCS =5 for Fosc/16 conversion clock
	//bit3:   x
	//bit2:   ADNREF= 0 with Vref- = Vss
	//bit1-0: ADPREF= 0 with Vref+ = Vdd
	//Resulting into:
	//ADCON1= 0xD0

	// Name: Set register ADCON1 for all ADC's (V0 and Vt), Type: C Code:
	adcon1= 0xD0;

	// Name: Set ports A0, A1 and B7 as analog input ports, Type: C Code:
	trisa=trisa | 0x03;  // set ports A0 and A1 as input
	trisb=trisb | 0x80;  // set B7 as input
	ansela = ansela|0x03;       // set ports A0 and A1 as analog ports
	anselb = anselb|0x80;       // set B7 as analog input

}

/*=----------------------------------------------------------------------=*\
   Use :Parameters for macro Voltage_to_ADC:
       :  FV_in : MX_FLOAT
       :
       :Returns : MX_UINT16
\*=----------------------------------------------------------------------=*/
MX_UINT16 FCM_Voltage_to_ADC(MX_FLOAT FCL_FV_IN)
{
	//Local variable definitions
	MX_FLOAT FCL_TEMP;
	MX_UINT16 FCR_RETVAL;


	// Name: Calculate FV_in in ADC units (max 1024), Type: Calculation:
	// Name: Calculate FV_in in ADC units (max 1024), Type:  .Temp = fmul (.FV_in,1024.0)
	// Name: Calculate FV_in in ADC units (max 1024), Type:  .Return = float2int (.Temp)
	// Name: Calculate FV_in in ADC units (max 1024), Type:  .Return = .Return / (5 * Voltage_Part)
	FCL_TEMP = flt_mul(FCL_FV_IN, 1024.0);
	FCR_RETVAL = flt_toi(FCL_TEMP);
	FCR_RETVAL = FCR_RETVAL / (5 * FCV_VOLTAGE_PART);

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Parameters for macro ADC_to_Voltage:
       :  High_Byte : MX_UINT8
       :  Low_Byte : MX_UINT8
       :
       :Returns : MX_FLOAT
\*=----------------------------------------------------------------------=*/
MX_FLOAT FCM_ADC_to_Voltage(MX_UINT8 FCL_HIGH_BYTE, MX_UINT8 FCL_LOW_BYTE)
{
	//Local variable definitions
	MX_FLOAT FCR_RETVAL;


	//Comment:
	//Transforms ADC reading into real voltages
	//Register ADCON1 for PIC16F1847:
	//bit7:   ADFM=1 with the 2 bits of ADRESH right justified

	// Name: Scale V without shunt, Type: Calculation:
	// Name: Scale V without shunt, Type:  ADC_reading = .High_Byte & 0x03 // only last 2 bits
	// Name: Scale V without shunt, Type:  ADC_reading = (ADC_reading << 8)
	// Name: Scale V without shunt, Type:  ADC_reading = ADC_reading + .Low_Byte
	// Name: Scale V without shunt, Type:  Temp_Z = ADC_reading * 5 //  5 volt
	// Name: Scale V without shunt, Type:  Temp_Z = Temp_Z * Voltage_Part // V= Voltage_part* Vadc
	// Name: Scale V without shunt, Type:  .return = int2float (Temp_Z)
	// Name: Scale V without shunt, Type:  .return = fdiv (.return,1024.0)
	FCV_ADC_READING = FCL_HIGH_BYTE & 0x03;
	FCV_ADC_READING = (FCV_ADC_READING << 8);
	FCV_ADC_READING = FCV_ADC_READING + FCL_LOW_BYTE;
	FCV_TEMP_Z = FCV_ADC_READING * 5;
	FCV_TEMP_Z = FCV_TEMP_Z * FCV_VOLTAGE_PART;
	FCR_RETVAL = flt_fromi(FCV_TEMP_Z);
	FCR_RETVAL = flt_div(FCR_RETVAL, 1024.0);

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Parameters for macro TriState_Output_Ports_A:
       :  LED_num : MX_UINT8
\*=----------------------------------------------------------------------=*/
void FCM_TriState_Output_Ports_A(MX_UINT8 FCL_LED_NUM)
{
	//Local variable definitions
	MX_UINT8 FCL_TEMP_INPUT;


	//Comment:
	//LED's 1 until 4 with tristate output of ports A6 and A7.
	//LED1 and 2 port A7 and 
	//LED3 and 4 port A6.
	//Low:  Output=0
	//Open: INPUT
	//High: Output=1

	// Name: A6 open  LED3 and LED4 off, Type: Input: A6 -> .Temp_Input
	FCL_TEMP_INPUT = GET_PORT_PIN(A,6);

	// Name: A7 open LED1 and LED2 off, Type: Input: A7 -> .Temp_Input
	FCL_TEMP_INPUT = GET_PORT_PIN(A,7);

	// Name: Schakel, Type: Switch: .LED_num?
	switch (FCL_LED_NUM)
	{
		case 1:
		{
			//Comment:
			//LED1 on
			//white/blue

			// Name: A7 low, LED1 on and LED2 off, Type: Output: 0 -> A7
			SET_PORT_PIN(A,7,(0));

			break;
		}
		case 2:
		{
			//Comment:
			//LED2 on
			//red

			// Name: A7 high, LED1 off and LED2 on, Type: Output: 1 -> A7
			SET_PORT_PIN(A,7,(1));

			break;
		}
		case 3:
		{
			//Comment:
			//LED3 on
			//orange

			// Name: A6 low, LED3 on and LED4 off, Type: Output: 0 -> A6
			SET_PORT_PIN(A,6,(0));

			break;
		}
		case 4:
		{
			//Comment:
			//LED4 on
			//green

			// Name: A6 high LED3 off and LED4 on, Type: Output: 1 -> A6
			SET_PORT_PIN(A,6,(1));

			break;
		}
		default:
		{
			//Comment:
			//All LED's off

		}
	}

}

/*=----------------------------------------------------------------------=*\
   Use :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCM_Current_and_Internal_resistance()
{
	//Local variable definitions
	MX_UINT8 FCR_RETVAL;


	//Comment:
	//-Calculate Ri in case current <>0, else stop
	//-Test on correct current (< maximum current)
	//-Test on realistic Ri values

	// Name: Calculate the shunt current, Type: Calculation:
	// Name: Calculate the shunt current, Type:  Current = fsub (FVshunt_topside,FVshunt_bottomside)
	// Name: Calculate the shunt current, Type:  Current = fdiv (Current,Rshunt) // Pay attention: Rshunt should be not equal 0
	FCV_CURRENT = flt_sub(FCV_FVSHUNT_TOPSIDE, FCV_FVSHUNT_BOTTOMSIDE);
	FCV_CURRENT = flt_div(FCV_CURRENT, FCV_RSHUNT);

	// Name: Current value as string, Type: Call Macro: FloatTo4Char(Current)
	FCM_FloatTo4Char(FCV_CURRENT);

	// Name: No current (below 100 mA or negative)?, Type: Decision: Current < 0.1?
	if (flt_lt(FCV_CURRENT, 0.1))
	{

		//Comment:
		//A negative current is possible if Vbat- is 
		//not conencted. The capacitors in the shunt
		//circuit can cause a reverse current.

		//Comment:
		//First step: Test connections and shunt resistance
		//Second step: Test diode and MOSFET on correct working

		// Name: Low or negative current error# (no dead end), Type: Calculation:
		// Name: Low or negative current error# (no dead end), Type:  ErrorNumber = 3
		FCV_ERRORNUMBER = 3;

	} else {

		// Name: Current to large?, Type: Decision: Current > Current_max?
		if (flt_gt(FCV_CURRENT, FCV_CURRENT_MAX))
		{

			// Name: High current error# (dead end fast flickering), Type: Calculation:
			// Name: High current error# (dead end fast flickering), Type:  ErrorNumber = 1
			FCV_ERRORNUMBER = 1;

		} else {

			// Name: Calculate internal resistance Ri , Type: Calculation:
			// Name: Calculate internal resistance Ri , Type:  FR_internal = fsub (FV0,FV_terminal)
			// Name: Calculate internal resistance Ri , Type:  FR_internal = fdiv (FR_internal,Current) // Current=0 is not allowed
			// Name: Calculate internal resistance Ri , Type:  FR_internal = fmul (FR_internal,1000.0) // Ri in mOhm
			FCV_FR_INTERNAL = flt_sub(FCV_FV0, FCV_FV_TERMINAL);
			FCV_FR_INTERNAL = flt_div(FCV_FR_INTERNAL, FCV_CURRENT);
			FCV_FR_INTERNAL = flt_mul(FCV_FR_INTERNAL, 1000.0);

			// Name: Ri value as string, Type: Call Macro: FloatTo4Char(FR_internal)
			FCM_FloatTo4Char(FCV_FR_INTERNAL);

			// Name: Internal resistance < 0.1 mOhm?, Type: Decision: FR_internal < 0.1?
			if (flt_lt(FCV_FR_INTERNAL, 0.1))
			{

				// Name: , Type: Decision: FR_internal >= 0?
				if (flt_ge(FCV_FR_INTERNAL, 0))
				{

					//Comment:
					//For very low values of 0<=Ri<0.1 mOhm, it is expected that 
					//the current I will become larger then Imax and stopt already 
					//at an earlier place in the program.

					// Name: Low resistance error# (no dead end), Type: Calculation:
					// Name: Low resistance error# (no dead end), Type:  ErrorNumber = 3
					FCV_ERRORNUMBER = 3;

				} else {

					//Comment:
					//Negative resistance can be due to a not correct
					//connection. Choosen is here for warning only.

					// Name: Negative resistance error# (no dead end), Type: Calculation:
					// Name: Negative resistance error# (no dead end), Type:  ErrorNumber = 3
					FCV_ERRORNUMBER = 3;

				}

			} else {

				// Name: Internal resistance > = 10 Ohm?, Type: Decision: FR_internal > 9999?
				if (flt_gt(FCV_FR_INTERNAL, 9999))
				{

					// Name: High resistance error# (no dead end), Type: Calculation:
					// Name: High resistance error# (no dead end), Type:  ErrorNumber = 3
					FCV_ERRORNUMBER = 3;

				// } else {

				}

			}

		}

	}

	// Name: Go on if still default errornumber?, Type: Decision: ErrorNumber = 0?
	if (FCV_ERRORNUMBER == 0)
	{

		//Comment:
		//Go on

		// Name: Correct values found, Type: Calculation:
		// Name: Correct values found, Type:  .Return = 1
		FCR_RETVAL = 1;

	} else {

		//Comment:
		//Error# changed then goto DEAD END

		// Name: High current in Shunt circuit, Type: Call Macro: Dead_end()
		FCM_Dead_end();

		// Name: No correct values found, Type: Calculation:
		// Name: No correct values found, Type:  .Return = 0
		FCR_RETVAL = 0;

	}

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :
\*=----------------------------------------------------------------------=*/
void FCM_ADC_AN1()
{

	//Comment:
	//ADC reading for AN1 (port A1) of PIC16F1847

	// Name: Set channel AN1 and enable ADC, Type: C Code:
	adcon0= 0x05;  // reset adcon0 and select channel AN1 (for ANx adcon0=x<<2)
	               // enable ADC (bit0 of adcon0)

	// Name: Wait ADC acquisition time of 10 usec , Type: Delay: Taquisition_usec us
	FCI_DELAYBYTE_US(FCV_TAQUISITION_USEC);

	// Name: Start conversion AN1 and wait until ready, Type: C Code:
	adcon0 = adcon0 | 0x02;  // start adc conversion. (Set bit1 of adcon0)
	while(ts_bit(adcon0,1)); // wait for end conversion, until bit1 has been reset

	FCV_LB0 = adresl;
	FCV_HB0 = adresh;

	// Name: Get ADC reading, Type: Calculation:
	// Name: Get ADC reading, Type:  ADC_reading = (HB0 << 8) + LB0
	FCV_ADC_READING = (FCV_HB0 << 8) + FCV_LB0;

}



/*========================================================================*\
   Use :Main
\*========================================================================*/
void main()
{
ANSELA = 0x00;
ANSELB = 0x00;

OPTION_REG = 0xC0;


	//Comment:
	//Activates accumulators (6V, 12, 24V) and determines battery qualities 0-30V
	//By means of a high current pulse during 100 usec (blue LED1 red) 
	//which will be reapeated each 30 seconds.
	//LED 2 (red),3 (orange) and 4 (green) shows the status of an accumulator.
	//LCD line 1 shows the battery/accumilator voltage without and
	//during the pulse.
	//LCD  line 2 shows the shunt current, internal battery / accumulator
	//resistance and count down seconds offtime.
	//Elektor Version 2.0
	//August 11, 2016
	//Jan H. Lichtenbelt, Nl

	//Comment:
	//PAY ATTENTION    PAY ATTENTION
	//Use B3 as output ONLY to activate the shunt!
	//E.g. check carefully
	//-  LCD ports, do NOT use the default port B3
	//-  Trisate input B3 NOT allowed 
	//   (Part of the tristate check will 
	//    use B3 as output, which is NOT allowed)

	//Comment:
	//Definition:
	//Accumalator or battery with a voltage on the terminals Vt and internal resistance Ri.
	//Without external load V0=Vt. The voltage Vi=V0-Vt is the voltage over the internal resistance Ri.
	//Vt will be measured with and without external shunt resistance.
	//Thare are three ranges 0-10V, 7-20V and 7-30V with shunt resistances Rs
	//of 50 resp 100 and 220 Ohm. 
	//The voltage at the shunt will be Vh (high side) and Vl (low side), with Vh>Vl.
	//Remark: Vl>0 due to thread resistance connected to the min-terminal.

	//Comment:
	//Setup:
	//The accumulator voltage will be measured with (Vt) 
	//and without (V0) load (shunt resistance Rshunt)
	//The voltages over the shunt are measured with Vh at the high-side and
	//Vl at the low-side of the shunt. 
	//The voltages with shunt will be measured during the 100 usec pulse.
	//The value for the current is: I= (Vh-Vl)/Rshunt. 
	//Then battery internal resistance Ri can be calculated with Ri= (V0-Vt)/I.
	//When measured the voltages directly at the accumulator/battery,
	//the error in the internal resistance Ri will due to the error in the 
	//real value of the shunt resistance and the contact potentials 
	//at the accumulator/battery.

	//Comment:
	//LEDs:
	//A7  low: LED1 Shunt activated
	//A7 high: LED2 red voltage     < 5.95V    < 11.9 Volt   < 23.8 Volt 
	//A6  low: LED3 orange voltage 5.95-6.25V 11.9-12.5 Volt 23.8-25.0 Volt
	//A6 high: LED4 green voltage   > 6.25 V    > 12.5 Volt   > 25.0 Volt 
	//Remark: A6 or A7 as input will deactivate the LEDs
	//ADCs:
	//A1: AN1=ADC1 Vt accumulator  (divide by 2, 4 or 6)
	//A0: AN0=ADC2 Vh Shunt + side (divide by 2, 4 or 6)
	//B7: AN6=ADC3 Vl Shunt - side (divide by 2, 4 or 6)
	//Tristate Input (low/open/high):
	//B4: Shunt 220(high) 100 (open) 50 mOhm (low)
	//B5: Voltage ratio 1:6 (open), 1:4 (high) or 1:2 (low)
	//Comparator Input- (with IN+= 2.048Volt):
	//A2: NTC  
	//Output:
	//B3 - MOSFET Gate (Anode gate driver) 
	//port LCD flatcable  LCD port flatcable
	//A3   D4   1         D4  A3   1
	//A4   En   2         D5  B6   3
	//B6   D5   3         D6  B0   5
	//B0   D6   5         D7  B1   7
	//B1   D7   7         R   B2   9
	//B2   R    9         En  A4   2
	//                    0V       8
	//                    5V       6
	//                    NC       4 and 10
	//Other inputs:
	//A5 Off time 30 sec (open) or 10 sec. (closed)

	//Comment:
	//Interrupts:
	//1. Timer0 interrupt with 61 Hz used to count down 30 seconds
	//2. Comparator on port A2 with Vref= 2.048 Volt
	//   If NTC > 100-135 oC interrupt to macro DEAD_END
	//Remark: Flowcode does not has a comparator interrupt. 
	//Therefor  the program uses C-codes for it.
	//Macros:
	//Reamark: Flowcode does have an ADC macro, but it seems that the shortes
	//pulse will be about 160 usec, while the macro in C-code take only 100 usec.
	//1. Init to initialise paramters
	//2. Current_and_ Internal_resistance to calculate I and Ri and to check both on extreme values
	//3. Test_Voltage_V0. Wait until V0 > V(min) and test V0> 10,20 or 30 Volt
	//4. Tristate_Input_ports_B, reads the low, open or high state of a B-port, except B3
	//5. Tristate_Output_Ports_A, activates LED1 until LED4 on A6 and A7
	//6. ADC_to_Voltage transforms the 10 bit ADC into Voltages
	//7. Voltage_to_ADC transforms a real into ADC units (0..1023)
	//8. ADC_AN1 read AN1
	//9. Dead_end is also an (comparator interrupt) macro.
	//10. FloatTo4Char Real to string conversion with 4 characters

	//Comment:
	//Program steps:
	//1. Initialise, with getting Rshunt, Part of Voltages (2, 4 or 6),
	//   offtime (10 or 30 sec)
	//2. Start 10/30 second loop
	//3. Test V0 is within limits
	//4. Setup ADC's
	//5. Start without shunt and read V0
	//6. START WITH SHUNT read Vt, Vh and Vl
	//7. Stop shunt
	//8. Transform ADC reading into real voltages
	//9. Show status by means of red, orange and green LEDs
	//10. Loop 10/30 seconds
	//11. Start LCD each second. V0, Vt, I, Ri and count down counter (offtime)

	//Comment:
	//Flowcode 6:
	//Most of the program is written in Flowcode 6.
	//Written in C:
	//- For the comparator there was no macro available
	//- The shortest time for three ADC's has been found 
	//  to take 150 usec, using Flowcode. 
	//  Written in C is takes 100 usec, is required.

	// Name: 16 MHZ internal oscillator, Type: C Code:
	osccon= 0x78;

	//Comment:
	//1. Initialise, with getting Rshunt, Part of Voltages (2, 4 or 6),
	//   offtime (10 or 30 sec)

	// Name: Initialise, Type: Call Macro: Init()
	FCM_Init();

	// Name: Endless loop, Type: Loop: While 1
	while (1)
	{

		//Comment:
		//2. Start 10/30 second loop

		//Comment:
		//3. Test V0 is within limits

		// Name: Wait until V0 > V0_min and stop on Vadc>=5V, Type: Call Macro: Test_Voltage_V0()
		FCM_Test_Voltage_V0();

		// Name: LED1 on (white/blue), Type: Call Macro: TriState_Output_Ports_A(1)
		FCM_TriState_Output_Ports_A(1);

		// Name: Stop temporary timer0, Type: Interrupt: Disable TMR0
		cr_bit(INTCON, TMR0IE);

		//Comment:
		//4. Setup ADC's

		//Comment:
		//ADC setup has been moved to INIT macro

		//Comment:
		//Tacq the aquisition time (to load the ADC condensor):
		//Tacq= 2.0 µsec +Tc + 0.05?T  
		//with ?T the temperature difference compared to 25 oC
		//and Tc =7.62*10pF*(8k+Rs)
		//with Rs the external load resistance. 
		//The optimal Rs is 10k and Tc = 1.4 usec
		//Other temperatures: increases Tacq with 1 usec/20 oC
		//The total conversion time is 11.5*Tad
		//The conversion time for 1 bit Tad 
		//is for 16 MHz oscillator and ADC clock at Fosc/16: 1 usec
		//This makes the total conversion time is 11.5 usec.
		//Ttotal=  Tacq + Tc = 2 + 2 + 11.5 about 16 usec
		//In the program Tacq is set to 10 usec, so Ttotal is about 22 usec

		//Comment:
		//5. Start without shunt and read V0

		// Name: Read ACD AN1 (V0), Type: Call Macro: ADC_AN1()
		FCM_ADC_AN1();

		// Name: Caluculate  Battery Voltage without shunt, Type: Call Macro: FV0=ADC_to_Voltage(HB0, LB0)
		FCV_FV0 = FCM_ADC_to_Voltage(FCV_HB0, FCV_LB0);

		//Comment:
		//6. START WITH SHUNT read Vt, Vh and Vl

		// Name: Activate gate of MOSFET: set B3 high, Type: Output: 1 -> B3
		SET_PORT_PIN(B,3,(1));

		//Comment:
		//It takes about 10 usec to get gate of 
		//the MOSFET to become > 4 Volt 

		// Name: 1. Wait until gate at >4V, Type: Delay: Tdelay_usec us
		FCI_DELAYBYTE_US(FCV_TDELAY_USEC);

		//Comment:
		//MOSFET is now on.

		//Comment:
		//Wait again 10 usec to load the ADC capacitor (hold time)

		// Name: 2. Wait ADC aquisition time of 10 usec, Type: Delay: Taquisition_usec us
		FCI_DELAYBYTE_US(FCV_TAQUISITION_USEC);

		// Name: Start conversion AN1 (Vt), wait until ready and save data, Type: C Code:
		adcon0 = adcon0 | 0x02;  // start adc conversion. (Set bit1 of adcon0)
		while(ts_bit(adcon0,1)); // wait for end conversion, until bit1 has been reset

		FCV_LB1 = adresl;
		FCV_HB1 = adresh;

		// Name: Set channel AN0 (Vh) and enable ADC, Type: C Code:
		adcon0= 0x01; // reset adcon0 and select channel AN0 (for ANx adcon0=x<<2)
		               // enable ADC (bit0 of adcon0)

		// Name: Wait ADC acquisition time of 10 usec , Type: Delay: Taquisition_usec us
		FCI_DELAYBYTE_US(FCV_TAQUISITION_USEC);

		// Name: Start conversion AN0 (Vh), wait until ready and save data, Type: C Code:
		adcon0 = adcon0 | 0x02;  // start adc conversion. (Set bit1 of adcon0)
		while(ts_bit(adcon0,1)); // wait for end conversion, until bit1 has been reset

		FCV_LB2 = adresl;   // safe low byte
		FCV_HB2 = adresh;  // safe high byte

		// Name: Set channel AN6 (Vl) and enable ADC, Type: C Code:
		adcon0= 0x19;   // reset adcon0 and select channel AN2 (for ANx adcon0=x<<2)
		                // enable ADC (bit0 of adcon0)

		// Name: Wait ADC aquisition time of 10 usec, Type: Delay: Taquisition_usec us
		FCI_DELAYBYTE_US(FCV_TAQUISITION_USEC);

		// Name: Start conversion AN6 (Vl), wait until ready and save data, Type: C Code:
		adcon0 = adcon0 | 0x02;  // start adc conversion. (Set bit1 of adcon0)
		while(ts_bit(adcon0,1)); // wait for end conversion, until bit1 has been reset

		FCV_LB3 = adresl;
		FCV_HB3 = adresh;

		//Comment:
		//7. STOP SHUNT     STOP SHUNT     STOP SHUNT     STOP SHUNT     

		// Name: Stop shunt: Reset B3 low, Type: Output: 0 -> B3
		SET_PORT_PIN(B,3,(0));

		//Comment:
		//Safety reasons dubble stop

		// Name: Stop shunt: Reset B3 low, Type: Output: 0 -> B3
		SET_PORT_PIN(B,3,(0));

		// Name: Disable ADC's, Type: C Code:
		adcon0=0x00;  // disable ADC's

		//Comment:
		//8. Transform ADC reading into real voltages

		// Name: (Re)set delay to off time, Type: Calculation:
		// Name: (Re)set delay to off time, Type:  Seconds = Wait_seconds // off time
		// Name: (Re)set delay to off time, Type:  Timer0_Counter = 61 // 61 Hz timer0
		FCV_SECONDS = FCV_WAIT_SECONDS;
		FCV_TIMER0_COUNTER = 61;

		// Name: Interrupt timer0 with 61 Hz with 16 MHz internal osc, Type: Interrupt: Enable TMR0
		cr_bit(OPTION_REG,T0CS);
		st_bit(OPTION_REG,T0SE);
		OPTION_REG = (OPTION_REG & 0xF0) | 0x07;
		st_bit(INTCON,GIE);
		st_bit(INTCON, TMR0IE);

		// Name: Calculate the V terminal with shunt, Type: Call Macro: FV_terminal=ADC_to_Voltage(HB1, LB1)
		FCV_FV_TERMINAL = FCM_ADC_to_Voltage(FCV_HB1, FCV_LB1);

		// Name: Calculate the Voltage at the top of the shunt, Type: Call Macro: FVshunt_topside=ADC_to_Voltage(HB2, LB2)
		FCV_FVSHUNT_TOPSIDE = FCM_ADC_to_Voltage(FCV_HB2, FCV_LB2);

		// Name: Caluclate the voltage at the bottom of the shunt, Type: Call Macro: FVshunt_bottomside=ADC_to_Voltage(HB3, LB3)
		FCV_FVSHUNT_BOTTOMSIDE = FCM_ADC_to_Voltage(FCV_HB3, FCV_LB3);

		//Comment:
		//7. Test V < Vmax and current <>0

		// Name: ADC value for V0 ithout shunt, Type: Calculation:
		// Name: ADC value for V0 ithout shunt, Type:  ADC_reading = ((HB0 << 8) + LB0)
		FCV_ADC_READING = ((FCV_HB0 << 8) + FCV_LB0);

		// Name: Calculate current and the internal resistance, Type: Call Macro: Calculations_without_error=Current_and_Internal_resistance()
		FCV_CALCULATIONS_WITHOUT_ERROR = FCM_Current_and_Internal_resistance();

		// Name: Vertraging, Type: Delay: 300 ms
		FCI_DELAYINT_MS(300);

		//Comment:
		//9. Show status by means of red, orange and green LEDs

		// Name: Correct calculations?, Type: Decision: Calculations_without_error = 1?
		if (FCV_CALCULATIONS_WITHOUT_ERROR == 1)
		{

			// Name: Time between pulses=10 sec?, Type: Decision: Wait_seconds = 10?
			if (FCV_WAIT_SECONDS == 10)
			{

				//Comment:
				//In case of batteries mostly 10 seconds
				//will be choosen. In this case the
				//LED showing the accumulator status is set off.

				// Name: Reset actual led number, Type: Calculation:
				// Name: Reset actual led number, Type:  Actual_Led_Number = 0
				FCV_ACTUAL_LED_NUMBER = 0;

			} else {

				//Comment:
				//For accumulators pulses are repeated each 30 seconds
				//In this case the red-orange-green LED show the stauts 
				//of the accumulator, based on the voltage

				// Name: Set acutal low-high values for lead accumulators, Type: Calculation:
				// Name: Set acutal low-high values for lead accumulators, Type:  Vlead_low = Vacc_low
				// Name: Set acutal low-high values for lead accumulators, Type:  Vlead_high = Vacc_high
				FCV_VLEAD_LOW = FCV_VACC_LOW;
				FCV_VLEAD_HIGH = FCV_VACC_HIGH;

				// Name: Voltages 0-10 Volt?, Type: Decision: Voltage_Part = 2?
				if (FCV_VOLTAGE_PART == 2)
				{

					// Name: V < 5 Volt  (lead accumultors with less then 3 cells)?, Type: Decision: ADC_reading < 512?
					if (FCV_ADC_READING < 512)
					{

						// Name: Set acutal low-high values for 1 lead accumulators, Type: Calculation:
						// Name: Set acutal low-high values for 1 lead accumulators, Type:  Vlead_low = Vlead_low / 3
						// Name: Set acutal low-high values for 1 lead accumulators, Type:  Vlead_high = Vlead_high / 3
						FCV_VLEAD_LOW = FCV_VLEAD_LOW / 3;
						FCV_VLEAD_HIGH = FCV_VLEAD_HIGH / 3;

						// Name: V < 2.5 Volt  (lead accumultors with 1 cells)?, Type: Decision: ADC_reading < 256?
						if (FCV_ADC_READING < 256)
						{

						} else {

							// Name: Set acutal low-high values for 2  lead accumulators, Type: Calculation:
							// Name: Set acutal low-high values for 2  lead accumulators, Type:  Vlead_low = Vlead_low << 1 // multiply with 2
							// Name: Set acutal low-high values for 2  lead accumulators, Type:  Vlead_high = Vlead_high << 1
							FCV_VLEAD_LOW = FCV_VLEAD_LOW << 1;
							FCV_VLEAD_HIGH = FCV_VLEAD_HIGH << 1;

						}

					// } else {

					}

				// } else {

				}

				// Name: High voltage?, Type: Decision: ADC_reading > Vlead_high?
				if (FCV_ADC_READING > FCV_VLEAD_HIGH)
				{

					// Name: Set green LED, Type: Calculation:
					// Name: Set green LED, Type:  LED_Number = 4
					FCV_LED_NUMBER = 4;

				} else {

					// Name: Low voltage?, Type: Decision: ADC_reading < Vlead_low?
					if (FCV_ADC_READING < FCV_VLEAD_LOW)
					{

						// Name: Set red LED, Type: Calculation:
						// Name: Set red LED, Type:  LED_Number = 2
						FCV_LED_NUMBER = 2;

					} else {

						// Name: Set yellow/orange LED, Type: Calculation:
						// Name: Set yellow/orange LED, Type:  LED_Number = 3
						FCV_LED_NUMBER = 3;

					}

				}

			}

			// Name: Set LED, Type: Call Macro: TriState_Output_Ports_A(LED_Number)
			FCM_TriState_Output_Ports_A(FCV_LED_NUMBER);

			// Name: Set flag, Type: Calculation:
			// Name: Set flag, Type:  PulseSent = 1
			FCV_PULSESENT = 1;

			// Name: Start LCD (Make self starting possible of LCD connected later), Type: Call Component Macro: lcd_eb005::Start()
			FCD_0ad31_lcd_eb005__Start();

		} else {

			// Name: Reset actual led number, Type: Calculation:
			// Name: Reset actual led number, Type:  Actual_Led_Number = 0
			FCV_ACTUAL_LED_NUMBER = 0;

			// Name: Reset flag, Type: Calculation:
			// Name: Reset flag, Type:  PulseSent = 0
			FCV_PULSESENT = 0;

		}

		//Comment:
		//10. Loop 10/30 seconds

		// Name: Start directly to show the results, Type: Calculation:
		// Name: Start directly to show the results, Type:  Timer0_Counter = 1 // pay attention NOT Timer0_Counter = 0
		FCV_TIMER0_COUNTER = 1;

		// Name: Count down the off timer, Type: Loop: While Seconds > 0
		while (FCV_SECONDS > 0)
		{

			//Comment:
			//10/30 second loop

			// Name: Seconds have been decreased?, Type: Decision: (Change_seconds = 1)?
			if ((FCV_CHANGE_SECONDS == 1))
			{

				//Comment:
				//11. Start LCD each second. V0, Vt, I, Ri and count down counter (offtime)

				// Name: First time after pulse?, Type: Decision: PulseSent = 1?
				if (FCV_PULSESENT == 1)
				{

					// Name: Clear LCD, Type: Call Component Macro: lcd_eb005::Clear()
					FCD_0ad31_lcd_eb005__Clear();

					// Name: Convert FV0  to string, Type: Call Macro: FloatTo4Char(FV0)
					FCM_FloatTo4Char(FCV_FV0);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString("V0:")
					FCD_0ad31_lcd_eb005__PrintString("V0:", 4);

					// Name: Print V0, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
					FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

					// Name: Convert FV-terminal  to string, Type: Call Macro: FloatTo4Char(FV_terminal)
					FCM_FloatTo4Char(FCV_FV_TERMINAL);

					// Name: Space, Type: Call Component Macro: lcd_eb005::PrintString(" ")
					FCD_0ad31_lcd_eb005__PrintString(" ", 2);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString("Vt:")
					FCD_0ad31_lcd_eb005__PrintString("Vt:", 4);

					// Name: Print V0, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
					FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

					// Name: 2nd line, Type: Call Component Macro: lcd_eb005::Cursor(0, 1)
					FCD_0ad31_lcd_eb005__Cursor(0, 1);

					// Name: print text, Type: Call Component Macro: lcd_eb005::PrintString("I:")
					FCD_0ad31_lcd_eb005__PrintString("I:", 3);

					// Name: Covert to string, Type: Call Macro: FloatTo4Char(Current)
					FCM_FloatTo4Char(FCV_CURRENT);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
					FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString("R:")
					FCD_0ad31_lcd_eb005__PrintString("R:", 3);

					// Name: Covert to string, Type: Call Macro: FloatTo4Char(FR_internal)
					FCM_FloatTo4Char(FCV_FR_INTERNAL);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString(StrTemp)
					FCD_0ad31_lcd_eb005__PrintString(FCV_STRTEMP, FCVsz_STRTEMP);

					// Name: Print text, Type: Call Component Macro: lcd_eb005::PrintString("m")
					FCD_0ad31_lcd_eb005__PrintString("m", 2);

					// Name: Print greef symbol omega for Ohm, Type: Call Component Macro: lcd_eb005::PrintAscii(0xF4)
					FCD_0ad31_lcd_eb005__PrintAscii(0xF4);

					// Name: Reset pulse flag, Type: Calculation:
					// Name: Reset pulse flag, Type:  PulseSent = 0
					FCV_PULSESENT = 0;

				// } else {

				}

				// Name: TAB second line place 14, Type: Call Component Macro: lcd_eb005::Cursor(14, 1)
				FCD_0ad31_lcd_eb005__Cursor(14, 1);

				// Name: less than 10 seconds?, Type: Decision: Seconds < 10?
				if (FCV_SECONDS < 10)
				{

					// Name: Print space, Type: Call Component Macro: lcd_eb005::PrintString(" ")
					FCD_0ad31_lcd_eb005__PrintString(" ", 2);

				// } else {

				}

				// Name: Print seconds (count down), Type: Call Component Macro: lcd_eb005::PrintNumber(Seconds)
				FCD_0ad31_lcd_eb005__PrintNumber(FCV_SECONDS);

				// Name: reset flag, Type: Calculation:
				// Name: reset flag, Type:  Change_seconds = 0
				FCV_CHANGE_SECONDS = 0;

				// Name: Correct calulcations I and Ri?, Type: Decision: Calculations_without_error = 1?
				if (FCV_CALCULATIONS_WITHOUT_ERROR == 1)
				{

				} else {

					//Comment:
					//Flickering of LED each second

					// Name: LED on/off, Type: Calculation:
					// Name: LED on/off, Type:  Actual_Led_Number = LED_Number - Actual_Led_Number
					FCV_ACTUAL_LED_NUMBER = FCV_LED_NUMBER - FCV_ACTUAL_LED_NUMBER;

					// Name: Set LED, Type: Call Macro: TriState_Output_Ports_A(Actual_Led_Number)
					FCM_TriState_Output_Ports_A(FCV_ACTUAL_LED_NUMBER);

				}

			// } else {

			}


		}


	}

	mainendloop: goto mainendloop;
}



/*========================================================================*\
   Use :Interrupt
\*========================================================================*/
void MX_INTERRUPT_MACRO(void)
{

	//Handler code for [TMR0]
	#ifndef MX_INTHANDLER_INTCON_TMR0IF
	#define MX_INTHANDLER_INTCON_TMR0IF
	if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
	{
		FCM_Timer0_Interrupt();
		cr_bit(INTCON, TMR0IF);
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <Timer0_Interrupt> may never get called."
	#endif


	//Handler code for [TMR0]
	#ifndef MX_INTHANDLER_INTCON_TMR0IF
	#define MX_INTHANDLER_INTCON_TMR0IF
	if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
	{
		FCM_Timer0_Interrupt();
		cr_bit(INTCON, TMR0IF);
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <Timer0_Interrupt> may never get called."
	#endif


	//Handler code for [TMR0]
	#ifndef MX_INTHANDLER_INTCON_TMR0IF
	#define MX_INTHANDLER_INTCON_TMR0IF
	if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
	{
		FCM_Timer0_Interrupt();
		cr_bit(INTCON, TMR0IF);
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <Timer0_Interrupt> may never get called."
	#endif


	//Handler code for [TMR0]
	#ifndef MX_INTHANDLER_INTCON_TMR0IF
	#define MX_INTHANDLER_INTCON_TMR0IF
	if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
	{
		FCM_Timer0_Interrupt();
		cr_bit(INTCON, TMR0IF);
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <Timer0_Interrupt> may never get called."
	#endif


}
Ama işine yararmı bilmem

Epsilon

@Mehmet Salim GÜLLÜCE elinize sağlık.

Ancak çok ilginç,bu son mesajınızda kodların olduğu kısma fare ile tıkladığımda (kodu seçip kopyalamak için falan)sayfa kilitleniyor,sayfada hiçbirşey çalışmıyor, "Alıntı Yap" butonu da çalışmıyor.Sanırım @gevv in kontrol etmesi gereken bir durum oluşuyor.

M.Salim GÜLLÜCE

#7
Alıntı yapılan: Epsilon - 03 Kasım 2019, 09:17:47@Mehmet Salim GÜLLÜCE elinize sağlık.

Ancak çok ilginç,bu son mesajınızda kodların olduğu kısma fare ile tıkladığımda (kodu seçip kopyalamak için falan)sayfa kilitleniyor,sayfada hiçbirşey çalışmıyor, "Alıntı Yap" butonu da çalışmıyor.Sanırım @gevv in kontrol etmesi gereken bir durum oluşuyor.
Mail verirseniz gönderebilirimde.

Özel Mesaj ile gönderdim

M.Salim GÜLLÜCE

Ayrıca flowcode bölümünde kürekli versiyon 8 war oradan indirip kendinde bakabilirsin.
Kaynak üzerinde en iyi çalışmayı o ortamda yaparsın.

Epsilon

Alıntı yapılan: Mehmet Salim GÜLLÜCE - 03 Kasım 2019, 12:52:02Ayrıca flowcode bölümünde kürekli versiyon 8 war oradan indirip kendinde bakabilirsin.
Kaynak üzerinde en iyi çalışmayı o ortamda yaparsın.
Haklısınız da ben hiç flowcode bilmiyorum.Youtube dada hemen hiçbir bilgi yok
Eklediğiniz versiyonunun 2 linkini de indirdim.Ama hiçbirşey bilmediğim için kurmadım.

M.Salim GÜLLÜCE

Alıntı yapılan: Epsilon - 03 Kasım 2019, 12:59:32Haklısınız da ben hiç flowcode bilmiyorum.Youtube dada hemen hiçbir bilgi yok
Eklediğiniz versiyonunun 2 linkini de indirdim.Ama hiçbirşey bilmediğim için kurmadım.

Benim eklediğim birkaç uygulama örneği war aslında.
Size fikir verir.

Bunlarıda seyrederseniz illaki size faydası olur.
https://www.youtube.com/results?search_query=flowcode+dersleri