main.c aktualisiert
This commit is contained in:
parent
54aeabad73
commit
a706146744
156
main.c
156
main.c
@ -37,14 +37,12 @@ NexEventObj fuellstandText;
|
|||||||
|
|
||||||
//---------------------Variablen------------------------
|
//---------------------Variablen------------------------
|
||||||
|
|
||||||
volatile unsigned long* Switch[8] ={&Switch0, &Switch1, &Switch2, &Switch3, &Switch4, &Switch5, &Switch6, &Switch7};
|
|
||||||
|
|
||||||
#define SOLLWERT 0x7F // 127d
|
#define SOLLWERT 0x7F // 127d
|
||||||
#define GAP 0x5F // 95d
|
#define GAP 0x5F // 95d
|
||||||
#define NACHLAUF 0x5
|
#define NACHLAUF 0x5
|
||||||
|
|
||||||
|
volatile unsigned long* Switch[8] ={&Switch0, &Switch1, &Switch2, &Switch3, &Switch4, &Switch5, &Switch6, &Switch7};
|
||||||
int nachlaufOffset = 0;
|
int nachlaufOffset = 0;
|
||||||
char buffer[24]; // ka ob wir die benutzen, zu faul zum Suchen
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
@ -58,25 +56,17 @@ void PortConfig(void)
|
|||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren
|
||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren
|
||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren
|
||||||
|
|
||||||
GPIOC -> CRL &= 0x00000000;
|
|
||||||
GPIOC -> CRL = 0x22222222;
|
|
||||||
GPIOC -> CRH = 0x22222222;
|
|
||||||
|
|
||||||
GPIOB -> CRL &= 0x00000000;
|
GPIOB -> CRL &= 0x00000000;
|
||||||
GPIOB -> CRL = 0x22222222;
|
GPIOB -> CRL = 0x22222222;
|
||||||
|
|
||||||
GPIOA -> CRL &= 0x00000000;
|
|
||||||
GPIOA -> CRL = 0x22222222;
|
|
||||||
|
|
||||||
//----- Inputs ------
|
|
||||||
|
|
||||||
GPIOA -> CRH &= 0x00000000;
|
|
||||||
GPIOA -> CRH |= 0x00088000;
|
|
||||||
|
|
||||||
GPIOB -> CRH &= 0x00000000;
|
GPIOB -> CRH &= 0x00000000;
|
||||||
GPIOB -> CRH |= 0x88880000;
|
GPIOB -> CRH |= 0x88880000;
|
||||||
|
|
||||||
|
GPIOA -> CRL &= 0x00000000;
|
||||||
|
GPIOA -> CRL = 0x22222222;
|
||||||
|
GPIOA -> CRH &= 0x00000000;
|
||||||
|
GPIOA -> CRH |= 0x00088000;
|
||||||
|
|
||||||
GPIOC -> CRL &= 0x00000000;
|
GPIOC -> CRL &= 0x00000000;
|
||||||
GPIOC -> CRL |= 0x28222222;
|
GPIOC -> CRL |= 0x28222222;
|
||||||
GPIOC -> CRH &= 0x00000000;
|
GPIOC -> CRH &= 0x00000000;
|
||||||
@ -94,20 +84,20 @@ 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;
|
||||||
|
|
||||||
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)
|
||||||
@ -169,11 +159,10 @@ void configProgressBar(void)
|
|||||||
pumpeInd.pushhandler = NULL;
|
pumpeInd.pushhandler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void configTextFields(void)
|
void configTextFields(void)
|
||||||
{
|
{
|
||||||
fuellstandText.pid = 0;
|
fuellstandText.pid = 0;
|
||||||
fuellstandText.cid = 1; // Component ID aus Nextion Editor
|
fuellstandText.cid = 1; // Component ID aus Nextion Editor
|
||||||
fuellstandText.name = "fuellstandn"; // Exakter Name!
|
fuellstandText.name = "fuellstandn"; // Exakter Name!
|
||||||
fuellstandText.pophandler = NULL;
|
fuellstandText.pophandler = NULL;
|
||||||
fuellstandText.pushhandler = NULL;
|
fuellstandText.pushhandler = NULL;
|
||||||
@ -203,13 +192,13 @@ void leerBlasen(int8_t 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;
|
||||||
@ -221,13 +210,13 @@ void fein(int8_t 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;
|
||||||
@ -239,13 +228,13 @@ void grob(int8_t 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 geoeffnet!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -257,13 +246,13 @@ void pumpe(int8_t 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;
|
||||||
@ -274,12 +263,12 @@ void fuellstand(int8_t 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("Uengueltiger Fuellstandswert!\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,10 +321,10 @@ int main(void)
|
|||||||
fein(0);
|
fein(0);
|
||||||
grob(0);
|
grob(0);
|
||||||
pumpe(0);
|
pumpe(0);
|
||||||
wait_sys_ms(20);
|
wait_sys_ms(20);
|
||||||
|
|
||||||
bool leerGeblasen = 0;
|
bool leerGeblasen = false;
|
||||||
bool leitungBenutzt = 0;
|
bool leitungBenutzt = false;
|
||||||
|
|
||||||
uart2_putString("Dosieranlage V01\r\n");
|
uart2_putString("Dosieranlage V01\r\n");
|
||||||
|
|
||||||
@ -346,54 +335,53 @@ int main(void)
|
|||||||
uint8_t istWert = SwitchesToInt();
|
uint8_t istWert = SwitchesToInt();
|
||||||
uint16_t effektiverWert = istWert + nachlaufOffset;
|
uint16_t effektiverWert = istWert + nachlaufOffset;
|
||||||
|
|
||||||
|
if(*Switch[7] == 0)
|
||||||
if(*Switch[7] == 0)
|
{
|
||||||
|
leerGeblasen = true;
|
||||||
|
leitungBenutzt = false;
|
||||||
|
|
||||||
|
pumpe(1);
|
||||||
|
|
||||||
|
if(effektiverWert < SOLLWERT - NACHLAUF)
|
||||||
{
|
{
|
||||||
leerGeblasen = 1;
|
fein(1);
|
||||||
leitungBenutzt = false;
|
leitungBenutzt = true;
|
||||||
|
}
|
||||||
pumpe(1);
|
else if(effektiverWert >= SOLLWERT - NACHLAUF)
|
||||||
|
{
|
||||||
if(effektiverWert < SOLLWERT - NACHLAUF)
|
fein(0);
|
||||||
{
|
}
|
||||||
fein(1);
|
|
||||||
leitungBenutzt = true;
|
if(effektiverWert < GAP)
|
||||||
}
|
{
|
||||||
else if(effektiverWert >= SOLLWERT - NACHLAUF)
|
grob(1);
|
||||||
{
|
leitungBenutzt = true;
|
||||||
fein(0);
|
}
|
||||||
}
|
else if(effektiverWert < SOLLWERT)
|
||||||
|
{
|
||||||
if(effektiverWert < GAP)
|
grob(0);
|
||||||
{
|
}
|
||||||
grob(1);
|
else
|
||||||
leitungBenutzt = true;
|
{
|
||||||
}
|
grob(0);
|
||||||
else if(effektiverWert < SOLLWERT)
|
}
|
||||||
{
|
|
||||||
grob(0);
|
setFuellstand(effektiverWert);
|
||||||
}
|
wait_sys_ms(5);
|
||||||
else
|
|
||||||
{
|
|
||||||
grob(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
setFuellstand(effektiverWert);
|
|
||||||
wait_sys_ms(5);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(leerGeblasen == 1)
|
if(leerGeblasen)
|
||||||
{
|
{
|
||||||
pumpe(0);
|
pumpe(0);
|
||||||
grob(0);
|
grob(0);
|
||||||
fein(0);
|
fein(0);
|
||||||
|
|
||||||
leerBlasen(1);
|
leerBlasen(1);
|
||||||
|
|
||||||
if(leitungBenutzt)
|
if(leitungBenutzt)
|
||||||
{
|
{
|
||||||
int time = 3000 / NACHLAUF;
|
int time = 3000 / NACHLAUF;
|
||||||
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
for(i = 0; i < NACHLAUF; i++)
|
for(i = 0; i < NACHLAUF; i++)
|
||||||
{
|
{
|
||||||
@ -408,8 +396,10 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
leerBlasen(0);
|
leerBlasen(0);
|
||||||
leerGeblasen = 0;
|
leerGeblasen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user