完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
/****************************************Copyright (c)**************************************************
** **---------------------------------------File Info----------------------------------------------------- ** File name: Uart ** Last modified Date: 2015-8-22 ** Last Version: 1.0 ** Descriptions: Uart **------------------------------------------------------------------------------------------------------ ** Created by: hn ** Created date: 2015-8-22 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ ** *********************************************************************************************************/ module UartRecv ( //input sys_clk , sys_rst_n , uart_rxd , //output uart_txd , LED ); //input ports input sys_clk ; //system clock; input sys_rst_n ; //system reset, low is active; input uart_rxd ; //uart rxd input ; //output ports output reg [WIDTH-1:0] LED ; output uart_txd ; //reg define reg [WIDTH-1:0] buff ; reg [WIDTH-1:0] data_out ; reg [SIZE-1:0] counter1 ; reg [23:0] delay_count ; reg [WIDTH-1:0] txd ; reg [0:0] g; reg uart_txd ; reg uart_rxd_dly1 ; //uart rxd input ; reg uart_rxd_dly2 ; //uart rxd input ; reg uart_rxd_dly3 ; //uart rxd input ; reg uart_rxd_dly4 ; //uart rxd input ; reg rxd_negdge_sig_dly1 ; //add by wuhzh reg rxd_negdge_sig_dly2 ; reg [SIZE-1:0] counter ; //wire define wire rxd_negdge_sig ; //parameter define parameter WIDTH = 8; parameter SIZE = 16; parameter DELAY_CNT = 10000000 ; /******************************************************************************************************* ** Main Program ** ********************************************************************************************************/ always @(posedge sys_clk or negedge sys_rst_n) begin if (sys_rst_n ==1'b0) begin uart_rxd_dly1 <= 1'b0; uart_rxd_dly2 <= 1'b0; uart_rxd_dly3 <= 1'b0; uart_rxd_dly4 <= 1'b0; end else begin uart_rxd_dly1 <= uart_rxd ; uart_rxd_dly2 <= uart_rxd_dly1; uart_rxd_dly3 <= uart_rxd_dly2; uart_rxd_dly4 <= uart_rxd_dly3; end end assign rxd_negdge_sig = (~uart_rxd_dly3) & uart_rxd_dly4; always @(posedge sys_clk or negedge sys_rst_n) begin if (sys_rst_n ==1'b0)begin rxd_negdge_sig_dly1 <= 1'b0; rxd_negdge_sig_dly2 <= 1'b0; end else begin rxd_negdge_sig_dly1 <= rxd_negdge_sig ; rxd_negdge_sig_dly2 <= rxd_negdge_sig_dly1; end end always @(posedge sys_clk or negedge sys_rst_n) begin if ( sys_rst_n == 1'b0 ) counter <= 16'b0; else if ( rxd_negdge_sig_dly2 == 1'b1 && counter > 57200 ) counter <= 16'b0; else if ( counter <= 57200 ) counter <= counter + 16' else ; end always @(posedge sys_clk or negedge sys_rst_n) begin if ( sys_rst_n == 1'b0 ) buff <= 8'b0; else begin case ( counter ) 7800 : buff[0] <= uart_rxd_dly4 ; 13000 : buff[1] <= uart_rxd_dly4 ; 18200 : buff[2] <= uart_rxd_dly4 ; 23400 : buff[3] <= uart_rxd_dly4 ; 28600 : buff[4] <= uart_rxd_dly4 ; 33800 : buff[5] <= uart_rxd_dly4 ; 39000 : buff[6] <= uart_rxd_dly4 ; 44200 : buff[7] <= uart_rxd_dly4 ; default : buff<=buff ; endcase end end always @(posedge sys_clk or negedge sys_rst_n) begin if (sys_rst_n ==1'b0) LED <= 8'b0; else LED <= buff; end always @(posedge sys_clk or negedge sys_rst_n ) begin if ( sys_rst_n ==1'b0 ) counter1 <= 16'b0; else if (counter1 <= 57200) counter1 <= counter1 + 16'b1; else counter1 <= 16'b0; end always @(*) begin if ((counter1 > 0) && (counter1 <= 5200 )) txd = 1'b0 ; else if ((counter1 > 5200) && (counter1 <= 10400)) txd = buff[0] ; else if ((counter1 > 10400) && (counter1 <= 15600)) txd = buff[1] ; else if ((counter1 > 15600) && (counter1 <= 20800)) txd = buff[2] ; else if ((counter1 > 20800) && (counter1 <= 26000)) txd = buff[3] ; else if ((counter1 > 26000) && (counter1 <= 31200)) txd = buff[4] ; else if ((counter1 > 31200) && (counter1 <= 36400)) txd = buff[5] ; else if ((counter1 > 36400) && (counter1 <= 41600)) txd = buff[6] ; else if ((counter1 > 41600) && (counter1 <= 46800)) txd = buff[7] ; else if ((counter1 > 46800) && (counter1 <= 52000)) txd = 1'b1 ; else if ((counter1 > 52000) && (counter1 <= 57200)) txd = 1'b1 ; else txd = 1'b1 ; end always @(posedge sys_clk or negedge sys_rst_n) begin if (sys_rst_n ==1'b0) uart_txd <= 1'b1; else uart_txd <= txd; end endmodule //end of RTL code |
|
相关推荐
1个回答
|
|
谢谢分享 先看看
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1851 浏览 1 评论
1590 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1810 浏览 0 评论
968 浏览 0 评论
2586 浏览 0 评论
1596 浏览 41 评论
5868 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 03:34 , Processed in 0.481925 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号