/*
* GccApplication1.c
*
* Created: 2016-07-04 12:07:23
* Author : Alexander
*/
#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
void Dash(void);
void Dot(void);
void Sendcq();
int sekund = 0;
int ggr = 0;
int paustid;
int main(void)
{
DDRB |= (1 << 0); //0 = input, 1 = output, PB0 is output, PB4 is input
DDRB |= (1 << 3); //PB3 as output.
ADMUX =
(1 << ADLAR) | // left shift result
(0 << REFS1) | // Sets ref. voltage to VCC, bit 1
(0 << REFS0) | // Sets ref. voltage to VCC, bit 0
(0 << MUX3) | // use ADC2 for input (PB4), MUX bit 3
(0 << MUX2) | // use ADC2 for input (PB4), MUX bit 2
(0 << MUX1) | // use ADC2 for input (PB4), MUX bit 1
(1 << MUX0); // use ADC2 for input (PB4), MUX bit 0
ADCSRA =
(1 << ADEN) | // Enable ADC
(1 << ADPS2) | // set prescaler to 64, bit 2
(1 << ADPS1) | // set prescaler to 64, bit 1
(0 << ADPS0); // set prescaler to 64, bit 0
while(1)
{
ADCSRA |= (1 << ADSC); // start ADC measurement
while (ADCSRA & (1 << ADSC) ); // wait till conversion complete
while(sekund < 60)
{
_delay_ms(1000);
sekund = sekund + 1;
}
sekund = 0;
if (ADCH > 58)
{
while(ggr < 4)
{
PORTB |= 1 << PB3; //öppna relä
_delay_ms(1000);
Sendcq();
_delay_ms(200);
PORTB &= ~(1 << PB3); //stäng relä
ggr = ggr +1;
}
ggr = 1;
}
else if (ADCH > 54)
{
while(ggr < 3)
{
PORTB |= 1 << PB3; //öppna relä
_delay_ms(1000);
Sendcq();
_delay_ms(200);
PORTB &= ~(1 << PB3); //stäng relä
ggr = ggr +1;
}
ggr = 1;
}
else if (ADCH > 50)
{
while(ggr < 2)
{
PORTB |= 1 << PB3; //öppna relä
_delay_ms(1000);
Sendcq();
_delay_ms(200);
PORTB &= ~(1 << PB3);
ggr = ggr +1;
}
ggr = 1;
}
else
{}
}
}
void Dash(void)
{
PORTB |= 1 << PB0;
_delay_ms(300);
PORTB &= ~(1 << PB0);
_delay_ms(100);
}
void Dot(void)
{
PORTB |= 1 << PB0;
_delay_ms(100);
PORTB &= ~(1 << PB0);
_delay_ms(100);
}
void Sendcq(void)
{
Dash();
Dot();
Dash();
Dot();
_delay_ms(300);
Dash();
Dash();
Dot();
Dash();
_delay_ms(700);
Dash();
_delay_ms(300);
Dot();
_delay_ms(300);
Dot();
Dot();
Dot();
_delay_ms(300);
Dash();
_delay_ms(700);
Dash();
Dot();
Dot();
_delay_ms(300);
Dot();
_delay_ms(700);
Dot();
Dot();
Dot();
_delay_ms(300);
Dot();
Dash();
_delay_ms(300);
Dash();
Dash();
Dot();
Dot();
Dot();
_delay_ms(300);
Dash();
Dot();
Dash();
Dot();
_delay_ms(300);
Dash();
Dot();
_delay_ms(300);
Dash();
Dash();
Dot();
_delay_ms(700);
}