-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecieve_store_signal3.v
144 lines (115 loc) · 2.62 KB
/
recieve_store_signal3.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//module shift9(w, Clock, Q, enable);
// input w, Clock, enable;
// output reg [0:8]Q;
//
// always@(posedge Clock)
// begin
// if (enable)
// if (enable2))
// begin
// Q[8] <= w;
// Q[7] <= Q[8];
// Q[6] <= Q[7];
// Q[5] <= Q[6];
// Q[4] <= Q[5];
// Q[3] <= Q[4];
// Q[2] <= Q[3];
// Q[1] <= Q[2];
// Q[0] <= Q[1];
// end
// end
//endmodule
module recieve_store_signal3 (GPIO_0, CLOCK_50, LEDR);
// Created a 16-bit register to store the incoming data
input CLOCK_50;
reg x1, x2, x3, x4;
reg [0:8]clockcycles;
integer i;
integer j;
integer k;
integer ticks = 0;
reg [9:0]counter;
reg outClock = 1'b1;
reg attention = 1'b1;
reg bytes = 0;
inout [0:4]GPIO_0;
output [14:17]LEDR;
assign signal = GPIO_0[4];
assign GPIO_0[0] = outClock;
assign GPIO_0[1] = attention;
assign LEDR[17] = x1;
assign LEDR[16] = x2;
assign LEDR[15] = x3;
assign LEDR[14] = x4;
// shift9(signal,CLOCK_50, clockcycles, enable);
reg enable;
// reg enable2;
always@(posedge CLOCK_50)
begin
if (counter == 10'd0)
counter <= 10'd49;
else counter <= counter - 1'd1;
enable <= counter == 10'd0;
end
always@(posedge CLOCK_50)
if (enable) begin
ticks = ticks + 1;
if (ticks > 699) begin
ticks = 0;
end
if (ticks == 13) begin
attention <= 1'b0;
end
if (ticks < 21) begin
outClock <= 1'b1;
end
if (ticks >= 21) begin
if (ticks <= 673) begin
if (ticks%16 == 0) begin
bytes <= bytes + 1;
end
if (bytes%2 == 0) begin
outClock <= 1'b1;
end else begin
outClock <= ~outClock;
//4th Byte
if (ticks > 128) begin
if (ticks < 148) begin
if ((ticks - 128)%2 == 0) begin
clockcycles[8] <= signal;
clockcycles[7] <= clockcycles[8];
clockcycles[6] <= clockcycles[7];
clockcycles[5] <= clockcycles[6];
clockcycles[4] <= clockcycles[5];
clockcycles[3] <= clockcycles[4];
clockcycles[2] <= clockcycles[3];
clockcycles[1] <= clockcycles[2];
clockcycles[0] <= clockcycles[1];
end
end
end
end
end
end
if (ticks >= 676) begin
outClock <= 1'b1;
end
if (ticks > 679) begin
attention <= 1'b1;
end
if (clockcycles[4] == 0) begin
x1 = 1'b1;
x2 = 1'b0;
end else if (clockcycles[5] == 0) begin
x1 = 1'b0;
x2 = 1'b1;
end else if (clockcycles[6] == 0) begin
x3 = 1'b1;
x4 = 1'b0;
if (clockcycles[7] == 0) begin
x3 = 1'b0;
x4 = 1'b1;
end
end
end
endmodule