Jack Hansdampf / MFS_Display_HAL_401

Dependents:   MFS_ADC_F401

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MFS.cpp Source File

MFS.cpp

00001 #include "MFS.h"
00002 
00003 MFS::MFS(void)
00004     {
00005     HAL_Init();
00006     GPIO_InitTypeDef GPIO_InitStruct = {0};
00007         /* GPIO Ports Clock Enable */
00008       __HAL_RCC_GPIOC_CLK_ENABLE();
00009       __HAL_RCC_GPIOH_CLK_ENABLE();
00010       __HAL_RCC_GPIOA_CLK_ENABLE();
00011       __HAL_RCC_GPIOB_CLK_ENABLE();
00012       __HAL_RCC_USART1_CLK_ENABLE();
00013 
00014   /*Configure GPIO pin Output Level */
00015   HAL_GPIO_WritePin(GPIOB, beep_Pin|latch_Pin, GPIO_PIN_SET);
00016   
00017 /*Configure GPIO pin : beep_Pin */
00018   GPIO_InitStruct.Pin = beep_Pin;
00019   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
00020   GPIO_InitStruct.Pull = GPIO_NOPULL;
00021   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
00022   HAL_GPIO_Init(beep_GPIO_Port, &GPIO_InitStruct);
00023 
00024   /*Configure GPIO pin : latch_Pin */
00025   GPIO_InitStruct.Pin = latch_Pin;
00026   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
00027   GPIO_InitStruct.Pull = GPIO_NOPULL;
00028   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
00029   
00030   HAL_GPIO_Init(latch_GPIO_Port, &GPIO_InitStruct);  
00031  
00032      /**USART1 GPIO Configuration
00033     PA8     ------> USART1_CK
00034     PA9     ------> USART1_TX
00035     PA10     ------> USART1_RX
00036     */
00037     GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
00038     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00039     GPIO_InitStruct.Pull = GPIO_NOPULL;
00040     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
00041     GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
00042     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00043     
00044       husart1.Instance = USART1;
00045       husart1.Init.BaudRate = 115000;
00046       husart1.Init.WordLength = USART_WORDLENGTH_8B;
00047       husart1.Init.StopBits = USART_STOPBITS_1;
00048       husart1.Init.Parity = USART_PARITY_NONE;
00049       husart1.Init.Mode = USART_MODE_TX_RX;
00050       husart1.Init.CLKPolarity = USART_POLARITY_LOW;
00051       husart1.Init.CLKPhase = USART_PHASE_1EDGE;
00052       husart1.Init.CLKLastBit = USART_LASTBIT_ENABLE;
00053       if (HAL_USART_Init(&husart1) != HAL_OK)
00054       {
00055         //Error_Handler();
00056         HAL_GPIO_WritePin(GPIOB,beep_Pin,GPIO_PIN_RESET);
00057       }
00058    };
00059 
00060     void MFS::send(void)
00061     {
00062             HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_RESET);
00063             HAL_USART_Transmit(&husart1,&dieSegmente,1,100);
00064             HAL_USART_Transmit(&husart1,&dieAuswahl,1,100);
00065             HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_SET);
00066     }
00067     void MFS::siebensegment(uint8_t wert)
00068     {
00069         dieSegmente=~wert;
00070         send();
00071     }
00072     void MFS::siebensegment(uint8_t awert,uint8_t wert)
00073     {
00074         dieSegmente=~wert;
00075         dieAuswahl=awert;
00076         send();
00077     }
00078     void MFS::bcd(int wert)
00079     {
00080         dieSegmente=~seg7[wert];
00081         send();
00082     }
00083     
00084     void MFS::bcd(uint8_t awert, int wert)
00085     {
00086         dieSegmente=~seg7[wert];
00087         dieAuswahl=awert;
00088         send();
00089     }    
00090     void MFS::auswahl(uint8_t wert)
00091     {
00092         dieAuswahl=wert;
00093         send();
00094     }
00095     
00096     void MFS::operator=(unsigned int wert)
00097     {
00098         char hilf=0, hilf2=wert;
00099         for (int i=0;i<8;i++)
00100         {
00101          hilf=(hilf<<1)+hilf2%2; 
00102          hilf2=hilf2/2;  
00103         }
00104         dieSegmente=(~hilf)&0xFF;
00105         dieAuswahl=(wert/0x100);
00106         send();
00107     }
00108     
00109     MFS::operator int(void)
00110     {
00111         char hilf=0, hilf2=~dieSegmente;
00112         for (int i=0;i<8;i++)
00113         {
00114          hilf=(hilf<<1)+hilf2%2; 
00115          hilf2=hilf2/2;  
00116         }        
00117         return dieAuswahl*0x100+hilf;
00118     }