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
MFS.cpp@11:64f579b3fd14, 2021-03-12 (annotated)
- Committer:
- jack1930
- Date:
- Fri Mar 12 10:03:30 2021 +0000
- Revision:
- 11:64f579b3fd14
- Parent:
- 9:8924db86f383
L152+F411+F103
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jack1930 | 0:92e4253d430a | 1 | #include "MFS.h" |
| jack1930 | 0:92e4253d430a | 2 | |
| jack1930 | 0:92e4253d430a | 3 | MFS::MFS(void) |
| jack1930 | 11:64f579b3fd14 | 4 | { |
| jack1930 | 0:92e4253d430a | 5 | HAL_Init(); |
| jack1930 | 0:92e4253d430a | 6 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| jack1930 | 0:92e4253d430a | 7 | /* GPIO Ports Clock Enable */ |
| jack1930 | 0:92e4253d430a | 8 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| jack1930 | 11:64f579b3fd14 | 9 | //__HAL_RCC_GPIOH_CLK_ENABLE(); //F103 |
| jack1930 | 0:92e4253d430a | 10 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| jack1930 | 0:92e4253d430a | 11 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| jack1930 | 0:92e4253d430a | 12 | __HAL_RCC_USART1_CLK_ENABLE(); |
| jack1930 | 0:92e4253d430a | 13 | |
| jack1930 | 0:92e4253d430a | 14 | /*Configure GPIO pin Output Level */ |
| jack1930 | 0:92e4253d430a | 15 | HAL_GPIO_WritePin(GPIOB, beep_Pin|latch_Pin, GPIO_PIN_SET); |
| jack1930 | 0:92e4253d430a | 16 | |
| jack1930 | 0:92e4253d430a | 17 | /*Configure GPIO pin : beep_Pin */ |
| jack1930 | 0:92e4253d430a | 18 | GPIO_InitStruct.Pin = beep_Pin; |
| jack1930 | 0:92e4253d430a | 19 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| jack1930 | 0:92e4253d430a | 20 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| jack1930 | 0:92e4253d430a | 21 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| jack1930 | 0:92e4253d430a | 22 | HAL_GPIO_Init(beep_GPIO_Port, &GPIO_InitStruct); |
| jack1930 | 0:92e4253d430a | 23 | |
| jack1930 | 0:92e4253d430a | 24 | /*Configure GPIO pin : latch_Pin */ |
| jack1930 | 0:92e4253d430a | 25 | GPIO_InitStruct.Pin = latch_Pin; |
| jack1930 | 0:92e4253d430a | 26 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| jack1930 | 0:92e4253d430a | 27 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| jack1930 | 11:64f579b3fd14 | 28 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| jack1930 | 11:64f579b3fd14 | 29 | |
| jack1930 | 0:92e4253d430a | 30 | |
| jack1930 | 0:92e4253d430a | 31 | HAL_GPIO_Init(latch_GPIO_Port, &GPIO_InitStruct); |
| jack1930 | 0:92e4253d430a | 32 | |
| jack1930 | 0:92e4253d430a | 33 | /**USART1 GPIO Configuration |
| jack1930 | 0:92e4253d430a | 34 | PA8 ------> USART1_CK |
| jack1930 | 0:92e4253d430a | 35 | PA9 ------> USART1_TX |
| jack1930 | 0:92e4253d430a | 36 | PA10 ------> USART1_RX |
| jack1930 | 0:92e4253d430a | 37 | */ |
| jack1930 | 0:92e4253d430a | 38 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; |
| jack1930 | 0:92e4253d430a | 39 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| jack1930 | 0:92e4253d430a | 40 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| jack1930 | 11:64f579b3fd14 | 41 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //F103 |
| jack1930 | 11:64f579b3fd14 | 42 | |
| jack1930 | 11:64f579b3fd14 | 43 | #ifndef __STM32F1xx_HAL_H |
| jack1930 | 11:64f579b3fd14 | 44 | GPIO_InitStruct.Alternate = GPIO_AF7_USART1; //F103 |
| jack1930 | 11:64f579b3fd14 | 45 | #endif |
| jack1930 | 0:92e4253d430a | 46 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| jack1930 | 0:92e4253d430a | 47 | |
| jack1930 | 0:92e4253d430a | 48 | husart1.Instance = USART1; |
| jack1930 | 0:92e4253d430a | 49 | husart1.Init.BaudRate = 115000; |
| jack1930 | 0:92e4253d430a | 50 | husart1.Init.WordLength = USART_WORDLENGTH_8B; |
| jack1930 | 0:92e4253d430a | 51 | husart1.Init.StopBits = USART_STOPBITS_1; |
| jack1930 | 0:92e4253d430a | 52 | husart1.Init.Parity = USART_PARITY_NONE; |
| jack1930 | 0:92e4253d430a | 53 | husart1.Init.Mode = USART_MODE_TX_RX; |
| jack1930 | 0:92e4253d430a | 54 | husart1.Init.CLKPolarity = USART_POLARITY_LOW; |
| jack1930 | 0:92e4253d430a | 55 | husart1.Init.CLKPhase = USART_PHASE_1EDGE; |
| jack1930 | 0:92e4253d430a | 56 | husart1.Init.CLKLastBit = USART_LASTBIT_ENABLE; |
| jack1930 | 0:92e4253d430a | 57 | if (HAL_USART_Init(&husart1) != HAL_OK) |
| jack1930 | 0:92e4253d430a | 58 | { |
| jack1930 | 0:92e4253d430a | 59 | //Error_Handler(); |
| jack1930 | 0:92e4253d430a | 60 | HAL_GPIO_WritePin(GPIOB,beep_Pin,GPIO_PIN_RESET); |
| jack1930 | 0:92e4253d430a | 61 | } |
| jack1930 | 0:92e4253d430a | 62 | }; |
| jack1930 | 0:92e4253d430a | 63 | |
| jack1930 | 0:92e4253d430a | 64 | void MFS::send(void) |
| jack1930 | 0:92e4253d430a | 65 | { |
| jack1930 | 0:92e4253d430a | 66 | HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_RESET); |
| jack1930 | 0:92e4253d430a | 67 | HAL_USART_Transmit(&husart1,&dieSegmente,1,100); |
| jack1930 | 0:92e4253d430a | 68 | HAL_USART_Transmit(&husart1,&dieAuswahl,1,100); |
| jack1930 | 0:92e4253d430a | 69 | HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_SET); |
| jack1930 | 0:92e4253d430a | 70 | } |
| jack1930 | 0:92e4253d430a | 71 | void MFS::siebensegment(uint8_t wert) |
| jack1930 | 0:92e4253d430a | 72 | { |
| jack1930 | 3:d5c27c45d24f | 73 | dieSegmente=~wert; |
| jack1930 | 0:92e4253d430a | 74 | send(); |
| jack1930 | 0:92e4253d430a | 75 | } |
| jack1930 | 0:92e4253d430a | 76 | void MFS::siebensegment(uint8_t awert,uint8_t wert) |
| jack1930 | 0:92e4253d430a | 77 | { |
| jack1930 | 3:d5c27c45d24f | 78 | dieSegmente=~wert; |
| jack1930 | 2:bb43e9b5a54d | 79 | dieAuswahl=awert; |
| jack1930 | 0:92e4253d430a | 80 | send(); |
| jack1930 | 0:92e4253d430a | 81 | } |
| jack1930 | 0:92e4253d430a | 82 | void MFS::bcd(int wert) |
| jack1930 | 0:92e4253d430a | 83 | { |
| jack1930 | 4:49654888d57b | 84 | dieSegmente=~seg7[wert]; |
| jack1930 | 0:92e4253d430a | 85 | send(); |
| jack1930 | 0:92e4253d430a | 86 | } |
| jack1930 | 0:92e4253d430a | 87 | |
| jack1930 | 0:92e4253d430a | 88 | void MFS::bcd(uint8_t awert, int wert) |
| jack1930 | 0:92e4253d430a | 89 | { |
| jack1930 | 4:49654888d57b | 90 | dieSegmente=~seg7[wert]; |
| jack1930 | 2:bb43e9b5a54d | 91 | dieAuswahl=awert; |
| jack1930 | 0:92e4253d430a | 92 | send(); |
| jack1930 | 0:92e4253d430a | 93 | } |
| jack1930 | 0:92e4253d430a | 94 | void MFS::auswahl(uint8_t wert) |
| jack1930 | 0:92e4253d430a | 95 | { |
| jack1930 | 2:bb43e9b5a54d | 96 | dieAuswahl=wert; |
| jack1930 | 0:92e4253d430a | 97 | send(); |
| jack1930 | 1:774b96b00aed | 98 | } |
| jack1930 | 1:774b96b00aed | 99 | |
| jack1930 | 1:774b96b00aed | 100 | void MFS::operator=(unsigned int wert) |
| jack1930 | 1:774b96b00aed | 101 | { |
| jack1930 | 7:99c81cc5ddbc | 102 | char hilf=0, hilf2=wert; |
| jack1930 | 7:99c81cc5ddbc | 103 | for (int i=0;i<8;i++) |
| jack1930 | 7:99c81cc5ddbc | 104 | { |
| jack1930 | 7:99c81cc5ddbc | 105 | hilf=(hilf<<1)+hilf2%2; |
| jack1930 | 7:99c81cc5ddbc | 106 | hilf2=hilf2/2; |
| jack1930 | 7:99c81cc5ddbc | 107 | } |
| jack1930 | 7:99c81cc5ddbc | 108 | dieSegmente=(~hilf)&0xFF; |
| jack1930 | 2:bb43e9b5a54d | 109 | dieAuswahl=(wert/0x100); |
| jack1930 | 1:774b96b00aed | 110 | send(); |
| jack1930 | 5:babdf868f544 | 111 | } |
| jack1930 | 5:babdf868f544 | 112 | |
| jack1930 | 5:babdf868f544 | 113 | MFS::operator int(void) |
| jack1930 | 5:babdf868f544 | 114 | { |
| jack1930 | 7:99c81cc5ddbc | 115 | char hilf=0, hilf2=~dieSegmente; |
| jack1930 | 7:99c81cc5ddbc | 116 | for (int i=0;i<8;i++) |
| jack1930 | 7:99c81cc5ddbc | 117 | { |
| jack1930 | 7:99c81cc5ddbc | 118 | hilf=(hilf<<1)+hilf2%2; |
| jack1930 | 7:99c81cc5ddbc | 119 | hilf2=hilf2/2; |
| jack1930 | 7:99c81cc5ddbc | 120 | } |
| jack1930 | 7:99c81cc5ddbc | 121 | return dieAuswahl*0x100+hilf; |
| jack1930 | 0:92e4253d430a | 122 | } |