在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 12479|回复: 1

[原创] UART--鉴定一下

[复制链接]
发表于 2013-10-16 22:47:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
//*******************************FILE HEAD**************************************
//// FILE NAME       : uart_transmitter.v
// FUNCTION        : UART数据发送模块
// AUTHOR          :
// DATE & REVISION :
// COMPANY         :
// UPDATE          :
//******************************************************************************

`timescale 1ns/1ns

module uart_transmitter
    (
        input i_rst_n,
        input i_clk,

        input i_tx_order, //UART数据发送指令
        input [7 : 0] i_tx_data, //UART发送的数据
        output o_uart_tx_busy, //UART发送模块忙      
        
        output o_uart_tx //UART数据输出
    );
   
    reg r_tx_order_buf;
    reg r_tx_order_rising;
   
    reg [4 : 0] r_div_cnt;  //时钟分频计数器
    reg r_div_clk;          //分频时钟信号
   
    reg [1 : 0] cstate, nstate;
    parameter [1 : 0] idle = 2'b00;
    parameter [1 : 0] load_data = 2'b01;
    parameter [1 : 0] shift_data = 2'b10;
   
    reg [4 : 0] r_shift_cnt;
    reg [9 : 0] r_shift;
   
    assign o_uart_tx = r_shift[0];
    assign o_uart_tx_busy = (cstate == idle)? 1'b0 : 1'b1;


//*********************************PROCESS**************************************
// FUNCTION        :产生分频时钟
//******************************************************************************     
                     
    always @(posedge i_clk, negedge i_rst_n)
    begin
        if(1'b0 == i_rst_n)
        begin
            r_div_cnt <= 4'd0;
            r_div_clk <= 1'b0;
        end
        else
        begin
            r_div_cnt <= r_div_cnt + 4'd1;
            r_div_clk <= r_div_cnt[3];
        end
    end

//*********************************PROCESS**************************************
// FUNCTION        :捕获UART发送指令的上升沿
//******************************************************************************     
    always @(posedge r_div_clk, negedge i_rst_n)
    begin
        if(1'b0 == i_rst_n)
        begin
            r_tx_order_buf <= 1'b0;
            r_tx_order_rising <= 1'b0;
        end
        else
        begin
            r_tx_order_buf <= i_tx_order;
            r_tx_order_rising <= i_tx_order & (~r_tx_order_buf);
        end
    end
   
//*********************************PROCESS**************************************
// FUNCTION        :UART下个状态转化到现状态
//******************************************************************************     
    always @(posedge r_div_clk, negedge i_rst_n)
    begin
        if(1'b0 == i_rst_n)
            cstate <= idle;
        else
            cstate <= nstate;
    end
   
   
//*********************************PROCESS**************************************
// FUNCTION        :UART下个状态转化进程
//******************************************************************************     
    always @(*)
    begin
        case(cstate)
            idle        :
                if(1'b1 == r_tx_order_rising)
                    nstate = shift_data;
                else
                    nstate = idle;
            shift_data  :
                if(4'd9 == r_shift_cnt)
                    nstate = idle;
                else
                    nstate = shift_data;
            default     :
                    nstate = idle;
         endcase
    end
   
//*********************************PROCESS**************************************
// FUNCTION        :UART在各个现状态下的操作
//******************************************************************************     
    always @(posedge r_div_clk, negedge i_rst_n)
    begin
        if(1'b0 == i_rst_n)
        begin
            r_shift <= 10'b1111111111;
            r_shift_cnt <= 4'd0;
        end
        else
        begin
            if(idle == cstate && 1'b1 == r_tx_order_rising)
            begin
                r_shift_cnt <= 4'd0;
                r_shift <= {1'b1, i_tx_data, 1'b0};
            end               
            else if(shift_data == cstate)
            begin
                r_shift_cnt <= r_shift_cnt + 4'd1;
                r_shift <= {1'b1, r_shift[9 : 1]};
            end
            else
            begin
                r_shift <= 10'b1111111111;
                r_shift_cnt <= 4'd0;
            end         
        end
    end
               
endmodule
// END OF uart_transmitter.v FILE ***************************************************
发表于 2013-10-20 19:49:16 | 显示全部楼层
,你自己仿真一下啊,看看仿真结果不就知道了啊,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-20 00:36 , Processed in 0.018137 second(s), 11 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表