“春节快乐”Verilog代码
Posted 高山流水123a s d
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了“春节快乐”Verilog代码相关的知识,希望对你有一定的参考价值。
原文参考链接:https://blog.csdn.net/weixin_44884357/article/details/104688665
用Verilog显示中文字符的例子
`timescale 1ns / 1ps
module gen_line
#(
parameter COL_CNT = 16'd80,
parameter TURN = 1'b1
)
(
input [127:0]row_data,
output odata,
input bit_clk, //100ns
input bit1_roll_clk, //2ns
input reset_p
);
reg [15:0]col_cnt;
wire odata_temp;
always@(posedge bit_clk or posedge reset_p)
begin
if(reset_p)
col_cnt <= 16'd0;
else if(col_cnt == COL_CNT-1)
col_cnt <= COL_CNT - 1'd1;
else
col_cnt <= col_cnt + 1'd1;
end
assign odata_temp_p = row_data[COL_CNT - 1 - col_cnt] ? bit1_roll_clk : 1'd1;
assign odata_temp_n = row_data[COL_CNT - 1 - col_cnt] ? 1'd1 : bit1_roll_clk;
assign odata = TURN ? odata_temp_n : odata_temp_p;
endmodule
`timescale 1ns/1ns
module sim_char_display();
wire [15:0]odata;
reg [63:0]data1_row[15:0];
reg [63:0]data2_row[15:0];
reg bit_clk;
reg bit1_roll_clk;
reg reset_p;
initial bit_clk = 1'b1;
always #50 bit_clk = ~bit_clk;
initial bit1_roll_clk = 1'b1;
always #1 bit1_roll_clk = ~bit1_roll_clk;
initial begin
data1_row[15] = 64'h0100044010800020 ;
data1_row[14] = 64'h7FFC0444108000F0 ;
data1_row[13] = 64'h0100FFFE10801F00 ;
data1_row[12] = 64'h3FF8044010881000 ;
data1_row[11] = 64'h020004485BFC1100 ;
data1_row[10] = 64'hFFFE7FFC54881100 ;
data1_row[9 ] = 64'h0440020850882104 ;
data1_row[8 ] = 64'h0820020890887FFE ;
data1_row[7 ] = 64'h1FF0020810880100 ;
data1_row[6 ] = 64'h282E02081FFE0100 ;
data1_row[5 ] = 64'hC824024810800920 ;
data1_row[4 ] = 64'h0FE0022811400910 ;
data1_row[3 ] = 64'h0820021011201108 ;
data1_row[2 ] = 64'h082002001210210C ;
data1_row[1 ] = 64'h0FE00200140E4504 ;
data1_row[0 ] = 64'h0820020018040200 ;
end
//reset
initial begin
reset_p = 1'b1;
#200
reset_p = 1'b0;
#8000
$stop;
end
generate
genvar i;
for(i=0;i<16;i=i+1)
begin:gen_line_data1
gen_line #(64,0)gen_line0(data1_row[i],odata[i],bit_clk,bit1_roll_clk,reset_p);
end
endgenerate
endmodule
如果想修改显示的字,只需修改sim_char_display模块中数据代码,这些数据是通过取模软件3H3CharacterMatrix生成的数据。
使用的是16x16的点阵,对于这4个字,一行有64个点,共16行,使用16个64bit数据就可以表示这些字符数据。sim_char_display模块中第20行代码就是每个字符对应的第1,2个数据,第21行代码就是每个字符对应的第3,4个数据,以此类推,对想显示的数据进行修改。
除此之外,还有个地方需要对应的做修改和设置,sim_char_display模块中代码55行,在进行gen_line例化时需要注意例化参数的修改。gen_line中参数COL_CNT是设置一行显示的字的个数*16。TURN参数是设置显示效果,COL_CNT设置为1效果是绿底黑字,设置为0效果是黑底绿字。
点击编辑—>导出代码
取模软件导出的数据一般两个16进制数为一个数据,如下:
/* GB2312 16x16点阵字库*/
/* 春[0xB4BA] 16x16 */
0x01,0x00,0x7F,0xFC,0x01,0x00,0x3F,0xF8,0x02,0x00,0xFF,0xFE,0x04,0x40,0x08,0x20,
0x1F,0xF0,0x28,0x2E,0xC8,0x24,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x08,0x20,
/* GB2312 16x16点阵字库*/
/* 节[0xBDDA] 16x16 */
0x04,0x40,0x04,0x44,0xFF,0xFE,0x04,0x40,0x04,0x48,0x7F,0xFC,0x02,0x08,0x02,0x08,
0x02,0x08,0x02,0x08,0x02,0x48,0x02,0x28,0x02,0x10,0x02,0x00,0x02,0x00,0x02,0x00,
/* GB2312 16x16点阵字库*/
/* 快[0xBFEC] 16x16 */
0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x88,0x5B,0xFC,0x54,0x88,0x50,0x88,0x90,0x88,
0x10,0x88,0x1F,0xFE,0x10,0x80,0x11,0x40,0x11,0x20,0x12,0x10,0x14,0x0E,0x18,0x04,
/* GB2312 16x16点阵字库*/
/* 乐[0xC0D6] 16x16 */
0x00,0x20,0x00,0xF0,0x1F,0x00,0x10,0x00,0x11,0x00,0x11,0x00,0x21,0x04,0x7F,0xFE,
0x01,0x00,0x01,0x00,0x09,0x20,0x09,0x10,0x11,0x08,0x21,0x0C,0x45,0x04,0x02,0x00,
这里每行64个16进制数,共8行,每行的数据实际是显示时的两行,我们可以截断为两行,然后将0x和 , 替换为空,就会如下显示,便于我们复制粘贴到代码中:
/* GB2312 16x16点阵字库*/
/* 春[B4BA] 16x16 */
01007FFC01003FF8
0200FFFE04400820
1FF0282EC8240FE0
082008200FE00820
/* GB2312 16x16点阵字库*/
/* 节[BDDA] 16x16 */
04400444FFFE0440
04487FFC02080208
0208020802480228
0210020002000200
/* GB2312 16x16点阵字库*/
/* 快[BFEC] 16x16 */
1080108010801088
5BFC548850889088
10881FFE10801140
11201210140E1804
/* GB2312 16x16点阵字库*/
/* 乐[C0D6] 16x16 */
002000F01F001000
1100110021047FFE
0100010009200910
1108210C45040200
之后我们再对它进行顺序调换,四个数字为一组,组成下面的代码
0100044010800020
7FFC0444108000F0
0100FFFE10801F00
3FF8044010881000
020004485BFC1100
FFFE7FFC54881100
0440020850882104
0820020890887FFE
1FF0020810880100
282E02081FFE0100
C824024810800920
0FE0022811400910
0820021011201108
082002001210210C
0FE00200140E4504
0820020018040200
复制到代码中就可以了
以上是关于“春节快乐”Verilog代码的主要内容,如果未能解决你的问题,请参考以下文章