5.串口发送模块的使用1
uart_tx_test
//使用串口发送模块 uart_byte_tx,设计一个
//数据发送器,每10ms(仿真用,实际上板改成100ms)以 115200 的波特率发送一个
//数据,每次发送的数据比前一个数据大1.
module uart_tx_test(
Clk,
Reset_n,
uart_tx
);
input Clk;
input Reset_n;
output uart_tx;
reg Send_Go;
reg[7:0] Data;
uart_byte_tx DUT(
.Clk(Clk),
.Reset_n(Reset_n),
.Data(Data),
.Send_Go(Send_Go),
.Baud_set(3'd4),
.uart_tx(uart_tx),
.Tx_done(Tx_done)
);
// 100ms 的计数器
reg[24:0] counter;
//reg [18:0] counter //仿真用10ms
always@(posedge Clk or negedge Reset_n)
if(!Reset_n)
counter <= 0;
else if(counter == 4999999)//counter == 499999//仿真用10ms
counter <= 0;
else
counter <= counter + 1;
always@(posedge Clk or negedge Reset_n)
if(!Reset_n)
Send_Go <= 0;
else if(counter == 1)
Send_Go <= 1;
else
Send_Go <= 0;
always@(posedge Clk or negedge Reset_n)
if(!Reset_n)
Data <= 0;
else if(Tx_done)
Data <= Data + 1'b1;
endmodule
uart_tx_test_tb
`timescale 1ns / 1ps
module uart_tx_test_tb();
reg Clk;
reg Reset_n;
wire uart_tx;
uart_tx_test uart_tx_test(
.Clk(Clk),
.Reset_n(Reset_n),
.uart_tx(uart_tx)
);
initial Clk = 1;
always#10 Clk = ~Clk;
initial begin
Reset_n = 0;
#201;
Reset_n = 1;
#50000000;
end
endmodule
波形仿真
上板验证
首先 io 约束如下
下载 bitstream 到板子里,打开友善串口调试助手