Rev 470 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Blitzdings main.c
* (c) pangu
*/
/******************************************************************/
/* WICHTIG: Fusebits in Ponyprog für 8MHz setzen:
Häkchen in Ponyprog:
CKSEL3 gesetzt
CKSEL2 nicht gesetzt
CKSEL1 gesetzt
CKSEL0 gesetzt
*/
/******************************************************************/
#include "main.h"
#include "timer.h"
#include "lprg.h"
/* Strings zum definieren von Dauer-Ein Dauer-Aus */
const char l_on[]="A";
const char l_off[]="a";
// Wait flags:
// . 10 ms
// : 20 ms
// ; 50 ms
// I 100 ms
// N 200 ms
// M 300 ms
// V 500 ms
// S 1s
// LED:
// A-an a-aus
// Rot+Grün blitzen dreimal kurz, zeitlich leicht versetzt, alle 1,5s
// 2 weisse und 2 blaue LEDs sind an und gehen alle 3s reihum kurz aus
char *led_posflash1[] = {
"A:aIA:aIA:aSV", // LED #1 rot
".", // LED #2
"NNaIASSNNN", // LED #3 blau
".", // LED #4
"NaIASSNNNN", // LED #5 weiss
"NA:aIA:aIA:aMS", // LED #6 grün
".", // LED #7
"aIASSNNNNN", // LED #8 weiss
".", // LED #9
"NNNaIASSNN" // LED #10 blau
};
// dasselbe, nur sind w/b dauer-an
char *led_posflash[] = {
"A", // LED #1 rot
"A", // LED #2
"A", // LED #3 blau
"A", // LED #4
"A;aIA;aIA;aSV", // LED #5 weiss
"NA;aIA;aIA;aMS", // LED #6 grün
"A", // LED #7
"A", // LED #8 weiss
"A", // LED #9
"A" // LED #10 blau
};
char *led_aus[] = {
l_off, // LED #1 rot
l_off, // LED #2 blau
l_off, // LED #3 blau
l_off, // LED #4
l_off, // LED #5 weiss
l_off, // LED #6 grün
l_off, // LED #7
l_off, // LED #8 weiss
l_off, // LED #9
l_off // LED #10
};
char *led_an[] = {
l_on, // LED #1 rot
l_on, // LED #2 blau
l_on, // LED #3 blau
l_on, // LED #4
l_on, // LED #5 weiss
l_on, // LED #6 grün
l_on, // LED #7
l_on, // LED #8 weiss
l_on, // LED #9
l_on // LED #10
};
// alle LEDs toggeln synchron, 300ms Leucht/Aus-Dauer
char *led_flash1[] = {
"aMAM", // LED #1 rot
"aMAM", // LED #2 blau
"aMAM", // LED #3 blau
"aMAM", // LED #4
"aMAM", // LED #5 weiss
"aMAM", // LED #6 grün
"aMAM", // LED #7
"aMAM", // LED #8 weiss
"aMAM", // LED #9
"aMAM" // LED #10
};
// low Volatage Warning: alle LEDs toggeln synchron, 100ms Leucht/Aus-Dauer
char *led_lowVolt[] = {
"aIAI", // LED #1 rot
"aIAI", // LED #2 blau
"aIAI", // LED #3 blau
"aIAI", // LED #4
"aIAI", // LED #5 weiss
"aIAI", // LED #6 grün
"aIAI", // LED #7
"aIAI", // LED #8 weiss
"aIAI", // LED #9
"aIAI" // LED #10
};
// alle LEDs toggeln mit verschiednen Zykluszeiten
char *led_flash2[] = {
"ASIIaIAIaIaV", // LED #1
"ASIIaIAIaIaV", // LED #2
"aSIIIAIaIIIIAIaI", // LED #3
"aSIIIAIaIIIAIaII", // LED #4
"aSIIIAIaIIAIaIII", // LED #5
"aVSIAIaIII", // LED #6
"aSIIIAIaIIIAIaII", // LED #7
"aSIIIAIaIIIIAIaI", // LED #8
"aSIIIAIaI IIII AI", // LED #9
"aSIIIAIaI IIII AI" // LED #10
};
// Hier die zu verwendenden LichtProgramme einfach eintragen.
int current = 0;
void *modes[]= { led_an, led_aus, led_posflash, led_flash2 };
void nextMode(void) {
current = ++current % (sizeof(modes)/sizeof(void *));
lprg_init(modes[current]);
}
ISR(INT1_vect)
{
static int doubleclick = 0;
if(doubleclick && !CheckDelay(doubleclick)) {
nextMode();
}
doubleclick = SetDelay(1000);
}
int main(void) {
int tim1s, tim3s, tim10s, analog_state=0;
int Vcurr, lowVwarn_on = 0;
SFIOR = 0x00; // Analog Comperator aus
ADCSRA = 0xD3; // Converter ein, single
// Ports einstellen
// Pin B |7|6|5|4|3|2|1|0
// Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h)
// Pin B0 und B2 als Ausgänge festlegen
DDRB = 0x05;
// Pin C |7|6|5|4|3|2|1|0
// Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h)
// Pin C1 bis C5 als Ausgänge festlegen
DDRC = 0x3E;
// Pin D |7|6|5|4|3|2|1|0
// Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h)
DDRD = 0xF0;
//Pullup für PD3 aktivieren
PORTD |= (1 << PD3);
//interrupt konfigurueren
GIMSK = 1<<INT1;
MCUCR = 1<<ISC10;
ALLES_OFF;
STATUS_ON;
Timer_Init();
lprg_init(modes[current]);
tim10s = SetDelay(20000);
tim3s = SetDelay(3000);
tim1s = SetDelay(1000);
sei(); //interrupts einschalten
while (1) {
if(flag10ms) { // every 10ms
flag10ms = 0;
lprg_step(); // next step in light prog
if(!analog_state) { // Sampling der SPannung starten
ADMUX = 0 | 0xC0; // Kanal 0, interne Referenz
ADCSRA |= 0x10; // Ready löschen
ADCSRA |= 0x40; // Start
analog_state++; // erst wieder sampeln, wenn der Wert ausgelesen wurde
}
}
// 1s-Task: Status-LED toggeln, Spannung checken
if(CheckDelay(tim1s)) {
if (ADCSRA & 0x10) { // Spannungs-Messung beendet?
ADCSRA = 0xD3;
Vcurr = ADCW; // Wert merken
analog_state = 0;
}
if(Vcurr < 180) {
lprg_init(led_lowVolt);
lowVwarn_on = 1;
}
if(lowVwarn_on && Vcurr>=180) {
lprg_init(modes[current]);
lowVwarn_on = 0;
}
STATUS_TOGGLE;
tim1s = SetDelay(1000);
}
// 3s-Task: Unterspannungswarnung ggf. zurücknehmen
if(CheckDelay(tim3s)) {
tim3s = SetDelay(3000);
}
// 10s-Task: DEMO: programm wechseln
if(CheckDelay(tim10s)) {
nextMode();
tim10s = SetDelay(10000);
}
}
}