Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /* Includes */
  2. #include "stm32f4xx.h"
  3. #include "stm32f429i_discovery.h"
  4. #include "stm32f429i_discovery_lcd.h"
  5. #include<stdio.h>
  6. #include <stdlib.h>
  7. #include<string.h>
  8.  
  9. uint8_t* morseCode[]={
  10. ".-", /* A */
  11. "-...",/* B */
  12. "-.-.",/* C */
  13. "-..", /* D */
  14. ".", /* E */
  15. "..-.",/* F */
  16. "--.", /* G */
  17. "....",/* H */
  18. "..", /* I */
  19. ".---",/* J */
  20. "-.-" /* K */
  21. };
  22.  
  23.  
  24. void myDelay(unsigned n)
  25. {
  26. volatile unsigned count=n;
  27. while(count--){}
  28. }
  29.  
  30. void sendDash(uint8_t dotLen)
  31. {
  32. STM_EVAL_LEDOn(LED3);
  33. myDelay(3*dotLen*40000);
  34. STM_EVAL_LEDOff(LED3);
  35. }
  36.  
  37. void sendDot(uint8_t dotLen)
  38. {
  39. STM_EVAL_LEDOn(LED3);
  40. myDelay(dotLen*40000);
  41. STM_EVAL_LEDOff(LED3);
  42. myDelay(dotLen/2*40000);
  43. }
  44.  
  45. void waitDahs(dotLen)
  46. {
  47. myDelay(3*dotLen*40000);
  48. }
  49.  
  50. void waitDot(dotLen)
  51. {
  52. myDelay(dotLen*40000);
  53. }
  54.  
  55. void sendCharMorse(char c, uint8_t dotLen)
  56. {
  57. c=toupper(c);
  58. if(c<'K' || c==' ')
  59. {
  60. char *code=morseCode[c-'A'];
  61. }
  62. for(int i=0; code[i]!='\0'; i++)//..-.
  63. {
  64. if(code[i]=='-')
  65. {
  66. sendDash(dotLen);
  67. }
  68. if(code[i]=='.')
  69. {
  70. sendDot(dotLen);
  71. }
  72. if(code[i]==' ')
  73. {
  74. waitDahs(dotLen);
  75. }
  76. }
  77. waitDot(dotLen);
  78. }
  79.  
  80. void sendCode(char *msg, uint8_t dotLen)
  81. {
  82. for(int i=0; msg[i]!='\0'; i++)
  83. {
  84. sendCharMorse(msg[i],dotLen);
  85. }
  86. }
  87.  
  88.  
  89.  
  90. /**
  91. **===========================================================================
  92. **
  93. ** Abstract: main program
  94. **
  95. **===========================================================================
  96. */
  97. int main(void)
  98. {
  99. STM_EVAL_LEDInit(LED3);
  100. STM_EVAL_LEDInit(LED4);
  101.  
  102. LCD_Init();
  103. LCD_LayerInit();
  104. LTDC_Cmd(ENABLE);
  105. LCD_SetLayer(LCD_FOREGROUND_LAYER);
  106. LCD_Clear(LCD_COLOR_WHITE);
  107. LCD_SetColors(LCD_COLOR_BLACK, LCD_COLOR_WHITE);
  108.  
  109. sendCode("JH HJ",150);
  110.  
  111. while(1)
  112. {
  113. }
  114. }
  115.  
  116.  
  117. uint32_t sEE_TIMEOUT_UserCallback(void)
  118. {
  119. /* TODO, implement your code here */
  120. while (1)
  121. {
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement