USART2 Ausgabe gefixt
This commit is contained in:
parent
bb88c8d84d
commit
e4506d41e6
130
main.c
130
main.c
@ -86,7 +86,7 @@ void PortConfig(void)
|
|||||||
|
|
||||||
void uart2_init(void)
|
void uart2_init(void)
|
||||||
{
|
{
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; // 0x4
|
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
|
||||||
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
|
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
|
||||||
|
|
||||||
GPIOA->CRL &= 0xFFFFF0FF;
|
GPIOA->CRL &= 0xFFFFF0FF;
|
||||||
@ -146,17 +146,32 @@ void configNexObjects(void)
|
|||||||
|
|
||||||
void fehler(bool state)
|
void fehler(bool state)
|
||||||
{
|
{
|
||||||
|
static bool lastStateF = true;
|
||||||
|
static bool firstCallF = true;
|
||||||
|
|
||||||
|
if (firstCallF)
|
||||||
|
{
|
||||||
|
firstCallF = false;
|
||||||
|
NexProgressBar_setValue(&fehlerInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (state == lastStateF)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStateF = state;
|
||||||
if(state)
|
if(state)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&fehlerInd, 100);
|
NexProgressBar_setValue(&fehlerInd, 100);
|
||||||
FEHLER = 1;
|
FEHLER = 1;
|
||||||
//uart2_putString("Fehler aufgetreten!\r\n");
|
uart2_putString("Fehler aufgetreten!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&fehlerInd, 0);
|
NexProgressBar_setValue(&fehlerInd, 0);
|
||||||
FEHLER = 0;
|
FEHLER = 0;
|
||||||
//uart2_putString("Fehler behoben!\r\n");
|
uart2_putString("Fehler behoben!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -164,17 +179,33 @@ void fehler(bool state)
|
|||||||
|
|
||||||
void leerBlasen(bool state)
|
void leerBlasen(bool state)
|
||||||
{
|
{
|
||||||
|
static bool lastStateB;
|
||||||
|
static bool firstCallB = true;
|
||||||
|
|
||||||
|
if (firstCallB)
|
||||||
|
{
|
||||||
|
firstCallB = false;
|
||||||
|
NexProgressBar_setValue(&leerInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (state == lastStateB)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStateB = state;
|
||||||
|
|
||||||
if(state)
|
if(state)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&leerInd, 100);
|
NexProgressBar_setValue(&leerInd, 100);
|
||||||
LEERBLASEN = 1;
|
LEERBLASEN = 1;
|
||||||
//uart2_putString("Leerblasventil geoeffnet!\r\n");
|
uart2_putString("Leerblasventil geoeffnet!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&leerInd, 0);
|
NexProgressBar_setValue(&leerInd, 0);
|
||||||
LEERBLASEN = 0;
|
LEERBLASEN = 0;
|
||||||
//uart2_putString("Leerblasventil geschlossen!\r\n");
|
uart2_putString("Leerblasventil geschlossen!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -182,17 +213,33 @@ void leerBlasen(bool state)
|
|||||||
|
|
||||||
void fein(bool state)
|
void fein(bool state)
|
||||||
{
|
{
|
||||||
|
static bool lastStateFein;
|
||||||
|
static bool firstCallFein = true;
|
||||||
|
|
||||||
|
if (firstCallFein)
|
||||||
|
{
|
||||||
|
firstCallFein = false;
|
||||||
|
NexProgressBar_setValue(&feinInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (state == lastStateFein)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStateFein = state;
|
||||||
|
|
||||||
if(state)
|
if(state)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&feinInd, 100);
|
NexProgressBar_setValue(&feinInd, 100);
|
||||||
FEIN = 1;
|
FEIN = 1;
|
||||||
//uart2_putString("Feinventil geoeffnet!\r\n");
|
uart2_putString("Feinventil geoeffnet!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&feinInd, 0);
|
NexProgressBar_setValue(&feinInd, 0);
|
||||||
FEIN = 0;
|
FEIN = 0;
|
||||||
//uart2_putString("Feinventil geschlossen!\r\n");
|
uart2_putString("Feinventil geschlossen!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -200,17 +247,33 @@ void fein(bool state)
|
|||||||
|
|
||||||
void grob(bool state)
|
void grob(bool state)
|
||||||
{
|
{
|
||||||
|
static bool lastStateGrob;
|
||||||
|
static bool firstCallGrob = true;
|
||||||
|
|
||||||
|
if (firstCallGrob)
|
||||||
|
{
|
||||||
|
firstCallGrob = false;
|
||||||
|
NexProgressBar_setValue(&grobInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (state == lastStateGrob)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStateGrob = state;
|
||||||
|
|
||||||
if(state)
|
if(state)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&grobInd, 100);
|
NexProgressBar_setValue(&grobInd, 100);
|
||||||
GROB = 1;
|
GROB = 1;
|
||||||
//uart2_putString("Grobventil geoeffnet!\r\n");
|
uart2_putString("Grobventil geoeffnet!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&grobInd, 0);
|
NexProgressBar_setValue(&grobInd, 0);
|
||||||
GROB = 0;
|
GROB = 0;
|
||||||
//uart2_putString("Grobventil geoeffnet!\r\n");
|
uart2_putString("Grobventil geschlossen!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -218,17 +281,33 @@ void grob(bool state)
|
|||||||
|
|
||||||
void pumpe(bool state)
|
void pumpe(bool state)
|
||||||
{
|
{
|
||||||
|
static bool lastState;
|
||||||
|
static bool firstCall = true;
|
||||||
|
|
||||||
|
if (firstCall)
|
||||||
|
{
|
||||||
|
firstCall = false;
|
||||||
|
NexProgressBar_setValue(&pumpeInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (state == lastState)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastState = state;
|
||||||
|
|
||||||
if(state)
|
if(state)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&pumpeInd, 100);
|
NexProgressBar_setValue(&pumpeInd, 100);
|
||||||
PUMPE = 1;
|
PUMPE = 1;
|
||||||
//uart2_putString("Pumpe eingeschaltet!\r\n");
|
uart2_putString("Pumpe eingeschaltet!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&pumpeInd, 0);
|
NexProgressBar_setValue(&pumpeInd, 0);
|
||||||
PUMPE = 0;
|
PUMPE = 0;
|
||||||
//uart2_putString("Pumpe ausgeschaltet!\r\n");
|
uart2_putString("Pumpe ausgeschaltet!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -236,18 +315,33 @@ void pumpe(bool state)
|
|||||||
|
|
||||||
void fuellstand(int8_t value)
|
void fuellstand(int8_t value)
|
||||||
{
|
{
|
||||||
|
static bool firstCall = true;
|
||||||
|
static int8_t lastValue = -1; // ungültiger Startwert
|
||||||
|
if(firstCall)
|
||||||
|
{
|
||||||
|
firstCall = false;
|
||||||
|
NexProgressBar_setValue(&fuellstandInd, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == lastValue)
|
||||||
|
{
|
||||||
|
return; // nichts geändert ? nichts tun
|
||||||
|
}
|
||||||
|
|
||||||
|
lastValue = value;
|
||||||
|
|
||||||
if (value >= 0 && value <= 100)
|
if (value >= 0 && value <= 100)
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&fuellstandInd, value);
|
NexProgressBar_setValue(&fuellstandInd, value);
|
||||||
//uart2_putString("Fuellstand geaendert!\r\n");
|
uart2_putString("Fuellstand geaendert!\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NexProgressBar_setValue(&fuellstandInd, 0);
|
NexProgressBar_setValue(&fuellstandInd, 0);
|
||||||
//uart2_putString("Uengueltiger Fuellstandswert!\r\n");
|
uart2_putString("Ungueltiger Fuellstandswert!\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t toPercent(uint8_t value, uint8_t max)
|
uint8_t toPercent(uint8_t value, uint8_t max)
|
||||||
{
|
{
|
||||||
if (value > max) value = max;
|
if (value > max) value = max;
|
||||||
@ -355,19 +449,11 @@ int main(void)
|
|||||||
if(leitungBenutzt)
|
if(leitungBenutzt)
|
||||||
{
|
{
|
||||||
int time = 3000 / NACHLAUF;
|
int time = 3000 / NACHLAUF;
|
||||||
int rest = 3000 % NACHLAUF;
|
|
||||||
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
for(i = 0; i < NACHLAUF; i++)
|
for(i = 0; i < NACHLAUF; i++)
|
||||||
{
|
{
|
||||||
wait_sys_ms(time);
|
wait_sys_ms(time);
|
||||||
|
|
||||||
if(rest > 0)
|
|
||||||
{
|
|
||||||
wait_sys_ms(1);
|
|
||||||
rest -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
nachlaufOffset += 1;
|
nachlaufOffset += 1;
|
||||||
setFuellstand(istWert + nachlaufOffset);
|
setFuellstand(istWert + nachlaufOffset);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user