Difference between revisions of "ARM ADC Programming"
(Created page with "category: ARM Tutorials ~~~~ ---- =Basics= =Schematic= =Code= <syntaxhighlight> </syntaxhighlight> {{DISQUS}}") |
|||
Line 6: | Line 6: | ||
=Code= | =Code= | ||
<syntaxhighlight> | <syntaxhighlight> | ||
+ | /*----------------------------------------------------------------------------- | ||
+ | note : | ||
+ | Refer adc.h to enable ADC channels. | ||
+ | ------------------------------------------------------------------------------*/ | ||
+ | #include "lpc17xx.h" //device specific heaader file | ||
+ | #include "uart.h" //Explore Embedded UART library which conatins the lcd routines | ||
+ | #include "adc.h" //Explore Embedded ADC library which conatins the adc routines | ||
+ | |||
+ | /* start the main program */ | ||
+ | int main() | ||
+ | { | ||
+ | uint16_t adc_result; | ||
+ | |||
+ | /* Setup and initialize the microcontroller system */ | ||
+ | SystemInit(); | ||
+ | |||
+ | /* Initialize the UART before displaying any thing on the lcd */ | ||
+ | UART_Init(UART0,9600); | ||
+ | |||
+ | /* Initialize the adc before starting the conversion */ | ||
+ | ADC_Init(); | ||
+ | |||
+ | /* Display "ADC Channel zero" on first line*/ | ||
+ | UART_Printf("ADC Channel zero"); | ||
+ | |||
+ | /* Display the adc channel zero value continously */ | ||
+ | while(1) | ||
+ | { | ||
+ | /*Get the adc value of channel zero */ | ||
+ | adc_result= ADC_GetAdcValue(5); | ||
+ | |||
+ | /*Display the adc value on UART*/ | ||
+ | UART_Printf("\n %u",adc_result); | ||
+ | } | ||
+ | } | ||
+ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{DISQUS}} | {{DISQUS}} |
Revision as of 12:59, 18 March 2015
Amruta (talk) 13:28, 17 March 2015 (IST)
Basics
Schematic
Code
/*----------------------------------------------------------------------------- note : Refer adc.h to enable ADC channels. ------------------------------------------------------------------------------*/ #include "lpc17xx.h" //device specific heaader file #include "uart.h" //Explore Embedded UART library which conatins the lcd routines #include "adc.h" //Explore Embedded ADC library which conatins the adc routines /* start the main program */ int main() { uint16_t adc_result; /* Setup and initialize the microcontroller system */ SystemInit(); /* Initialize the UART before displaying any thing on the lcd */ UART_Init(UART0,9600); /* Initialize the adc before starting the conversion */ ADC_Init(); /* Display "ADC Channel zero" on first line*/ UART_Printf("ADC Channel zero"); /* Display the adc channel zero value continously */ while(1) { /*Get the adc value of channel zero */ adc_result= ADC_GetAdcValue(5); /*Display the adc value on UART*/ UART_Printf("\n %u",adc_result); } }