Advertisement
Guest User

usart

a guest
Jul 11th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. /**
  2.  *  Keil project template
  3.  *
  4.  *  Before you start, select your target, on the right of the "Load" button
  5.  *
  6.  *  @author     Tilen Majerle
  7.  *  @email      tilen@majerle.eu
  8.  *  @website    http://stm32f4-discovery.com
  9.  *  @ide        Keil uVision 5
  10.  *  @conf       PLL parameters are set in "Options for Target" -> "C/C++" -> "Defines"
  11.  *  @packs      STM32F4xx Keil packs version 2.4.0 or greater required
  12.  *  @stdperiph  STM32F4xx Standard peripheral drivers version 1.5.0 or greater required
  13.  */
  14. /* Include core modules */
  15. #include "stm32f4xx.h"
  16. /* Include my libraries here */
  17. #include "defines.h"
  18. #include "tm_stm32f4_delay.h"
  19. #include "tm_stm32f4_disco.h"
  20. #include "tm_stm32f4_usart.h"
  21. #include "tm_stm32f4_stdio.h"
  22.  
  23. int main(void) {
  24.    
  25.     /* Initialize system */
  26.     SystemInit();
  27.    
  28.     /* Initialize delay */
  29.     TM_DELAY_Init();
  30.    
  31.     TM_USART_Init(USART2, TM_USART_PinsPack_1, 9600);
  32.    
  33.     while (1) {
  34.         int a,b;
  35.         a=b=10;
  36.         printf("a=");
  37.         scanf("%d", &a);
  38.         printf("b=");
  39.         scanf("%d", &b);
  40.         printf("a*b=%d", a*b);
  41.         Delayms(1000);
  42.     }
  43. }
  44.  
  45. /* Handle stdout actions */
  46. int TM_STDIO_StdoutHandler(int ch, FILE* f) {
  47.     /* Send data to USART1 */
  48.     TM_USART_Putc(USART2, (char) ch);
  49.  
  50.     /* Return ch, it means OK */
  51.     return ch;
  52.     /* If you want to return error, then you have to send EOF (-1) */
  53.     //return -1;
  54. }
  55.  
  56. /* Handle stdin actions */
  57. int TM_STDIO_StdinHandler(FILE* f) {
  58.     /* If any data at USART, return them */
  59.     /* Do your custom implementation here when string ends */
  60.     if (!TM_USART_BufferEmpty(USART2)) {
  61.         return (int)TM_USART_Getc(USART2);
  62.     }
  63.     /* End of data, string is valid */
  64.     /* You have to send -1 at the end of string */
  65.     return -1;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement