-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADC.c
64 lines (59 loc) · 1.62 KB
/
ADC.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
////////////////////////////////////////////////////////////////////////////////////////////////////
// file: C:\Users\Mohammad\Desktop\AVRCLibrary\AVRCLibrary\ADC.c
//
// summary: ADC class
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
*
* ADC.c
*
*
* |_______Avr ADC library_______|
*
*
*
*
* Created: 2020-08-19 23:09:46
*
* Filename: ADC.c
* Controller: Atmega8/16/32/128
* Oscillator: 1 MHz
* Author: XploreLabz
* website: www.xplorelabz.com
* Reference:Atmega32 dataSheet
*
*/
#include <avr/io.h>
#include "Configuration.h"
#include <util/delay.h>
#include "ADC.h"
/*
*
* Description :This function initializes the ADC control registers
* I/P Arguments: none
* Return value: none
*
*/
void ADC_Init ( )
{
ADCSRA =0x81 ; //Enable ADC , sampling freq=osc_freq/2
ADMUX = 0x00 ; //Result right justified, select channel zero
}
/*
*
* Description :This function does the ADC conversioin for the Selected Channel and returns the converted 10bit result
* I/P Arguments: char(channel number)
* Return value : int(10 bit ADC result)
*
*/
unsigned int ADC_StartConversion ( unsigned char channel )
{
ADMUX = channel ;
_delay_ms ( 5 ) ;
ADCSRA = 0xc1 ;
while ( ( ADCSRA & ( 1 << ADIF ) ) == 0 ) ;
return ( ADCW ) ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// End of C:\Users\Mohammad\Desktop\AVRCLibrary\AVRCLibrary\ADC.c
////////////////////////////////////////////////////////////////////////////////////////////////////