/*
 * @Description:5 * @Date: 2019-07-03 09:32:04
 * @Author: 吳星萍 iris@e-besthealth.com
 * @LastEditors: 吳星萍 iris@e-besthealth.com
 * @LastEditTime: 2020-06-17 
 * @copyright: BEST HEALTH ELECTRONIC INC (c) 2019
 */
#include "common.h"

//#define DEBUG 1		//主機	
#define DEBUG 0		//從機

void main()
{
	// 判斷是否為上電復位或者非正常情況下的復位
	// 如果是上電復位，執行上電復位初始化，反之執行WDT溢出初始化
	if (_to == 0 || _pdf ==0)
	{
		// System
		Drv_SysClockInit();
		Drv_RamInit();
		SET_WDTTIME_125MS();
		SET_LVR_1V9();
		
//		IIC  demo
	#if	DEBUG
		unsigned char i,data;
		data=0x10;
		for (i = 0; i < IIC_TXDATALENGHT; i++)
		{
			gu8v_IIC_WData[i]=data;
			data++;
		}

	#else	
		unsigned char i,data;
		data=0x40;
		
		SIM_Data.TxBuf[0]=0x40;
		SIM_Data.TxBuf[1]=0x41;
		SIM_Data.TxBuf[2]=0x42;
		/*for(i=0;i<2;i++)
		{
			data++;
			SIM_Data.TxBuf[i]=data;
			
		}*/
		Drv_SIM_PowerOn();
	#endif

	}
	else
	{
		// WDT溢出復位初始化
		GCC_CLRWDT();

	}
	//主循環
	while(1)
	{
		GCC_CLRWDT();
		// IIC master demo				
	#if	DEBUG
		Drv_IICWrite_Data(IIC_ADDRESS, 3);
		GCC_DELAY(1000);
		Drv_IICRead_Data(IIC_ADDRESS, 3);
		GCC_DELAY(1000);
	#endif

	}
}