//************************************************************************************
//**  
//**  File name:     G:\Tft for pic\Omaa koodia\Flowcode\Flowcode1.c
//**  Generated by:  Flowcode v4.5.18.74
//**  Date:          Thursday, October 13, 2011 17:49:14
//**  Licence:       Professional
//**  Registered to: Mika Silvennoinen
//**  
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Määrittää mikro-ohjaimen
#define P18F4680
#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 trisd
#define MX_PWM_2 4
#define MX_ECAN

//funktiot
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic18.h>
#endif

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

//Sisäiset toiminnot
#include "G:\flowcode4\FCD\internals.h"

//Makro-funktion kuvaukset


//Muuttujakuvaukset




//Custom2(0): //Defines:
#include <string.h>

//Common defines
#define MX_DATA_PORT 		portc
#define MX_DATA_TRIS		trisc
#define MX_CONTROL_PORT		portd
#define MX_CONTROL_TRIS		trisd
#define MX_CS	      1
#define MX_CD		2
#define MX_RD		3
#define MX_RW			4


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

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

#endif
// this is from glcd component

	//global variables
		short LCD_Back_Color;
		short LCD_Fore_Color;

	
		//global variables
	

	



//Custom2(0): //Makro-funktion kuvaukset

void FCD_Custom20_GetDefines();
void FCD_Custom20_LCD_Init();
void FCD_Custom20_LCD_Set_Fore_Color(char Red, char Green, char Blue);
void FCD_Custom20_LCD_Set_Back_Color(char Red, char Green, char Blue);
void FCD_Custom20_LCD_Draw_Rect(char X1, char Y1, char X2, char Y2, char Transparent, char Solid);
void FCD_Custom20_LCD_Print_String(char* String, char MSZ_String, char X, char Y, char Font, char Transparent);
void FCD_Custom20_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent);
void FCD_Custom20_LCD_Draw_Line(char X1, char Y1, char X2, char Y2);
void FCD_Custom20_LCD_Display_Clear();
void FCD_Custom20_LCD_Send_Cmd(char command);
void FCD_Custom20_LCD_Sent_Data(char dat);
void FCD_Custom20_LCD_Set_Pixel(char x, short y, short color);



//Custom2(0): //Makro-toteutukset


void FCD_Custom20_GetDefines()
{
	

}

void FCD_Custom20_LCD_Init()
{
	//Error Reading Code For default::Macro_LCD_Init
}

void FCD_Custom20_LCD_Set_Fore_Color(char Red, char Green, char Blue)
{
	
		

			if (Red > 0x3F)
				Red = 0x3F;

			if (Green > 0x1F)
				Green = 0x1F;

			if (Blue > 0x1F)
				Blue = 0x1F;

			LCD_Fore_Color = Green | (Red << 5);
			LCD_Fore_Color = LCD_Fore_Color | (Blue << 11);

		
}

void FCD_Custom20_LCD_Set_Back_Color(char Red, char Green, char Blue)
{
	
			if (Red > 0x3F)
				Red = 0x3F;

			if (Green > 0x1F)
				Green = 0x1F;

			if (Blue > 0x1F)
				Blue = 0x1F;

			LCD_Back_Color = Green | (Red << 5);
			LCD_Back_Color = LCD_Back_Color | (Blue << 11);
			FCD_Custom20_LCD_Display_Clear();

		



}

void FCD_Custom20_LCD_Draw_Rect(char X1, char Y1, char X2, char Y2, char Transparent, char Solid)
{
	    char X,Y;
	    short Pixel,Count,Color;

	    FCD_Custom20_LCD_Draw_Line(X1, Y1, X2, Y1);    //draw border
	    FCD_Custom20_LCD_Draw_Line(X2, Y1, X2, Y2);
	    FCD_Custom20_LCD_Draw_Line(X1, Y2, X2, Y2);
	    FCD_Custom20_LCD_Draw_Line(X1, Y1, X1, Y2);

	    if (!Transparent)
	    {
	        X1 = X1 + 2;    //srink box to make room for border
	        Y1 = Y1 + 2;
	        //gLCD_Window(X1,Y1,X2,Y2);        //define window

	        X = X2 - X1;
	        X++;                            //# of X-Pixel
	        Y = Y2 - Y1;
	        Y++;                               //# of Y-Pixel
	        Pixel = X * Y;                   //# of total pixel

	        if (Solid)
	            Color = LCD_Fore_Color;
	        else
	            Color = LCD_Back_Color;

	        for (Count=0;Count<Pixel;Count++)
	        {
				//ForePlot each pixel in the defined output window
			    FCD_Custom20_LCD_Set_Pixel (X,Y,LCD_Fore_Color);
	        }
	    }
}

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

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

	    length_Str = strlen(String);       //Get length of string

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

	    xcount = 0;
	    for (i=0;i<length_Str;i++)         //Start at beginning of string and work along
	    {

	        pos_Str = *(String + i) - 32;      //Calculate place in ASCII memory

	        for (count = 0; count < 5; count++)        //Use correct buffer location
	        {
	            if (pos_Str < 12)
	            {
					position = (pos_Str * 5) + count;
	                temp[count]=ASCII1[position];
	            }
	            else if (pos_Str < 24)
	            {
					position = ((pos_Str - 12)*5) + count;
	                temp[count]=ASCII2[position];
	            }
	            else if (pos_Str < 36)
	            {
					position = ((pos_Str - 24)*5) + count;
	                temp[count]=ASCII3[position];
	            }
	            else if (pos_Str < 48)
	            {
					position = ((pos_Str - 36)*5) + count;
	                temp[count]=ASCII4[position];
	            }
	            else if (pos_Str < 60)
	            {
					position = ((pos_Str - 48)*5) + count;
	                temp[count]=ASCII5[position];
	            }
	            else if (pos_Str < 72)
	            {
					position = ((pos_Str - 60)*5) + count;
	                temp[count]=ASCII6[position];
	            }
	            else if (pos_Str < 84)
	            {
					position = ((pos_Str - 72)*5) + count;
	                temp[count]=ASCII7[position];
	            }
	            else if (pos_Str < 95)
	            {
					position = ((pos_Str - 84)*5) + count;
	                temp[count]=ASCII8[position];
	            }
	        }

	        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
	        {
	            for (width=0;width<Fontwidth;width++)
	            {
	                ycount = 0;
	                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
	                {
	                    for (height=0;height<Fontheight;height++)
	                    {
	                        if (test_bit(temp[xpix],ypix))
	                        {
	                            FCD_Custom20_LCD_Set_Pixel(X + xcount, Y + ycount, LCD_Fore_Color);
	                        }
	                        else if (Transparent == 0)
	                        {
								
								FCD_Custom20_LCD_Set_Pixel(X,Y,LCD_Back_Color);
								
	                        }
	                        ycount++;
	                    }
	                }
	                xcount++;
	            }
	        }
	    }
}

void FCD_Custom20_LCD_Print_Number(short Number, char X, char Y, char Font, char Transparent)
{
		char temp_str[6];
		FCI_TOSTRING(Number,temp_str,6);					//Convert number to String
		FCD_Custom20_LCD_Print_String(temp_str, 6, X, Y, Font, Transparent);		//Send string to Print function
}

void FCD_Custom20_LCD_Draw_Line(char X1, char Y1, char X2, char Y2)
{
	    int C1, M1;
	    signed int D1 = 0;
	    signed int Pixelx = X2 - X1;    //number of X-pixels;
	    signed int Pixely = Y2 - Y1;    //Number of Y-pixels
	    signed char Xinc = 1;
	    signed char Yinc = 1;

	    if (Pixelx < 0)        //If negative X direction
	    {
	        Xinc = -1;
	        Pixelx = Pixelx * -1;
	    }
	    if (Pixely < 0)        //If negative Y direction
	    {
	        Yinc = -1;
	        Pixely = Pixely * -1;
	    }
	    if (Pixely <= Pixelx)
	    {
	        C1 = 2 * Pixelx;
	        M1 = 2 * Pixely;
	        while (X1 != X2)
	        {
	            FCD_Custom20_LCD_Set_Pixel(X1, Y1,LCD_Fore_Color);    //ForePlot line
	            X1 = X1 + Xinc;
	            D1 = D1 + M1;
	            if (D1 > Pixelx)
	            {
	                Y1 = Y1 + Yinc;
	                D1 = D1 - C1;
	            }
	        }
	    }
	    else
	    {
	        C1 = 2 * Pixely;
	        M1 = 2 * Pixelx;
	        while (Y1 != Y2)
	        {
	            FCD_Custom20_LCD_Set_Pixel(X1, Y1,LCD_Fore_Color);    //ForePlot Line
	            Y1 = Y1 + Yinc;
	            D1 = D1 + M1;
	            if (D1 > Pixely)
	            {
	                X1 = X1 + Xinc;
	                D1 = D1 - C1;
	            }
	        }
	        FCD_Custom20_LCD_Set_Pixel(X1, Y1,LCD_Fore_Color);
	    }
}

void FCD_Custom20_LCD_Display_Clear()
{
	//Error Reading Code For default::Macro_LCD_Display_Clear
}

void FCD_Custom20_LCD_Send_Cmd(char command)
{
	
		MX_DATA_PORT = command;
		clear_bit(MX_CONTROL_PORT,MX_CD);		//CD LOW for display data
		clear_bit(MX_CONTROL_PORT,MX_RW);
		set_bit(MX_CONTROL_PORT,MX_RD);	
		clear_bit(MX_CONTROL_PORT,MX_CS);	  //CS low for read										
		set_bit(MX_CONTROL_PORT,MX_CS);      //CS high
		
		
}

void FCD_Custom20_LCD_Sent_Data(char dat)
{
	
		MX_DATA_PORT = dat;
		set_bit(MX_CONTROL_PORT,MX_CD);		//CD HIGH for display data
		clear_bit(MX_CONTROL_PORT,MX_RW);
		set_bit(MX_CONTROL_PORT,MX_RD);	
		clear_bit(MX_CONTROL_PORT,MX_CS);	  //CS low for read										
		set_bit(MX_CONTROL_PORT,MX_CS);      //CS high
		
		
}

void FCD_Custom20_LCD_Set_Pixel(char x, short y, short color)
{
	//Error Reading Code For default::Macro_LCD_Set_Pixel
}

//Makro-toteutukset

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


	//Keskeytyksen alustuskoodi
	


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Init
	FCD_Custom20_LCD_Init();


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Set_Fore_Color(3, 3, 3)
	FCD_Custom20_LCD_Set_Fore_Color(3, 3, 3);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Set_Back_Color(3, 3, 3)
	FCD_Custom20_LCD_Set_Back_Color(3, 3, 3);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Draw_Rect(2, 2, 3, 3, 1, 3)
	FCD_Custom20_LCD_Draw_Rect(2, 2, 3, 3, 1, 3);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Print_String("as", 3, 3, 3, 1)
	FCD_Custom20_LCD_Print_String("as",2, 3, 3, 3, 1);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Print_Number(23, 3, 3, 4, 5)
	FCD_Custom20_LCD_Print_Number(23, 3, 3, 4, 5);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Draw_Line(1, 1, 2, 2)
	FCD_Custom20_LCD_Draw_Line(1, 1, 2, 2);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Display_Clear
	FCD_Custom20_LCD_Display_Clear();


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Send_Cmd(3)
	FCD_Custom20_LCD_Send_Cmd(3);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Sent_Data(5)
	FCD_Custom20_LCD_Sent_Data(5);


	//Kutsu komponenttimakro
	//Kutsu komponenttimakro: Custom2(0)::LCD_Set_Pixel(2, 4, 567)
	FCD_Custom20_LCD_Set_Pixel(2, 4, 567);


	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}



