//************************************************************************************
//**  
//**  File name:     C:\Documents and Settings\devry\My Documents\DeVry\ECT108\Flowcode\Test_Compare.c
//**  Generated by:  Flowcode v3.4.7.48
//**  Date:          Thursday, July 29, 2010 22:07:42
//**  Licence:       50 User
//**  Registered to: DeVry University Laptop
//**  
//**  
//**     NOT FOR COMMERCIAL USE
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P16F88
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_B
#define MX_SPI_SDI 1
#define MX_SPI_SDO 2
#define MX_SPI_SCK 4
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 5
#define MX_UART_RX 2
#define MX_I2C
#define MX_I2C_B
#define MX_I2C_SDA 1
#define MX_I2C_SCL 4
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisb
#define MX_PWM_1 0
#define MX_PWM_TRIS1a trisb
#define MX_PWM_1a 3

//Functions
#include <system.h>
#pragma CLOCK_FREQ 19660800

//Configuration data

//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V3\FCD\internals.h"

//Macro function declarations
void FCM_Init_vars();
void FCM_test_strings();
void FCM_print_ok();
void FCM_print_not_ok();
void FCM_print_num();
void FCM_Third_Test();
void FCM_Second_Test();
void FCM_First_Test();


//Variable declarations
#define FCSZ_SECOND_STRING 20
#define FCSZ_OKAY 20
#define FCSZ_NOT_MATCH 20
#define FCSZ_FIRST_STRING 20
#define FCSZ_THIRD_STRING 20
#define FCSZ_MESSAGE 20
#define FCSZ_FOURTH_STRING 20
char FCV_FIRST_ROW;
char FCV_MSG_OK_POS;
char FCV_SECOND_STRING[FCSZ_SECOND_STRING];
char FCV_OKAY[FCSZ_OKAY];
char FCV_NOT_MATCH[FCSZ_NOT_MATCH];
char FCV_FIRST_STRING[FCSZ_FIRST_STRING];
char FCV_THIRD_STRING[FCSZ_THIRD_STRING];
char FCV_LENGTH;
char FCV_NUMBER;
char FCV_SECOND_ROW;
char FCV_MSG_NOT_POS;
char FCV_NUM_CHAR;
char FCV_MESSAGE[FCSZ_MESSAGE];
char FCV_MSG_POS;
char FCV_COMP;
char FCV_FOURTH_STRING[FCSZ_FOURTH_STRING];




//LCDDisplay0: //Macro function declarations

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);

//Supplementary defines




//LCDDisplay0: //Macro implementations


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

	//component connections
	#define LCD_66672_PORT    portb
	#define LCD_66672_TRIS    trisb
	#define LCD_66672_BIT0    0
	#define LCD_66672_BIT1    1
	#define LCD_66672_BIT2    2
	#define LCD_66672_BIT3    3
	#define LCD_66672_RS      4
	#define LCD_66672_E       5

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



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

	//internal function implementations
	void LCD_66672_RawSend(char nIn, char nMask)
	{
		unsigned char pt;
		unsigned char outVal;
		outVal = LCD_66672_PORT;
		clear_bit(outVal, LCD_66672_BIT0);
		clear_bit(outVal, LCD_66672_BIT1);
		clear_bit(outVal, LCD_66672_BIT2);
		clear_bit(outVal, LCD_66672_BIT3);
		clear_bit(outVal, LCD_66672_RS);
		clear_bit(outVal, LCD_66672_E);
		pt = ((nIn >> 4) & 0x0f);
		if (pt & 0x01)
		    set_bit(outVal, LCD_66672_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_66672_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_66672_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_66672_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_66672_RS);
		LCD_66672_PORT = outVal;
		LCD_66672_DELAY;
		set_bit (LCD_66672_PORT, LCD_66672_E);
		LCD_66672_DELAY;
		clear_bit (LCD_66672_PORT, LCD_66672_E);
		pt = (nIn & 0x0f);
		LCD_66672_DELAY;
		outVal = LCD_66672_PORT;
		clear_bit(outVal, LCD_66672_BIT0);
		clear_bit(outVal, LCD_66672_BIT1);
		clear_bit(outVal, LCD_66672_BIT2);
		clear_bit(outVal, LCD_66672_BIT3);
		clear_bit(outVal, LCD_66672_RS);
		clear_bit(outVal, LCD_66672_E);
		if (pt & 0x01)
		    set_bit(outVal, LCD_66672_BIT0);
		if (pt & 0x02)
		    set_bit(outVal, LCD_66672_BIT1);
		if (pt & 0x04)
		    set_bit(outVal, LCD_66672_BIT2);
		if (pt & 0x08)
		    set_bit(outVal, LCD_66672_BIT3);
		if (nMask)
		    set_bit(outVal, LCD_66672_RS);
		LCD_66672_PORT = outVal;
		LCD_66672_DELAY;
		set_bit (LCD_66672_PORT, LCD_66672_E);
		LCD_66672_DELAY;
		clear_bit (LCD_66672_PORT, LCD_66672_E);
		LCD_66672_DELAY;
	}

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

}

void FCD_LCDDisplay0_Start()
{
	
		clear_bit(LCD_66672_TRIS, LCD_66672_BIT0);
		clear_bit(LCD_66672_TRIS, LCD_66672_BIT1);
		clear_bit(LCD_66672_TRIS, LCD_66672_BIT2);
		clear_bit(LCD_66672_TRIS, LCD_66672_BIT3);
		clear_bit(LCD_66672_TRIS, LCD_66672_RS);
		clear_bit(LCD_66672_TRIS, LCD_66672_E);

		delay_ms(12);

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

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

}

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

}

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

}

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

}

void FCD_LCDDisplay0_RawSend(char in, char mask)
{
	//Error Reading Code For LCD 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=0x94;
		else
			y=0xd4;
	  #endif

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

}

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

		tmp_int = Number;
		if (Number >= 10000)
		{
			tmp_byte = tmp_int / 10000;
			LCD_66672_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_66672_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_66672_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_66672_RawSend('0' + tmp_byte, 0x10);

			while (tmp_byte > 0)
			{
				tmp_int = tmp_int - 10;
				tmp_byte--;
			}
		}
		LCD_66672_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_66672_RawSend(String[idx], 0x10);
		}

}

//Macro implementations

void FCM_Init_vars()
{
	
	//Initialize Variables
	//Calculation:
	//  comp = 0
	//  msg_pos = 3
	//  msg_ok_pos = 5
	//  msg_not_pos = 3
	//  first_row = 0
	//  second_row = 1
	//  num_char = 0
	FCV_COMP = 0;
	FCV_MSG_POS = 3;
	FCV_MSG_OK_POS = 5;
	FCV_MSG_NOT_POS = 3;
	FCV_FIRST_ROW = 0;
	FCV_SECOND_ROW = 1;
	FCV_NUM_CHAR = 0;
	

	//String Manipulation
	//String Manipulation:
	//  first_string = "123456"
	//  second_string = "123456"
	//  third_string = "654321"
	//  message = "Strings do"
	//  okay = "match!"
	//  not_match = "not match!"
	FCI_CONCATENATE("123456",6,"",0,FCV_FIRST_STRING,FCSZ_FIRST_STRING);
	FCI_CONCATENATE("123456",6,"",0,FCV_SECOND_STRING,FCSZ_SECOND_STRING);
	FCI_CONCATENATE("654321",6,"",0,FCV_THIRD_STRING,FCSZ_THIRD_STRING);
	FCI_CONCATENATE("Strings do",10,"",0,FCV_MESSAGE,FCSZ_MESSAGE);
	FCI_CONCATENATE("match!",6,"",0,FCV_OKAY,FCSZ_OKAY);
	FCI_CONCATENATE("not match!",10,"",0,FCV_NOT_MATCH,FCSZ_NOT_MATCH);
	

	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Start
	FCD_LCDDisplay0_Start();


}

void FCM_test_strings()
{
	//To test Strings comparison.
	
	//Call Macro
	//Call Macro: First_Test
	FCM_First_Test();


	//Call Macro
	//Call Macro: Second_Test
	FCM_Second_Test();


	//Call Macro 
	//Call Macro: Third_Test
	FCM_Third_Test();


}

void FCM_print_ok()
{
	
	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(msg_pos, first_row)
	FCD_LCDDisplay0_Cursor(FCV_MSG_POS, FCV_FIRST_ROW);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::PrintString(message)
	FCD_LCDDisplay0_PrintString(FCV_MESSAGE,FCSZ_MESSAGE);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(msg_ok_pos, second_row)
	FCD_LCDDisplay0_Cursor(FCV_MSG_OK_POS, FCV_SECOND_ROW);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::PrintString(okay)
	FCD_LCDDisplay0_PrintString(FCV_OKAY,FCSZ_OKAY);


}

void FCM_print_not_ok()
{
	
	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(msg_pos, first_row)
	FCD_LCDDisplay0_Cursor(FCV_MSG_POS, FCV_FIRST_ROW);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::PrintString(message)
	FCD_LCDDisplay0_PrintString(FCV_MESSAGE,FCSZ_MESSAGE);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(msg_not_pos, second_row)
	FCD_LCDDisplay0_Cursor(FCV_MSG_NOT_POS, FCV_SECOND_ROW);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::PrintString(not_match)
	FCD_LCDDisplay0_PrintString(FCV_NOT_MATCH,FCSZ_NOT_MATCH);


}

void FCM_print_num()
{
	
	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::Cursor(num_char, second_row)
	FCD_LCDDisplay0_Cursor(FCV_NUM_CHAR, FCV_SECOND_ROW);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(0)::PrintNumber(number)
	FCD_LCDDisplay0_PrintNumber(FCV_NUMBER);


}

void FCM_Third_Test()
{
	
	//Compare strings two and three!
	//String Manipulation:
	//  length = Length$(first_string)
	//  fourth_string = Mid$(first_string, 0, 5)
	//  comp = Compare$(first_string, fourth_string, length)
	FCV_LENGTH = FCI_GETLENGTH(FCV_FIRST_STRING,FCSZ_FIRST_STRING);
	FCI_MIDSTRING(FCV_FIRST_STRING,FCSZ_FIRST_STRING,FCV_FOURTH_STRING,FCSZ_FOURTH_STRING,0,5);
	FCV_COMP = FCI_COMPARE(FCV_FIRST_STRING,FCSZ_FIRST_STRING,FCV_FOURTH_STRING,FCSZ_FOURTH_STRING,FCV_LENGTH);
	

	//Decision
	//Decision: comp = 1?
	if (FCV_COMP == 1)
	{
		//Call  Not Okay
		//Call Macro: print_not_ok
		FCM_print_not_ok();


	} else {
		//Call Macro
		//Call Macro: print_ok
		FCM_print_ok();


	}


	//Calculation
	//Calculation:
	//  number = 3
	FCV_NUMBER = 3;
	

	//Call Macro
	//Call Macro: print_num
	FCM_print_num();


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


}

void FCM_Second_Test()
{
	
	//Comment:
	//Compare two unequal 
	//strings!


	//Compare strings two and three!
	//String Manipulation:
	//  length = Length$(first_string)
	//  comp = Compare$(first_string, third_string, length)
	FCV_LENGTH = FCI_GETLENGTH(FCV_FIRST_STRING,FCSZ_FIRST_STRING);
	FCV_COMP = FCI_COMPARE(FCV_FIRST_STRING,FCSZ_FIRST_STRING,FCV_THIRD_STRING,FCSZ_THIRD_STRING,FCV_LENGTH);
	

	//Decision
	//Decision: comp = 1?
	if (FCV_COMP == 1)
	{
		//Call  Not Okay
		//Call Macro: print_not_ok
		FCM_print_not_ok();


	} else {
		//Call Macro
		//Call Macro: print_ok
		FCM_print_ok();


	}


	//Calculation
	//Calculation:
	//  number = 2
	FCV_NUMBER = 2;
	

	//Call Macro
	//Call Macro: print_num
	FCM_print_num();


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


}

void FCM_First_Test()
{
	
	//String Manipulation
	//String Manipulation:
	//  length = Length$(first_string)
	//  comp = Compare$(first_string, second_string, length)
	FCV_LENGTH = FCI_GETLENGTH(FCV_FIRST_STRING,FCSZ_FIRST_STRING);
	FCV_COMP = FCI_COMPARE(FCV_FIRST_STRING,FCSZ_FIRST_STRING,FCV_SECOND_STRING,FCSZ_SECOND_STRING,FCV_LENGTH);
	

	//Comment:
	//Compare two equal
	//strings!


	//Compare strings one and two
	//Decision: comp = 0?
	if (FCV_COMP == 0)
	{
		//Call Macro
		//Call Macro: print_ok
		FCM_print_ok();


	} else {
		//Call  Not Okay
		//Call Macro: print_not_ok
		FCM_print_not_ok();


	}


	//Calculation
	//Calculation:
	//  number = 1
	FCV_NUMBER = 1;
	

	//Call Macro
	//Call Macro: print_num
	FCM_print_num();


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


}

//Supplementary implementations


void main()
{
	
	//Initialisation
	ansel = 0;
	cmcon = 0x07;


	//Interrupt initialisation code
	option_reg = 0xC0;


	//Set variables and start LCD
	//Call Macro: Init_vars
	FCM_Init_vars();


	//Test strings
	//Call Macro: test_strings
	FCM_test_strings();


	mainendloop: goto mainendloop;
}

void interrupt(void)
{
}



