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
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(); //F103 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 00031 HAL_GPIO_Init(latch_GPIO_Port, &GPIO_InitStruct); 00032 00033 /**USART1 GPIO Configuration 00034 PA8 ------> USART1_CK 00035 PA9 ------> USART1_TX 00036 PA10 ------> USART1_RX 00037 */ 00038 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; 00039 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00040 GPIO_InitStruct.Pull = GPIO_NOPULL; 00041 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //F103 00042 00043 #ifndef __STM32F1xx_HAL_H 00044 GPIO_InitStruct.Alternate = GPIO_AF7_USART1; //F103 00045 #endif 00046 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00047 00048 husart1.Instance = USART1; 00049 husart1.Init.BaudRate = 115000; 00050 husart1.Init.WordLength = USART_WORDLENGTH_8B; 00051 husart1.Init.StopBits = USART_STOPBITS_1; 00052 husart1.Init.Parity = USART_PARITY_NONE; 00053 husart1.Init.Mode = USART_MODE_TX_RX; 00054 husart1.Init.CLKPolarity = USART_POLARITY_LOW; 00055 husart1.Init.CLKPhase = USART_PHASE_1EDGE; 00056 husart1.Init.CLKLastBit = USART_LASTBIT_ENABLE; 00057 if (HAL_USART_Init(&husart1) != HAL_OK) 00058 { 00059 //Error_Handler(); 00060 HAL_GPIO_WritePin(GPIOB,beep_Pin,GPIO_PIN_RESET); 00061 } 00062 }; 00063 00064 void MFS::send(void) 00065 { 00066 HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_RESET); 00067 HAL_USART_Transmit(&husart1,&dieSegmente,1,100); 00068 HAL_USART_Transmit(&husart1,&dieAuswahl,1,100); 00069 HAL_GPIO_WritePin(GPIOB, latch_Pin, GPIO_PIN_SET); 00070 } 00071 void MFS::siebensegment(uint8_t wert) 00072 { 00073 dieSegmente=~wert; 00074 send(); 00075 } 00076 void MFS::siebensegment(uint8_t awert,uint8_t wert) 00077 { 00078 dieSegmente=~wert; 00079 dieAuswahl=awert; 00080 send(); 00081 } 00082 void MFS::bcd(int wert) 00083 { 00084 dieSegmente=~seg7[wert]; 00085 send(); 00086 } 00087 00088 void MFS::bcd(uint8_t awert, int wert) 00089 { 00090 dieSegmente=~seg7[wert]; 00091 dieAuswahl=awert; 00092 send(); 00093 } 00094 void MFS::auswahl(uint8_t wert) 00095 { 00096 dieAuswahl=wert; 00097 send(); 00098 } 00099 00100 void MFS::operator=(unsigned int wert) 00101 { 00102 char hilf=0, hilf2=wert; 00103 for (int i=0;i<8;i++) 00104 { 00105 hilf=(hilf<<1)+hilf2%2; 00106 hilf2=hilf2/2; 00107 } 00108 dieSegmente=(~hilf)&0xFF; 00109 dieAuswahl=(wert/0x100); 00110 send(); 00111 } 00112 00113 MFS::operator int(void) 00114 { 00115 char hilf=0, hilf2=~dieSegmente; 00116 for (int i=0;i<8;i++) 00117 { 00118 hilf=(hilf<<1)+hilf2%2; 00119 hilf2=hilf2/2; 00120 } 00121 return dieAuswahl*0x100+hilf; 00122 }
Generated on Sat Jul 23 2022 13:43:19 by
1.7.2