完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这个例子是想从rx-1采集到串行数据,通过data0-data7发送出去,数据采集那块工作正常,可是发送(标红)那块怎么都不行,功能是采集的到的数据送入rxdb这个寄存器,当有lock信号输出锁存,当有下一个lock信号时,再输出下一个数据。求大神帮看看。
module uart_para(clk,rst,rx_1,indicate,data0,data1,data2,data3,data4,data5,data6,data7,select,lock); input clk; input rst; input select;// 片选信号,为1选中此cpld,为0则所有输出管脚为高阻态。 input lock;// 锁存信号,为1时才可发送信号。 input rx_1; output data0; output data1; output data2; output data3; output data4; output data5; output data6; output data7; output indicate; wire bps_start_1; wire clk_bps_1; wire[7:0]rx_data_1; wire rx_int1; speed_select_1 speed_rx_1( .clk(clk), .rst(rst), .bps_start1(bps_start_1), .rx_clk_bps1(clk_bps_1) ); uart_rx_1 my_uart_rx_1( .clk(clk), .rst(rst), .rx_1(rx_1), .rx_data_1(rx_data_1), .rx_int1(rx_int1), .clk_bps1(clk_bps_1), .bps_start1(bps_start_1) ); transmit my_transmit( .clk(clk), .rst(rst), .rx_data_1(rx_data_1), .rx_int1(rx_int1), .data0(data0), .data1(data1), .data2(data2), .data3(data3), .data4(data4), .data5(data5), .data6(data6), .data7(data7), .indicate(indicate), .select(select), .lock(lock) ); endmodule ///////////////////////////////////////////////采集数据。 module uart_rx_1(clk,rst,rx_1,rx_data_1,rx_int1,clk_bps1,bps_start1); input clk; input rst; input rx_1; input clk_bps1; output reg bps_start1; output[7:0]rx_data_1; output reg rx_int1; //reg rx_1_0,rx_1_1,rx_1_2,rx_1_3; wire neg_rx1; /******** always@(posedge clk or negedge rst) if(!rst)begin rx_1_0 <= 1'b0; rx_1_1 <= 1'b0; rx_1_2 <= 1'b0; rx_1_3 <= 1'b0; end else begin rx_1_0 <= rx_1; rx_1_1 <= rx_1_0; rx_1_2 <= rx_1_1; rx_1_3 <= rx_1_2; end assign neg_rx1=rx_1_3&~rx_1_2&~rx_1_1&~rx_1_0; ***//// assign neg_rx1=~rx_1; reg[3:0] num_1; always@(posedge clk or negedge rst) if(!rst) bps_start1 <= 1'b0; else if (!bps_start1 && neg_rx1) bps_start1 <= 1'b1; else if ((num_1==4'd9)&& clk_bps1) bps_start1 <=1'b0; reg[7:0] rx_temp_data_1; always@(posedge clk or negedge rst) if(!rst)begin rx_temp_data_1<=8'd0; num_1<=4'd0; rx_int1<=1'b0; end else if(bps_start1) begin if(clk_bps1) begin if(num_1<4'd9) begin num_1<=num_1+1'b1; rx_int1<=1'b0; end else begin num_1<=4'd0; rx_int1<=1'b1; end case(num_1) 4'd1: rx_temp_data_1[0]<=rx_1; 4'd2: rx_temp_data_1[1]<=rx_1; 4'd3: rx_temp_data_1[2]<=rx_1; 4'd4: rx_temp_data_1[3]<=rx_1; 4'd5: rx_temp_data_1[4]<=rx_1; 4'd6: rx_temp_data_1[5]<=rx_1; 4'd7: rx_temp_data_1[6]<=rx_1; 4'd8: rx_temp_data_1[7]<=rx_1; default:; endcase end else rx_int1<=1'b0; end else rx_int1<=1'b0; assign rx_data_1=rx_temp_data_1; endmodule //------------------------------------------------------BAUD RATE DESIGN port1 module speed_select_1(clk,rst,bps_start1,rx_clk_bps1); input clk; input rst; input bps_start1; output reg rx_clk_bps1; /*********************baud rate account // main clock=50MHZ parameter bps9600 = 5207, bps19200 = 2603, bps38400 = 1301, bps57600 = 867, bps115200 = 433, parameter bps9600_2 = 2603, bps19200_2 = 1301, bps38400-2 = 650, bps57600_2 = 433, bps115200_2 = 216, ***************************************/ parameter bps_para = 5207; parameter bps_para_2 = 2603; reg[12:0] cnt1; always@(posedge clk or negedge rst) if (!rst) cnt1<=13'd0; else if ((cnt1==bps_para)||!bps_start1) cnt1 <= 13'd0; else cnt1 <= cnt1 + 1'b1; always@(posedge clk or negedge rst) if (!rst) rx_clk_bps1 <= 1'b0; else if (cnt1==bps_para_2) rx_clk_bps1 <= 1'b1; else rx_clk_bps1 <= 1'b0; endmodule //////////////////////////////////////////// module transmit(clk,rst,rx_data_1,rx_int data0,data1,data2,data3,data4,data5,data6,data7,indicate,select,lock); input clk; input rst; input select; input lock; input[7:0] rx_data_1; input rx_int1; output reg data0; output reg data1; output reg data2; output reg data3; output reg data4; output reg data5; output reg data6; output reg data7; output reg indicate; reg[13:0] data_temp; reg[1:0] wr_pt,rd_pt; reg[13:0] rxdb[3:0]; wire log; reg singal; reg tip; always@(posedge clk or negedge rst) if (!rst) begin rxdb[0]<=14'd0; rxdb[1]<=14'd0; rxdb[2]<=14'd0; rxdb[3]<=14'd0; wr_pt<=4'd0; end else if(rx_int1) begin wr_pt<=wr_pt+1'b1; rxdb[wr_pt]<=((1*256)+rx_data_1); singal<=1; end else singal<=0; always@(negedge rst or posedge lock) if (!rst) begin rd_pt<=4'b0; end else begin if((rd_pt!=wr_pt)&&(singal)) begin data_temp<=rxdb[rd_pt]; rd_pt<=rd_pt+1'b1; end end always@( posedge clk) if (select) begin data0<=data_temp[0]; data1<=data_temp[1]; data2<=data_temp[2]; data3<=data_temp[3]; data4<=data_temp[4]; data5<=data_temp[5]; data6<=data_temp[6]; data7<=data_temp[7]; indicate<=1'b1; end else begin data0<=1'bz; data1<=1'bz; data2<=1'bz; data3<=1'bz; data4<=1'bz; data5<=1'bz; data6<=1'bz; data7<=1'bz; indicate<=1'bz; tip<=0; end endmodule |
|
相关推荐
|
|
1586 浏览 1 评论
1351 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1563 浏览 0 评论
930 浏览 0 评论
2361 浏览 0 评论
1468 浏览 35 评论
5681 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 16:13 , Processed in 0.586106 second(s), Total 65, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号