main.c aktualisiert
This commit is contained in:
parent
00dc991ce3
commit
c5aa70028e
384
main.c
384
main.c
@ -1,112 +1,272 @@
|
|||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include <armv30_std.h>
|
#include <armv30_std.h>
|
||||||
#include <Nextion.h>
|
#include <Nextion.h>
|
||||||
#include "nex_ui.h"
|
#include "nex_ui.h"
|
||||||
|
|
||||||
extern NexEventObj fuellstand;
|
//extern NexEventObj fuellstand;
|
||||||
NexEventObj *nextlisten_list[]= {NULL};
|
//NexEventObj *nextlisten_list[]= {NULL};
|
||||||
|
|
||||||
NexEventObj fuellstand_j0;
|
NexEventObj fuellstandInd;
|
||||||
NexEventObj fuellstand_n0;
|
NexEventObj pumpeInd;
|
||||||
|
NexEventObj leerInd;
|
||||||
//---------------------Alias-Defines------------------------
|
NexEventObj feinInd;
|
||||||
|
NexEventObj grobInd;
|
||||||
#define BITBAND_PERI(a,b) ((PERIPH_BB_BASE + (a-PERIPH_BASE)*32 + (b*4)))
|
NexEventObj fehlerInd;
|
||||||
|
|
||||||
#define FEHLER *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,1))) // V3
|
|
||||||
#define LEERBLASEN *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,2))) // V4
|
//---------------------Alias-Defines------------------------
|
||||||
#define FEIN *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,13))) // V5
|
|
||||||
#define GROB *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,7))) // V6
|
#define BITBAND_PERI(a,b) ((PERIPH_BB_BASE + (a-PERIPH_BASE)*32 + (b*4)))
|
||||||
#define PUMPE *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,6))) // V7
|
|
||||||
|
#define FEHLER *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,1))) // V3
|
||||||
//----------------------------------------------------------
|
#define LEERBLASEN *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,2))) // V4
|
||||||
|
#define FEIN *((volatile unsigned long *)(BITBAND_PERI(GPIOC_ODR,13))) // V5
|
||||||
char buffer[24];
|
#define GROB *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,7))) // V6
|
||||||
|
#define PUMPE *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,6))) // V7
|
||||||
void SysTick_Handler()
|
|
||||||
{
|
//----------------------------------------------------------
|
||||||
STD_IncTick();
|
|
||||||
}
|
char buffer[24];
|
||||||
|
|
||||||
void PortConfig(void)
|
void SysTick_Handler()
|
||||||
{
|
{
|
||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren
|
STD_IncTick();
|
||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren
|
}
|
||||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren
|
|
||||||
|
void PortConfig(void)
|
||||||
GPIOC -> CRL &= 0x00000000;
|
{
|
||||||
GPIOC -> CRL = 0x22222222;
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren
|
||||||
GPIOC -> CRH = 0x22222222;
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren
|
||||||
|
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren
|
||||||
GPIOB -> CRL &= 0x00000000;
|
|
||||||
GPIOB -> CRL = 0x22222222;
|
GPIOC -> CRL &= 0x00000000;
|
||||||
|
GPIOC -> CRL = 0x22222222;
|
||||||
GPIOA -> CRL &= 0x00000000;
|
GPIOC -> CRH = 0x22222222;
|
||||||
GPIOA -> CRL = 0x22222222;
|
|
||||||
}
|
GPIOB -> CRL &= 0x00000000;
|
||||||
|
GPIOB -> CRL = 0x22222222;
|
||||||
void uart2_init(void)
|
|
||||||
{
|
GPIOA -> CRL &= 0x00000000;
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
|
GPIOA -> CRL = 0x22222222;
|
||||||
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
|
}
|
||||||
|
|
||||||
GPIOA->CRL &= 0xFFFFF0FF;
|
void uart2_init(void)
|
||||||
GPIOA->CRL |= 0xB00;
|
{
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
|
||||||
GPIOA->CRL &= 0xFFFF0FFF;
|
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
|
||||||
GPIOA->CRL |= 0x4000;
|
|
||||||
|
GPIOA->CRL &= 0xFFFFF0FF;
|
||||||
USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit
|
GPIOA->CRL |= 0xB00;
|
||||||
USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled
|
|
||||||
USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil
|
GPIOA->CRL &= 0xFFFF0FFF;
|
||||||
USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
|
GPIOA->CRL |= 0x4000;
|
||||||
USART2->CR1 |= 0x0C; // enable Receiver and Transmitter
|
|
||||||
USART2->CR1 |= 0x2000; // Set USART Enable Bit
|
USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit
|
||||||
|
USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled
|
||||||
}
|
USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil
|
||||||
|
USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
|
||||||
void uart2_putChar(char zeichen)
|
USART2->CR1 |= 0x0C; // enable Receiver and Transmitter
|
||||||
{
|
USART2->CR1 |= 0x2000; // Set USART Enable Bit
|
||||||
while(!((USART2->SR & 0x80) == 0x80));
|
|
||||||
USART2->DR = zeichen;
|
}
|
||||||
}
|
|
||||||
|
void uart2_putChar(char zeichen)
|
||||||
void uart2_putString(char* string)
|
{
|
||||||
{
|
while(!((USART2->SR & 0x80) == 0x80));
|
||||||
while(*string)
|
USART2->DR = zeichen;
|
||||||
{
|
}
|
||||||
uart2_putChar(*string++);
|
|
||||||
}
|
void uart2_putString(char* string)
|
||||||
}
|
{
|
||||||
|
while(*string)
|
||||||
char uart2_getChar(void)
|
{
|
||||||
{
|
uart2_putChar(*string++);
|
||||||
while(!(USART2->SR & 0x20));
|
}
|
||||||
return ((char) (USART2->DR & 0xFF));
|
}
|
||||||
}
|
|
||||||
|
char uart2_getChar(void)
|
||||||
int main(void)
|
{
|
||||||
{
|
while(!(USART2->SR & 0x20));
|
||||||
PortConfig();
|
return ((char) (USART2->DR & 0xFF));
|
||||||
uart2_init();
|
}
|
||||||
|
|
||||||
Nex_Init(0);
|
void configProgressBar(void)
|
||||||
Init_Nex_UI();
|
{
|
||||||
|
fuellstandInd.pid = 0;
|
||||||
uart2_putString("Dosieranlage V01 ");
|
fuellstandInd.cid = 1;
|
||||||
|
fuellstandInd.name = "fuellstand";
|
||||||
while(1)
|
fuellstandInd.pophandler = NULL;
|
||||||
{
|
fuellstandInd.pushhandler = NULL;
|
||||||
// Nex_Event_Loop(nextlisten_list); // Touch Event ?
|
|
||||||
|
fehlerInd.pid = 0;
|
||||||
NexProgressBar_setValue(&fuellstand, 100);
|
fehlerInd.cid = 1;
|
||||||
|
fehlerInd.name = "fehlerInd";
|
||||||
wait_sys_ms(1);
|
fehlerInd.pophandler = NULL;
|
||||||
|
fehlerInd.pushhandler = NULL;
|
||||||
FEHLER = 1;
|
|
||||||
LEERBLASEN = 1;
|
leerInd.pid = 0;
|
||||||
FEIN = 1;
|
leerInd.cid = 1;
|
||||||
GROB = 1;
|
leerInd.name = "leerInd";
|
||||||
PUMPE = 1;
|
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 fehler(int8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&fehlerInd, 100);
|
||||||
|
FEHLER = 1;
|
||||||
|
uart2_putString("Fehler aufgetreten!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&fehlerInd, 0);
|
||||||
|
FEHLER = 0;
|
||||||
|
uart2_putString("Fehler behoben!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void leerBlasen(int8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&leerInd, 100);
|
||||||
|
LEERBLASEN = 1;
|
||||||
|
uart2_putString("Leerblasventil geoeffnet!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&leerInd, 0);
|
||||||
|
LEERBLASEN = 0;
|
||||||
|
uart2_putString("Leerblasventil geschlossen!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fein(int8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&feinInd, 100);
|
||||||
|
FEIN = 1;
|
||||||
|
uart2_putString("Feinventil geoeffnet!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&feinInd, 0);
|
||||||
|
FEIN = 0;
|
||||||
|
uart2_putString("Feinventil geschlossen!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void grob(int8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&grobInd, 100);
|
||||||
|
GROB = 1;
|
||||||
|
uart2_putString("Grobventil geoeffnet!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&grobInd, 0);
|
||||||
|
GROB = 0;
|
||||||
|
uart2_putString("Grobventil geoeffnet!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void pumpe(int8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&pumpeInd, 100);
|
||||||
|
PUMPE = 1;
|
||||||
|
uart2_putString("Pumpe eingeschaltet!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&pumpeInd, 0);
|
||||||
|
PUMPE = 0;
|
||||||
|
uart2_putString("Pumpe ausgeschaltet!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fuellstand(int8_t value)
|
||||||
|
{
|
||||||
|
if(value >= 0 && value <= 100)
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&fuellstandInd, value);
|
||||||
|
uart2_putString("Fuellstand geaendert!\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NexProgressBar_setValue(&fuellstandInd, 0);
|
||||||
|
uart2_putString("Uengueltiger Fuellstandswert!\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
PortConfig();
|
||||||
|
uart2_init();
|
||||||
|
|
||||||
|
NexEventObj *nextlisten_list[] = {NULL};
|
||||||
|
configProgressBar();
|
||||||
|
Nex_Init(0);
|
||||||
|
Init_Nex_UI();
|
||||||
|
|
||||||
|
uart2_putString("Dosieranlage V01\r\n");
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
Nex_Event_Loop(nextlisten_list);
|
||||||
|
wait_sys_ms(20);
|
||||||
|
|
||||||
|
fuellstand(67);
|
||||||
|
fehler(1);
|
||||||
|
leerBlasen(1);
|
||||||
|
fein(1);
|
||||||
|
grob(1);
|
||||||
|
pumpe(1);
|
||||||
|
|
||||||
|
wait_sys_ms(3000);
|
||||||
|
|
||||||
|
fuellstand(10);
|
||||||
|
fehler(0);
|
||||||
|
leerBlasen(0);
|
||||||
|
fein(0);
|
||||||
|
grob(0);
|
||||||
|
pumpe(0);
|
||||||
|
|
||||||
|
wait_sys_ms(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user