CH552/projects/examples/ADC/Main.C

52 lines
2.3 KiB
C++
Raw Normal View History

2018-10-17 10:44:45 +02:00
/********************************** (C) COPYRIGHT *******************************
* File Name : Main.C
* Author : WCH
* Version : V1.0
* Date : 2017/01/20
* Description : CH544 ADC<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC<EFBFBD>жϺͲ<EFBFBD>ѯ<EFBFBD><EFBFBD>ʽ<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>ʾʾ<EFBFBD><EFBFBD>
*******************************************************************************/
#include "..\Public\CH554.H"
#include "..\Public\Debug.H"
#include "ADC.H"
#include "stdio.h"
#include <string.h>
#pragma NOAREGS
void main( )
{
UINT16 i;
UINT16 j = 0;
CfgFsys( ); //CH554ʱ<34><CAB1>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mDelaymS(20);
mInitSTDIO( ); //<2F><><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
printf("start ...\n");
ADCInit( 0 ); //ADCʱ<43><CAB1><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>0(96clk) 1(384clk)<29><>ADCģ<43><EFBFBD><E9BFAA>
#if ADC_INTERRUPT //ADC<44>жϷ<D0B6>ʽ
EA = 1;
while(1)
{
for(i=0;i<4;i++){
printf("AIN%02x ",(UINT16)i); //ADC<44><43><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ADC_ChannelSelect( i ); //ADC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>i(0-3)<29><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
ADC_START = 1; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD>ж<EFBFBD>
mDelayuS(30); //<2F>ȴ<EFBFBD><C8B4>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>һͨ<D2BB><CDA8>
}
}
#else
while(1) //ADC <20><>ѯ<EFBFBD><D1AF>ʽ
{
for(i=0;i<4;i++){
printf("AIN%02x ",(UINT16)i);
ADC_ChannelSelect( i ); //ADC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
ADC_START = 1; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD>ж<EFBFBD>
while(ADC_START); //ADC_START<52><54>Ϊ0ʱ<30><CAB1><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("DATA: %02x\n",(UINT16)ADC_DATA);
mDelaymS(100); //ģ<>ⵥƬ<E2B5A5><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
#endif
}