Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stddef.h>
- #include "stm32f10x.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_gpio.h"
- #include "stm32f10x_usart.h"
- int getchar(void);
- int putchar(int c);
- void putString(char *string);
- int znak;
- int main(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- USART_InitTypeDef USART_InitStruct;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
- | RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO, ENABLE);
- //1-inicijalizacija PBO za LED
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Write(GPIOB, 0xFFFF);
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- //2-Inicijalizacija USART1
- //2a - Inicijalizacija Tx pina (GPIOA, GPIO_Pin_9)
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- //2b - Inicijalizacija Tx pina (GPIOA, GPIO_Pin_10)
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- //2c - komunikacijski parametri USART1
- USART_StructInit(&USART_InitStruct);
- USART_InitStruct.USART_BaudRate = 115200;
- USART_InitStruct.USART_WordLength = USART_WordLength_8b;
- USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
- USART_InitStruct.USART_Parity = USART_Parity_No;
- USART_InitStruct.USART_StopBits = USART_StopBits_1;
- USART_InitStruct.USART_HardwareFlowControl =
- USART_HardwareFlowControl_None;
- USART_Init(USART1, &USART_InitStruct);
- USART_Cmd(USART1, ENABLE);
- while(1){
- znak = getchar();
- if(znak==-1)continue;
- putchar(znak);
- switch(znak){
- case 'p' :
- case 'P' : GPIO_WriteBit(GPIOB, GPIO_Pin_0, RESET);
- break;
- case 'g' :
- case 'G' : GPIO_WriteBit(GPIOB, GPIO_Pin_0, SET);
- break;
- default : break;
- }
- }
- }
- int getchar(void){
- if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET){
- return USART1->DR & 0xff;
- }else{
- return -1;
- }
- }
- int putchar(int c){
- while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
- USART1->DR = c & 0xff;
- return 0;
- }
- void putString(char *string){
- }
Advertisement
RAW Paste Data
Copied
Advertisement