Skip to content

Commit 5dea7d0

Browse files
committed
arrange: the structure of the project
1 parent a402e09 commit 5dea7d0

18 files changed

+592
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 103 计算机 现代硬件电路源码
2+
3+
```
4+
.
5+
├── README.md # 说明文档
6+
├── core # 内核部分电路
7+
│ ├── core_top.v # 内核部分顶层模块
8+
│ ├── arith_unit.v # 运算器 АУ
9+
│ ├── arith_ctrl.v # 局部程序发送器 МПД
10+
│ ├── operator.v # 操作器 БО
11+
│ ├── start_reg.v # 启动寄存器 ПР
12+
│ ├── select_reg.v # 选择寄存器 СР
13+
│ ├── pulse_unit.v # 脉冲分配器 РИ
14+
│ ├── memory.v # 存贮器 ЗУ & МП
15+
│ └── io_unit.v # 输入输出电子部件 ЭУВВ
16+
├── shell # 外壳部分电路
17+
│ ├── shell_top.v # 外壳部分顶层模块
18+
│ ├── driver_74lv165.v # 74LV165 串行输入驱动模块
19+
│ ├── driver_74lv595.v # 74LV595 串行输出驱动模块
20+
│ ├── button_pulse.v # 按钮-脉冲信号
21+
│ └── switch_level.v # 开关-电平信号
22+
├── include # 涉及的外部模块
23+
└── docs # 文档
24+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

memory.v renamed to core/memory.v

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

shell/button_pulse.v

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module button_pulse (
2+
input clk,
3+
input resetn,
4+
5+
input btn, // button
6+
output pulse // pulse
7+
);
8+
9+
reg btn_r;
10+
reg pulse_r;
11+
12+
always @(posedge clk) begin
13+
if (~resetn) begin
14+
btn_r <= 1'b0;
15+
pulse_r <= 1'b0;
16+
end else begin
17+
btn_r <= btn;
18+
pulse_r <= !btn && btn_r;
19+
end
20+
end
21+
22+
assign pulse = pulse_r;
23+
24+
endmodule

shell/driver_74lv165.v

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
module driver_74lv165 (
2+
input clk,
3+
input resetn,
4+
5+
output [15:0] data_0,
6+
output [15:0] data_1,
7+
output [15:0] data_2,
8+
output [15:0] data_3,
9+
output [15:0] data_4,
10+
11+
output SH_LDn, // high for shift, low for load
12+
output RCLK, // clock
13+
14+
input QH_0, // serial input
15+
input QH_1, // serial input
16+
input QH_2, // serial input
17+
input QH_3, // serial input
18+
input QH_4 // serial input
19+
);
20+
21+
reg serial_clk;
22+
reg shift_clk;
23+
reg shiftn_load;
24+
25+
reg [ 4:0] cnt;
26+
27+
reg [15:0] data_0_r;
28+
reg [15:0] data_1_r;
29+
reg [15:0] data_2_r;
30+
reg [15:0] data_3_r;
31+
reg [15:0] data_4_r;
32+
33+
reg [15:0] data_0_s;
34+
reg [15:0] data_1_s;
35+
reg [15:0] data_2_s;
36+
reg [15:0] data_3_s;
37+
reg [15:0] data_4_s;
38+
39+
always @(posedge clk) begin
40+
if (~resetn) begin
41+
serial_clk <= 1'b0;
42+
end else begin
43+
serial_clk <= ~serial_clk;
44+
end
45+
end
46+
47+
always @(posedge clk) begin
48+
if (~resetn) begin
49+
cnt <= 5'd0;
50+
end else if (!serial_clk) begin
51+
if (cnt == 5'd16) begin
52+
cnt <= 5'd0;
53+
end else begin
54+
cnt <= cnt + 5'd1;
55+
end
56+
end
57+
end
58+
59+
always @(posedge clk) begin
60+
if (~resetn) begin
61+
shift_clk <= 1'b0;
62+
end else if (serial_clk) begin
63+
shift_clk <= 1'b0;
64+
end else begin
65+
if (cnt == 5'd16) begin
66+
shift_clk <= 1'b0;
67+
end else begin
68+
shift_clk <= 1'b1;
69+
end
70+
end
71+
end
72+
73+
always @(posedge clk) begin
74+
if (~resetn) begin
75+
shiftn_load <= 1'b0;
76+
end else if (serial_clk) begin
77+
shiftn_load <= 1'b0;
78+
end else begin
79+
if (cnt == 5'd16) begin
80+
shiftn_load <= 1'b1;
81+
end else begin
82+
shiftn_load <= 1'b0;
83+
end
84+
end
85+
end
86+
87+
always @(posedge clk) begin
88+
if (~resetn) begin
89+
data_0_r <= 16'd0;
90+
data_1_r <= 16'd0;
91+
data_2_r <= 16'd0;
92+
data_3_r <= 16'd0;
93+
data_4_r <= 16'd0;
94+
end else if (!serial_clk && cnt == 5'd16) begin
95+
data_0_r <= data_0_s;
96+
data_1_r <= data_1_s;
97+
data_2_r <= data_2_s;
98+
data_3_r <= data_3_s;
99+
data_4_r <= data_4_s;
100+
end
101+
end
102+
103+
always @(posedge clk) begin
104+
if (~resetn) begin
105+
data_0_s <= 16'd0;
106+
data_1_s <= 16'd0;
107+
data_2_s <= 16'd0;
108+
data_3_s <= 16'd0;
109+
data_4_s <= 16'd0;
110+
end else if (!serial_clk && cnt != 5'd16) begin
111+
data_0_s <= {data_0_s[14:0], QH_0};
112+
data_1_s <= {data_1_s[14:0], QH_1};
113+
data_2_s <= {data_2_s[14:0], QH_2};
114+
data_3_s <= {data_3_s[14:0], QH_3};
115+
data_4_s <= {data_4_s[14:0], QH_4};
116+
end
117+
end
118+
119+
assign SH_LDn = !shiftn_load;
120+
assign RCLK = shift_clk;
121+
assign data_0 = data_0_r;
122+
assign data_1 = data_1_r;
123+
assign data_2 = data_2_r;
124+
assign data_3 = data_3_r;
125+
assign data_4 = data_4_r;
126+
127+
endmodule

shell/driver_74lv595.v

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
module driver_74lv595 (
2+
input clk,
3+
input resetn,
4+
5+
input [15:0] data_0,
6+
input [15:0] data_1,
7+
input [15:0] data_2,
8+
input [15:0] data_3,
9+
10+
output RCLK, // storage register clock
11+
output SRCLK, // shift register clock
12+
13+
output SER_0, // serial output
14+
output SER_1, // serial output
15+
output SER_2, // serial output
16+
output SER_3 // serial output
17+
);
18+
19+
reg serial_clk;
20+
reg shift_clk;
21+
reg store_clk;
22+
23+
reg [ 4:0] cnt;
24+
25+
reg [15:0] data_0_r;
26+
reg [15:0] data_1_r;
27+
reg [15:0] data_2_r;
28+
reg [15:0] data_3_r;
29+
30+
always @(posedge clk) begin
31+
if (~resetn) begin
32+
serial_clk <= 1'b0;
33+
end else begin
34+
serial_clk <= ~serial_clk;
35+
end
36+
end
37+
38+
always @(posedge clk) begin
39+
if (~resetn) begin
40+
cnt <= 5'd0;
41+
end else if (!serial_clk) begin
42+
if (cnt == 5'd16) begin
43+
cnt <= 5'd0;
44+
end else begin
45+
cnt <= cnt + 5'd1;
46+
end
47+
end
48+
end
49+
50+
always @(posedge clk) begin
51+
if (~resetn) begin
52+
shift_clk <= 1'b0;
53+
end else if (serial_clk) begin
54+
shift_clk <= 1'b0;
55+
end else begin
56+
if (cnt == 5'd16) begin
57+
shift_clk <= 1'b0;
58+
end else begin
59+
shift_clk <= 1'b1;
60+
end
61+
end
62+
end
63+
64+
always @(posedge clk) begin
65+
if (~resetn) begin
66+
store_clk <= 1'b0;
67+
end else if (serial_clk) begin
68+
store_clk <= 1'b0;
69+
end else begin
70+
if (cnt == 5'd16) begin
71+
store_clk <= 1'b1;
72+
end else begin
73+
store_clk <= 1'b0;
74+
end
75+
end
76+
end
77+
78+
always @(posedge clk) begin
79+
if (~resetn) begin
80+
data_0_r <= 16'd0;
81+
data_1_r <= 16'd0;
82+
data_2_r <= 16'd0;
83+
data_3_r <= 16'd0;
84+
end else if (serial_clk) begin
85+
if (cnt == 5'd0) begin
86+
data_0_r <= data_0;
87+
data_1_r <= data_1;
88+
data_2_r <= data_2;
89+
data_3_r <= data_3;
90+
end else begin
91+
data_0_r <= {data_0_r[14:0], 1'b0};
92+
data_1_r <= {data_1_r[14:0], 1'b0};
93+
data_2_r <= {data_2_r[14:0], 1'b0};
94+
data_3_r <= {data_3_r[14:0], 1'b0};
95+
end
96+
end
97+
end
98+
99+
assign RCLK = store_clk;
100+
assign SRCLK = shift_clk;
101+
assign SER_0 = data_0_r[15];
102+
assign SER_1 = data_1_r[15];
103+
assign SER_2 = data_2_r[15];
104+
assign SER_3 = data_3_r[15];
105+
106+
endmodule

0 commit comments

Comments
 (0)