首页资源分类嵌入式系统 > LPC4357学习笔记-ADC

LPC4357学习笔记-ADC

已有 445110个资源

下载专区

文档信息举报收藏

标    签:LPC4357ADC

分    享:

文档简介

LPC4357学习笔记-ADC

文档预览

LPC4357学习笔记-ADC 作者:BLUEFLAME 20140403 见手册UM10503-Rev. 1.8 — 28 January 2014 P1305 寄存器如下 以下n=0~7 CR-------------控制寄存器 GDR------------全局数据寄存器 INTEN----------中断使能寄存器 DRn------------通道n数据寄存器 /* Clock Control Unit register bits */ #define CCU_CLK_CFG_RUN (1 << 0) #define CCU_CLK_CFG_AUTO (1 << 1) #define CCU_CLK_STAT_RUN (1 << 0) #define ADCChannel0 (1UL << 0) #define ADCChannel1 (1UL << 1) #define ADCChannel2 (1UL << 2) #define ADCChannel3 (1UL << 3) #define ADCChannel4 (1UL << 4) #define ADCChannel5 (1UL << 5) #define ADCChannel6 (1UL << 6) #define ADCChannel7 (1UL << 7) #define ADCChannelStatus0 (1UL << 0) #define ADCChannelStatus1 (1UL << 1) #define ADCChannelStatus2 (1UL << 2) #define ADCChannelStatus3 (1UL << 3) #define ADCChannelStatus4 (1UL << 4) #define ADCChannelStatus5 (1UL << 5) #define ADCChannelStatus6 (1UL << 6) #define ADCChannelStatus7 (1UL << 7) void ADCxInit(void)//查询模式 { // Setup potentiometer pin ADC0_1 LPC_CCU1->CLK_APB3_ADC0_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN; while (!(LPC_CCU1->CLK_APB3_ADC0_STAT & CCU_CLK_STAT_RUN)); /* Configure ADC0_1 见UM10503 P1308*/ LPC_ADC0->CR = (1UL << 1) | // Select ADCx_1 pin for conversion (2UL << 8) | // 12MHz / (2+1) = 4MHz (1UL << 21) ; // ADC is operational LPC_ADC0->CR |= (1UL << 16); //连续转换,注:连续转换时START不能起作用 // LPC_ADC0->CR |= (1UL << 24); //START开始转换 } unsigned int GetADCxValue(void) { unsigned int Value; if(((LPC_ADC0->STAT)&ADCChannelStatus1) == ADCChannelStatus1)//判断是否转换完毕 { Value = (LPC_ADC0->DR[1] >> 6) & 0x3FF; } else ; return Value; } void ADCxInterruptInit(void)//中断模式 { // Setup potentiometer pin ADC0_1 LPC_CCU1->CLK_APB3_ADC0_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN; while (!(LPC_CCU1->CLK_APB3_ADC0_STAT & CCU_CLK_STAT_RUN)); /* Configure ADC0_1 见UM10503 P1308*/ LPC_ADC0->CR = (1UL << 1) | // Select ADCx_1 pin for conversion (2UL << 8) | // 12MHz / (2+1) = 4MHz (1UL << 21) ; // ADC is operational // Enable Channel 1 interrupt LPC_ADC0->INTEN |= (1UL << 1); LPC_ADC0->CR |= (1UL << 24); // Start conversion NVIC_EnableIRQ (ADC0_IRQn); } unsigned int ADCValue; void ADC0_IRQHandler (void) { // Value = LPC_ADC0->STAT; //读取状态 LPC_ADC0->GDR; //Clear IRQ request flag ADCValue = (LPC_ADC0->DR[1] >> 6) & 0x3FF; // Read value and clear IRQ } //----------------------------------------------------------------------------//

Top_arrow
回到顶部
EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高进,我们会尽快处理。