//Test the AD of STC12C4052
//P1.7 is connected to a variable resistor. P3.5 is cleared to start conversion
#include "STC12C4052AD.h"
void delay()
{
unsigned char l2;
unsigned char l3 = 10;
while(--l3)
{
l2 = 20;
while( --l2);
}
}
main()
{
P3_7 = 0;
ADC_CONTER = 0x80; //Turn on ad comparison voltagewhile
(1)
{
P3_5 = 1;
if ( P3_5 == 0 )
{
P1M0 = 0x80; //P1.7 is open drain
inputP1M1 = 0x80; //P1.7 is high impedance
inputADC_CONTER = 0xE7; //P1_7 is ad
delay();
ADC_DATA = 0;
ADC_CONTER |= 0x08;
while ((ADC_CONTER & 0x10) != 0x10 )P1 = ADC_CONTER;
ADC_CONTER &= 0xe7;
P1 = ADC_DATA;
P3_7 = 1;
P1M0 = 0;
while(1);
}
}
}
//-------------------The second method--------------------
#define uchar unsigned char
#define uint unsigned int
#include "stc12c5410ad.h"
void InitAd(void)
{
P1M0=0xff;
P1M1=0xff;
}
void InitUart(void)
{
SCON|=0X50;
TH1=TL1=0XFB;
TMOD|=0X20;
ES=1;
TR1=1;
}
void delay(void)
{
uint i;
for(i=0;i<0xfff0;i++);
}
void ReadAd(void)
{
uchar temp[16],i;
for(i=0;i<8;i++)
{
ADC_CONTR=i;
ADC_CONTR|=0x88;
while(!(ADC_CONTR&0x10));
ADC_CONTR=ADC_CONTR&0xef;
temp[2*i]=ADC_DATA;
temp[2*i+1]=ADC_LOW2;
}
SBUF=0xa0;
while(!TI);
TI=0;
for(i=0;i<16;i++)
{
SBUF=temp[i];
while(!TI);
TI=0;
}
SBUF=0xf6;
while(!TI);
TI=0;
}
main()
{
InitAd();
InitUart();
while(1)
{
ReadAd();
delay();
}
}
Previous article:Common methods for single-chip hardware anti-interference
Next article:P89LPC952 UART1
Recommended ReadingLatest update time:2024-11-16 12:56
- Popular Resources
- Popular amplifiers
- MATLAB and FPGA implementation of wireless communication
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Operational Amplifier Practical Reference Handbook (Edited by Liu Changsheng, Zhao Mingying, Liu Xu, etc.)
- A Complete Illustrated Guide to Operational Amplifier Applications (Written by Wang Zhenhong)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to change the library file in the schematic diagram in orcad?
- Free application: Domestic FPGA Gaoyunjia Little Bee Family GW1N Series Development Board
- Taking stock of the college entrance examination experience of Internet tycoons! How many points did you get in the exam?
- Without American EDA software, we can’t make chips?
- 【Share】Flash management tools: FAL (Flash Abstraction Layer) library
- [Awards awarded] Grab the post! Download the TWS headset white paper, write a wonderful review, and win a JD card!
- Constant voltage circuit and constant current circuit composed of operational amplifier and triode
- [RVB2601 Creative Application Development] Record the startup process of the hello world system
- How to initialize the key port of the power button in C language
- About the use and description of idconfig