
/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2021/12/29
* IC:			SN8F5762
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2021/12/29	Roger		1. First release
*____________________________________________________________________________
*****************************************************************************/





/*_____ I N C L U D E S _________________________________*/
#include <SN8F5762.h>
#include "timer.h"
/*_____ F U N C T I O N S _______________________________*/
void TIMER1_Initialization(void);
void GPIO_Initialization(void);

/*_____ D E F I N I T I O N S ___________________________*/


/*_____ D E C L A R A T I O N S _________________________*/



/*_____ M A C R O S _____________________________________*/
#define    IO_PORT0_OUTPUT_LOW        P0M |= 0xFF;    P0 &= 0x00;
#define    IO_PORT1_OUTPUT_LOW        P1M |= 0xFF;    P1 &= 0x00;
#define    IO_PORT2_OUTPUT_LOW        P2M |= 0xFF;    P2 &= 0x00;

/**
 *	@Brief		main: Timer1 Demo Function
 *	@param		None
 *	@return		None
 */

void main(void)
{
	/*
   *	System initial:
	 *	(1) GPIO
	 *	(2) Timer1
	 *  
	 */	
		GPIO_Initialization(); 												/*	(1)	*/ 
		TIMER1_Initialization();        							/*	(2)	*/


	while(1)
	{
		WDTR = 0x5A;																	/*	Clear Watchdog Timer	*/
	}
}

/**
 *	@Brief		TIMER1_ExecuteTimerInit: Timer1 Demo Function
 *	@param		None
 *	@return		None
 */


void TIMER1_Initialization(void)
{
	/*
	 *	(1) Set Timer1 Mode1 (13-bit Timer)	And IHRC As Timer Source
	 *	(2) Set	TL1 Overflow Value
	 *	(3)	Set	TH1 Overflow Value
	 *	  
	 */		
		TMOD |= (mskTMOD_T1_MODE1|mskTMOD_T1CT);			/*	(1) */
		TH1 = TH1_VALUE;            									/*	(2)	*/
    TL1 = TH1_VALUE;            									/*	(3)	*/	
		TCON0 |= mskTCON0_T1_DIV128;  								 	
	  IEN0 |= mskIEN0_ET1;  												
		EAL =	1;																			
		TCON |=	mskTCON_TR1;													

}

/**
 *  @Brief    initial GPIO status
 *  @param    None
 *  @return   None
 */
void GPIO_Initialization(void)
{
    IO_PORT0_OUTPUT_LOW
    IO_PORT1_OUTPUT_LOW
    IO_PORT2_OUTPUT_LOW     
}





/**
 *	@Brief		ISR_Timer1: Timer1 ISR Function
 *	@param		None
 *	@return		None
 */
void ISR_Timer1(void) interrupt ISRTimer1   
{
	/*
	 *	(1)	Timer1 ISR Test Pin	Toggle
	 *	(2) Re-load Timer1 Counter	
	 *
	 */		
		OB_TEST_PIN ^=  1;															/*	(1)	*/ 
		TCON &=	TIMER_STOP;														
		TL1 = TL1_VALUE; 																/*	(2)	*/
		TH1 = TH1_VALUE;																/*	(2)	*/
		TCON |=	(mskTCON_TR1);													
}

