#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "MCG.h"
#include "Display.h"

#include "ADC.h"
#include "VREF.h"
#include "DAC.h"
#include "OPAMP.h"
#include "PDB.h"

void main(void) 
{
  EnableInterrupts;
  vfnMCG_Init();
  vfnSCIInit();
  
	/** Enabled VREF to source internal peripherals */
    vfnVREF_Init (_IntUseOnly);
    
    /** Enable sine wave to exit from DAC*/
    vfnDACFillBuffer();
    vfnDACInit(gu8DACConfig1, gu8DACConfig2);
    vfnDACSetPointer (0,15);
    
    /** Amplify DACO with OPAMP0*/
    vfnOPAMPInit ();
    vfnOPAMPConfig (OPAMP0);

    /** Configure PDB to trigger DAC */
    vfnPDBInit();
    vfnPDBConfig(PDB_CONTINUOUS_MODE);
    PDB_TRIGGER;
    
    /** Configure ADC */
    vfnADC_Init ();
    vfnADConfigChannel(1);
    ADC_CONVERT_CONTINUOUS_CHANNEL(1);
 
 
  for(;;) 
  {
	if (ADC_COCO)
	{
		ADC_COCO_CLEAR;
		vfnGraphicWords(&sADC.gu16LatestResult[0]);
	}
	
  __RESET_WATCHDOG();	
  } 
}


