Subversion Repositories group.electronics

Rev

Rev 28 | Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 29
Line 77... Line 77...
77
 
77
 
78
int main(void) {
78
int main(void) {
79
 
79
 
80
  ACSR |= (1<<ACD); // Disable analog comparator
80
  ACSR |= (1<<ACD); // Disable analog comparator
81
 
81
 
82
  ADMUX = (1<<ADLAR) | (0<<REFS0) | (0<<REFS1);
82
  //ADMUX = (1<<ADLAR) | (0<<REFS0);
83
  ADCSRA = (1<<ADEN) | (0<<ADSC);
83
  ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) | (0<<ADSC);
84
 
84
 
85
  /*
85
  /*
86
  DDR : 1 = Output, 0 = Input
86
  DDR : 1 = Output, 0 = Input
87
  PORT: 1 = Pullup for Input, otherwise set output
87
  PORT: 1 = Pullup for Input, otherwise set output
88
  PIN : Read input pin
88
  PIN : Read input pin
Line 170... Line 170...
170
    }
170
    }
171
  }
171
  }
172
}
172
}
173
 
173
 
174
uint8_t analogRead(uint8_t pin) {
174
uint8_t analogRead(uint8_t pin) {
175
	ADMUX |= (1<<pin);
175
	//ADMUX |= (1<<pin);
-
 
176
	ADMUX = (1<<ADLAR) | (0<<REFS0) | (pin & 0x0f);
176
	ADCSRA |= (1<<ADSC);		// Start converting
177
	ADCSRA |= (1<<ADSC);		// Start converting
177
 
178
 
178
	while (((ADCSRA >> ADSC) & 1)) {}	//Wait until conversion finished
179
	while (((ADCSRA >> ADSC) & 1)) {}	//Wait until conversion finished
179
	uint8_t result = ADCH;
180
	uint8_t result = ADCH;
180
	ADCSRA |= (0<<ADSC);		// Stop converting
181
	ADCSRA |= (0<<ADSC);		// Stop converting