|
楼主 |
发表于 2014-1-4 22:54:35
|
显示全部楼层
本帖最后由 oldbeginner 于 2014-1-4 23:01 编辑
oc8051有几个版本,先看ver1
**************************************
module oc8051_acc (clk, rst, bit_in, data_in, data2_in, wr, wr_bit, wad2, wr_addr,
data_out, p);
input clk, rst, wr, wr_bit, wad2, bit_in;
input [7:0] wr_addr, data_in, data2_in;
output p;
output [7:0] data_out;
reg [7:0] data_out;
assign p = ^data_out;
always @(posedge clk or posedge rst)
begin
if (rst)
data_out <= #1 `OC8051_RST_ACC;
else if (wad2)
data_out <= #1 data2_in;
else
case ({wr, wr_bit})
2'b10: begin
if (wr_addr==`OC8051_SFR_ACC)
data_out <= #1 data_in;
end
2'b11: begin
if (wr_addr[7:3]==`OC8051_SFR_B_ACC)
data_out[wr_addr[2:0]] <= #1 bit_in;
end
endcase
end
endmodule
*****************************************
再看ver1.13
module oc8051_acc (clk, rst,
bit_in, data_in, data2_in,
data_out,
wr, wr_bit, wr_addr,
p, wr_sfr);
input clk, rst, wr, wr_bit, bit_in;
input [1:0] wr_sfr;
input [7:0] wr_addr, data_in, data2_in;
output p;
output [7:0] data_out;
reg [7:0] data_out;
reg [7:0] acc;
wire wr_acc, wr2_acc, wr_bit_acc;
assign p = ^acc;
assign wr_acc = (wr_sfr==`OC8051_WRS_ACC1) | (wr & !wr_bit & (wr_addr==`OC8051_SFR_ACC));
assign wr2_acc = (wr_sfr==`OC8051_WRS_ACC2);
assign wr_bit_acc = (wr & wr_bit & (wr_addr[7:3]==`OC8051_SFR_B_ACC));
always @(wr_sfr or data2_in or wr2_acc or wr_acc or wr_bit_acc or wr_addr[2:0] or data_in or bit_in or data_out)
begin
if (wr2_acc)
acc = data2_in;
else if (wr_acc)
acc = data_in;
else if (wr_bit_acc)
case (wr_addr[2:0]) /* synopsys full_case parallel_case */
3'b000: acc = {data_out[7:1], bit_in};
3'b001: acc = {data_out[7:2], bit_in, data_out[0]};
3'b010: acc = {data_out[7:3], bit_in, data_out[1:0]};
3'b011: acc = {data_out[7:4], bit_in, data_out[2:0]};
3'b100: acc = {data_out[7:5], bit_in, data_out[3:0]};
3'b101: acc = {data_out[7:6], bit_in, data_out[4:0]};
3'b110: acc = {data_out[7], bit_in, data_out[5:0]};
3'b111: acc = {bit_in, data_out[6:0]};
endcase
else
acc = data_out;
end
always @(posedge clk or posedge rst)
begin
if (rst)
data_out <= #1 `OC8051_RST_ACC;
else
data_out <= #1 acc;
end
`ifdef OC8051_SIMULATION
always @(data_out)
if (data_out===8'hxx) begin
$display("time ",$time, " faulire: invalid write to ACC (oc8051_acc)");
#22
$finish;
end
`endif
endmodule
*****************************************
ver1.13功能变复杂了,代码也复杂了。
还是用ver1版本完成第一遍理解再说。
复习一下verilog格式
module 模块名1(输入输出端口2)
input 输入3
output 输出4
reg 定义寄存器5
assign 赋值6
always@触发条件7
begin
核心功能8
end
endmodule |
|