#include "def_principais.h"
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned int adc_valor=0;
void Ports_setup();
void ADC_setup();
#define pb_decr PA0
#define pb_incr PA1
#define D PB0
#define CLK PB1
#define STB PB2
unsigned char i;
unsigned char Display[3]={0,0,0};
const char tabla[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void Ports_setup()
{
DDRA = 0X00;
}
void ADC_setup()
{
ADMUX = (0<<REFS1)|(1<<REFS0)|(0<<MUX5)|(0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(1<<MUX0);
ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(0<<ADIF)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
ADCSRB = (0<<BIN)|(0<<ACME)|(0<<ADLAR)|(0<<ADTS2)|(0<<ADTS1)|(0<<ADTS0);
DIDR0 = (0<<ADC7D)|(0<<ADC6D)|(0<<ADC5D)|(0<<ADC4D)|(0<<ADC3D)|(0<<ADC2D)|(0<<ADC1D)|(0<<ADC0D);
}
ISR(ADC_vect,ISR_NAKED)
{
adc_valor= ADC;
reti();
}
void serial_paral(unsigned char c)
{
unsigned char i=8;
do
{i--;
if (tst_bit(c,i))
set_bit(PORTB,D);
else
clr_bit(PORTB,D);
set_bit(PORTB,CLK);
clr_bit(PORTB,CLK);
} while (i);
set_bit(PORTB,STB);
clr_bit(PORTB,STB);
}
void entero(int valor)
{
for (i=0;i<=2;i++)
{
Display[i]= 0;
}
i = 2;
while (valor > 0)
{
Display[i--] = (valor % 10);
valor /= 10;
}
}
int main(void)
{
Ports_setup();
ADC_setup();
sei();
int contador;
signed char x;
DDRB = 0b00000111;
DDRA = 0b00000000;
for (x=0;x<=2;x++)
{
serial_paral(0x3F);
}
while (1)
{
contador= (adc_valor*35)/60;
_delay_us(1000);
entero(contador);
for (x=2;x>=0;x--)
{
serial_paral(tabla[Display[x]]);
}
}
}