-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorse_code.c
164 lines (129 loc) · 3.98 KB
/
morse_code.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
===============================================================================
Name : morse_code.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
*/
#include <board_api.h>
#include <chip.h>
#include <gpio_8xx.h>
#include <lpc_types.h>
#include <stdint.h>
#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif
#include <cr_section_macros.h>
#include "morse.h"
// TODO: insert other include files here
// TODO: insert other definitions and declarations here
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Private functions
****************************************************************************/
/**
* @brief Function display short signal(Green LED and "." on 7-segment display)
*/
void shortSignal() {
Board_LED_Toggle(2);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 10, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 11, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 12, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 13, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 15, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 16, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 17, FALSE);
}
/**
* @brief Function display long signal(Blue LED and "-" on 7-segment display)
*/
void longSignal() {
Board_LED_Toggle(2);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 10, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 11, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 12, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 13, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 15, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 16, FALSE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 17, TRUE);
}
/**
* @brief Function off display
*/
void off() {
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 10, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 11, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 12, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 13, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 15, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 16, TRUE);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 17, TRUE);
}
/**
* @brief Function delay
* @param[in] delay - delay time
*/
static void delay(uint32_t delay) {
while (delay--) {
}
}
int main(void) {
SystemCoreClockUpdate();
#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
#endif
#endif
// TODO: insert code here
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 10); //a
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 11); //b
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 12); //c
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 13); //d
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 14); //e
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 15); //f
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 16, FALSE); //g
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 17, FALSE); //h
off();
char name[] = "Rafal";
int nameInMorseCode[15];
morse_createNameInMorseCode(name, 15, nameInMorseCode);
// Force the counter to be placed into memory
volatile static int i = 0;
// Enter an infinite loop, just incrementing a counter
while (1) {
i++;
for (int i = 0; i < 15; i++) {
switch (nameInMorseCode[i]) {
case SHORT:
shortSignal();
delay(1000000);
off();
delay(1000000);
break;
case LONG:
longSignal();
delay(3000000);
off();
delay(2000000);
break;
default:
break;
}
}
delay(5000000); //end of name
}
return 0;
}