-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop.v
More file actions
108 lines (93 loc) · 2.23 KB
/
top.v
File metadata and controls
108 lines (93 loc) · 2.23 KB
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
module top (
input wire clk, //100 MHZ
// SCCB
output wire sio_c, // clock
inout wire sio_d, // data
// Camera outputs
input wire vsync,
input wire href,
input wire pclk,
input wire [7:0] data, // D0-D7
// Control signals
output wire xclk, // Camera clk 25 MHZ
output wire reset_cam, // Camera reset (active low)
output wire pwdn, // Power down control (active low)
//output wire [7:0] read_data,
//led
output wire [3:0] led,
input wire [3:0] btn
);
assign pwdn = 1'b0;
reg clk_div_xclk = 0;
reg clk25MHZ = 0;
wire rst = btn[0];
assign reset_cam = rst;
always @(posedge clk) begin
clk_div_xclk <= clk_div_xclk + 1;
if (clk_div_xclk == 1) begin
clk_div_xclk <= 0;
clk25MHZ <= ~clk25MHZ;
end
end
assign xclk = clk25MHZ;
localparam OV7670 = 8'h43;
wire rw_enable;
wire rw;
wire finished;
wire [7:0] data1;
wire [7:0] data2;
wire [2:0] i2ch_state;
wire [3:0] i2c_state;
wire i2c_wire;
reg rw_mode = 0;
i2c_handler I2C_HANDLER (
.clk(clk),
.rst(rst),
.rw_enable(rw_enable),
.rw(rw),
.finished(finished),
.rw_mode(rw_mode),
.data1(data1),
.data2(data2),
.state_out(i2ch_state)
);
wire [7:0] read_data;
reg [7:0] read_data_stored;
i2c_unit I2C (
.clk(clk),
.rst(rst),
.rw_enable(rw_enable),
.rw(rw),
.device(OV7670),
.finished(finished),
.data1(data1),
.data2(data2),
.read_data(read_data),
.i2c_wire_out(i2c_wire),
.i2c_wire_in(sio_d),
.scl(sio_c),
.state_out(i2c_state)
);
assign sio_d = i2c_wire ? 1'bz : 1'b0;
reg [24:0] counter = 0;
reg [3:0] led_reg = 0;
reg handler_display = 0;
always @(posedge clk) begin
if(rst)
rw_mode <= 0;
if(read_data != 8'b00000000 && finished)
read_data_stored <= read_data;
if (btn[1])
led_reg <= i2c_state;
else if (btn[2]) begin
rw_mode <= 1;
end
else if (btn[3]) begin
led_reg <= read_data_stored;
end
else begin
led_reg <= i2ch_state;
end
end
assign led = led_reg;
endmodule