8 ADC modulus conversion for bare metal manymany-2440

Source: Internet
Author: User
Tags modulus

//************************************** *************
// To measure and control the temperature, pressure, flow, speed, displacement, and other physical quantities
// The sensor converts the above physical quantity into an electrical signal that simulates the physical quantity, that is, a simulated electrical signal, and then passes through the module
// The converter is converted to a digital volume and sent to the processor for processing.
// Objective: To understand the use of ADC
//************************************** *************
// Designed by: http://blog.ednchina.com/Manymany/
// 2009-07-10
/*************************************** *************************
Function:
The AD function converts analog channels by adjusting the adjustable resistance connected to the channels.
Changes the analog input and displays the echo data to the terminal through the serial port.
**************************************** *************************/
# Include "2440addr. H"
# Include "2440lib. H"

Void test_adc (void );

Void xmain (void)
{
Changeclockdivider (); //
Changempllvalue (405, 2, 1); // MHz
Port_init ();
Isr_init ();
Uart_init (0, 115200 );
Uart_select (0 );
Uart_printf ("the main is running \ n ");
 
Test_adc (); // ad test function
}

// ================================================ ========================================================== ====
Int readadc (INT ch) // read the ADC function. ch determines the channel to be selected. The number of channels (CH is 0-7)
{
Int I;
Static int prevch = "-1 ";

// Enable ADC settings
// Set the number division value to 49.
// Select the channel bit. the voltage on the selected channel is connected to the ad
Radccon = (1 <14) | (49 <6) | (CH <3 );

If (prevch! = CH)
{
For (I = 0; I <1000; I ++); // delay to set up the next channel
Prevch = "ch ";
}
Radccon | = 0x1; // enables the ADC.

While (! (Radccon & 0x8000); // determines whether the conversion is complete. If the conversion is completed, skip to the next statement,
// Otherwise, an endless loop is generated until it is completed.
// Adccon [15] bit: the flag of the conversion result, which is a read-only bit. If the value is 0, it indicates
// If the value is 1, the modulus conversion is completed.
Return (INT) radcdat0 & 0x3ff); // The number returned is the number converted by the ADC.
}

// ================================================ ========================================================== ====

Void test_adc (void)
{
Int adcdata = "0"; // defines a variable to store the converted number.
Uart_printf ("\ NADC input test, Press ESC key to exit! \ N ");
While (uart_getkey ()! = Esc_key)
{
Adcdata = "readadc" (adc_ch );
Uart_printf ("Ain % d: % 04d \ n", adc_ch, adcdata); // terminal display
Delay (2000 );
}
}

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.