电压在1501mv~1800mv时,LED2、LED3、LED4、LED5点亮
电压在1001mv~1500mv时,LED2、LED3、LED4点亮
电压在501mv~1000mv时,LED2、LED3点亮
电压在0mv~500mv时,LED2闪烁
#include "exynos_4412.h"void delay(unsigned int time){while(time--);}int main(){unsigned int adcvalue;//将adc的转换精度设置为12位ADCCON=ADCCON | (1<<16);//使能adc分频器ADCCON=ADCCON | (1<<14);//设置adc分频值,adc的时钟频率100/(19+1)=5MHZ,转换频率是5MHZ/5=1MHZ;ADCCON=ADCCON & (~(0xff<<6)) | (19<<6);//关闭待机模式,使能正常模式ADCCON=ADCCON & (~(1<<2));//关闭通过读使能ad转换ADCCON=ADCCON & (~(1<<1));//选择转换通道3ADCMUX=3;//LED2控制引脚设置输出模式GPX2.CON=GPX2.CON & (~(0XF<<28)) | (1<<28);//LED3控制引脚设置输出模式GPX1.CON=GPX1.CON & (~(0XF)) | (1);//LED4控制引脚设置输出模式GPF3.CON=GPF3.CON & (~(0XF<<16)) | (1<<16);//LED5控制引脚设置输出模式GPF3.CON=GPF3.CON & (~(0XF<<20)) | (1<<20);while(1){//开始转换ADCCON=ADCCON | 1;//等待转换完成while(!(ADCCON & (1<<15)));//读取转换结果adcvalue=ADCDAT & (0XFFF);//将结果转换成实际的电压值//mv 1800/4096 adcvalue=adcvalue * 0.44;//打印转换结果printf("adcvalue= %d mv\n",adcvalue);if(adcvalue<501){//LED2闪烁//GPX2.DAT=GPX2.DAT | (1<<7);delay(1000000);GPX2.DAT=GPX2.DAT & (~(1<<7));delay(1000000);//其他LED关闭GPX1.DAT=GPX1.DAT & (~1); GPF3.DAT=GPF3.DAT & (~(1<<4));GPF3.DAT=GPF3.DAT & (~(1<<5));}else if(adcvalue>500&&adcvalue<1001){GPX2.DAT=GPX2.DAT | (1<<7);GPX1.DAT=GPX1.DAT | 1; //关闭LED4,LED5GPF3.DAT=GPF3.DAT & (~(1<<4));GPF3.DAT=GPF3.DAT & (~(1<<5));}else if(adcvalue>1000&&adcvalue<1501){GPX2.DAT=GPX2.DAT | (1<<7);GPX1.DAT=GPX1.DAT | 1; GPF3.DAT=GPF3.DAT | (1<<4);//关闭LED5GPF3.DAT=GPF3.DAT & (~(1<<5));}else {GPX2.DAT=GPX2.DAT | (1<<7);GPX1.DAT=GPX1.DAT | 1; GPF3.DAT=GPF3.DAT | (1<<4);GPF3.DAT=GPF3.DAT | (1<<5);}}return 0;
}