adding nextion logic

This commit is contained in:
Fabian Schieder 2026-01-29 07:40:46 +00:00
parent 6094d5af4b
commit bb37f9c256

223
main.c
View File

@ -1,111 +1,112 @@
#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;
//---------------------Alias-Defines------------------------ NexEventObj *nextlisten_list[]= {NULL};
#define BITBAND_PERI(a,b) ((PERIPH_BB_BASE + (a-PERIPH_BASE)*32 + (b*4))) NexEventObj fuellstand_j0;
NexEventObj fuellstand_n0;
#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
void SysTick_Handler() #define GROB *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,7))) // V6
{ #define PUMPE *((volatile unsigned long *)(BITBAND_PERI(GPIOB_ODR,6))) // V7
STD_IncTick();
} //----------------------------------------------------------
void PortConfig(void) char buffer[24];
{
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren void SysTick_Handler()
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren {
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren STD_IncTick();
}
GPIOC -> CRL &= 0x00000000;
GPIOC -> CRL = 0x22222222; void PortConfig(void)
GPIOC -> CRH = 0x22222222; {
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN; //Takt für Port C aktivieren
GPIOB -> CRL &= 0x00000000; RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN; //Takt für Port B aktivieren
GPIOB -> CRL = 0x22222222; RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; //Takt für Port A aktivieren
GPIOA -> CRL &= 0x00000000; GPIOC -> CRL &= 0x00000000;
GPIOA -> CRL = 0x22222222; GPIOC -> CRL = 0x22222222;
} GPIOC -> CRH = 0x22222222;
void uart2_init(void) GPIOB -> CRL &= 0x00000000;
{ GPIOB -> CRL = 0x22222222;
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung GPIOA -> CRL &= 0x00000000;
GPIOA -> CRL = 0x22222222;
GPIOA->CRL &= 0xFFFFF0FF; }
GPIOA->CRL |= 0xB00;
void uart2_init(void)
GPIOA->CRL &= 0xFFFF0FFF; {
GPIOA->CRL |= 0x4000; RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit
USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled GPIOA->CRL &= 0xFFFFF0FF;
USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil GPIOA->CRL |= 0xB00;
USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
USART2->CR1 |= 0x0C; // enable Receiver and Transmitter GPIOA->CRL &= 0xFFFF0FFF;
USART2->CR1 |= 0x2000; // Set USART Enable Bit GPIOA->CRL |= 0x4000;
} USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit
USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled
void uart2_putChar(char zeichen) USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil
{ USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz)
while(!((USART2->SR & 0x80) == 0x80)); USART2->CR1 |= 0x0C; // enable Receiver and Transmitter
USART2->DR = zeichen; USART2->CR1 |= 0x2000; // Set USART Enable Bit
}
}
void uart2_putString(char* string)
{ void uart2_putChar(char zeichen)
while(*string) {
{ while(!((USART2->SR & 0x80) == 0x80));
uart2_putChar(*string++); USART2->DR = zeichen;
} }
}
void uart2_putString(char* string)
char uart2_getChar(void) {
{ while(*string)
while(!(USART2->SR & 0x20)); {
return ((char) (USART2->DR & 0xFF)); uart2_putChar(*string++);
} }
}
int main(void)
{ char uart2_getChar(void)
PortConfig(); {
uart2_init(); while(!(USART2->SR & 0x20));
return ((char) (USART2->DR & 0xFF));
Nex_Init(0); }
Init_Nex_UI();
int main(void)
uart2_putString("Dosieranlage V01 "); {
PortConfig();
while(1) uart2_init();
{
Nex_Event_Loop(nextlisten_list); // Touch Event ? Nex_Init(0);
wait_sys_ms(1); Init_Nex_UI();
FEHLER = 1; uart2_putString("Dosieranlage V01 ");
LEERBLASEN = 1;
FEIN = 1; while(1)
GROB = 1; {
PUMPE = 1; // Nex_Event_Loop(nextlisten_list); // Touch Event ?
Nex_Event_Loop(nextlisten_list); NexProgressBar_setValue(&fuellstand, 100);
wait_sys_ms(1);
wait_sys_ms(1);
FEHLER = 0;
LEERBLASEN = 0; FEHLER = 1;
FEIN = 0; LEERBLASEN = 1;
GROB = 0; FEIN = 1;
PUMPE = 0; GROB = 1;
} PUMPE = 1;
} }
}