1
0
Fork 0
lego_sensor_i2c/i2c_test_attiny85/led_gen.c

58 lines
1 KiB
C
Executable file

/*
* led_gen.c
*
* Created: 03/12/2021 14:25:05
* Author: 40008304
*/
#include "led_gen.h"
volatile unsigned char led1_state=0;
volatile unsigned char led2_state=0;
void led1_init(void)
{
TCCR1|=(1<<CTC1)|(1<<COM1A0); //on active le mode CTC en comparant OCR1C, COM1A0 : mode toggle
OCR1C=68; //d'apres retroingenieurie OCR1C=16
TCCR1|=(1<<CS10)|(1<<CS11); //on active la clock, prediv de 4
DDRB |= (1<<PB1);
led1_state=1;
}
void led2_init(void)
{
GTCCR|=(1<<COM1B0); //COM1B0 : mode toggle
OCR1C=68; //d'apres retroingenieurie OCR1C=16
TCCR1|=(1<<CS10)|(1<<CS11); //on active la clock, prediv de 4
DDRB |= (1<<PB4);
led2_state=1;
}
void led1_stop(void)
{
DDRB &= ~(1<<PB1);
TCCR1 &= ~(1<<COM1A0);
led1_state=0;
}
void led2_stop(void)
{
DDRB &= ~(1<<PB4);
GTCCR &= ~(1<<COM1B0);
led2_state=0;
}
void timer0_init(void)
{
TCCR0A=0x00; //Normal mode
TCCR0B=0x00;
TCCR0B |= (1<<CS01); //prescaling with 8
TCNT0=0;
TIMSK|=(1<<TOIE0);
}