2012-07-17 01:05:27 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
2012-08-27 09:17:56 +02:00
|
|
|
|
2012-07-26 01:34:49 +02:00
|
|
|
|
2012-08-12 01:35:00 +02:00
|
|
|
|
|
|
|
uint16_t sw_v = 0;
|
|
|
|
uint16_t darkness = 0;
|
|
|
|
uint16_t darkval = 0;
|
|
|
|
uint16_t last_darkval = 0;
|
|
|
|
|
|
|
|
|
2012-08-06 13:25:33 +02:00
|
|
|
|
|
|
|
|
2012-08-27 09:17:56 +02:00
|
|
|
void __attribute__((noreturn))
|
|
|
|
main(void)
|
2012-07-17 01:05:27 +02:00
|
|
|
{
|
2012-08-11 21:08:50 +02:00
|
|
|
|
2012-08-27 09:17:56 +02:00
|
|
|
/* here the show begins:*/
|
|
|
|
|
|
|
|
DDRC = 0b00100011;
|
|
|
|
PORTC = 0b00000001;
|
|
|
|
PORTC = 0b00000000;
|
|
|
|
DDRD = 0x00;
|
|
|
|
PORTD = 0b00000011; //enable pullups
|
|
|
|
DDRB = 0xFF;
|
|
|
|
PORTB=0xFF;
|
2012-08-11 21:08:50 +02:00
|
|
|
|
2012-08-12 01:35:00 +02:00
|
|
|
/* set timer2 to CTC & prescaler 64 → ???125kHz increment */
|
2012-08-11 21:08:50 +02:00
|
|
|
TCCR2A = (1 << WGM21);
|
2012-08-12 01:35:00 +02:00
|
|
|
TCCR2B = (1 << CS20)|(1 << CS21);
|
2012-08-11 21:08:50 +02:00
|
|
|
|
2012-08-27 09:17:56 +02:00
|
|
|
OCR2A = 0x3F; /* TOP */
|
2012-08-11 21:08:50 +02:00
|
|
|
TCNT2 = 0;
|
|
|
|
/*enable interrupt*/
|
|
|
|
TIMSK2 |= (1<<OCIE2A);
|
|
|
|
|
2012-08-27 09:17:56 +02:00
|
|
|
sei();
|
2012-07-17 01:05:27 +02:00
|
|
|
|
2012-08-06 00:16:17 +02:00
|
|
|
|
2012-08-07 20:08:57 +02:00
|
|
|
for(;;) /* ever */ {
|
|
|
|
|
|
|
|
//do something
|
2012-08-27 09:17:56 +02:00
|
|
|
//synth_poll();
|
|
|
|
/* if (10 == 1){
|
2012-08-12 01:35:00 +02:00
|
|
|
uint16_t out = darkval;
|
|
|
|
USART0_put_uint16(out);
|
|
|
|
USART0_crlf();
|
|
|
|
//last_darkval=darkval;
|
2012-08-27 09:17:56 +02:00
|
|
|
};*/
|
|
|
|
|
|
|
|
DDRC |= (1 << PORTC0) | (1 << PORTC2) |
|
|
|
|
(1 << PORTC3) | (1 << PORTC1) ;
|
|
|
|
/* initially one led is on */
|
|
|
|
if ((PIND & 0b00000001)==0){
|
|
|
|
PORTC |= 0b00000001;
|
|
|
|
PORTB |= 0b00000010;
|
|
|
|
} else {
|
|
|
|
PORTC &= 0b11111110;
|
|
|
|
//PORTB &= 0b11111101;
|
|
|
|
|
|
|
|
};
|
|
|
|
if ((PIND & 0b00000010)==0){
|
|
|
|
PORTC |= 0b00000100;
|
|
|
|
} else {
|
|
|
|
PORTC &= 0b11111011;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-12 01:35:00 +02:00
|
|
|
//USART0_put_uint16(0xA09F);
|
|
|
|
//USART0_crlf();
|
2012-08-14 22:53:25 +02:00
|
|
|
}
|
2012-07-18 15:55:20 +02:00
|
|
|
|
2012-08-14 22:53:25 +02:00
|
|
|
/* never return 0; */
|
2012-07-18 15:55:20 +02:00
|
|
|
}
|
2012-08-05 22:13:43 +02:00
|
|
|
|
|
|
|
|
2012-08-12 01:35:00 +02:00
|
|
|
|
2012-08-11 21:08:50 +02:00
|
|
|
ISR(TIMER2_COMPA_vect)
|
|
|
|
{
|
2012-08-27 09:17:56 +02:00
|
|
|
//invert c5 and b2
|
|
|
|
PORTB ^=0b00000100;
|
|
|
|
PORTC ^= 0b00100000;
|
|
|
|
|
2012-08-11 21:08:50 +02:00
|
|
|
}
|