功能实现:
1.按键控制串口数据接收
2.数码管显示串口接收的数据
工具: in - system sources and probes editor 的使用
下面为部分代码,完成例程以文件形式上传
说明:此例程基于小梅哥板卡,以及小梅哥教程扩展
详细了解请百度小梅哥教程或者搜索发烧友网站小梅哥专版
module uart_tx_top(clk,rst_n,rs232_tx,key_in0,sel,seg,led); input clk; input rst_n; input key_in0; wire [32:0]disp_data; output rs232_tx; output led; output [7:0] sel;//数码管位选(选择当前要显示的数码管) output [6:0] seg;//数码管段选(当前要显示的内容) .................. endmodule
module uart_tx( clk, rst_n, data_byte, send_en, baud_set, rs232_tx, tx_done, uart_state ); input clk,rst_n; input [7:0]data_byte; //发送字节 input send_en;//发送控制 input [3:0]baud_set;//波特率选择 output reg rs232_tx;//数据发送 output reg tx_done;//发送完成 output reg uart_state;//是否处于空闲状态 .................. endmodule
module key_filter(clk,rst_n,key_in,key_flag,key_state); input clk; input rst_n; input key_in; output reg key_flag; output reg key_state; localparam IDEL = 4'b0001, FILTER0 = 4'b0010, DOWN = 4'b0100, FILTER1 = 4'b1000; ................ endmodule
module HEX8(clk,rst_n,En,disp_data,sel,seg); input clk; //50M input rst_n; input En; //数码管显示使能,1使能,0关闭 input [31:0]disp_data; output [7:0] sel;//数码管位选(选择当前要显示的数码管) output reg [6:0] seg;//数码管段选(当前要显示的内容) reg [14:0]divider_cnt;//25000-1 reg clk_1K; reg [7:0]sel_r; ................. endmodule
`timescale 1ns/1ns `define clk_period 20 module uart_tx_tb; reg clk; reg rst_n; reg send_en; reg [3:0]baud_set; reg [7:0]data_byte; wire rs232_tx; wire tx_done; wire uart_state; uart_tx uart_tx( .clk(clk), .rst_n(rst_n), .data_byte(data_byte), .send_en(send_en), .baud_set(baud_set), .rs232_tx(rs232_tx), .tx_done(tx_done), .uart_state(uart_state) ); initial clk = 1; always#(`clk_period/2)clk = ~clk; initial begin rst_n = 1'b0; //key_in0 = 1'b1; data_byte = 8'd0; send_en = 1'd0; baud_set = 3'd4; #(`clk_period*20 + 1 ) rst_n = 1'b1; //key_in0 = 1'b1; #(`clk_period*50); data_byte = 8'haa; send_en = 1'd1; #`clk_period; send_en = 1'd0; @(posedge tx_done) #(`clk_period*5000); data_byte = 8'h55; send_en = 1'd1; #`clk_period; send_en = 1'd0; @(posedge tx_done) #(`clk_period*5000); $stop; end endmodule
仿真:
效果:
文章评论(0条评论)
登录后参与讨论