49 #pragma message ( "avr_adc.h included" ) 66 #define ADC_PIN_MASK 0x0F 73 #define ADC_VOLTAGE_REFERENCE_AREF (0<<REFS0) 74 #define ADC_VOLTAGE_REFERENCE_AVCC (1<<REFS0) 75 #define ADC_VOLTAGE_REFERENCE_IREF (1<<REFS1) | (1<<REFS0) 76 #define ADC_VOLTAGE_REFERENCE_MASK (1<<REFS1) | (1<<REFS0) 83 #define ADC_PRESCALER_2 (1<<ADPS0) 84 #define ADC_PRESCALER_4 (1<<ADPS1) 85 #define ADC_PRESCALER_8 (1<<ADPS1) | (1<<ADPS0) 86 #define ADC_PRESCALER_16 (1<<ADPS2) 87 #define ADC_PRESCALER_32 (1<<ADPS2) | (1<<ADPS0) 88 #define ADC_PRESCALER_64 (1<<ADPS2) | (1<<ADPS1) 89 #define ADC_PRESCALER_128 (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) 90 #define ADC_PRESCALER_MASK (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) 97 #define ADC_TEMP_TOS 0x01 98 #define ADC_TEMP_K 0x01 105 typedef struct ADC_ConfigData
107 uint8_t VoltageReference;
116 inline void ADC_DisableInterrupt();
117 inline void ADC_EnableInterrupt();
124 inline void ADC_Init(ADC_ConfigData Data);
125 inline void ADC_DeInit();
132 uint16_t ADC_ReadPin(uint8_t Pin);
133 uint16_t ADC_ReadTemperature();
141 inline void ADC_DisableInterrupt()
151 inline void ADC_EnableInterrupt()
162 inline void ADC_Init(ADC_ConfigData Data)
164 ADMUX = Data.VoltageReference | VBG;
165 ADCSRA = (1<<ADEN) | Data.Prescaler;
173 inline void ADC_DeInit()
177 ADC_DisableInterrupt();
186 uint16_t ADC_ReadPin(uint8_t Pin)
189 ADMUX = (ADMUX & ADC_VOLTAGE_REFERENCE_MASK) | Pin;
191 while (ADCSRA & (1<<ADSC));
194 return (High<<8) | Low;
202 uint16_t ADC_ReadTemperature()
205 ADMUX = ADC_VOLTAGE_REFERENCE_IREF | ADC8;
207 while (ADCSRA & (1<<ADSC));
210 return (((High<<8) | Low) - ADC_TEMP_TOS) / ADC_TEMP_K;
إرسال تعليق