Jack Hansdampf / MFS_Display_HAL

Dependents:   MFS_ADC MFS-7_Segment-Interrupt MFS_USART_Test_HAL MFS_02-Luftschlange ... more

MFS.cpp

Committer:
jack1930
Date:
2021-02-03
Revision:
2:bb43e9b5a54d
Parent:
1:774b96b00aed
Child:
3:d5c27c45d24f

File content as of revision 2:bb43e9b5a54d:

#include "MFS.h"

MFS::MFS(void)
    {
    HAL_Init();
    GPIO_InitTypeDef GPIO_InitStruct = {0};
        /* GPIO Ports Clock Enable */
      __HAL_RCC_GPIOC_CLK_ENABLE();
      __HAL_RCC_GPIOH_CLK_ENABLE();
      __HAL_RCC_GPIOA_CLK_ENABLE();
      __HAL_RCC_GPIOB_CLK_ENABLE();
      __HAL_RCC_USART1_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, beep_Pin|latch_Pin, GPIO_PIN_SET);
  
/*Configure GPIO pin : beep_Pin */
  GPIO_InitStruct.Pin = beep_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(beep_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : latch_Pin */
  GPIO_InitStruct.Pin = latch_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  
  HAL_GPIO_Init(latch_GPIO_Port, &GPIO_InitStruct);  
 
     /**USART1 GPIO Configuration
    PA8     ------> USART1_CK
    PA9     ------> USART1_TX
    PA10     ------> USART1_RX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    
      husart1.Instance = USART1;
      husart1.Init.BaudRate = 115000;
      husart1.Init.WordLength = USART_WORDLENGTH_8B;
      husart1.Init.StopBits = USART_STOPBITS_1;
      husart1.Init.Parity = USART_PARITY_NONE;
      husart1.Init.Mode = USART_MODE_TX_RX;
      husart1.Init.CLKPolarity = USART_POLARITY_LOW;
      husart1.Init.CLKPhase = USART_PHASE_1EDGE;
      husart1.Init.CLKLastBit = USART_LASTBIT_ENABLE;
      if (HAL_USART_Init(&husart1) != HAL_OK)
      {
        //Error_Handler();
        HAL_GPIO_WritePin(GPIOB,beep_Pin,GPIO_PIN_RESET);
      }
   };

    void MFS::send(void)
    {
            HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_RESET);
            HAL_USART_Transmit(&husart1,&dieSegmente,1,100);
            HAL_USART_Transmit(&husart1,&dieAuswahl,1,100);
            HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_SET);
    }
    void MFS::siebensegment(uint8_t wert)
    {
        dieSegmente=wert;
        send();
    }
    void MFS::siebensegment(uint8_t awert,uint8_t wert)
    {
        dieSegmente=wert;
        dieAuswahl=awert;
        send();
    }
    void MFS::bcd(int wert)
    {
        dieSegmente=seg7[wert];
        send();
    }
    
    void MFS::bcd(uint8_t awert, int wert)
    {
        dieSegmente=seg7[wert];
        dieAuswahl=awert;
        send();
    }    
    void MFS::auswahl(uint8_t wert)
    {
        dieAuswahl=wert;
        send();
    }
    
    void MFS::operator=(unsigned int wert)
    {
        dieSegmente=wert&0xFF;
        dieAuswahl=(wert/0x100);
        send();
    }