main.c aktualisiert

This commit is contained in:
Fabian Schieder 2026-02-02 23:55:01 +00:00
parent 89625f8966
commit bd178f6632

133
main.c
View File

@ -37,6 +37,9 @@ NexEventObj fuellstandText;
//---------------------Variablen------------------------ //---------------------Variablen------------------------
#define NEX_PID_MAIN 0
#define NEX_CID_PROG 1
#define SOLLWERT 0x7F // 127d #define SOLLWERT 0x7F // 127d
#define GAP 0x5F // 95d #define GAP 0x5F // 95d
#define NACHLAUF 0x5 #define NACHLAUF 0x5
@ -84,7 +87,7 @@ void PortConfig(void)
void uart2_init(void) void uart2_init(void)
{ {
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
GPIOA->CRL &= 0xFFFFF0FF; GPIOA->CRL &= 0xFFFFF0FF;
GPIOA->CRL |= 0xB00; GPIOA->CRL |= 0xB00;
@ -92,12 +95,12 @@ void uart2_init(void)
GPIOA->CRL &= 0xFFFF0FFF; GPIOA->CRL &= 0xFFFF0FFF;
GPIOA->CRL |= 0x4000; GPIOA->CRL |= 0x4000;
USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit
USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled
USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil
USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz) USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
USART2->CR1 |= 0x0C; // enable Receiver and Transmitter USART2->CR1 |= 0x0C; // enable Receiver and Transmitter
USART2->CR1 |= 0x2000; // Set USART Enable Bit USART2->CR1 |= 0x2000; // Set USART Enable Bit
} }
void uart2_putChar(char zeichen) void uart2_putChar(char zeichen)
@ -120,75 +123,48 @@ char uart2_getChar(void)
return ((char) (USART2->DR & 0xFF)); return ((char) (USART2->DR & 0xFF));
} }
void configProgressBar(void) static void NexEventObj_Init(NexEventObj *obj, uint8_t pid, uint8_t cid, const char *name)
{ {
fuellstandInd.pid = 0; obj->pid = pid;
fuellstandInd.cid = 1; obj->cid = cid;
fuellstandInd.name = "fuellstand"; obj->name = name;
fuellstandInd.pophandler = NULL; obj->pophandler = NULL;
fuellstandInd.pushhandler = NULL; obj->pushhandler = NULL;
fehlerInd.pid = 0;
fehlerInd.cid = 1;
fehlerInd.name = "fehlerInd";
fehlerInd.pophandler = NULL;
fehlerInd.pushhandler = NULL;
leerInd.pid = 0;
leerInd.cid = 1;
leerInd.name = "leerInd";
leerInd.pophandler = NULL;
leerInd.pushhandler = NULL;
feinInd.pid = 0;
feinInd.cid = 1;
feinInd.name = "feinInd";
feinInd.pophandler = NULL;
feinInd.pushhandler = NULL;
grobInd.pid = 0;
grobInd.cid = 1;
grobInd.name = "grobInd";
grobInd.pophandler = NULL;
grobInd.pushhandler = NULL;
pumpeInd.pid = 0;
pumpeInd.cid = 1;
pumpeInd.name = "pumpeInd";
pumpeInd.pophandler = NULL;
pumpeInd.pushhandler = NULL;
} }
void configTextFields(void) void configNexObjects(void)
{ {
fuellstandText.pid = 0; NexEventObj_Init(&fuellstandInd, NEX_PID_MAIN, NEX_CID_PROG, "fuellstand");
fuellstandText.cid = 1; // Component ID aus Nextion Editor NexEventObj_Init(&fehlerInd, NEX_PID_MAIN, NEX_CID_PROG, "fehlerInd");
fuellstandText.name = "fuellstandn"; // Exakter Name! NexEventObj_Init(&leerInd, NEX_PID_MAIN, NEX_CID_PROG, "leerInd");
fuellstandText.pophandler = NULL; NexEventObj_Init(&feinInd, NEX_PID_MAIN, NEX_CID_PROG, "feinInd");
fuellstandText.pushhandler = NULL; NexEventObj_Init(&grobInd, NEX_PID_MAIN, NEX_CID_PROG, "grobInd");
NexEventObj_Init(&pumpeInd, NEX_PID_MAIN, NEX_CID_PROG, "pumpeInd");
NexEventObj_Init(&fuellstandText, NEX_PID_MAIN, NEX_CID_PROG, "fuellstandn");
} }
void fehler(int8_t state) void fehler(bool state)
{ {
if(state == 1) 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;
} }
void leerBlasen(int8_t state) void leerBlasen(bool state)
{ {
if(state == 1) if(state)
{ {
NexProgressBar_setValue(&leerInd, 100); NexProgressBar_setValue(&leerInd, 100);
LEERBLASEN = 1; LEERBLASEN = 1;
@ -204,9 +180,9 @@ void leerBlasen(int8_t state)
return; return;
} }
void fein(int8_t state) void fein(bool state)
{ {
if(state == 1) if(state)
{ {
NexProgressBar_setValue(&feinInd, 100); NexProgressBar_setValue(&feinInd, 100);
FEIN = 1; FEIN = 1;
@ -222,9 +198,9 @@ void fein(int8_t state)
return; return;
} }
void grob(int8_t state) void grob(bool state)
{ {
if(state == 1) if(state)
{ {
NexProgressBar_setValue(&grobInd, 100); NexProgressBar_setValue(&grobInd, 100);
GROB = 1; GROB = 1;
@ -240,9 +216,9 @@ void grob(int8_t state)
return; return;
} }
void pumpe(int8_t state) void pumpe(bool state)
{ {
if(state == 1) if(state)
{ {
NexProgressBar_setValue(&pumpeInd, 100); NexProgressBar_setValue(&pumpeInd, 100);
PUMPE = 1; PUMPE = 1;
@ -309,17 +285,16 @@ int main(void)
uart2_init(); uart2_init();
NexEventObj *nextlisten_list[] = {NULL}; NexEventObj *nextlisten_list[] = {NULL};
configProgressBar(); configNexObjects();
configTextFields();
Nex_Init(0); Nex_Init(0);
Init_Nex_UI(); Init_Nex_UI();
fuellstand(0); fuellstand(0);
fehler(0); fehler(false);
leerBlasen(0); leerBlasen(false);
fein(0); fein(false);
grob(0); grob(false);
pumpe(0); pumpe(false);
wait_sys_ms(20); wait_sys_ms(20);
bool leerGeblasen = false; bool leerGeblasen = false;
@ -339,30 +314,30 @@ int main(void)
leerGeblasen = true; leerGeblasen = true;
leitungBenutzt = false; leitungBenutzt = false;
pumpe(1); pumpe(true);
if(effektiverWert < SOLLWERT - NACHLAUF) if(effektiverWert < SOLLWERT - NACHLAUF)
{ {
fein(1); fein(true);
leitungBenutzt = true; leitungBenutzt = true;
} }
else if(effektiverWert >= SOLLWERT - NACHLAUF) else if(effektiverWert >= SOLLWERT - NACHLAUF)
{ {
fein(0); fein(false);
} }
if(effektiverWert < GAP) if(effektiverWert < GAP)
{ {
grob(1); grob(true);
leitungBenutzt = true; leitungBenutzt = true;
} }
else if(effektiverWert < SOLLWERT) else if(effektiverWert < SOLLWERT)
{ {
grob(0); grob(false);
} }
else else
{ {
grob(0); grob(false);
} }
setFuellstand(effektiverWert); setFuellstand(effektiverWert);
@ -372,10 +347,10 @@ int main(void)
{ {
if(leerGeblasen) if(leerGeblasen)
{ {
pumpe(0); pumpe(false);
grob(0); grob(false);
fein(0); fein(false);
leerBlasen(1); leerBlasen(true);
if(leitungBenutzt) if(leitungBenutzt)
{ {
@ -394,7 +369,7 @@ int main(void)
wait_sys_ms(3000); wait_sys_ms(3000);
} }
leerBlasen(0); leerBlasen(false);
leerGeblasen = false; leerGeblasen = false;
} }
} }