• 欢迎来到 - 我就爱电子网 - http://www.592dz.com !
您的位置:> 我就爱电子网电子文章EDA/PLD好用的Verilog串口UART程序 -- 正文
正文

好用的Verilog串口UART程序

[10-21 14:24:02]   来源:http://www.592dz.com  EDA/PLD   阅读:9367

 

概要:input reset ;input txclk ;input ld_tx_data ;input [7:0] tx_data ;input tx_enable ;output tx_out ;output tx_empty ;input rxclk ;input uld_rx_data ;output [7:0] rx_data ;input rx_enable ;input rx_in ;output rx_empty ;// Internal Variables reg [7:0] tx_reg ;reg tx_empty ;reg tx_over_run ;reg [3:0] tx_cnt ;reg tx_out ;reg [7:

好用的Verilog串口UART程序,http://www.592dz.com

==========================================================================
//-----------------------------------------------------
// Design Name : uart
// File Name   : uart.v
// Function    : Simple UART
// Coder       : Deepak Kumar Tala
//-----------------------------------------------------
module uart (
reset          ,
txclk          ,
ld_tx_data     ,
tx_data        ,
tx_enable      ,
tx_out         ,
tx_empty       ,
rxclk          ,
uld_rx_data    ,
rx_data        ,
rx_enable      ,
rx_in          ,
rx_empty
);
// Port declarations
input        reset          ;
input        txclk          ;
input        ld_tx_data     ;
input [7:0] tx_data        ;
input        tx_enable      ;
output       tx_out         ;
output       tx_empty       ;
input        rxclk          ;
input        uld_rx_data    ;
output [7:0] rx_data        ;
input        rx_enable      ;
input        rx_in          ;
output       rx_empty       ;

// Internal Variables
reg [7:0]    tx_reg         ;
reg          tx_empty       ;
reg          tx_over_run    ;
reg [3:0]    tx_cnt         ;
reg          tx_out         ;
reg [7:0]    rx_reg         ;
reg [7:0]    rx_data        ;
reg [3:0]    rx_sample_cnt ;
reg [3:0]    rx_cnt         ;
reg          rx_frame_err   ;
reg          rx_over_run    ;
reg          rx_empty       ;
reg          rx_d1          ;
reg          rx_d2          ;
reg          rx_busy        ;

// UART RX Logic
always @ (posedge rxclk or posedge reset)
if (reset) begin
rx_reg        <= 0;
rx_data       <= 0;
rx_sample_cnt <= 0;
rx_cnt        <= 0;
rx_frame_err <= 0;
rx_over_run   <= 0;
rx_empty      <= 1;
rx_d1         <= 1;
rx_d2         <= 1;
rx_busy       <= 0;
end else begin
// Synchronize the asynch signal
rx_d1 <= rx_in;
rx_d2 <= rx_d1;
// Uload the rx data
if (uld_rx_data) begin
    rx_data <= rx_reg;
    rx_empty <= 1;
end
// Receive data only when rx is enabled
if (rx_enable) begin

[1] [2]  下一页


标签:EDA/PLDeda技术大全,eda技术实用教程EDA/PLD
《好用的Verilog串口UART程序》相关文章