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@9:8924db86f383, 2021-03-11 (annotated)
- Committer:
- jack1930
- Date:
- Thu Mar 11 11:59:29 2021 +0000
- Revision:
- 9:8924db86f383
- Parent:
- 7:99c81cc5ddbc
- Child:
- 11:64f579b3fd14
l152
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 | 9:8924db86f383 | 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 | 0:92e4253d430a | 9 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 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 | 0:92e4253d430a | 28 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| jack1930 | 0:92e4253d430a | 29 | |
| jack1930 | 0:92e4253d430a | 30 | HAL_GPIO_Init(latch_GPIO_Port, &GPIO_InitStruct); |
| jack1930 | 0:92e4253d430a | 31 | |
| jack1930 | 0:92e4253d430a | 32 | /**USART1 GPIO Configuration |
| jack1930 | 0:92e4253d430a | 33 | PA8 ------> USART1_CK |
| jack1930 | 0:92e4253d430a | 34 | PA9 ------> USART1_TX |
| jack1930 | 0:92e4253d430a | 35 | PA10 ------> USART1_RX |
| jack1930 | 0:92e4253d430a | 36 | */ |
| jack1930 | 0:92e4253d430a | 37 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; |
| jack1930 | 0:92e4253d430a | 38 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| jack1930 | 0:92e4253d430a | 39 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| jack1930 | 0:92e4253d430a | 40 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| jack1930 | 0:92e4253d430a | 41 | GPIO_InitStruct.Alternate = GPIO_AF7_USART1; |
| jack1930 | 0:92e4253d430a | 42 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| jack1930 | 0:92e4253d430a | 43 | |
| jack1930 | 0:92e4253d430a | 44 | husart1.Instance = USART1; |
| jack1930 | 0:92e4253d430a | 45 | husart1.Init.BaudRate = 115000; |
| jack1930 | 0:92e4253d430a | 46 | husart1.Init.WordLength = USART_WORDLENGTH_8B; |
| jack1930 | 0:92e4253d430a | 47 | husart1.Init.StopBits = USART_STOPBITS_1; |
| jack1930 | 0:92e4253d430a | 48 | husart1.Init.Parity = USART_PARITY_NONE; |
| jack1930 | 0:92e4253d430a | 49 | husart1.Init.Mode = USART_MODE_TX_RX; |
| jack1930 | 0:92e4253d430a | 50 | husart1.Init.CLKPolarity = USART_POLARITY_LOW; |
| jack1930 | 0:92e4253d430a | 51 | husart1.Init.CLKPhase = USART_PHASE_1EDGE; |
| jack1930 | 0:92e4253d430a | 52 | husart1.Init.CLKLastBit = USART_LASTBIT_ENABLE; |
| jack1930 | 0:92e4253d430a | 53 | if (HAL_USART_Init(&husart1) != HAL_OK) |
| jack1930 | 0:92e4253d430a | 54 | { |
| jack1930 | 0:92e4253d430a | 55 | //Error_Handler(); |
| jack1930 | 0:92e4253d430a | 56 | HAL_GPIO_WritePin(GPIOB,beep_Pin,GPIO_PIN_RESET); |
| jack1930 | 0:92e4253d430a | 57 | } |
| jack1930 | 0:92e4253d430a | 58 | }; |
| jack1930 | 0:92e4253d430a | 59 | |
| jack1930 | 0:92e4253d430a | 60 | void MFS::send(void) |
| jack1930 | 0:92e4253d430a | 61 | { |
| jack1930 | 0:92e4253d430a | 62 | HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_RESET); |
| jack1930 | 0:92e4253d430a | 63 | HAL_USART_Transmit(&husart1,&dieSegmente,1,100); |
| jack1930 | 0:92e4253d430a | 64 | HAL_USART_Transmit(&husart1,&dieAuswahl,1,100); |
| jack1930 | 0:92e4253d430a | 65 | HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_SET); |
| jack1930 | 0:92e4253d430a | 66 | } |
| jack1930 | 0:92e4253d430a | 67 | void MFS::siebensegment(uint8_t wert) |
| jack1930 | 0:92e4253d430a | 68 | { |
| jack1930 | 3:d5c27c45d24f | 69 | dieSegmente=~wert; |
| jack1930 | 0:92e4253d430a | 70 | send(); |
| jack1930 | 0:92e4253d430a | 71 | } |
| jack1930 | 0:92e4253d430a | 72 | void MFS::siebensegment(uint8_t awert,uint8_t wert) |
| jack1930 | 0:92e4253d430a | 73 | { |
| jack1930 | 3:d5c27c45d24f | 74 | dieSegmente=~wert; |
| jack1930 | 2:bb43e9b5a54d | 75 | dieAuswahl=awert; |
| jack1930 | 0:92e4253d430a | 76 | send(); |
| jack1930 | 0:92e4253d430a | 77 | } |
| jack1930 | 0:92e4253d430a | 78 | void MFS::bcd(int wert) |
| jack1930 | 0:92e4253d430a | 79 | { |
| jack1930 | 4:49654888d57b | 80 | dieSegmente=~seg7[wert]; |
| jack1930 | 0:92e4253d430a | 81 | send(); |
| jack1930 | 0:92e4253d430a | 82 | } |
| jack1930 | 0:92e4253d430a | 83 | |
| jack1930 | 0:92e4253d430a | 84 | void MFS::bcd(uint8_t awert, int wert) |
| jack1930 | 0:92e4253d430a | 85 | { |
| jack1930 | 4:49654888d57b | 86 | dieSegmente=~seg7[wert]; |
| jack1930 | 2:bb43e9b5a54d | 87 | dieAuswahl=awert; |
| jack1930 | 0:92e4253d430a | 88 | send(); |
| jack1930 | 0:92e4253d430a | 89 | } |
| jack1930 | 0:92e4253d430a | 90 | void MFS::auswahl(uint8_t wert) |
| jack1930 | 0:92e4253d430a | 91 | { |
| jack1930 | 2:bb43e9b5a54d | 92 | dieAuswahl=wert; |
| jack1930 | 0:92e4253d430a | 93 | send(); |
| jack1930 | 1:774b96b00aed | 94 | } |
| jack1930 | 1:774b96b00aed | 95 | |
| jack1930 | 1:774b96b00aed | 96 | void MFS::operator=(unsigned int wert) |
| jack1930 | 1:774b96b00aed | 97 | { |
| jack1930 | 7:99c81cc5ddbc | 98 | char hilf=0, hilf2=wert; |
| jack1930 | 7:99c81cc5ddbc | 99 | for (int i=0;i<8;i++) |
| jack1930 | 7:99c81cc5ddbc | 100 | { |
| jack1930 | 7:99c81cc5ddbc | 101 | hilf=(hilf<<1)+hilf2%2; |
| jack1930 | 7:99c81cc5ddbc | 102 | hilf2=hilf2/2; |
| jack1930 | 7:99c81cc5ddbc | 103 | } |
| jack1930 | 7:99c81cc5ddbc | 104 | dieSegmente=(~hilf)&0xFF; |
| jack1930 | 2:bb43e9b5a54d | 105 | dieAuswahl=(wert/0x100); |
| jack1930 | 1:774b96b00aed | 106 | send(); |
| jack1930 | 5:babdf868f544 | 107 | } |
| jack1930 | 5:babdf868f544 | 108 | |
| jack1930 | 5:babdf868f544 | 109 | MFS::operator int(void) |
| jack1930 | 5:babdf868f544 | 110 | { |
| jack1930 | 7:99c81cc5ddbc | 111 | char hilf=0, hilf2=~dieSegmente; |
| jack1930 | 7:99c81cc5ddbc | 112 | for (int i=0;i<8;i++) |
| jack1930 | 7:99c81cc5ddbc | 113 | { |
| jack1930 | 7:99c81cc5ddbc | 114 | hilf=(hilf<<1)+hilf2%2; |
| jack1930 | 7:99c81cc5ddbc | 115 | hilf2=hilf2/2; |
| jack1930 | 7:99c81cc5ddbc | 116 | } |
| jack1930 | 7:99c81cc5ddbc | 117 | return dieAuswahl*0x100+hilf; |
| jack1930 | 0:92e4253d430a | 118 | } |