//************************************************************************************
//**  
//**  File name:     D:\sachs_work\ECIO\ECIO_Test_Files\v3 anz_test\anz_test.c
//**  Generated by:  Flowcode v3.6.11.53
//**  Date:          Saturday, September 19, 2009 14:23:53
//**  Licence:       Professional
//**  Registered to: sachs wolfgang
//**  
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Definitionen für Microcontroller
#define P18F4620
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 1024
#define MX_SPI
#define MX_SPI_C
#define MX_SPI_SDI 4
#define MX_SPI_SDO 5
#define MX_SPI_SCK 3
#define MX_UART
#define MX_UART_C
#define MX_UART_TX 6
#define MX_UART_RX 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_C
#define MX_I2C_SDA 4
#define MX_I2C_SCL 3
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 2
#define MX_PWM_TRIS2 trisc
#define MX_PWM_2 1
#define MX_PWM_TRIS2a trisb
#define MX_PWM_2a 3

//Funktionen
#include <system.h>
#pragma CLOCK_FREQ 39321600

//Konfigurations-Daten
#pragma DATA 0x300000, 0xff
#pragma DATA 0x300001, 0x6
#pragma DATA 0x300002, 0x19
#pragma DATA 0x300003, 0x1e
#pragma DATA 0x300004, 0xff
#pragma DATA 0x300005, 0x81
#pragma DATA 0x300006, 0x80
#pragma DATA 0x300007, 0xff
#pragma DATA 0x300008, 0xf
#pragma DATA 0x300009, 0xc0
#pragma DATA 0x30000a, 0xf
#pragma DATA 0x30000b, 0xe0
#pragma DATA 0x30000c, 0xf
#pragma DATA 0x30000d, 0x40

//Interne Funktionen
#include "C:\Programme\Matrix Multimedia\Flowcode V3\FCD\internals.h"

//Makro-Funktions-Deklarationen


//Variablen-Deklarationen
char FCV_NUMMER;




//LCDDisplay0: //Makro-Funktions-Deklarationen

void FCD_LCDDisplay0_GetDefines();
void FCD_LCDDisplay0_Start();
void FCD_LCDDisplay0_Clear();
void FCD_LCDDisplay0_PrintASCII(char Character);
void FCD_LCDDisplay0_Command(char in);
void FCD_LCDDisplay0_RawSend(char in, char mask);
void FCD_LCDDisplay0_Cursor(char x, char y);
void FCD_LCDDisplay0_PrintNumber(short Number);
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String);

//Ergänzende Definitionen




//LCDDisplay0: //Makro-Implementierungen


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

	//component connections
	#define LCD_1969722_PORT    porta
	#define LCD_1969722_TRIS    trisa
	#define LCD_1969722_BIT0    0
	#define LCD_1969722_BIT1    1
	#define LCD_1969722_BIT2    2
	#define LCD_1969722_BIT3    3
	#define LCD_1969722_RS      4
	#define LCD_1969722_E       5

	#ifdef _BOOSTC
	  #define LCD_1969722_DELAY   delay_10us(10)
	#endif
	#ifdef _C2C_
	  #define LCD_1969722_DELAY   delay_us(100)
	#endif
	#ifndef LCD_1969722_DELAY
	  #define LCD_1969722_DELAY   delay_us(100)
	#endif



	//internal function prototypes
	void LCD_1969722_RawSend(char nIn, char nMask);

	//internal function implementations
	void LCD_1969722_RawSend(char nIn, char nMask)
	{
		unsigned char pt;
		unsigned char outVal;
		outVal = LCD_1969722_PORT;
		clear_bit(outVal, LCD_1969722_BIT0);
		clear_bit(outVal, LCD_1969722_BIT1);
		clear_bit(outVal, LCD_1969722_BIT2);
		clear_bit(outVal, LCD_1969722_BIT3);
		clear_bit(outVal, LCD_1969722_RS);
		clear_bit(outVal, LCD_1969722_E);
		pt = ((nIn >> 4) & 0x0f);
		if (pt & 0x01)
		    set_bit(outVal, LCD_1969722_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_1969722_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_1969722_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_1969722_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_1969722_RS);
		LCD_1969722_PORT = outVal;
		LCD_1969722_DELAY;
		set_bit (LCD_1969722_PORT, LCD_1969722_E);
		LCD_1969722_DELAY;
		clear_bit (LCD_1969722_PORT, LCD_1969722_E);
		pt = (nIn & 0x0f);
		LCD_1969722_DELAY;
		outVal = LCD_1969722_PORT;
		clear_bit(outVal, LCD_1969722_BIT0);
		clear_bit(outVal, LCD_1969722_BIT1);
		clear_bit(outVal, LCD_1969722_BIT2);
		clear_bit(outVal, LCD_1969722_BIT3);
		clear_bit(outVal, LCD_1969722_RS);
		clear_bit(outVal, LCD_1969722_E);
		if (pt & 0x01)
		    set_bit(outVal, LCD_1969722_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_1969722_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_1969722_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_1969722_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_1969722_RS);
		LCD_1969722_PORT = outVal;
		LCD_1969722_DELAY;
		set_bit (LCD_1969722_PORT, LCD_1969722_E);
		LCD_1969722_DELAY;
		clear_bit (LCD_1969722_PORT, LCD_1969722_E);
		LCD_1969722_DELAY;
	}

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

}

void FCD_LCDDisplay0_Start()
{
	
		clear_bit(LCD_1969722_TRIS, LCD_1969722_BIT0);
		clear_bit(LCD_1969722_TRIS, LCD_1969722_BIT1);
		clear_bit(LCD_1969722_TRIS, LCD_1969722_BIT2);
		clear_bit(LCD_1969722_TRIS, LCD_1969722_BIT3);
		clear_bit(LCD_1969722_TRIS, LCD_1969722_RS);
		clear_bit(LCD_1969722_TRIS, LCD_1969722_E);

		delay_ms(12);

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

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

}

void FCD_LCDDisplay0_Clear()
{
	
		LCD_1969722_RawSend(0x01, 0);
		delay_ms(2);
		LCD_1969722_RawSend(0x02, 0);
		delay_ms(2);

}

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

}

void FCD_LCDDisplay0_Command(char in)
{
	
		LCD_1969722_RawSend(in, 0);
		delay_ms(2);

}

void FCD_LCDDisplay0_RawSend(char in, char mask)
{
	//Error Reading Code For LC-Display::Macro_RawSend
}

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

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

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

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

}

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

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

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

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

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

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

}

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

}

//Makro-Implementierungen

//Ergänzende Implementierungen


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


	//Interrupt-Initialisierungs-Kode
	


	//Kommentar:
	//18F4620 v3 anz_test
	//39321600 HZ


	//Kommentar:
	//for my board settings
	//start


	//adresse 0
	//Output: 0 -> PORT E
	trise = trise & 0xf8;
	porte = (porte & 0xf8) | (0 & 0x07);


	//i/o select
	//Output: 1 -> C0
	trisc = trisc & 0xfe;
	if (1)
		portc = (portc & 0xfe) | 0x01;
	else
		portc = portc & 0xfe;


	//disp backgr
	//Output: 1 -> C4
	trisc = trisc & 0xef;
	if (1)
		portc = (portc & 0xef) | 0x10;
	else
		portc = portc & 0xef;


	//rdx/wrx
	//Output: 1 -> C5
	trisc = trisc & 0xdf;
	if (1)
		portc = (portc & 0xdf) | 0x20;
	else
		portc = portc & 0xdf;


	//rd/wr
	//Output: 1 -> C6
	trisc = trisc & 0xbf;
	if (1)
		portc = (portc & 0xbf) | 0x40;
	else
		portc = portc & 0xbf;


	//lo/hi
	//Output: 1 -> C7
	trisc = trisc & 0x7f;
	if (1)
		portc = (portc & 0x7f) | 0x80;
	else
		portc = portc & 0x7f;


	//Kommentar:
	//for my board settings
	//end


	//Berechnung
	//Berechnung:
	//  nummer = 0
	FCV_NUMMER = 0;
	

	//Aufruf Komponenten-Makro
	//Aufruf Komponenten-Makro: LCDDisplay(0)::Start
	FCD_LCDDisplay0_Start();


	//Aufruf Komponenten-Makro
	//Aufruf Komponenten-Makro: LCDDisplay(0)::PrintASCII("Anzeigentest:")
	FCD_LCDDisplay0_PrintASCII('A');
	FCD_LCDDisplay0_PrintASCII('n');
	FCD_LCDDisplay0_PrintASCII('z');
	FCD_LCDDisplay0_PrintASCII('e');
	FCD_LCDDisplay0_PrintASCII('i');
	FCD_LCDDisplay0_PrintASCII('g');
	FCD_LCDDisplay0_PrintASCII('e');
	FCD_LCDDisplay0_PrintASCII('n');
	FCD_LCDDisplay0_PrintASCII('t');
	FCD_LCDDisplay0_PrintASCII('e');
	FCD_LCDDisplay0_PrintASCII('s');
	FCD_LCDDisplay0_PrintASCII('t');
	FCD_LCDDisplay0_PrintASCII(':');


	//Verbindungspunkt
	//Verbindungspunkt: A
FCC_Haupt_A:


	//Berechnung
	//Berechnung:
	//  nummer = nummer + 1
	FCV_NUMMER = FCV_NUMMER + 1;
	

	//Aufruf Komponenten-Makro
	//Aufruf Komponenten-Makro: LCDDisplay(0)::Cursor(0, 1)
	FCD_LCDDisplay0_Cursor(0, 1);


	//Aufruf Komponenten-Makro
	//Aufruf Komponenten-Makro: LCDDisplay(0)::PrintNumber(nummer)
	FCD_LCDDisplay0_PrintNumber(FCV_NUMMER);


	//Warten
	//Warten: 500 ms
	delay_ms(255);
	delay_ms(245);


	//Gehe zum Verbindungspunkt
	//Gehe zum Verbindungspunkt: A
	goto FCC_Haupt_A;


	mainendloop: goto mainendloop;
}

void interrupt(void)
{
}



