当前位置:首页 > 基于FPGA的温度监控系统 - 图文
山东科技大学学士学位论文 附录
dq_out <= data_w[cnt_bit]; end else if(cnt < 'd65) begin link <= 0; end else begin cnt <= 0; cnt_bit <= cnt_bit + 1; if(cnt_bit == 'd7) begin cnt_bit <= 0; state <= WAIT_800MS; end end end
WAIT_800MS: begin cnt <= cnt + 1; if(cnt == 'd800000) begin cnt <= 0; state <= RESET2; end end
RESET2: begin cnt <= cnt + 1; if(cnt < 'd500) begin link <= 1; dq_out <= 0; end else if(cnt < 'd1000) begin link <= 0; end else begin cnt <= 0;
state <= WRITE_CC2;
41
//等待800ms //第二次复位 山东科技大学学士学位论文 附录
data_w <= 8'hcc; cnt_bit <= 0; end end
WRITE_CC2: begin //吸入跳过rom命令 cnt <= cnt + 1; if(cnt < 'd5) begin link <= 1; dq_out <= 0; end else if(cnt < 'd60) begin dq_out <= data_w[cnt_bit]; end else if(cnt < 'd65) begin link <= 0; end else begin cnt <= 0; cnt_bit <= cnt_bit + 1; if(cnt_bit == 'd7) begin state <= WRITE_BE; cnt_bit <= 0; data_w <= 8'hbe; end end end
WRITE_BE: begin cnt <= cnt + 1; if(cnt < 'd5) begin link <= 1; dq_out <= 0; end
else if(cnt < 'd60)
42
//写入读数据命令 山东科技大学学士学位论文 附录
begin dq_out <= data_w[cnt_bit]; end else if(cnt < 'd65) begin link <= 0; end else begin cnt <= 0; cnt_bit <= cnt_bit + 1; if(cnt_bit == 'd7) begin state <= READ1; cnt_bit <= 0; end end end
READ1: begin cnt <= cnt + 1; if(cnt < 'd3) begin link <= 1; dq_out <= 0; end else if(cnt == 'd3) link <= 0; else if(cnt == 'd12) data_r[cnt_bit] <= dq_in; else if(cnt > 'd65) begin cnt <= 0; cnt_bit <= cnt_bit + 1; if(cnt_bit == 'd7) begin cnt_bit <= 0; temp[7:0] <= data_r; state <= READ2;
end
43
//读入第一个字节 山东科技大学学士学位论文 附录
end end READ2:
begin //读入第二个字节 cnt <= cnt + 1; if(cnt < 'd3) begin link <= 1; dq_out <= 0; end else if(cnt == 'd3) link <= 0; else if(cnt == 'd12) data_r[cnt_bit] <= dq_in; else if(cnt > 'd65) begin cnt <= 0; cnt_bit <= cnt_bit + 1; if(cnt_bit == 'd7) begin cnt_bit <= 0; temp[15:8] <= data_r; state <= RESET1; end end end endcase end
endmodule 分频模块: module clk_gen( input rst, input clk, output reg clk_1k, output reg clk_1m ); reg[14:0] cnt_1k;
44
共分享92篇相关文档