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





/*_____ I N C L U D E S _________________________________*/
#define __XRAM_SFR_H__
#include <SN8F5754.h>
#include "timer.h"
/*_____ F U N C T I O N S _______________________________*/
void TIMER3_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;
#define    IO_PORT3_OUTPUT_LOW        P3M |= 0xFF;    P3 &= 0x00;

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

void main(void)
{
	/*
   *	System initial:
	 *	(1) GPIO
	 *	(2) Timer3
	 *  
	 */	
		GPIO_Initialization(); 												/*	(1)	*/ 
    TIMER3_Initialization();        							/*	(2)	*/


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

/**
 *	@Brief		TIMER3_ExecuteTimerInit: Timer3 Initial Function
 *	@param		None
 *	@return		None
 */

void TIMER3_Initialization(void)
{
	/*
	 *	(1) Set	First Time Timer High Counter	
	 *	(2) Set	First Time Timer Low Counter	
	 *	(3)	Set	Re-load Timer High Counter	
	 *	(4)	Set	Re-load Timer Low Counter	
	 *	
	 */	
		T3CL	|=	(T3C_VALUE&0x00FF);        						/*	(1)	*/
		T3CH	|=	(T3C_VALUE&0xFF00)>>8;     						/*	(2)	*/
		T3RL	|=	(T3R_VALUE&0x00FF);     							/*	(3)	*/
		T3RH	|=	(T3R_VALUE&0xFF00)>>8;     						/*	(4)	*/
		T3M |=	mskT3M_T3_DIV128;											
		T3M |=	mskT3M_T3CKS;													
		IEN2	|=	mskIEN2_ET3;													
		EAL	=	1;																			
		T3M |=	mskT3M_T3EN;														

}

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


/**
 *	@Brief		ISR_Timer3: Timer3 ISR Function
 *	@param		None
 *	@return		None
 */
void ISR_Timer3(void) interrupt ISRTimer3 using 3
{
		OB_TEST_PIN ^=  1;																/*	Timer3 ISR Test Pin	Toggle	*/ 
}
