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