main.c aktualisiert

This commit is contained in:
Fabian Schieder 2026-02-02 23:18:43 +00:00
parent 9ed1d398c7
commit 54aeabad73

158
main.c
View File

@ -1,13 +1,9 @@
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!! !!!!!!!!!!
!!!!!!!!!! Hab ein bischen herumprobiert. Ich versteh nicht wie wir die Angabe umsetzen sollen !!!!!!!!!!
!!!!!!!!!! !!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
#include <stm32f10x.h>
#include <armv30_std.h>
#include <Nextion.h>
#include "nex_ui.h"
#include <stdbool.h>
//---------------------Nextion-Objekte------------------------
@ -20,9 +16,6 @@ NexEventObj fehlerInd;
NexEventObj fuellstandText;
//---------------------Alias-Defines------------------------
#define BITBAND_PERI(a,b) ((PERIPH_BB_BASE + (a-PERIPH_BASE)*32 + (b*4)))
@ -42,14 +35,19 @@ NexEventObj fuellstandText;
#define Switch2 *((volatile unsigned long *)(BITBAND_PERI(GPIOA_IDR,11))) // DIL2
#define Switch3 *((volatile unsigned long *)(BITBAND_PERI(GPIOA_IDR,12))) // DIL3
//---------------------Variables------------------------
//---------------------Variablen------------------------
#define SOLLWERT 0x7F
volatile unsigned long* Switch[8] ={&Switch0, &Switch1, &Switch2, &Switch3, &Switch4, &Switch5, &Switch6, &Switch7};
#define SOLLWERT 0x7F // 127d
#define GAP 0x5F // 95d
#define NACHLAUF 0x5
int nachlaufOffset = 0;
char buffer[24]; // ka ob wir die benutzen, zu faul zum Suchen
//------------------------------------------------------
char buffer[24];
void SysTick_Handler()
{
STD_IncTick();
@ -91,7 +89,6 @@ void PortConfig(void)
GPIOA -> ODR |= 0x1800;
GPIOB -> ODR |= 0xF000;
GPIOC -> ODR |= 0x0440;
}
void uart2_init(void)
@ -111,7 +108,6 @@ void uart2_init(void)
USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
USART2->CR1 |= 0x0C; // enable Receiver and Transmitter
USART2->CR1 |= 0x2000; // Set USART Enable Bit
}
void uart2_putChar(char zeichen)
@ -176,11 +172,11 @@ void configProgressBar(void)
void configTextFields(void)
{
fuellstandText.pid = 0;
fuellstandText.cid = 1; // Component ID aus Nextion Editor
fuellstandText.name = "fuellstandn"; // Exakter Name!
fuellstandText.pophandler = NULL;
fuellstandText.pushhandler = NULL;
fuellstandText.pid = 0;
fuellstandText.cid = 1; // Component ID aus Nextion Editor
fuellstandText.name = "fuellstandn"; // Exakter Name!
fuellstandText.pophandler = NULL;
fuellstandText.pushhandler = NULL;
}
void fehler(int8_t state)
@ -255,7 +251,6 @@ void grob(int8_t state)
return;
}
void pumpe(int8_t state)
{
if(state == 1)
@ -288,40 +283,38 @@ void fuellstand(int8_t value)
}
}
static uint8_t scale_7bit_to_percent(uint8_t value)
uint8_t toPercent(uint8_t value, uint8_t max)
{
if (value > 0x7F) value = 0x7F;
return (uint8_t)((value * 100u + 63u) / 127u); // gerundet
if (value > max) value = max;
return (value * 100 + max / 2) / max;
}
void fuellstand_ui(uint8_t percent)
{
if (percent <= 100)
{
NexProgressBar_setValue(&fuellstandInd, percent);
}
}
void set_fuellstand_process(uint8_t istwert_7bit)
{
uint8_t ui_value;
if (istwert_7bit > SOLLWERT)
istwert_7bit = SOLLWERT;
ui_value = scale_7bit_to_percent(istwert_7bit);
fuellstand_ui(ui_value);
}
void fuellstandSetText(uint8_t value)
void setFuellstand(uint8_t value) // setzt Füllstand Text über progress bar
{
char buf[20];
sprintf(buf, "%u l", value);
NexText_setText(&fuellstandText, buf);
fuellstand(toPercent(value, 255));
}
int SwitchesToInt(void) // DIL Leiste zu Int
{
int result = 0;
uint8_t i = 0;
for (i = 0; i < 7; i++)
{
if (!*Switch[i])
{
result |= (1 << i);
} }
return result;
}
int main(void)
{
PortConfig();
@ -333,8 +326,6 @@ int main(void)
Nex_Init(0);
Init_Nex_UI();
uint8_t currentFuellstand = 0;
fuellstand(0);
fehler(0);
leerBlasen(0);
@ -343,17 +334,82 @@ int main(void)
pumpe(0);
wait_sys_ms(20);
uart2_putString("Dosieranlage V01\r\n");
bool leerGeblasen = 0;
bool leitungBenutzt = 0;
uart2_putString("Dosieranlage V01\r\n");
while(1)
{
Nex_Event_Loop(nextlisten_list);
wait_sys_ms(20);
wait_sys_ms(5);
uint8_t istWert = SwitchesToInt();
uint16_t effektiverWert = istWert + nachlaufOffset;
set_fuellstand_process(100);
fuellstandSetText(67);
wait_sys_ms(10);
if(*Switch[7] == 0)
{
leerGeblasen = 1;
leitungBenutzt = false;
pumpe(1);
if(effektiverWert < SOLLWERT - NACHLAUF)
{
fein(1);
leitungBenutzt = true;
}
else if(effektiverWert >= SOLLWERT - NACHLAUF)
{
fein(0);
}
if(effektiverWert < GAP)
{
grob(1);
leitungBenutzt = true;
}
else if(effektiverWert < SOLLWERT)
{
grob(0);
}
else
{
grob(0);
}
setFuellstand(effektiverWert);
wait_sys_ms(5);
}
else
{
if(leerGeblasen == 1)
{
pumpe(0);
grob(0);
fein(0);
leerBlasen(1);
if(leitungBenutzt)
{
int time = 3000 / NACHLAUF;
uint8_t i = 0;
for(i = 0; i < NACHLAUF; i++)
{
wait_sys_ms(time);
nachlaufOffset += 1;
setFuellstand(istWert + nachlaufOffset);
}
}
else
{
wait_sys_ms(3000);
}
leerBlasen(0);
leerGeblasen = 0;
}
}
}
}