forked from KorayGocmen/Small-Useful-Verilog-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMorse-Code-with-LED.v
127 lines (113 loc) · 2.11 KB
/
Morse-Code-with-LED.v
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
`timescale 1ns / 1ns // `timescale time_unit/time_precision
module Morse_Display (SW, LEDR, KEY, CLOCK_50);
input [2:0] SW;
input CLOCK_50;
output [0:0] LEDR;
input [1:0] KEY;
wire [10:0] w;
wire a;
wire mrs_out;
lut uo (
.in({SW[0],SW[1],SW[2]}),
.out(w)
);
RateDivider u3(
.clk_in(CLOCK_50),
.clk_out(a),
.s0(0),
.s1(1)
);
hft_reg u1 (
.start(KEY[0]),
.in(w),
.out(mrs_out),
.reset(KEY[1]),
.clock(CLOCK_50),
.enable(a)
);
Morse u2 (
.clock(a),
.Clear_b(1),
.Enable(mrs_out),
.q(LEDR[0])
);
endmodule
module lut (in, out);
input [2:0] in;
output reg [10:0] out;
always @(*)
begin
case (in)
3'b000: out = 11'b00000011101;
3'b001: out = 11'b00101010111;
3'b010: out = 11'b10111010111;
3'b100: out = 11'b00001010111;
3'b011: out = 11'b00000000001;
3'b101: out = 11'b00101110101;
3'b110: out = 11'b00101110111;
3'b111: out = 11'b00001010101;
default: out = 11'b00000000000;
endcase
end
endmodule
module shft_reg (in, out, reset, clock, start, enable);
input clock;
input start;
input enable;
integer i;
input [10:0] in;
input reset;
reg [10:0] store;
output reg out;
always @(posedge clock)
begin
if (enable == 1'b1) begin
if (reset == 1'b0) begin
store <= 0;
out = 0;
end
else if (start == 1'b0)begin
out = store[0];
store = store >> 1;
end
else begin
store = in;
out = 0;
end
end
end
endmodule
module RateDivider (clk_in, clk_out, s0, s1);
input clk_in;
input s0, s1;
output reg clk_out = 1'b0;
reg [27:0] w = 28'b0;
always @(*)
begin
case ({s0,s1})
2'b00: clk_out = (w >= 1);
2'b01: clk_out = (w >= 29999999);
2'b10: clk_out = (w >= 99999999);
2'b11: clk_out = (w >= 199999999);
default: clk_out = 0;
endcase
end
always @(posedge clk_in)
begin
if (clk_out) w <= 28'b0;
else w <= w + 1'b1;
end
endmodule
module Morse (clock, Clear_b, q, Enable);
input clock;
input Clear_b;
input Enable;
output reg q;
always @(posedge clock)
begin
if (Clear_b == 1'b0)
q <= 0;
else
q <= Enable;
end
endmodule