gestione ciclo
This commit is contained in:
@@ -31,11 +31,36 @@
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
typedef enum{
|
||||
omchiuso,
|
||||
omapertura1,
|
||||
omapertura2,
|
||||
omapertura3,
|
||||
omapertura4,
|
||||
omapertura5,
|
||||
omapertura6,
|
||||
omstopapertura,
|
||||
omaperto,
|
||||
omchiusura1,
|
||||
omchiusura2,
|
||||
omchiusura3,
|
||||
omchiusura4,
|
||||
omchiusura5,
|
||||
omchiusura6,
|
||||
omstopchiusura,
|
||||
}omCiclo_st;
|
||||
typedef enum{
|
||||
bzoff,
|
||||
bzmoving,
|
||||
}stBuz_st;
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define P1START 0x01
|
||||
#define P1STOP 0x02
|
||||
#define P2START 0x04
|
||||
#define P2STOP 0x08
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
@@ -63,6 +88,12 @@ extern uint16_t ch7 ;
|
||||
extern uint16_t ch8 ;
|
||||
|
||||
uint8_t pulsanti=0;
|
||||
volatile uint8_t rtP1=0;
|
||||
volatile uint8_t rtP2=0;
|
||||
|
||||
uint8_t stPulsanti=0;
|
||||
omCiclo_st stCiclo=omchiuso;
|
||||
volatile stBuz_st stBuz=bzoff;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -88,26 +119,115 @@ void HAL_SYSTICK_Callback(void){
|
||||
|
||||
if (++c10ms >= 10) { // 10 ms
|
||||
c10ms = 0;
|
||||
if(rtP1)rtP1--;
|
||||
if(rtP2)rtP2--;
|
||||
|
||||
//**** legge i tasti********************************************************************************
|
||||
inidx++;
|
||||
inidx&=0x03;
|
||||
if(HAL_GPIO_ReadPin(P1_GPIO_Port, P1_Pin)==GPIO_PIN_SET)inbuf[inidx]|=INP1;else inbuf[inidx]&=(~INP1);
|
||||
if(HAL_GPIO_ReadPin(P2_GPIO_Port, P2_Pin)==GPIO_PIN_SET)inbuf[inidx]|=INP2;else inbuf[inidx]&=(~INP2);
|
||||
if(HAL_GPIO_ReadPin(P1_GPIO_Port, P1_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INP1;else inbuf[inidx]&=(~INP1);
|
||||
if(HAL_GPIO_ReadPin(P2_GPIO_Port, P2_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INP2;else inbuf[inidx]&=(~INP2);
|
||||
pulsanti|=(inbuf[0]&inbuf[1]&inbuf[2]&inbuf[3]);
|
||||
pulsanti&=(inbuf[0]|inbuf[1]|inbuf[2]|inbuf[3]);
|
||||
//**** legge adc ***********************************************************************************
|
||||
readAdc();
|
||||
if (++c100ms >= 10) { // 10 ms
|
||||
|
||||
c100ms = 0; //flag_10ms = 1; // set a flag; do real work in main loop
|
||||
//**** gestione buzzer *****************************************************************************
|
||||
if(stBuz==bzmoving){
|
||||
if(c1s>=5)HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_RESET);else HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_SET);
|
||||
}else{//bzoff
|
||||
HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
//**************************************************************************************************
|
||||
if (++c1s >= 10) { // 10 ms
|
||||
c1s = 0;
|
||||
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
|
||||
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void managePulsanti(void){
|
||||
if(pulsanti&INP1){
|
||||
if(rtP1==0)stPulsanti|=P1START;
|
||||
}else{
|
||||
if(stPulsanti&P1START)stPulsanti&=(~P1START);
|
||||
else if(rtP1<=190){
|
||||
stPulsanti|=P1STOP;
|
||||
}
|
||||
rtP1=200;
|
||||
}
|
||||
if(pulsanti&INP2){
|
||||
if(rtP2==0)stPulsanti|=P2START;
|
||||
}else{
|
||||
if(stPulsanti&P2START)stPulsanti&=(~P2START);
|
||||
else if(rtP2<=190)stPulsanti|=P2STOP;
|
||||
rtP2=200;
|
||||
}
|
||||
}
|
||||
|
||||
void manageCiclo(void){
|
||||
switch(stCiclo){
|
||||
case omchiuso:
|
||||
if(stPulsanti&P1START){
|
||||
stBuz=bzmoving;
|
||||
stCiclo=omapertura1;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura1:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura2:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura3:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura4:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura5:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura6:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omstopapertura:
|
||||
stBuz=bzoff;
|
||||
stCiclo=omchiuso;
|
||||
stPulsanti&=(~P1STOP);
|
||||
break;
|
||||
case omaperto:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura1:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura2:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura3:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura4:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura5:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura6:
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omstopchiusura:
|
||||
stBuz=bzoff;
|
||||
stCiclo=omaperto;
|
||||
stPulsanti&=(~P1STOP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -156,7 +276,7 @@ int main(void)
|
||||
StopMot(timMot4,FWMot4);
|
||||
StopMot(timMot4,BWMot4);
|
||||
//CDC_Transmit_FS((uint8_t*)"Start\r\n", 7);
|
||||
while (CDC_Transmit_FS((uint8_t*)"Start\r\n", 7) == USBD_BUSY);
|
||||
//while (CDC_Transmit_FS((uint8_t*)"Start\r\n", 7) == USBD_BUSY);
|
||||
if (EE_Init() != EE_OK){
|
||||
for(;;);//errore eeprom
|
||||
}
|
||||
@@ -167,6 +287,8 @@ int main(void)
|
||||
while (1){
|
||||
manageCDC();
|
||||
manageAdc();
|
||||
managePulsanti();
|
||||
manageCiclo();
|
||||
// while (CDC_Available()) {
|
||||
// int c = CDC_ReadByte();
|
||||
//if (c < 0) break;
|
||||
@@ -209,7 +331,7 @@ void SystemClock_Config(void)
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
||||
Reference in New Issue
Block a user