/***********************************************************************/
/* */
/* FILE :ad_da.c */
/* DATE :Thu, Nov 27, 2003 */
/* DESCRIPTION :Main Program */
/* CPU TYPE :Other */
/* */
/* This file is generated by Renesas Project Generator (Ver.3.0). */
/* */
/***********************************************************************/

#include "7047s.h"


#ifdef __cplusplus
//#include <ios> // Remove the comment when you use ios
//int ios_base::Init::init_cnt; // Remove the comment when you use ios
#endif
#ifdef __cplusplus
extern "C" {
#endif
void abort(void);
#ifdef __cplusplus
}
#endif

unsigned short data;

void InitSH(void)
{



PFC.PECRL1.WORD=0;
PFC.PECRL2.WORD=0;
PFC.PEIORL.WORD=0xFFFF;//PE I/O 書き出しモード

PFC.PACRL2.WORD=0;
PFC.PAIORL.WORD=0xFFFF;

PFC.PBCR1.BIT.PB5MD=0; //PB=出力
PFC.PBCR2.BIT.PB5MD=0;
PFC.PBCR1.WORD=0;

PFC.PBIOR.BIT.B5=1;

PFC.PBIOR.WORD=0XFFFF;

PFC.PDIORL.WORD=0xFFFF;


MST.CR2.BIT._AD0=0; // without this setting,ADC wouldn't work!
AD0.ADCR.BIT.ADST=0;
AD0.ADCR.BYTE=0;
AD0.ADCSR.BYTE=0;
AD0.ADCR.BIT.CKS=0x3;
AD0.ADCR.BIT.ADST=1; //start AD
}


void main(void)
{
InitSH();

while(1)
{
PE.DRL.BIT.B12=1;
if(AD0.ADCSR.BIT.ADF)
{

AD0.ADCR.BIT.ADST=0;
data=AD0.ADDR0.WORD;

data=data>>6; //1024の範囲に入るように調節する
data +=0x8300; //AD無入力時の値を足す
PE.DRL.WORD =data;
AD0.ADCSR.BIT.ADF=0;
AD0.ADCR.BIT.ADST=1;
}

PE.DRL.BIT.B12=0;
}

}

void abort(void)
{

}