当前位置:首页 > 电源 > 数字电源
[导读]========================================================================== //----------------------------------------------------- // Design Name : uart // File Name : uart.v // Function : S

==========================================================================
//-----------------------------------------------------
// 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
    // Check if just received start of frame[!--empirenews.page--]
    if (!rx_busy && !rx_d2) begin
      rx_busy       <= 1;
      rx_sample_cnt <= 1;
      rx_cnt        <= 0;
    end
    // Start of frame detected, Proceed with rest of data
    if (rx_busy) begin
       rx_sample_cnt <= rx_sample_cnt + 1;
       // Logic to sample at middle of data
       if (rx_sample_cnt == 7) begin
          if ((rx_d2 == 1) && (rx_cnt == 0)) begin
            rx_busy <= 0;
          end else begin
            rx_cnt <= rx_cnt + 1;
            // Start storing the rx data
            if (rx_cnt > 0 && rx_cnt < 9) begin
              rx_reg[rx_cnt - 1] <= rx_d2;
            end
            if (rx_cnt == 9) begin
               rx_busy <= 0;
               // Check if End of frame received correctly
               if (rx_d2 == 0) begin
                 rx_frame_err <= 1;
               end else begin
                 rx_empty     <= 0;
                 rx_frame_err <= 0;
                 // Check if last rx data was not unloaded,
                 rx_over_run <= (rx_empty) ? 0 : 1;
               end
            end
          end
       end
    end
end
if (!rx_enable) begin
    rx_busy <= 0;
end
end

// UART TX Logic
always @ (posedge txclk or posedge reset)
if (reset) begin
tx_reg        <= 0;
tx_empty      <= 1;
tx_over_run   <= 0;
tx_out        <= 1;
tx_cnt        <= 0;
end else begin
   if (ld_tx_data) begin
      if (!tx_empty) begin
        tx_over_run <= 0;
      end else begin
        tx_reg   <= tx_data;
        tx_empty <= 0;
      end
   end
   if (tx_enable && !tx_empty) begin
     tx_cnt <= tx_cnt + 1;
     if (tx_cnt == 0) begin
       tx_out <= 0;
     end
     if (tx_cnt > 0 && tx_cnt < 9) begin
        tx_out <= tx_reg[tx_cnt -1];
     end
     if (tx_cnt == 9) begin
       tx_out <= 1;
       tx_cnt <= 0;
       tx_empty <= 1;
     end
   end
   if (!tx_enable) begin
     tx_cnt <= 0;
   end
end

endmodule

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

北京2024年5月20日 /美通社/ -- 过去五年里,支付和收款方式日新月异,其发展和变化比过去五十年都要迅猛。从嵌入式数字商务的出现,到"一拍即付"的...

关键字: VI BSP PAY COM

助力科研与检测新突破 上海2024年5月15日 /美通社/ -- 全球知名的科学仪器和服务提供商珀金埃尔默公司今日在上海举办了主题为"创新不止,探索无界"的新品发布会,集中展示了其在分析仪器领域的最...

关键字: 质谱仪 BSP DSC 气相色谱

上海2024年5月16日 /美通社/ -- 2024年5月10日至5月13日,富士胶片(中国)投资有限公司携旗下影像产品创新力作亮相北京P&E 2024。在数码相机展览区域,全新制定的集团使命"为世界绽...

关键字: 富士 数码相机 影像 BSP

贝克曼库尔特目前已成为MeMed Key免疫分析平台和MeMed BV检测技术的授权经销商 在原有合作的基础上,继续开发适用于贝克曼库尔特免疫分析仪的MeMed BV检测 加州布瑞亚和以色列海法2024年5月16日...

关键字: BSP IO 检测技术 免疫分析仪

英国英泰力能的燃料电池是可产业化的产品解决方案 英国首个专为乘用车市场开发的燃料电池系统 在 157kW 功率下,此燃料电池比乘用车的其他发动机更为强大 &...

关键字: ENERGY INTELLIGENT 氢燃料电池 BSP

深爱人才,共赴"芯"程 深圳2024年5月15日 /美通社/ -- 5月11日,深圳国资国企"博士人才荟"半导体与集成电路产业专场活动在深圳市重投天科半导体有限公司(简...

关键字: 半导体 集成电路产业 BSP 人工智能

武汉2024年5月15日 /美通社/ -- 北京时间4月26日-5月4日,2024 VEX 机器人世界锦标赛于美国得克萨斯州达拉斯市举办。本届 VEX 世锦赛为期九天,设有 VIQRC 小学组/初中组、V5RC 初中组/...

关键字: 机器人 BSP RC POWERED

上海2024年5月15日 /美通社/ -- 由生成式人工智能(AI)驱动的临床阶段生物医药科技公司英矽智能宣布,与复星医药(600196.SH;02196.HK)合作开发的潜在"全球首创"候选药物IS...

关键字: ISM BSP PC 人工智能

上海2024年5月13日 /美通社/ -- 5月8日,浦东新区国资委组织陆家嘴集团等9家区属企业与立邦中国召开合作交流会,旨在贯彻落实浦东新区区委、区政府工作要求,进一步放大进博会溢出带动效应,持续扩大区属企业与进博会重...

关键字: BSP 数字化 自动化立体仓库 智慧园区

上海2024年5月13日 /美通社/ -- 在数字化时代,高效的税务管理和ERP系统成为企业发展的关键。为了满足这一需求商应信息科技与Exact Software 易科软件就金四全电票税系统与ERP系统集成及商务合作建立...

关键字: AC 软件 BSP 数字化
关闭
关闭