Created
September 10, 2016 16:11
-
-
Save skl/10a32cf602ff9aee4043f0f4f4c66e66 to your computer and use it in GitHub Desktop.
ATmega 328P Internal Temperature Sensor on ADC8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Initialise A/D multiplex register for internal temp. sensor (ADC8) | |
; Use internal (1.1V) as reference voltage and left-adjust | |
ADC_TempSensor_Init: | |
ldi r17, (1<<REFS1) | (1<<REFS0) | (1<<MUX3) | (1<<ADLAR) | |
sts ADMUX, r17 ; out of range for OUT, using STS instead | |
ret | |
; Reads ADCL into r21 and ADCH into r22 | |
ADC_TempSensor_Read: | |
; Enable ADC with a clock division factor of 128 (125 kHz) | |
ldi r17, (1<<ADEN) | (1<<ADSC) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) | |
sts ADCSRA, r17 | |
ADC_Wait_TempSensor: | |
lds r17, ADCSRA | |
sbrc r17, ADSC | |
rjmp ADC_Wait_TempSensor | |
lds r21, ADCL | |
lds r22, ADCH | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment