搜索
bottom↓
回复: 5

课程设计之【基于FPGA的串口通信模块设计】

[复制链接]

出0入0汤圆

发表于 2011-12-1 10:44:43 | 显示全部楼层 |阅读模式
最近一共代同学做了五个课程设计,这是其中之一。放在电脑里太浪费,所以发上论坛和大家一起分享、交流和学习。待其他课设验收完,后续将会陆续上传。
这个文件主要包括三个模块:发送,接收,按键防抖。实现RS232串口的接收和发送功能。可自己在参数里设置波特率。其中按键防抖用的是网上现成的模块,不知是谁的,其他的为原创。时钟50Mhz,HDL用的是Verilog。

点击此处下载 ourdev_700460R6DMCH.rar(文件大小:1.75M) (原文件名:RS232.rar)



(原文件名:串口模拟.jpg)

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2011-12-1 11:23:01 | 显示全部楼层
//////////////////Transmit.v////////////////////////////
module Transmit(
                clk,                 //System Clock 50Mhz
                data_in,        //8-bits pararel data input
                tx_en,        //Transmit enable:posedge is effective
                tx,                //Serial output port
                busy,                //Busy flag. High is effective
                );                       
  input clk;
  input [7:0]data_in;
  input tx_en;
  output busy;
  output tx;
  
  reg busy=0;
  reg tx=1;
  
  reg [7:0]tx_reg=0;
  reg clk_d=0;
  reg [9:0]state=0;
  reg en_pos=0;
  wire tx_cs;
  
  /*************Generate Baud rate************/
  parameter BAUD_RATE=9600;  //Clock=50Mhz,BD=9600bps
  integer count=0;
  always @(posedge clk)
    begin
      count <=count+1;
      if(count==(25000000/BAUD_RATE))
        begin
          clk_d <=~clk_d;
          count <=0;
        end
    end
   
  /***********Generate Control Timing************/
  assign tx_cs=en_pos&~tx_en;
  always @(posedge clk_d)
    begin
      en_pos <=tx_en;
    end
  
  /**************Send Serial Data***************/
  parameter
            IDLE =10'b0000000001,
            START=10'b0000000010,
            BIT_0=10'b0000000100,
            BIT_1=10'b0000001000,
            BIT_2=10'b0000010000,
            BIT_3=10'b0000100000,
            BIT_4=10'b0001000000,
            BIT_5=10'b0010000000,
            BIT_6=10'b0100000000,
            BIT_7=10'b1000000000;   
  always @(posedge clk_d or posedge tx_cs)
    begin
      if(tx_cs)
        begin
          state <=START;
          tx_reg <=data_in;
          busy <=1;
        end
      else
        begin
          case(state)
            IDLE:   begin tx<=1; busy<=0; state<=IDLE ; end
            START:  begin tx<=0; state<=BIT_0;          end
            BIT_0:  begin tx<=tx_reg[0];  state<=BIT_1; end
            BIT_1:  begin tx<=tx_reg[1];  state<=BIT_2; end
            BIT_2:  begin tx<=tx_reg[2];  state<=BIT_3; end
            BIT_3:  begin tx<=tx_reg[3];  state<=BIT_4; end
            BIT_4:  begin tx<=tx_reg[4];  state<=BIT_5; end
            BIT_5:  begin tx<=tx_reg[5];  state<=BIT_6; end
            BIT_6:  begin tx<=tx_reg[6];  state<=BIT_7; end
            BIT_7:  begin tx<=tx_reg[7];  state<=IDLE ; end
          endcase
        end
    end
endmodule

出0入0汤圆

 楼主| 发表于 2011-12-1 11:24:28 | 显示全部楼层
/***************************Receive.v***************************/
module Receive(
                clk,                 //50MHZ
                rx,                //Serial data input
                data_out,  //Pararel data output
                busy,      //Busy flag. High level is effective.
                );
  input clk;
  input rx;
  output [7:0]data_out;
  output busy;
      
  reg [7:0]data_out=0;
  reg busy=0;
  reg clk_bd=0;
  reg [9:0]state=0;
  reg [7:0]rx_reg=0;
      
  /*************Generate Baud rate************/
  parameter BAUD_RATE=9600;  //Clock=50Mhz,BD=9600bps
  integer count=0;
  
  always @(posedge clk)
    begin
      count <=count+1;
      if(count==(25000000/BAUD_RATE))
        begin
          clk_bd <=~clk_bd;
          count <=0;
        end
    end
   
  /**************Recieve Serial Data***************/
  parameter
            IDLE =10'b0000000001,
            BIT_0=10'b0000000100,
            BIT_1=10'b0000001000,
            BIT_2=10'b0000010000,
            BIT_3=10'b0000100000,
            BIT_4=10'b0001000000,
            BIT_5=10'b0010000000,
            BIT_6=10'b0100000000,
            BIT_7=10'b1000000000;   
  always @(posedge clk_bd)
    begin
      if(!rx && !busy)
        begin
        state <=BIT_0;
        busy  <=1;
        end
      else
        begin
          case(state)
            IDLE:   begin
                      data_out<=rx_reg;
                      state<=IDLE ;
                      busy<=0;
                    end
            BIT_0:  begin rx_reg[0]<=rx;  state<=BIT_1; end
            BIT_1:  begin rx_reg[1]<=rx;  state<=BIT_2; end
            BIT_2:  begin rx_reg[2]<=rx;  state<=BIT_3; end
            BIT_3:  begin rx_reg[3]<=rx;  state<=BIT_4; end
            BIT_4:  begin rx_reg[4]<=rx;  state<=BIT_5; end
            BIT_5:  begin rx_reg[5]<=rx;  state<=BIT_6; end
            BIT_6:  begin rx_reg[6]<=rx;  state<=BIT_7; end
            BIT_7:  begin rx_reg[7]<=rx;  state<=IDLE ; end
          endcase
        end
    end
  
endmodule

出0入0汤圆

发表于 2011-12-1 13:45:34 | 显示全部楼层
采样一次?

出0入0汤圆

发表于 2012-1-9 16:56:40 | 显示全部楼层
不错如果有源码就更好了

出0入0汤圆

发表于 2013-8-11 20:22:01 | 显示全部楼层
学习一下
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 05:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表