#ifndef __main_H 
#define __main_H

#include 	<hs16p2811.h>


#define	_NOP()		asm("NOP")    
#define	CLRWDT()	asm("clrwdt")    
#define	SLEEP()		asm("sleep")    
#define	DAA()		asm("DAA")    
#define	DAS()		asm("DAS")    
#define	INT()		asm("INT")    
#define	CLRA()		asm("CLRA")    
//#define	ACC_0()		asm("MOVLW 0X00");	//ACC=0    
//#define	RETURN()	asm("RETURN"); 

// ******************************************************************
// ****function declaration****//
// ******************************************************************
void GPIO_Init(void);

void System_Init(void);

void CLR_RAM_EveryBank(void);

void DelayUs(unsigned char delayUs);   

void _send_data_uart(unsigned char Uart_Data);

  
// ******************************************************************
#define 	ANSEL15_GND		15
#define 	ANSEL14_PA7		14
#define 	ANSEL13_PA6		13
#define 	ANSEL12_qVDD	12

#define 	ANSEL11_PA5		11
#define 	ANSEL10_PA4		10
#define 	ANSEL9_PC5		9
#define 	ANSEL8_PC4		8

#define 	ANSEL7_PC3		7
#define 	ANSEL6_PC2		6
#define 	ANSEL5_PC1		5
#define 	ANSEL4_PC0		4

#define 	ANSEL3_PA3		3
#define 	ANSEL2_PA2		2
#define 	ANSEL1_PA1		1
#define 	ANSEL0_PA0		0

// ADC 
#define 	ADC_DeInit()	do{ADM = 0x00; ADR = 0x00; VREFH = 0x00; ADPCON = 0; ADPCON1 = 0; ADT = 0;}while(0)
// ADM config
#define 	AD_ADBEN_EN()		ADM |= (1<<7)
#define 	AD_ADBEN_DIS()		ADM &= ~(1<<7)
#define 	AD_ADS_Start()		ADM |= (1<<6)
#define 	AD_EOC_Conver()		ADM &= ~(1<<5)
#define 	AD_GCHS_EN()		ADM |= (1<<4)

#define 	AD_AINx_EN(x)	do{ADM &= ~0x0f;	ADM |= x;}while(0)//x<16

// ADR config
#define 	ADCKS_Fcpu_16()		do{ADR = 0;		ADR |= 0x00;}	while(0)
#define 	ADCKS_Fcpu_8()		do{ADR = 0;		ADR |= 0x10;}	while(0)
#define 	ADCKS_Fcpu()		do{ADR = 0;		ADR |= 0x40;}	while(0)
#define 	ADCKS_Fcpu_2()		do{ADR = 0;		ADR |= 0x50;}	while(0)

// VREFH config
#define 	AD_VREFH_VDD()		do{VREFH = 0;	VREFH |= 0x03;}	while(0)
#define 	AD_VREFH_4V()		do{VREFH = 0;	VREFH |= 0x02;}	while(0)
#define 	AD_VREFH_3V()		do{VREFH = 0;	VREFH |= 0x01;}	while(0)
#define 	AD_VREFH_2V()		do{VREFH = 0;	VREFH |= 0x00;}	while(0)

#define 	AD_VREFH_ExVDD()	do{VREFH |= 0x80;}while(0)

// ADPCON & ADPCON1 config


// ADT config

#define		ADT_DeInit()	ADT = 0x00;


#endif
