-
Notifications
You must be signed in to change notification settings - Fork 0
/
coded.c
188 lines (160 loc) · 3.36 KB
/
coded.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <pic14\pic16f876.h>
#include <stdint.h> //Needed for uint16_t
#define DIT 2000
#define DA 6000
#define GAP 6000
#define SP 14000
// Configurations
static __code uint16_t __at (0x2007) config = _HS_OSC & _PWRTE_ON & _BODEN_OFF & _WDT_OFF & _LVP_OFF;
unsigned int delayCount = 0;
void gap()
{
// port off
PORTB = 0x00;
CCPR1L = 0b00000000 ;
while ( delayCount < GAP ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
}
void space()
{
// port off
PORTB = 0x00;
CCPR1L = 0b00000000 ;
while ( delayCount < SP ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
}
void dit()
{
// port on
PORTB = 0x01;
CCPR1L = 0b01001101 ;
while ( delayCount < DIT ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
// port off
PORTB = 0x00;
CCPR1L = 0b00000000 ;
// delay while off
while ( delayCount < DIT ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
}
void da()
{
// port on
PORTB = 0x01;
CCPR1L = 0b01001101 ;
while ( delayCount < DA ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
// port off
PORTB = 0x00;
CCPR1L = 0b00000000 ;
// delay while off
while ( delayCount < DA ) // Delay Loop
{
delayCount++;
}
delayCount = 0; // reset counter
}
/* hello world in morse is
H ....
E .
L .-..
L .-..
O ---
W .--
O ---
R .-.
L .-..
D -..
*/
// Main body
void main() {
// Initializing ports
PORTB = 0;
PORTC = 0;
// Set RB0 as output
TRISB = 0x00;
TRISC = 0x00;
/*
* PWM registers configuration
* Fosc = 8000000 Hz
* Fpwm = 801.28 Hz (Requested : 800 Hz)
* Duty Cycle = 50 %
* Resolution is 10 bits
* Prescaler is 16
* Ensure that your PWM pin is configured as digital output
* see more details on http:https://www.micro-examples.com/
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b10011011 ;
T2CON = 0b00000111 ;
CCPR1L = 0b01001101 ;
CCP1CON = 0b00111100 ;
PORTB = 0x01;
PORTC = 0x03;
// keep repeating
while(1) {
space();
dit();
dit();
dit();
dit();
gap(); //H
dit();
gap(); //E
dit();
da();
dit();
dit();
gap(); //L
dit();
da();
dit();
dit();
gap(); //L
da();
da();
da();
gap(); //O
space();
dit();
da();
da();
gap(); //W
da();
da();
da();
gap(); //O
dit();
da();
dit();
gap(); //R
dit();
da();
dit();
dit();
gap(); //L
da();
dit();
dit();
gap(); //D
space();
space();
space();
}
}