Rev 311 |
Rev 341 |
Go to most recent revision |
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 "analog.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:aIA:aIA:aSV", // LED #1 rot
".", // LED #2
"A", // LED #3 blau
".", // LED #4
"A", // LED #5 weiss
"NA:aIA:aIA:aMS", // LED #6 grün
".", // LED #7
"A", // LED #8 weiss
".", // 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[] = {
"a.A.", // LED #1 rot
"a:A:", // LED #2 blau
"a;A;", // LED #3 blau
"aIAI", // LED #4
"aNAN", // LED #5 weiss
"aMAM", // LED #6 grün
"aMIAMI", // LED #7
"aVAV", // LED #8 weiss
"aVIAVI", // LED #9
"aSAS" // LED #10
};
// Hier die zu verwendenden LichtProgramme einfach eintragen.
int current = 0;
void *modes[]= { led_posflash, led_an, led_aus };
void nextMode() {
current = ++current % (sizeof(modes)/sizeof(void *));
lprg_init(modes[current]);
}
ISR(INT1_vect)
{
nextMode();
}
int main() {
int tim1s, tim3s, tim10s;
int Vcurr;
// 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(10000);
tim3s = SetDelay(3000);
tim1s = SetDelay(1000);
sei(); //interrupts einschalten
while (1) {
if(flag10ms) { // every 10ms
flag10ms = 0;
lprg_step(); // next step in light prog
}
// 1s-Task: Status-LED toggeln, Spannung checken
if(CheckDelay(tim1s)) {
Vcurr = getVcurr();
if(Vcurr < 180) {
lprg_init(led_lowVolt);
}
STATUS_TOGGLE;
tim1s = SetDelay(1000);
}
// 3s-Task: Unterspannungswarnung ggf. zurücknehmen
if(CheckDelay(tim3s)) {
if(Vcurr>=180) {
lprg_init(modes[current]);
}
tim3s = SetDelay(3000);
}
// 10s-Task: DEMO: programm wechseln
if(CheckDelay(tim10s)) {
// nextMode();
tim10s = SetDelay(10000);
}
}
}