#include #include #include #include #include #include #include "utils.h" #include "main.h" #include "uart.h" #define BUFSIZE 40 #define CURRENT_MAX 30000 // 30 Ampere is max volatile uint16_t syscounter = 0; volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 }; volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 }; uint8_t digit = 0; uint8_t leddigit = 0; // values send over uart from powerboard uint16_t voltage = 0; int16_t current_in = 0; int16_t current_out = 0; uint8_t dumpsw = 0; //TODO: make bitfield uint8_t loadsw = 0; //TODO: make bitfield uint8_t gensw = 0; //TODO: make bitfield uint16_t display = 0; uint16_t power_gen = 0; uint16_t power_load = 0; unsigned char data_count = 0; unsigned char data_in[BUFSIZE]; char command_in[BUFSIZE]; const uint8_t segment_translate[10] = { 63, 6, 91, 79, 102, 109, 125, 7, 127, 111 }; const uint8_t smallbar_translate[9] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; const uint8_t bigbar_translate[15][2] = { { 0x00, 0xc0}, { 0x00, 0x60}, { 0x00, 0x30}, { 0x00, 0x18}, { 0x00, 0x0c}, { 0x00, 0x06}, { 0x00, 0x03}, { 0x01, 0x01}, { 0x03, 0x00}, { 0x06, 0x00}, { 0x0c, 0x00}, { 0x18, 0x00}, { 0x30, 0x00}, { 0x60, 0x00}, { 0xc0, 0x00} }; //static void timer_init(void) { // clock is 8MHz //TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64 //OCR1A = 250; // 500Hz //TIMSK = _BV(OCIE1A); //sei(); // enable interrupts //} // Timer init ISR( TIMER1_COMPA_vect ) // Interruptbehandlungsroutine { OCR1A = 2500-OCR1A; // Das Servosignal wird aus der Differenz von // Periodenlänge (2500*0,008ms=20ms) und letztem // Vergleichswert (OCR1A) gebildet } static void ports_init(void) { // make column / digit driver pins to output DDRB = 0b11111100; PORTB = (1<= 100) { uart_putc('a'); // send a to receive values set_servo(power_gen) syscounter = 0; } } return(0); } // system timer SIGNAL(TIMER1_COMPA_vect) { syscounter++; // output to sevensegment and leds // make this here to reduce display flicker digit++; if(digit >5) digit = 0; leddigit++; if(leddigit >3) leddigit = 0; SEVENSEG_PORT = digitbuffer[digit]; SEVENSEGDIG_PORT = _BV(digit+DIG0); LED_PORT = leddigitbuffer[leddigit]; LEDDIG_PORT = _BV(leddigit); }