#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)); } }
Previous article:EMC driver norflash for LPC1788
Next article:lSerial communication of PC1788
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- [Rawpixel RVB2601 development board trial experience] 1. Unboxing and familiarizing yourself with the circuit diagram
- STM32WB55 review article summary
- Texas Instruments micro devices bring five major changes to engineers
- Industrial Board Disassembly Appreciation DAQe-2206
- What is the function of each layer of PCB? (Detailed explanation)
- BlueNRG video tutorial: BlueNRG-1 GUI advanced
- Raspiberry Pico runs openmv successfully
- Maxim's open source portable precision calibrator
- eetop.cn_100 Practical Tips for FPGA Design Experts (Original English Version)
- Some experience summary on AD conversion design