146 lines
2.6 KiB
C
146 lines
2.6 KiB
C
|
|
#include <avr/io.h>
|
|
#include <stdint.h>
|
|
#include <util/delay.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
#include "global.h"
|
|
#include "shift_register.h"
|
|
#include "uart.h"
|
|
#include "ds1307.h"
|
|
#include "adc.h"
|
|
#include "ldr.h"
|
|
#include "pwm.h"
|
|
|
|
volatile uint8_t uart_str_complete = 0;
|
|
volatile char uart_buffer[UART_MAXSTRLEN + 1] = "";
|
|
|
|
volatile uint8_t flag_50ms;
|
|
volatile uint8_t flag_1sec;
|
|
|
|
ISR(TIMER0_COMPA_vect)
|
|
{
|
|
|
|
static uint8_t millisekunden = 0;
|
|
static uint8_t sekunden = 0;
|
|
|
|
if (millisekunden++ == 5)
|
|
{
|
|
//TOGL(PORTC, PC0);
|
|
millisekunden = 0;
|
|
sekunden++;
|
|
flag_50ms = 1;
|
|
}
|
|
|
|
if (sekunden == 20)
|
|
{
|
|
sekunden = 0;
|
|
flag_1sec = 1;
|
|
}
|
|
}
|
|
|
|
|
|
ISR(USART_RX_vect)
|
|
{
|
|
uart_str_complete = UART_rx_str();
|
|
}
|
|
|
|
void init_timer0(void)
|
|
{
|
|
// Timer0 initialisieren.
|
|
TCCR0A = (1 << WGM01); // CTC Modus (Clear Timer on Compare)
|
|
TCCR0B = (1 << CS02 | 1 << CS00); // Prescaler: 1024
|
|
OCR0A = 180-1; // Zaehlwert auf 180 setzen
|
|
TIMSK0 |= (1 << OCIE0A); // Timer Interrupt Maske aktivieren
|
|
}
|
|
|
|
int8_t UART_bla(void)
|
|
{
|
|
if (uart_str_complete)
|
|
{
|
|
uart_str_complete = 0;
|
|
if (uart_buffer[0] == 'L' && uart_buffer[1] == 'E' && uart_buffer[2] == 'D'
|
|
&& uart_buffer[3] >= 0x1 && uart_buffer[3] <= 0xf)
|
|
{
|
|
return uart_buffer[3];
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
uint8_t toggle = 0,
|
|
led = 1;
|
|
int8_t input = 0;
|
|
flag_50ms = 0;
|
|
flag_1sec = 0;
|
|
|
|
//init_timer0();
|
|
PWM_init_timer();
|
|
//shiftReg_Init();
|
|
ADC_init();
|
|
UART_init(BAUD_RATE, (char *) uart_buffer);
|
|
|
|
LED_DDR = (1 << LED_PIN);
|
|
LED_PORT &= ~(1 << LED_PIN);
|
|
|
|
sei();
|
|
|
|
//UART_tx_str("\n### QLOCKTWO ###\n");
|
|
/*
|
|
t_TIME date;
|
|
date.seconds = 43; // 0100 0011
|
|
date.minutes = 10; // 0001 0000
|
|
date.hours = 10;
|
|
date.mode = MODE_24;
|
|
date.ampm = PM; // 0001 0000
|
|
date.weekday = 1;
|
|
date.day = 19; // 0001 1001
|
|
date.month = 3; // 0000 0011
|
|
date.year = 11; // 0001 0001
|
|
|
|
|
|
int err = DS1307_init(date, DS1307_SQWE_ON, DS1307_1HZ, DS1307_OUT_H);
|
|
if (err)
|
|
TOGL(LED_PORT, LED_PIN);
|
|
|
|
|
|
uint8_t ds1307_date[8] = {0,0,0,0,0,0,0,0};
|
|
int err = DS1307_read(ds1307_date, 8, 0);
|
|
if (err)
|
|
TOGL(LED_PORT, LED_PIN);
|
|
|
|
//UART_tx_str("\nread\n");
|
|
for (int byte = 0; byte < 8; byte++)
|
|
{
|
|
UART_tx_char(BCD_TO_INT(ds1307_date[byte]));
|
|
}
|
|
UART_tx_char('\n');
|
|
*/
|
|
uint8_t status;
|
|
while(1)
|
|
{
|
|
PWM_update();
|
|
status = PWM_get_status();
|
|
/*
|
|
if (status)
|
|
SET(LED_PORT, LED_PIN);
|
|
else
|
|
CLR(LED_PORT, LED_PIN);
|
|
*/
|
|
/*
|
|
UART_tx_char((ldr / 100) & 0xff);
|
|
UART_tx_char((ldr % 100) & 0xff);
|
|
UART_tx_char('\n');
|
|
|
|
_delay_ms(100);
|
|
*/
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|