You are on page 1of 2

/*

* adc_pot.c
*
* Created: 03-Aug-14 12:50:49 AM
* Author: Jamil
*/
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <math.h>
int main(void)
{
DDRB = 0xFF;
DDRC = 0xFF;
ADCSRA |= 1<<ADPS2;
ADMUX |= 1<<ADLAR;
ADMUX |= 1<<REFS0;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
while(1)
{
}
}
ISR(ADC_vect)
{
uint8_t x=0;
uint8_t d1=0;
uint8_t d2=0;
uint8_t d3=0;
uint8_t d4=0;
float display;
int dig[10] = {
0b11000000,//0
0b11111001,//1
0b10100100,//2
0b10110000,//3
0b10011001,//4
0b10010010,//5
0b10000010,//6
0b11111000,//7
0b10000000,//8
0b10010000//9
};
display= (150/128)*AVCH;
display= round(display);
x= display/10;
d4= display%10;
d3= x%10;
d2= display/100;
PORTC = dig[d4];

PORTB = 0b10000000;
_delay_ms(10);
PORTB = 0b00000000;
PORTC = dig[d3];
PORTB = 0b01000000;
_delay_ms(10);
PORTB = 0b00000000;
PORTC = dig[d2];
PORTB = 0b00100000;
_delay_ms(10);
PORTB = 0b00000000;
ADCSRA |= 1<<ADSC;
}

You might also like