基于CYCLONE2 FPGA设计的频率计+串口通信实验quartus9.0工程源码+文档说明资料, /******************************************************************************* ** 文件名称:uart.v ** 功能描述:串口通信__FPGA和上位机通信(波特率:9600bps,10个bit是1位起始位,8个数据位,1个结束) *******************************************************************************/ module uart( clk, rst, rxd, txd, start, data_cnt, count1, count2, count3, count4, count5, count6, count7, count8, send_finish ); input clk; //系统50MHZ时钟 input rst; //复位 input rxd; //串行数据接收端 output txd; //串行数据发送端 input start; //开始采集信号 input[3:0] data_cnt; //数据位标志 output send_finish; //发送完成标志 input [7:0] count1; input [7:0] count2; input [7:0] count3; input [7:0] count4; input [7:0] count5; input [7:0] count6; input [7:0] count7; input [7:0] count8; reg[15:0] div_reg; //分频计数器,分频值由波特率决定。分频后得到频率8倍波特率的时钟 reg[2:0] div8_tras_reg; //该寄存器的计数值对应发送时当前位于的时隙数 reg[3:0] state_tras; //发送状态寄存器 reg clkbaud_tras; //以波特率为频率的发送使能信号 reg clkbaud8x; //以8倍波特率为频率的时钟,它的作用是将发送或接受一个bit的时钟周期分为8个时隙 reg trasstart; //开始发送标志 reg send_finish; reg txd_reg; //发送寄存器 reg[7:0] rxd_buf; //接受数据缓存 reg[7:0] txd_buf; //发送数据缓存 reg[3:0] send_state; //发送状态寄存器 parameter div_par=16'h145; //分频参数,其值由对应的波特率计算而得,按此参数分频的时钟频率是波倍特率的8 //倍,此处值对应9600的波特率,即分频出的时钟频率是9600*8 (CLK50M) assign txd = txd_reg; // assign send_state=data_cnt; /*******分频得到8倍波特率的时钟*********/ always@(posedge clk ) begin if(!rst) div_reg<=0; else begin if(div_reg==div_par-1'b1) div_reg<=0; else div_reg<=div_reg+1'b1; end end always@(posedge clk) begin if(!rst) clkbaud8x<=0; else if(div_reg==div_par-1'b1) clkbaud8x<=~clkbaud8x;//分频得到8倍波特率的时钟:clkbaud8x end // *******************************/ always@(posedge clkbaud8x or negedge rst)//clkbaud8x