//************************************************************************************
//**  
//**  File name:     D:\Data\Hobbies\Electronica\E-blocks\Eigen ontwerpen\RS232\Auto baud rate\RX UART Auto-Baud V3.c
//**  Title:         
//**  Description:   
//**  
//**  Generated by:  Flowcode v5.5.0.1
//**  Date:          Sunday, January 27, 2013 18:54:46
//**  Licence:       Professional
//**  Registered to: Jan Lichtenbelt
//**  Licence key:   M798V0
//**  
//**  
//**  http://www.matrixmultimedia.com
//**  
//************************************************************************************


#define MX_PIC

#define MX_USES_UINT8 1
#define MX_USES_SINT16 0
#define MX_USES_CHAR 2
#define MX_USES_FLOAT 0
#define MX_USES_SINT32 0
#define MX_USES_BOOL 1
#define MX_USES_UINT16 1
#define MX_USES_UINT32 1
//Defines voor de microcontroller
#define P16F1939
#define FC_CAL_PIC
#define MX_ADC
#define MX_ADC_TYPE_18
#define MX_ADC_BITS_10
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 256
#define MX_SPI_1
#define MX_SPI_1_MISO_PORT portc
#define MX_SPI_1_MISO_TRIS trisc
#define MX_SPI_1_MISO_PIN 4
#define MX_SPI_1_MOSI_PORT portc
#define MX_SPI_1_MOSI_TRIS trisc
#define MX_SPI_1_MOSI_PIN 5
#define MX_SPI_1_CLK_PORT portc
#define MX_SPI_1_CLK_TRIS trisc
#define MX_SPI_1_CLK_PIN 3
#define MX_SPI_1_SS_PORT portc
#define MX_SPI_1_SS_TRIS trisc
#define MX_UART_1
#define MX_UART_1_TX_PORT portc
#define MX_UART_1_TX_TRIS trisc
#define MX_UART_1_TX_PIN 6
#define MX_UART_1_RX_PORT portc
#define MX_UART_1_RX_TRIS trisc
#define MX_UART_1_RX_PIN 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_1
#define MX_I2C_1_SDA_PORT portc
#define MX_I2C_1_SDA_TRIS trisc
#define MX_I2C_1_SDA_PIN 4
#define MX_I2C_1_SCL_PORT portc
#define MX_I2C_1_SCL_TRIS trisc
#define MX_I2C_1_SCL_PIN 3
#define MX_PWM
#define MX_PWM_CNT 5
#define MX_PWM_PSCA1
#define MX_PWM_PSCA4
#define MX_PWM_PSCA16
#define MX_PWM_1_PORT portc
#define MX_PWM_1_TRIS trisc
#define MX_PWM_1_PIN 2
#define MX_PWM_2_PORT portc
#define MX_PWM_2_TRIS trisc
#define MX_PWM_2_PIN 1
#define MX_PWM_2_PORT_A portb
#define MX_PWM_2_TRIS_A trisb
#define MX_PWM_2_PIN_A 3
#define MX_PWM_3_PORT porte
#define MX_PWM_3_TRIS trise
#define MX_PWM_3_PIN 0
#define MX_PWM_3_PORT_A portb
#define MX_PWM_3_TRIS_A trisb
#define MX_PWM_3_PIN_A 5
#define MX_PWM_4_PORT portd
#define MX_PWM_4_TRIS trisd
#define MX_PWM_4_PIN 1
#define MX_PWM_5_PORT porte
#define MX_PWM_5_TRIS trise
#define MX_PWM_5_PIN 2

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

//Configuratiegegevens
#ifdef _BOOSTC
#pragma DATA 0x8007, 0xfe2
#endif
#ifdef HI_TECH_C
__CONFIG(0xfe2);
#endif
#ifdef _BOOSTC
#pragma DATA 0x8008, 0x1633
#endif
#ifdef HI_TECH_C
__CONFIG(0x1633);
#endif

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

//Macro functie declaraties
MX_UINT32 FCM_ABD(MX_UINT32 FCL_BRG_FREQ);


//Variable declaraties
#define FCSZ_BAUDRATE_STRING 20
#define FCV_TRUE (1)
#define FCV_FALSE (0)
MX_UINT32 FCV_BAUD_RATE;
MX_CHAR FCV_BAUDRATE_STRING[FCSZ_BAUDRATE_STRING];
MX_UINT8 FCV_TEMP;
MX_UINT32 FCV_OSC_FREQ;




//LCDDisplay(0): //Defines:

/**** Macro Substitutions ****
a = Unique Component Reference Number
b = D1 Port Letter
c = D2 Port Letter
d = D3 Port Letter
e = D4 Port Letter
f = RS Port Letter
g = E Port Letter
h = Data 1_Pin
i = Data 2 Pin
j = Data 3 Pin
k = Data 4 Pin
l = RS Pin
m = Enable Pin
n = Row Count
o = Column Count
******************************/

	//component connections
	//Port pin lat workaround for 8-bit PIC devices running >= 32MHz
	//seems we need this mod for 19660800 16F1937 so changed to >= 16MHz

  #ifdef FC_CAL_PIC
   #if MX_CLK_SPEED >= 32000000
	#define LCD_1__PORT0    latb
	#define LCD_1__PORT1    latb
	#define LCD_1__PORT2    latb
	#define LCD_1__PORT3    latb
	#define LCD_1__PORT4    latb
	#define LCD_1__PORT5    latb
   #else
    #ifdef MX_LCD_PORT_LAT
	 #define LCD_1__PORT0    latb
	 #define LCD_1__PORT1    latb
	 #define LCD_1__PORT2    latb
	 #define LCD_1__PORT3    latb
	 #define LCD_1__PORT4    latb
	 #define LCD_1__PORT5    latb
    #else
	 #define LCD_1__PORT0    portb
	 #define LCD_1__PORT1    portb
	 #define LCD_1__PORT2    portb
	 #define LCD_1__PORT3    portb
	 #define LCD_1__PORT4    portb
	 #define LCD_1__PORT5    portb
	#endif
   #endif
  #else
	#define LCD_1__PORT0    portb
	#define LCD_1__PORT1    portb
	#define LCD_1__PORT2    portb
	#define LCD_1__PORT3    portb
	#define LCD_1__PORT4    portb
	#define LCD_1__PORT5    portb
  #endif

	#define LCD_1__TRIS0    trisb
	#define LCD_1__TRIS1    trisb
	#define LCD_1__TRIS2    trisb
	#define LCD_1__TRIS3    trisb
	#define LCD_1__TRIS4    trisb
	#define LCD_1__TRIS5    trisb
	#define LCD_1__BIT0    	0
	#define LCD_1__BIT1    	1
	#define LCD_1__BIT2    	2
	#define LCD_1__BIT3    	3
	#define LCD_1__RS      	4
	#define LCD_1__E       	5
	#define LCD_1__ROWCNT	2
	#define LCD_1__COLCNT	16

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




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

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



//LCDDisplay(0): //Macro implementaties


void FCD_LCDDisplay0_RawSend(MX_UINT8 in, MX_UINT8 mask)
{
	
		MX_UINT8 pt;

		FC_CAL_Bit_Low(LCD_1__PORT0, LCD_1__BIT0);
		FC_CAL_Bit_Low(LCD_1__PORT1, LCD_1__BIT1);
		FC_CAL_Bit_Low(LCD_1__PORT2, LCD_1__BIT2);
		FC_CAL_Bit_Low(LCD_1__PORT3, LCD_1__BIT3);
		FC_CAL_Bit_Low(LCD_1__PORT4, LCD_1__RS);
		FC_CAL_Bit_Low(LCD_1__PORT5, LCD_1__E);
		pt = ((in >> 4) & 0x0f);
		if (pt & 0x01)
		    FC_CAL_Bit_High(LCD_1__PORT0, LCD_1__BIT0);
		if (pt & 0x02)
		    FC_CAL_Bit_High(LCD_1__PORT1, LCD_1__BIT1);
		if (pt & 0x04)
		    FC_CAL_Bit_High(LCD_1__PORT2, LCD_1__BIT2);
		if (pt & 0x08)
		    FC_CAL_Bit_High(LCD_1__PORT3, LCD_1__BIT3);
		if (mask)
		    FC_CAL_Bit_High(LCD_1__PORT4, LCD_1__RS);
		LCD_1__DELAY;
		FC_CAL_Bit_High (LCD_1__PORT5, LCD_1__E);
		LCD_1__DELAY;
		FC_CAL_Bit_Low (LCD_1__PORT5, LCD_1__E);
		pt = (in & 0x0f);
		LCD_1__DELAY;
		FC_CAL_Bit_Low(LCD_1__PORT0, LCD_1__BIT0);
		FC_CAL_Bit_Low(LCD_1__PORT1, LCD_1__BIT1);
		FC_CAL_Bit_Low(LCD_1__PORT2, LCD_1__BIT2);
		FC_CAL_Bit_Low(LCD_1__PORT3, LCD_1__BIT3);
		FC_CAL_Bit_Low(LCD_1__PORT4, LCD_1__RS);
		FC_CAL_Bit_Low(LCD_1__PORT5, LCD_1__E);
		if (pt & 0x01)
		    FC_CAL_Bit_High(LCD_1__PORT0, LCD_1__BIT0);
		if (pt & 0x02)
		    FC_CAL_Bit_High(LCD_1__PORT1, LCD_1__BIT1);
		if (pt & 0x04)
		    FC_CAL_Bit_High(LCD_1__PORT2, LCD_1__BIT2);
		if (pt & 0x08)
		    FC_CAL_Bit_High(LCD_1__PORT3, LCD_1__BIT3);
		if (mask)
		    FC_CAL_Bit_High(LCD_1__PORT4, LCD_1__RS);
		LCD_1__DELAY;
		FC_CAL_Bit_High (LCD_1__PORT5, LCD_1__E);
		LCD_1__DELAY;
		FC_CAL_Bit_Low (LCD_1__PORT5, LCD_1__E);
		LCD_1__DELAY;

}

void FCD_LCDDisplay0_Start()
{
	
		FC_CAL_Bit_Low_DDR(LCD_1__PORT0, LCD_1__TRIS0, LCD_1__BIT0);
		FC_CAL_Bit_Low_DDR(LCD_1__PORT1, LCD_1__TRIS1, LCD_1__BIT1);
		FC_CAL_Bit_Low_DDR(LCD_1__PORT2, LCD_1__TRIS2, LCD_1__BIT2);
		FC_CAL_Bit_Low_DDR(LCD_1__PORT3, LCD_1__TRIS3, LCD_1__BIT3);
		FC_CAL_Bit_Low_DDR(LCD_1__PORT4, LCD_1__TRIS4, LCD_1__RS);
		FC_CAL_Bit_Low_DDR(LCD_1__PORT5, LCD_1__TRIS5, LCD_1__E);

		Wdt_Delay_Ms(12);

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

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

}

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

}

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

}

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

}

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

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

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

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

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

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

}

void FCD_LCDDisplay0_PrintNumber(MX_SINT16 Number)
{
	
		MX_SINT16 tmp_int;
		MX_UINT8 tmp_byte;

		if (Number < 0)
		{
			FCD_LCDDisplay0_RawSend('-', 0x10);
			Number = 0 - Number;
		}

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

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

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

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

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

}

void FCD_LCDDisplay0_PrintString(MX_STRING String, MX_UINT8 MSZ_String)
{
	
		MX_UINT8 idx = 0;

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

}

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

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

				cmd = 0x18;
				break;

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

				cmd = 0x1C;
				break;

			default:
				break;
		}

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

}

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

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

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

		#if (LCD_1__ROWCNT == 4)
			#if (LCD_1__COLCNT == 16)
				rowcount=16;
			#endif
			#if (LCD_1__COLCNT == 20)
				rowcount=20;
			#endif
		#endif

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

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

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

}

void FCD_LCDDisplay0_RAM_Write(MX_UINT8 nIdx, MX_UINT8 d0, MX_UINT8 d1, MX_UINT8 d2, MX_UINT8 d3, MX_UINT8 d4, MX_UINT8 d5, MX_UINT8 d6, MX_UINT8 d7)
{
	   //set CGRAM address

	   FCD_LCDDisplay0_RawSend(64 + (nIdx << 3), 0);
	   delay_ms(2);

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

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

}

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

//Macro implementaties


MX_UINT32 FCM_ABD(MX_UINT32 FCL_BRG_FREQ)
{
	//Definities van locale variabelen
	MX_UINT32 FCL_BAUD_RATE;
	MX_UINT16 FCL_COUNTS;
	MX_UINT8 FCL_CHAR_IN;


	MX_UINT32 FCR_RETVAL;

	//Baud Rate Clock Rates
	//C Code:
	// Baud rate generator:
	// BRG16=0, BRGH=0  Fosc/512
	// BRG16=0, BRGH=1  Fosc/128
	// BRG16=1, BRGH=0  Fosc/128
	// BRG16=1, BRGH=1  Fosc/32
	FCL_BRG_FREQ = FCL_BRG_FREQ >> 5;
	st_bit(txsta,BRGH);  // 1= high speed
	st_bit(baudcon,BRG16);  // 1= 16 bit baud rate generator

	//Baud rate preset
	//C Code:
	FCL_BAUD_RATE = 0xFFFFFFFF;

	//Initialise EUSART Rx
	//C Code:
	cr_bit(txsta,SYNC);  // set asynchronous mode
	st_bit(rcsta,SPEN);  // Enable serial port (Rx,...)
	st_bit(rcsta,CREN);  // enable asynchronous receiver


	//Label AUTOBAUD and set any baud rate
	//C Code:
	AUTOBAUD:
	spbrgh=0;            // Baud Rate generator BRG
	spbrgl=31;            // Baud Rate generator BRG


	//Check overflow and not busy
	//C Code:
	cr_bit(baudcon,ABDOVF);   // clear ABD counter-overflow flag
	while (!(baudcon.RCIDL)); // check Auto-BRD is not busy

	//Wait until 'U' characters has been received
	//C Code:
	while (!(pir1.RCIF));     // wait until USART incoming 'U'
	                          // at the end ABDEN will be reset
	FCL_CHAR_IN= RCREG;          // Read RCREG to clear RCIF interrupt bit
	                          // due to unknown baud rate, the contents of RCREG 
	                          // does not have a meaning here
	FCL_COUNTS= spbrgh<<8+spbrgl-1;   // place into Uint with correction of 1
	FCL_COUNTS=FCL_COUNTS<<3;       // BRG = BRG(during ABD)* 8

	//Commentaar:
	//Ready. The rest is to show the result.

	//Save baud rate
	//C Code:
	spbrgh= FCL_COUNTS>>8;          // replace into BRG
	spbrgl= FCL_COUNTS-spbrgh;


	//Show received character on LCD screen and on diodes on port D
	//C Code:
	while (!(baudcon.RCIDL)); // check Auto-BRD is not busy
	FCL_CHAR_IN= RCREG;         // read new character
	FCD_LCDDisplay0_ClearLine(0);  // clean line
	FCD_LCDDisplay0_PrintNumber(FCL_CHAR_IN);  // print number
	trisd = 0x00;                 // set D as output
	portd = (FCL_CHAR_IN);           // pint temp



	//Repeat procedure if no 'U'charachter has been detected
	//C Code:
	if (FCL_CHAR_IN !=  'U') goto AUTOBAUD;   // repeat if not ?U?


	//Baud rate to high  (ABD counts <4)
	//Decision: .Counts < 32?
	if (FCL_COUNTS < 32)
	{

		//Wrong baud rate
		//Calculation:
		//  .Return = 0xFFFFFFFF
		FCR_RETVAL = 0xFFFFFFFF;

	} else {

		//Calculate baud rate from # of counts
		//Calculation:
		//  .Baud_Rate = .BRG_Freq
		//  .Baud_Rate = .Baud_Rate / .Counts
		//  .Return = .Baud_Rate
		FCL_BAUD_RATE = FCL_BRG_FREQ;
		FCL_BAUD_RATE = FCL_BAUD_RATE / FCL_COUNTS;
		FCR_RETVAL = FCL_BAUD_RATE;

	}

	return (FCR_RETVAL);
	//Definities van locale variabelen

}



void main()
{
	//Initialisatie
	ansela = 0x00;
anselb = 0x00;
anseld = 0x00;
ansele = 0x00;


	//Interrupt-initialisatiecode
	option_reg = 0xC0;


	//Commentaar:
	//Test Auto baud rate detection
	//Use PIC16F1939 with input on Rx (pin C7)
	//Use ABD macro with LCD output and LED outputs for testing
	//Principal:
	//1) Counts the 5 pulses of oscilator with frequency Fosc/32 of the incoming
	//character "U", start and stop bit included.
	//2) Read the U-charcater at least twice. First for the auto-baud detection
	//   and second to check if the U-character is read correctly.
	//Refrences:
	//1) http://www.microchip.com/forums/m233642.aspx
	//2) Datasheet 16F1939 chapter 25
	//January 27,2013
	//Jan Lichtenbelt, NL

	//Start LCD
	//Component Macro Aanroepen: Start()
	FCD_LCDDisplay0_Start();

	//Set Rx as input
	//Input: C7 -> Temp
	trisc = trisc | 0x80;
	FCV_TEMP = ((portc & 0x80) == 0x80);

	//Set microchip oscillator frequency
	//Calculation:
	//  Osc_Freq = 19660800 // Hz
	FCV_OSC_FREQ = 19660800;

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

		//Start Auto baud detection
		//Call Macro: Baud_Rate=ABD(Osc_Freq)
		FCV_BAUD_RATE = FCM_ABD(FCV_OSC_FREQ);

		//change into string
		//Calculation:
		//  baudrate_string = tostring$ (Baud_Rate)
		FCI_TOSTRING(FCV_BAUD_RATE, FCV_BAUDRATE_STRING,FCSZ_BAUDRATE_STRING);

		//Show baud rate
		//Component Macro Aanroepen: PrintString(Baudrate_String)
		FCD_LCDDisplay0_PrintString(FCV_BAUDRATE_STRING, FCSZ_BAUDRATE_STRING);


	}

	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}



