Last active
March 3, 2021 08:05
-
-
Save MarrekNozka/6083d4f18f4cf6ba6327054db4b668c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Vzorový projekt | |
| #include "stm8s.h" | |
| #include "assert.h" | |
| #include "stdio.h" | |
| #include "milis.h" | |
| //#include "spse_stm8.h" | |
| //#include "stm8_hd44780.h" | |
| #define LED_PORT GPIOC | |
| #define LED_PIN GPIO_PIN_5 | |
| #define LED_ON (GPIO_WriteHigh(LED_PORT, LED_PIN)) | |
| #define LED_OFF (GPIO_WriteLow(LED_PORT, LED_PIN)) | |
| #define LED_REVERSE (GPIO_WriteReverse(LED_PORT, LED_PIN)) | |
| char znak; | |
| int cislo; | |
| uint32_t time = 0; | |
| void main(void){ | |
| CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // taktovat MCU na 16MHz | |
| init_milis(); // rozběhnout milis časovač | |
| UART1_DeInit(); // smaže starou konfiguraci (kdyby náhodou...) | |
| UART1_Init((uint32_t)115200, // komunikační rychlost | |
| UART1_WORDLENGTH_8D, // délka slova | |
| UART1_STOPBITS_1, // počet STOP bitů | |
| UART1_PARITY_NO, // zakážu parití bit | |
| UART1_SYNCMODE_CLOCK_DISABLE, // A-synchronní mód | |
| UART1_MODE_TXRX_ENABLE // Tx-vysílání Rx-příjem | |
| ); | |
| UART1_Cmd(DISABLE); // zakáže UART | |
| UART1_Cmd(ENABLE); // povolím UART | |
| GPIO_Init(LED_PORT, LED_PIN ,GPIO_MODE_OUT_PP_LOW_SLOW); | |
| printf("Zacatek programu...."); | |
| while (1){ | |
| znak = getchar(); | |
| putchar(znak); | |
| if (milis() - time > 333) { | |
| time = milis(); | |
| LED_REVERSE; | |
| } | |
| } | |
| } | |
| char putchar (char c) | |
| { | |
| /* Loop until the end of transmission */ | |
| while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); | |
| /* Write a character to the UART1 */ | |
| UART1_SendData8(c); | |
| return (c); | |
| } | |
| char getchar (void) | |
| { | |
| int c = 0; | |
| /* Loop until the Read data register flag is SET */ | |
| while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) { | |
| ; // čekám až přjde znak | |
| } | |
| c = UART1_ReceiveData8(); | |
| return (c); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment