Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MFS_ADC MFS-7_Segment-Interrupt MFS_USART_Test_HAL MFS_02-Luftschlange ... more
Revision 0:92e4253d430a, committed 2021-02-03
- Comitter:
- jack1930
- Date:
- Wed Feb 03 16:22:30 2021 +0000
- Child:
- 1:774b96b00aed
- Commit message:
- Version 1.0
Changed in this revision
| MFS.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MFS.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MFS.cpp Wed Feb 03 16:22:30 2021 +0000
@@ -0,0 +1,94 @@
+#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<<4;
+ send();
+ }
+ void MFS::bcd(int wert)
+ {
+ dieSegmente=seg7[wert];
+ send();
+ }
+
+ void MFS::bcd(uint8_t awert, int wert)
+ {
+ dieSegmente=seg7[wert];
+ dieAuswahl=awert<<4;
+ send();
+ }
+ void MFS::auswahl(uint8_t wert)
+ {
+ dieAuswahl=wert<<4;
+ send();
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MFS.h Wed Feb 03 16:22:30 2021 +0000
@@ -0,0 +1,29 @@
+#include "stm32l1xx_hal.h"
+#include "mbed.h"
+
+#define USART_TX_Pin GPIO_PIN_2
+#define USART_TX_GPIO_Port GPIOA
+#define USART_RX_Pin GPIO_PIN_3
+#define USART_RX_GPIO_Port GPIOA
+#define beep_Pin GPIO_PIN_3
+#define beep_GPIO_Port GPIOB
+#define latch_Pin GPIO_PIN_5
+#define latch_GPIO_Port GPIOB
+
+class MFS
+{
+ private:
+ uint8_t dieAuswahl=0;
+ uint8_t dieSegmente=0xFF;
+ char seg7[10]={0x03,0x9F,0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F, 0x01, 0x09};
+ USART_HandleTypeDef husart1;
+ public:
+ MFS(void);
+ void siebensegment(uint8_t wert);
+ void siebensegment(uint8_t awert,uint8_t wert);
+ void bcd(int wert);
+ void bcd(uint8_t awert, int wert);
+ void auswahl(uint8_t wert);
+ private:
+ void send(void);
+};
\ No newline at end of file