收藏0 举报
/*---------------------------------------------------------------------------------------------------------*/ /* */ /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved. */ /* */ /*---------------------------------------------------------------------------------------------------------*/ //*********************************************************************************************************** // Nuvoton Technoledge Corp. // Website: http://www.nuvoton.com // E-Mail : MicroC-8bit@nuvoton.com // Date : Apr/21/2017 //*********************************************************************************************************** //*********************************************************************************************************** // File Function: N76E003 ADC demo code //*********************************************************************************************************** #include "N76E003.h" #include "SFR_Macro.h" #include "Function_define.h" #include "Common.h" #include "Delay.h" //***************** The Following is in define in Fucntion_define.h *************************** //****** Always include Function_define.h call the define you want, detail see main(void) ******* //*********************************************************************************************** #if 0 //#define Enable_ADC_AIN0 ADCCON0&=0xF0;P17_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT0;ADCCON1|=SET_BIT0 //P17 //#define Enable_ADC_AIN1 ADCCON0&=0xF0;ADCCON0|=0x01;P30_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT1;ADCCON1|=SET_BIT0 //P30 //#define Enable_ADC_AIN2 ADCCON0&=0xF0;ADCCON0|=0x02;P07_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT2;ADCCON1|=SET_BIT0 //P07 //#define Enable_ADC_AIN3 ADCCON0&=0xF0;ADCCON0|=0x03;P06_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT3;ADCCON1|=SET_BIT0 //P06 //#define Enable_ADC_AIN4 ADCCON0&=0xF0;ADCCON0|=0x04;P05_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT4;ADCCON1|=SET_BIT0 //P05 //#define Enable_ADC_AIN5 ADCCON0&=0xF0;ADCCON0|=0x05;P04_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT5;ADCCON1|=SET_BIT0 //P04 //#define Enable_ADC_AIN6 ADCCON0&=0xF0;ADCCON0|=0x06;P03_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT6;ADCCON1|=SET_BIT0 //P03 //#define Enable_ADC_AIN7 ADCCON0&=0xF0;ADCCON0|=0x07;P11_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT7;ADCCON1|=SET_BIT0 //P11 //#define Enable_ADC_BandGap ADCCON0|=0x0F;ADCCON1|=SET_BIT0 //Band-gap 1.22V //#define PWM0_FALLINGEDGE_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM2_FALLINGEDGE_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM4_FALLINGEDGE_TRIG_ADC ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM0_RISINGEDGE_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM2_RISINGEDGE_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM4_RISINGEDGE_TRIG_ADC ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM0_CENTRAL_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM2_CENTRAL_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM4_CENTRAL_TRIG_ADC ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM0_END_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM2_END_TRIG_ADC ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define PWM4_END_TRIG_ADC ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1|=SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1 //#define P04_FALLINGEDGE_TRIG_ADC ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6 //#define P13_FALLINGEDGE_TRIG_ADC ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6 //#define P04_RISINGEDGE_TRIG_ADC ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6 //#define P13_RISINGEDGE_TRIG_ADC ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6 #endif /****************************************************************************** * FUNCTION_PURPOSE: ADC interrupt Service Routine ******************************************************************************/ void ADC_ISR (void) interrupt 11 { clr_ADCF; // Clear ADC interrupt flag printf ("\n Value = 0x%bx",ADCRH); // printf display will cause delay in ADC interrupt P30 ^= 1; // Check the P3.0 toggle at falling edge of PWM } /****************************************************************************** The main C function. Program execution starts here after stack initialization. ******************************************************************************/ void main (void) { Set_All_GPIO_Quasi_Mode; InitialUART0_Timer1(9600); /*------------------------------------------------- ADC trig initial setting Please modify #if value to open diffent type --------------------------------------------------*/ #if 1 // By PWM falling edge PWM0_P12_OUTPUT_ENABLE; Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input PWM0_FALLINGEDGE_TRIG_ADC; #endif #if 0 // By PWM rising edge PWM0_P12_OUTPUT_ENABLE; Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input PWM0_RISINGEDGE_TRIG_ADC; #endif #if 0 // By PWM central point PWM0_P12_OUTPUT_ENABLE; Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input PWM_CENTER_TYPE; PWM0_CENTRAL_TRIG_ADC; #endif #if 0 // By PWM end point PWM0_P12_OUTPUT_ENABLE; Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input PWM_CENTER_TYPE; PWM0_END_TRIG_ADC; #endif // Setting PWM value PWMPH = 0x07; //Setting PWM value PWMPL = 0xFF; PWM0H = 0x02; PWM0L = 0xFF; set_LOAD; // PWM run set_PWMRUN; // Setting ADC set_EADC; // Enable ADC interrupt (if use interrupt) EA = 1; while(1); }
598330983 发表于 2018-12-3 23:40 不知道,你是测几路的? 如果一路的,PWM触发后直接累加到SUM里,然后计数次数到100了,就求个平均值。这样 ...
yiy 发表于 2018-12-8 23:04 没看明白16*6是啥。
huangcunxiake 发表于 2018-12-7 10:32
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
人才类勋章
等级类勋章
发帖类勋章
时间类勋章
151
1176
10
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号