//************************************************************************************
//**  
//**  File name:     C:\Users\dbasnett\Desktop\Flowcode_V4_Examples\Examples\Components\LCD\5. Digital clock.c
//**  Generated by:  Flowcode v4.3.9.65
//**  Date:          Wednesday, August 17, 2011 17:57:31
//**  Licence:       Free version
//**  
//**        ***FREE/DEMO VERSION***
//**  
//**  
//**     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
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif

//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x2007, 0x3f2a
#endif
#ifdef HI_TECH_C
__CONFIG(0x3f2a);
#endif
#ifdef _BOOSTC
#pragma DATA 0x2008, 0x3ffc
#endif
#ifdef HI_TECH_C
__CONFIG(0x3ffc);
#endif

//Internal functions
#include "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h"

//Macro function declarations
void FCM_INTERRUPT_TMR0();
void FCM_INTERRUPT_RB0INT();
void FCM_INTERRUPT_PORTB();
void FCM_SECONDS();
void FCM_INITIALISE();
void FCM_MINUTES();
void FCM_HOURS();
void FCM_DISPLAYTIME();
void FCM_TEST_SETTINGS();


//Variable declarations
char FCV_HOURS_UNITS_LCD;
char FCV_SECONDS_UNITS_LCD;
char FCV_MINUTES_UNITS;
char FCV_SECONDS;
char FCV_HOURS_TENS_LCD;
char FCV_MINUTES_TENS_LCD;
char FCV_MINUTES;
char FCV_HOURS_UNITS;
char FCV_SECOND_COUNTER;
char FCV_SECONDS_TENS;
char FCV_SECONDS_UNITS;
char FCV_MINUTES_TENS;
char FCV_HOURS;
char FCV_COLON;
char FCV_SECONDS_TENS_LCD;
char FCV_HOURS_TENS;
char FCV_MINUTES_UNITS_LCD;


//Defines:

/**** Macro Substitutions ****
portb = D1 Port
trisb = D1 Data Direction
portb = D2 Port
trisb = D2 Data Direction
portb = D3 Port
trisb = D3 Data Direction
portb = D4 Port
trisb = D4 Data Direction
portb = RS Port
trisb = RS Data Direction
portb = E Port
trisb = E Data Direction
0 = Data 1_Pin
1 = Data 2 Pin
2 = Data 3 Pin
3 = Data 4 Pin
4 = RS Pin
5 = Enable Pin
LCD_5443922 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/

	//component connections
	#define LCD_5443922_PORT0    portb
	#define LCD_5443922_TRIS0    trisb
	#define LCD_5443922_PORT1    portb
	#define LCD_5443922_TRIS1    trisb
	#define LCD_5443922_PORT2    portb
	#define LCD_5443922_TRIS2    trisb
	#define LCD_5443922_PORT3    portb
	#define LCD_5443922_TRIS3    trisb
	#define LCD_5443922_PORT4    portb
	#define LCD_5443922_TRIS4    trisb
	#define LCD_5443922_PORT5    portb
	#define LCD_5443922_TRIS5    trisb
	#define LCD_5443922_BIT0    	0
	#define LCD_5443922_BIT1    	1
	#define LCD_5443922_BIT2    	2
	#define LCD_5443922_BIT3    	3
	#define LCD_5443922_RS      	4
	#define LCD_5443922_E       	5
	#define LCD_5443922_ROWCNT	2
	#define LCD_5443922_COLCNT	16

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




//LCDDisplay(1): //Macro function declarations

void FCD_LCDDisplay1_RawSend(char in, char mask);
void FCD_LCDDisplay1_Start();
void FCD_LCDDisplay1_Clear();
void FCD_LCDDisplay1_PrintASCII(char Character);
void FCD_LCDDisplay1_Command(char in);
void FCD_LCDDisplay1_Cursor(char x, char y);
void FCD_LCDDisplay1_PrintNumber(short Number);
void FCD_LCDDisplay1_PrintString(char* String, char MSZ_String);
void FCD_LCDDisplay1_ScrollDisplay(char Direction, char Num_Positions);
void FCD_LCDDisplay1_ClearLine(char Line);
void FCD_LCDDisplay1_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7);



//LCDDisplay(1): //Macro implementations


void FCD_LCDDisplay1_RawSend(char in, char mask)
{
		unsigned char pt;

		clear_bit(LCD_5443922_PORT0, LCD_5443922_BIT0);
		clear_bit(LCD_5443922_PORT1, LCD_5443922_BIT1);
		clear_bit(LCD_5443922_PORT2, LCD_5443922_BIT2);
		clear_bit(LCD_5443922_PORT3, LCD_5443922_BIT3);
		clear_bit(LCD_5443922_PORT4, LCD_5443922_RS);
		clear_bit(LCD_5443922_PORT5, LCD_5443922_E);
		pt = ((in >> 4) & 0x0f);
		if (pt & 0x01)
		    set_bit(LCD_5443922_PORT0, LCD_5443922_BIT0);
		if (pt & 0x02)
		    set_bit(LCD_5443922_PORT1, LCD_5443922_BIT1);
		if (pt & 0x04)
		    set_bit(LCD_5443922_PORT2, LCD_5443922_BIT2);
		if (pt & 0x08)
		    set_bit(LCD_5443922_PORT3, LCD_5443922_BIT3);
		if (mask)
		    set_bit(LCD_5443922_PORT4, LCD_5443922_RS);
		LCD_5443922_DELAY;
		set_bit (LCD_5443922_PORT5, LCD_5443922_E);
		LCD_5443922_DELAY;
		clear_bit (LCD_5443922_PORT5, LCD_5443922_E);
		pt = (in & 0x0f);
		LCD_5443922_DELAY;
		clear_bit(LCD_5443922_PORT0, LCD_5443922_BIT0);
		clear_bit(LCD_5443922_PORT1, LCD_5443922_BIT1);
		clear_bit(LCD_5443922_PORT2, LCD_5443922_BIT2);
		clear_bit(LCD_5443922_PORT3, LCD_5443922_BIT3);
		clear_bit(LCD_5443922_PORT4, LCD_5443922_RS);
		clear_bit(LCD_5443922_PORT5, LCD_5443922_E);
		if (pt & 0x01)
		    set_bit(LCD_5443922_PORT0, LCD_5443922_BIT0);
		if (pt & 0x02)
		    set_bit(LCD_5443922_PORT1, LCD_5443922_BIT1);
		if (pt & 0x04)
		    set_bit(LCD_5443922_PORT2, LCD_5443922_BIT2);
		if (pt & 0x08)
		    set_bit(LCD_5443922_PORT3, LCD_5443922_BIT3);
		if (mask)
		    set_bit(LCD_5443922_PORT4, LCD_5443922_RS);
		LCD_5443922_DELAY;
		set_bit (LCD_5443922_PORT5, LCD_5443922_E);
		LCD_5443922_DELAY;
		clear_bit (LCD_5443922_PORT5, LCD_5443922_E);
		LCD_5443922_DELAY;
}

void FCD_LCDDisplay1_Start()
{
	
		clear_bit(LCD_5443922_TRIS0, LCD_5443922_BIT0);
		clear_bit(LCD_5443922_TRIS1, LCD_5443922_BIT1);
		clear_bit(LCD_5443922_TRIS2, LCD_5443922_BIT2);
		clear_bit(LCD_5443922_TRIS3, LCD_5443922_BIT3);
		clear_bit(LCD_5443922_TRIS4, LCD_5443922_RS);
		clear_bit(LCD_5443922_TRIS5, LCD_5443922_E);

		Wdt_Delay_Ms(12);

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

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

}

void FCD_LCDDisplay1_Clear()
{
	
		FCD_LCDDisplay1_RawSend(0x01, 0);
		Wdt_Delay_Ms(2);
		FCD_LCDDisplay1_RawSend(0x02, 0);
		Wdt_Delay_Ms(2);

}

void FCD_LCDDisplay1_PrintASCII(char Character)
{
	
		FCD_LCDDisplay1_RawSend(Character, 0x10);

}

void FCD_LCDDisplay1_Command(char in)
{
	
		FCD_LCDDisplay1_RawSend(in, 0);
		Wdt_Delay_Ms(2);

}

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

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

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

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

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

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

}

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

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

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

}

void FCD_LCDDisplay1_PrintString(char* String, char MSZ_String)
{
	
		char idx = 0;

		for (idx=0; idx<MSZ_String; idx++)
		{
			#ifdef _BOOSTC
				if (String[idx] == 0)
				{
					break;
				}
				FCD_LCDDisplay1_RawSend(String[idx], 0x10);
			#endif

			#ifdef HI_TECH_C
				if (*String == 0)
				{
					break;
				}
				FCD_LCDDisplay1_RawSend(*String, 0x10);
				String++;
			#endif
		}

}

void FCD_LCDDisplay1_ScrollDisplay(char Direction, char Num_Positions)
{
	
		char cmd = 0;
		char 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_LCDDisplay1_Command(cmd);
		}

}

void FCD_LCDDisplay1_ClearLine(char Line)
{
	
		char count;
		char rowcount;

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

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

		#if (LCD_5443922_ROWCNT == 4)
			#if (LCD_5443922_COLCNT == 16)
				rowcount=16;
			#endif
			#if (LCD_5443922_COLCNT == 20)
				rowcount=20;
			#endif
		#endif

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

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

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

}

void FCD_LCDDisplay1_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7)
{
	   //set CGRAM address
	   FCD_LCDDisplay1_RawSend(64 + (nIdx << 3), 0);
	   delay_ms(2);

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

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

//Macro implementations

void FCM_INTERRUPT_TMR0()
{
	
	//Calculation
	//Calculation:
	//  SECOND_COUNTER = SECOND_COUNTER + 1
	FCV_SECOND_COUNTER = FCV_SECOND_COUNTER + 1;
	

}

void FCM_INTERRUPT_RB0INT()
{
	
}

void FCM_INTERRUPT_PORTB()
{
	
}

void FCM_SECONDS()
{
	//Update every second
	
	// needed for a second
	//Decision: SECOND_COUNTER >= 150?
	if (FCV_SECOND_COUNTER >= 150)
	{
		//Calculation
		//Calculation:
		//  SECOND_COUNTER = 0
		FCV_SECOND_COUNTER = 0;
		

		//Add a second
		//Calculation:
		//  SECONDS = SECONDS + 1
		FCV_SECONDS = FCV_SECONDS + 1;
		

		//Output
		//Output: SECONDS -> PORT A
		trisa = trisa & 0xe0;
		porta = (porta & 0xe0) | (FCV_SECONDS & 0x1f);


		//Calculation
		//Calculation:
		//  SECONDS_UNITS = SECONDS_UNITS + 1
		FCV_SECONDS_UNITS = FCV_SECONDS_UNITS + 1;
		

		//Decision
		//Decision: SECONDS_UNITS >= 10?
		if (FCV_SECONDS_UNITS >= 10)
		{
			//Calculation
			//Calculation:
			//  SECONDS_UNITS = 0
			FCV_SECONDS_UNITS = 0;
			

			//Calculation
			//Calculation:
			//  SECONDS_TENS = SECONDS_TENS + 1
			FCV_SECONDS_TENS = FCV_SECONDS_TENS + 1;
			

			//Decision
			//Decision: SECONDS_TENS >= 6?
			if (FCV_SECONDS_TENS >= 6)
			{
				//Calculation
				//Calculation:
				//  SECONDS_TENS = 0
				FCV_SECONDS_TENS = 0;
				

			}


		}


	}


}

void FCM_INITIALISE()
{
	//Initialise the clock to zero
	
	//Interrupt
	//Interrupt: Enable TMR0
	cr_bit(option_reg,T0CS);
	st_bit(option_reg,T0SE);
	option_reg = (option_reg & 0xF0) | 0x06;
	st_bit(intcon,GIE);
	st_bit(intcon, TMR0IE);


	//Calculation
	//Calculation:
	//  SECOND_COUNTER = 0
	FCV_SECOND_COUNTER = 0;
	

	//Calculation
	//Calculation:
	//  SECONDS = 0
	FCV_SECONDS = 0;
	

	//Calculation
	//Calculation:
	//  SECONDS_UNITS = 0
	FCV_SECONDS_UNITS = 0;
	

	//Calculation
	//Calculation:
	//  SECONDS_TENS = 0
	FCV_SECONDS_TENS = 0;
	

	//Calculation
	//Calculation:
	//  MINUTES = 0
	FCV_MINUTES = 0;
	

	//Calculation
	//Calculation:
	//  MINUTES_UNITS = 0
	FCV_MINUTES_UNITS = 0;
	

	//Calculation
	//Calculation:
	//  MINUTES_TENS = 0
	FCV_MINUTES_TENS = 0;
	

	//Calculation
	//Calculation:
	//  HOURS = 0
	FCV_HOURS = 0;
	

	//Calculation
	//Calculation:
	//  HOURS_UNITS = 0
	FCV_HOURS_UNITS = 0;
	

	//Calculation
	//Calculation:
	//  HOURS_TENS = 0
	FCV_HOURS_TENS = 0;
	

	//Reset LCD
	//Call Component Macro: LCDDisplay(1)::Start
	FCD_LCDDisplay1_Start();


}

void FCM_MINUTES()
{
	//Calculate Minutes
	
	//Decision
	//Decision: SECONDS >= 60?
	if (FCV_SECONDS >= 60)
	{
		//Add a minute
		//Calculation:
		//  MINUTES = MINUTES + 1
		FCV_MINUTES = FCV_MINUTES + 1;
		

		//Calculation
		//Calculation:
		//  SECONDS = 0
		FCV_SECONDS = 0;
		

		//Calculation
		//Calculation:
		//  MINUTES_UNITS = MINUTES_UNITS + 1
		FCV_MINUTES_UNITS = FCV_MINUTES_UNITS + 1;
		

		//Decision
		//Decision: MINUTES_UNITS >= 10?
		if (FCV_MINUTES_UNITS >= 10)
		{
			//Calculation
			//Calculation:
			//  MINUTES_UNITS = 0
			FCV_MINUTES_UNITS = 0;
			

			//Calculation
			//Calculation:
			//  MINUTES_TENS = MINUTES_TENS + 1
			FCV_MINUTES_TENS = FCV_MINUTES_TENS + 1;
			

			//Decision
			//Decision: MINUTES_TENS >= 6?
			if (FCV_MINUTES_TENS >= 6)
			{
				//Calculation
				//Calculation:
				//  MINUTES_TENS = 0
				FCV_MINUTES_TENS = 0;
				

			}


		}


	}


}

void FCM_HOURS()
{
	//Set the hours
	
	//Decision
	//Decision: MINUTES >= 60?
	if (FCV_MINUTES >= 60)
	{
		//Calculation
		//Calculation:
		//  HOURS = HOURS + 1
		FCV_HOURS = FCV_HOURS + 1;
		

		//Calculation
		//Calculation:
		//  MINUTES = 0
		FCV_MINUTES = 0;
		

		//Calculation
		//Calculation:
		//  HOURS_UNITS = HOURS_UNITS + 1
		FCV_HOURS_UNITS = FCV_HOURS_UNITS + 1;
		

		//Decision
		//Decision: HOURS_UNITS >= 10?
		if (FCV_HOURS_UNITS >= 10)
		{
			//Calculation
			//Calculation:
			//  HOURS_UNITS = 0
			FCV_HOURS_UNITS = 0;
			

			//Calculation
			//Calculation:
			//  HOURS_TENS = HOURS_TENS + 1
			FCV_HOURS_TENS = FCV_HOURS_TENS + 1;
			

		}


		//A whole day
		//Decision: HOURS >= 24?
		if (FCV_HOURS >= 24)
		{
			//Calculation
			//Calculation:
			//  HOURS = 0
			FCV_HOURS = 0;
			

			//Calculation
			//Calculation:
			//  HOURS_UNITS = 0
			FCV_HOURS_UNITS = 0;
			

			//Calculation
			//Calculation:
			//  HOURS_TENS = 0
			FCV_HOURS_TENS = 0;
			

		}


	}


}

void FCM_DISPLAYTIME()
{
	//Display the Time
	
	//Call Macro
	//Call Component Macro: LCDDisplay(1)::Cursor(0, 0)
	FCD_LCDDisplay1_Cursor(0, 0);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(HOURS_TENS)
	FCD_LCDDisplay1_PrintNumber(FCV_HOURS_TENS);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(HOURS_UNITS)
	FCD_LCDDisplay1_PrintNumber(FCV_HOURS_UNITS);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintASCII(':')
	FCD_LCDDisplay1_PrintASCII(':');


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(MINUTES_TENS)
	FCD_LCDDisplay1_PrintNumber(FCV_MINUTES_TENS);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(MINUTES_UNITS)
	FCD_LCDDisplay1_PrintNumber(FCV_MINUTES_UNITS);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintASCII(':')
	FCD_LCDDisplay1_PrintASCII(':');


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(SECONDS_TENS)
	FCD_LCDDisplay1_PrintNumber(FCV_SECONDS_TENS);


	//Call Macro
	//Call Component Macro: LCDDisplay(1)::PrintNumber(SECONDS_UNITS)
	FCD_LCDDisplay1_PrintNumber(FCV_SECONDS_UNITS);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(1)::Cursor(0, 1)
	FCD_LCDDisplay1_Cursor(0, 1);


	//Call Component Macro
	//Call Component Macro: LCDDisplay(1)::PrintString("Hello world")
	FCD_LCDDisplay1_PrintString("Hello world",11);


}

void FCM_TEST_SETTINGS()
{
	//Put any test settings here...
	
	//Calculation
	//Calculation:
	//  MINUTES = 59
	FCV_MINUTES = 59;
	

	//Calculation
	//Calculation:
	//  MINUTES_UNITS = 9
	FCV_MINUTES_UNITS = 9;
	

	//Calculation
	//Calculation:
	//  MINUTES_TENS = 5
	FCV_MINUTES_TENS = 5;
	

	//Calculation
	//Calculation:
	//  HOURS = 23
	FCV_HOURS = 23;
	

	//Calculation
	//Calculation:
	//  HOURS_UNITS = 3
	FCV_HOURS_UNITS = 3;
	

	//Calculation
	//Calculation:
	//  HOURS_TENS = 2
	FCV_HOURS_TENS = 2;
	

}

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


	//Interrupt initialisation code
	option_reg = 0xC0;


	//Call Macro
	//Call Macro: INITIALISE
	FCM_INITIALISE();


	//Loop
	//Loop: While 1
	while (1)
	{
		//Call Macro
		//Call Macro: SECONDS
		FCM_SECONDS();


		//Call Macro
		//Call Macro: MINUTES
		FCM_MINUTES();


		//Call Macro
		//Call Macro: HOURS
		FCM_HOURS();


		//Call Macro
		//Call Macro: DISPLAYTIME
		FCM_DISPLAYTIME();


	}


	mainendloop: goto mainendloop;
}

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_INTERRUPT_TMR0();
		cr_bit(intcon, TMR0IF);
	}
	#else
	#warning "This interrupt has previously been enabled, so the macro <INTERRUPT_TMR0> may never get called."
	#endif


}



