Вс янв 26, 2020 11:43:38
DDRB |= _BV(PB1);
/*
* test_dac10bit.c
*
* Created: 25.01.2020 17:39:05
* Author : Dima
*/
#include <avr/io.h>
#include <avr/interrupt.h>
// One 10-bit analogue output from an ATtiny85 ************************************
volatile int Dac = 0;
volatile int Cycle = 0;
// Overflow interrupt
ISR (TIMER1_OVF_vect) {
static int remain;
if (Cycle == 0) remain = Dac;
if (remain >= 256) { OCR1A = 255; remain = remain - 256; }
else { OCR1A = remain; remain = 0; }
Cycle = (Cycle + 1) & 0x03;
}
void analogWrite10 (int value) {
cli(); Dac = value; sei();
}
int main(void)
{
// Timer/Counter1 doing PWM on OC1A (PB1)
TCCR1 = 1<<PWM1A | 1<<COM1A0 | 1<<CS10;
TIMSK |= _BV(TOIE1);
DDRB |= _BV(PB1);
/* Replace with your application code */
while (1)
{
analogWrite10(511);
}
}
Вс янв 26, 2020 12:05:11
Вс янв 26, 2020 12:31:11
Вс янв 26, 2020 12:47:32
Вс янв 26, 2020 13:11:54
Вс янв 26, 2020 13:22:32
Вс янв 26, 2020 17:49:27
ISR (TIMER1_OVF_vect)
TCCR1 = 1<<PWM1A | 1<<COM1A0 | 1<<CS10;
Вс янв 26, 2020 18:58:23