LPC1788 ADC and DAC usage

Publisher:快乐微笑Latest update time:2017-01-13 Source: eefocusKeywords:LPC1788  ADC  DAC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#ifndef __ADC1_H_

#define __ADC1_H_

 

#include "common.h"

#include "delay.h"

 

void adc_init(u8 ch,u8 div);

 

u16 adc_cover(u8 ch);

 

 

 

 

#endif

 

 

 

 

 

 

#include "adc1.h"

 

 

 

void adc_init(u8 ch,u8 div)//The maximum clock should not be greater than 12.4M

{

    //Turn on the ADC and IO port clocks

    LPC_SC->PCONP |= (1<<15)|(1<<12);

    switch(ch)

    {

    case 0:

        LPC_IOCON->P0_23 = 0x00;

        LPC_IOCON->P0_23 |= (1<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 1:

        LPC_IOCON->P0_24 = 0x00;

        LPC_IOCON->P0_24 |= (1<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 2:

        LPC_IOCON->P0_25 = 0x00;

        LPC_IOCON->P0_25 |= (1<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 3:

        LPC_IOCON->P0_26 = 0x00;

        LPC_IOCON->P0_26 |= (1<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 4:

        LPC_IOCON->P0_30 = 0x00;

        LPC_IOCON->P0_30 |= (3<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 5:

        LPC_IOCON->P0_31 = 0x00;

        LPC_IOCON->P0_31 |= (3<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 6:

        LPC_IOCON->P0_12 = 0x00;

        LPC_IOCON->P0_12 |= (3<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    case 7:

        LPC_IOCON->P0_13 = 0x00;

        LPC_IOCON->P0_13 |= (3<<0)|(1<<8)|(1<<10); //unfiltered analog adc open drain

        break;

    }

    LPC_ADC->CR = 0X00;

    LPC_ADC->CR |= (1<

    LPC_ADC->INTEN = 0x00; //Disable all interrupts

   

}

 

u16 adc_cover(u8 ch)

{

    u16 temp;

    LPC_ADC->CR &= ~(0x000000ff);

    LPC_ADC->CR |= (1<

    LPC_ADC->CR |= 1<<24; //Start conversion

    while(!(LPC_ADC->GDR &(1u<<31)));//Wait for the conversion to end

    temp = (u16)((LPC_ADC->GDR & 0x00000fff0)>>4);

    return temp;

}

 

 

 

 

 

 

#ifndef __ADC_H_

#define __ADC_H_

 

#include "common.h"

 

#define DAC_IO_CON  LPC_IOCON->P0_26

 

void dac_init(void);

 

void dac_set_value(u16 value);

 

#endif

 

 

 

 

#include "dac.h"

 

 

void dac_init(void)

{

    //io port initialization

    DAC_IO_CON = 0x00;

    DAC_IO_CON |= (2<<0)|(1<<16)/*|(1<<10)*/;//使能DAC

   

    LPC_DAC->CTRL = 0x00; //Double buffering disabled, timeout disabled, DMA disabled

    LPC_DAC->CR = 1<<16;

//  LPC_DAC->CNTVAL = 100;

}

 

 

void dac_set_value(u16 value)

{

    if(value > 1024)

    {

        return;

    }

    else

    {

        LPC_DAC->CR = (u16)((1<<16)|(value<<6));       

    }

}


Keywords:LPC1788  ADC  DAC Reference address:LPC1788 ADC and DAC usage

Previous article:EMC driver norflash for LPC1788
Next article:lSerial communication of PC1788

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号