Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Includes */
- #include "stm32f4xx.h"
- #include "stm32f429i_discovery.h"
- #include "stm32f429i_discovery_lcd.h"
- #include<stdio.h>
- #include <stdlib.h>
- #include<string.h>
- uint8_t* morseCode[]={
- ".-", /* A */
- "-...",/* B */
- "-.-.",/* C */
- "-..", /* D */
- ".", /* E */
- "..-.",/* F */
- "--.", /* G */
- "....",/* H */
- "..", /* I */
- ".---",/* J */
- "-.-" /* K */
- };
- void myDelay(unsigned n)
- {
- volatile unsigned count=n;
- while(count--){}
- }
- void sendDash(uint8_t dotLen)
- {
- STM_EVAL_LEDOn(LED3);
- myDelay(3*dotLen*40000);
- STM_EVAL_LEDOff(LED3);
- }
- void sendDot(uint8_t dotLen)
- {
- STM_EVAL_LEDOn(LED3);
- myDelay(dotLen*40000);
- STM_EVAL_LEDOff(LED3);
- myDelay(dotLen/2*40000);
- }
- void waitDahs(dotLen)
- {
- myDelay(3*dotLen*40000);
- }
- void waitDot(dotLen)
- {
- myDelay(dotLen*40000);
- }
- void sendCharMorse(char c, uint8_t dotLen)
- {
- c=toupper(c);
- if(c<'K' || c==' ')
- {
- char *code=morseCode[c-'A'];
- }
- for(int i=0; code[i]!='\0'; i++)//..-.
- {
- if(code[i]=='-')
- {
- sendDash(dotLen);
- }
- if(code[i]=='.')
- {
- sendDot(dotLen);
- }
- if(code[i]==' ')
- {
- waitDahs(dotLen);
- }
- }
- waitDot(dotLen);
- }
- void sendCode(char *msg, uint8_t dotLen)
- {
- for(int i=0; msg[i]!='\0'; i++)
- {
- sendCharMorse(msg[i],dotLen);
- }
- }
- /**
- **===========================================================================
- **
- ** Abstract: main program
- **
- **===========================================================================
- */
- int main(void)
- {
- STM_EVAL_LEDInit(LED3);
- STM_EVAL_LEDInit(LED4);
- LCD_Init();
- LCD_LayerInit();
- LTDC_Cmd(ENABLE);
- LCD_SetLayer(LCD_FOREGROUND_LAYER);
- LCD_Clear(LCD_COLOR_WHITE);
- LCD_SetColors(LCD_COLOR_BLACK, LCD_COLOR_WHITE);
- sendCode("JH HJ",150);
- while(1)
- {
- }
- }
- uint32_t sEE_TIMEOUT_UserCallback(void)
- {
- /* TODO, implement your code here */
- while (1)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement