Test the AD of STC12C4052

Publisher:心灵舞者Latest update time:2016-11-21 Source: eefocusKeywords:STC12C4052 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//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();
}
}


Keywords:STC12C4052 Reference address:Test the AD of STC12C4052

Previous article:Common methods for single-chip hardware anti-interference
Next article:P89LPC952 UART1

Recommended ReadingLatest update time:2024-11-16 12:56

Principle and Application of AD5933 Impedance Measurement Chip
  1 AD5933 Chip Overview   1.1 Main performance   AD5933 is a high-precision impedance measurement chip, which integrates a frequency generator with a 12-bit AD converter with a sampling rate of up to 1MSPS. This frequency generator can generate a specific frequency to excite the external resistor. The response sign
[Test Measurement]
Principle and Application of AD5933 Impedance Measurement Chip
Application of SC2121 compatible with AD2S1205 in permanent magnet synchronous motor drive system
Permanent magnet synchronous motors are widely used in high-speed and high-power speed regulation systems due to their simple and reliable structure, good maintainability, high power density and working efficiency, and good control performance. In most cases, rotor magnetic field oriented vector control strategies a
[Embedded]
Application of SC2121 compatible with AD2S1205 in permanent magnet synchronous motor drive system
Complete machine design of digital voltmeter based on microcontroller and AD678 chip
Digital voltmeters have been designed and developed in many types and styles. Traditional digital voltmeters have their own characteristics. They are suitable for manual measurement on site. To complete remote measurements and further analyze and process the measurement data, traditional digital voltmeters cannot comp
[Microcontroller]
Complete machine design of digital voltmeter based on microcontroller and AD678 chip
AD saturation fault of electromagnetic flowmeter and its elimination
When the electromagnetic flowmeter is used, A/D saturation occurs, which is usually caused by improper installation and layout of the electromagnetic flowmeter or the mixing of heterogeneous substances in the medium in the pipeline. Improper installation and layout of the electromagnetic flowmeter are mainly manifes
[Test Measurement]
STC89C51 AD analog-to-digital conversion ---- self-study notes
1. AD analog-to-digital conversion and its related terms AAnalog signal DDigital signal AD analog-to-digital conversion converts analog signals into digital signals 2. Main technical indicators of AD converter 2.1 Resolution The resolution of an ADC refers to the change in the input analog voltage required to change
[Microcontroller]
STC89C51 AD analog-to-digital conversion ---- self-study notes
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号