Тема: ATtiny45 ADC
Single Ended Input
Voltage Reference VCC
#define CLK PB2 // TM1637
#define DIO PB1 // TM1637
// PB4 INPUT
void setup(){
cli();
ADMUX |= (1 << MUX1);
ADCSRA |= (1<<ADEN)|(1 << ADATE)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
sei();
}
void loop(){
long u=0;
for(int n=0;n<10;n++){
while((ADCSRA & (1 << ADIF)) == 0);
int u_data = (ADCL|ADCH << 8);
u += u_data;delay(100);
}
u=u/10;
tm_print(500*u/1023,1,5);
}
void tm_dec(byte dig){
for(byte i = 0; i < 8; i++) {
DDRB |= (1 << CLK);del();
if (dig & 0x01)
DDRB &= ~(1 << DIO);
else
DDRB |= (1 << DIO);del();
DDRB &= ~(1 << CLK);del();
dig = dig >> 1;
}
DDRB |= (1 << CLK);
DDRB &= ~(1 << DIO);del();
DDRB &= ~(1 << CLK);del();
if (((PINB >> DIO) & 1) == 0)
DDRB |= (1 << DIO);del();
DDRB |= (1 << CLK);del();
}
void tm_stop(){
DDRB |= (1 << DIO);del();
DDRB &= ~(1 << CLK);del();
DDRB &= ~(1 << DIO);del();
}
void tm_start(){
DDRB |= (1 << DIO);del();
}
void tm_print(int t, bool pd_t, byte br){
tm_start();tm_dec(0b10001000 + br);
tm_dec(0x40);tm_stop();tm_start();
int data0 =10;
int data1 = t / 100 % 10;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
if(pd_t==1){data1 = data1+0b10000000;}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delay(1);}