Kod: Markera allt
#include "avr/io.h"
#include "inttypes.h"
#include "avr/interrupt.h"
#include "avr/signal.h"
#include "string.h"
#include "stdio.h"
#define clock = 2000000
unsigned char secs = 0;
unsigned char tsecs = 0;
unsigned char mins = 0;
unsigned char tmins = 0;
unsigned char hrs = 0;
unsigned char thrs = 0;
void delay1()
{
unsigned char delayvar1;
delayvar1 = 255;
while(delayvar1 != 0)
{
delayvar1--;
}
}
void setup()
{
DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0b00011000;
//OCR1A = 31250;
TCCR1A = (3<<CS10); //(CK/64)
//TCCR1B = (1<<CTC1);
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
TIMSK = (1<<TOIE1);
sei();
}
SIGNAL(SIG_OVERFLOW1)
{
secs++;
if ((secs == 10))
{
secs = 0;
tsecs++;
}
if ((tsecs == 6))
{
tsecs = 0;
mins++;
}
if ((mins == 10))
{
mins = 0;
tmins++;
}
if ((tmins == 6))
{
tmins = 0;
hrs++;
}
if ((hrs == 10))
{
hrs = 0;
thrs++;
}
if ((thrs == 2)&&(hrs == 4))
{
secs = 0;
tsecs = 0;
mins = 0;
tmins = 0;
hrs = 0;
thrs = 0;
}
PORTA = ((secs)|(tsecs<<4));
PORTB = ((mins)|(tmins<<4));
PORTC = ((hrs)|(thrs<<4));
delay1();
}
int main(void)
{
setup();
sei();
for(;;)
{
}
}