LPC1788 ADC and DAC use

Source: Internet
Author: User

#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)//MAX clock must not be greater than 12.4M

{

Opening the ADC and IO port clocks

LPC_SC, Pconp |= (1<<) | ( 1<<);

Switch (ch)

{

case 0:

Lpc_iocon-p0_23 = 0x00;

Lpc_iocon, p0_23 |= (1<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 1:

Lpc_iocon-p0_24 = 0x00;

Lpc_iocon, p0_24 |= (1<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 2:

Lpc_iocon-p0_25 = 0x00;

Lpc_iocon, p0_25 |= (1<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 3:

Lpc_iocon-p0_26 = 0x00;

Lpc_iocon, p0_26 |= (1<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 4:

Lpc_iocon-p0_30 = 0x00;

Lpc_iocon, p0_30 |= (3<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 5:

Lpc_iocon-p0_31 = 0x00;

Lpc_iocon, p0_31 |= (3<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 6:

Lpc_iocon-P0_12 = 0x00;

Lpc_iocon, P0_12 |= (3<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

Case 7:

Lpc_iocon-p0_13 = 0x00;

Lpc_iocon, p0_13 |= (3<<0) | ( 1<<8) | (1<<); No filter analog ADC open-drain

Break ;

}

LPC_ADCCR = 0x00;

LPC_ADCCR |= (1<<ch) | ( Div<<8) | (1<<); Working with irregular transitions and selecting response channels

LPC_ADC-Inten = 0x00; Disable all interrupts

}

U16 Adc_cover(u8 ch)

{

U16 Temp;

LPC_ADCCR &= ~ (0x000000ff);

LPC_ADCCR |= (1<<ch);

LPC_ADCCR |= 1<<; Start conversion

while (!( GDR &, LPC_ADC (1u<<)); Wait for 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<<)/*| (1<<10) */; Enable DAC

Lpc_dacCTRL = 0x00; Dual buffering Disable, timeout disable DMA disable

Lpc_dacCR = 1<<;

Lpc_dac->cntval = 100;

}

void Dac_set_value(U16 value)

{

if (value > 1024x768)

{

return ;

}

Else

{

Lpc_dacCR = (U16) ((1<<) | ( Value<<6));

}

}

LPC1788 ADC and DAC use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.