ADC First Read

Source: Internet
Author: User

In Adccon, the last 0 bits and 1 bits are mutually exclusive.
If the 1-bit option is 1, the 0-bit value is not valid.
The 0-bit value is valid if the 1-bit option is 0.
When 1 bits of 1 are selected: This is the application layer of the program
#if adstart==0
void Niuniu (void)
{
Uart_init ();
Adc_init ();
Beeper_init ();

Adc_read ();

while (1)
{
Itoa (Adc_read ());
if (Adc_read () > 2500)
{
Beeper_on ();
}
Else
{
Beeper_off ();
}
Delay (10000);
}
}
#endif
Note here that the while loop must have Adc_read () above it, and if the Adc_read () is removed, the situation is as follows:
Add a
Uart_init ();
Adc_init ();
Beeper_init ();
Puts ("\ r \ n Loudan");
Adc_read ();
while (1)
{
Itoa (Adc_read ());
if (Adc_read () > 2500)
{
Beeper_on ();
}
Else
{
Beeper_off ();
}
Delay (10000);
}
The test results are as follows:
loudan0000
3069
3069
3069
3069
3069
3069
3069
3069
3069
?
loudan0000 (This is where I restarted the development version again)
3069
3069
3069
3069
3069
3069
3069
3069
3069
3069
3069
3069

loudan0000
3069
3069
*******************************************
If the client is forced to send a data that is converted by the ADC at the back of the contact, it must be correct every time, but the first data is wrong when the adc_read () is removed.
Here is the situation of the driver inside:
void Adc_init (void)
{
#if adstart==0
Adc. Adccon = 0x1<<1|0xff<<6|0x1<<14;
#elif adstart==1
Adc. Adccon = 0xff<<6|0x1<<14;
#endif
}

#if adstart==1
void adc_enable (void)
{
Adc. Adccon |= 0x1;
}
#endif

int Adc_read (void)
{
int result;

#if Adstart==0 (This is the first adccon of our analysis, the 0-bit value is invalid if 1 bits is selected for 1.) If result = ADC. adcdat0&0x3ff; to the bottom of the program will not run)
result = ADC. adcdat0&0x3ff;

while (!) ( Adc. adccon& (0x1<<15)))
{
}
#elif Adstart==1 (This is the first adccon of our analysis, the 0-bit value is valid if the 1-bit option is 0.) These two while instead, both the while and the result swap positions cannot run the program. )
while (!) ( Adc. adccon& (0x1<<15)))
{
}

result = ADC. adcdat0&0x3ff;
#endif

return 3300/0x3ff*result;
}
#endif

ADC First Read

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.