FPGA-基于UART的QVGA显示(二)(实现PC端发送字母数字汉字的分别显示通过按键可以删除字符)

简介: FPGA-基于UART的QVGA显示(二)(实现PC端发送字母数字汉字的分别显示通过按键可以删除字符)

基础:由PC通过UART发送数据在VGA显示。数据可以为字母,数字,汉字(任选10个字),VGA分为左右两个区域,输入字母或者数字时在VGA左边显示,输入汉字时在VGA右边显示。

发挥:有删除功能,可通过按键删除显示的数字,字母或者汉字。左边的按键按下字母或者数字删除,右边的按键按下汉字删除。每次仅可删除一个字符。举例:VGA左侧显示FPGA 时,按下左边的键,VGA显示FPG,再按一下,显示FP。

这里不得不提的是当你用汉字内码时候的选择:

如果发送的是HEX的:选取Unicode编码的汉字则会接收到信号

如果发送的是ASCII码:选择GB2312编码的汉字内码(我不知道是因为我的软件问题还是别的可能会有出入,还未求证,知道的欢迎来扰)

之前在选择汉字内码忘记了对这两种区分导致显示失败希望以后学习的新手不要再这个上面吃亏了

附上一个比较好用的汉字编码的查询网址:

https://www.qqxiuzi.cn/bianma/zifuji.php

实现了所有的功能的完整模块设计:


1、串口通信的接收端模块(之前博文有详细的提到)

2、英文字符的缓冲区

3、中文字符的缓冲区

4、qvga显示屏的驱动模块(具体见:前文提到的lcd显示屏字符驱动)

5、按键控制

RTL视图:


image.png

top.v:


moduletop(ext_clk_25m,ext_rst_n,uart_rx,
lcd_light_en,lcd_clk,lcd_hsy,lcd_vsy,
lcd_r,lcd_g,lcd_b,key_left,key_righ    );
inputext_clk_25m;
inputext_rst_n;
inputuart_rx;
inputkey_left;
inputkey_righ;
outputlcd_light_en;
outputlcd_clk;
outputlcd_hsy;
outputlcd_vsy;
output [4:0] lcd_r;
output [5:0] lcd_g;
output [4:0] lcd_b;
wire [7:0]data_byte;
wirerxd_finish;
wirerxd_state;
wire [79:0]data_db;
wire [79:0]data_db_han;
wire [3:0]data_ab;
wirekey0_flag;
wirekey1_flag;
//按键控制模块key_controlleruut_keys(
    .clk(ext_clk_25m),
    .rst_n(ext_rst_n),
    .key_left(key_left),
    .key_righ(key_righ),
    .key0_flag(key0_flag),
    .key1_flag(key1_flag)
    );
//接收模块rxduut_rxd(
    .clk(ext_clk_25m),
    .rst_n(ext_rst_n),
    .bps_set(2'd1),    .rxd(uart_rx),
    .data_byte(data_byte),
    .rxd_finish(rxd_finish),
    .uart_state(rxd_state)
    );
//英文数字字符缓冲区dat_bufuut_dat_buf(
    .clk(ext_clk_25m),
    .rst_n(ext_rst_n),
    .data_db_chars(data_db),
    .data_byte(data_byte),
    .rxd_finish(rxd_finish),
    .data_ab(data_ab),
    .key0_flag(key0_flag)
    );
//汉字字符缓冲区dat_buf_hanuut_dat_buf_han(
    .clk(ext_clk_25m),
    .rst_n(ext_rst_n),
    .data_db_chars(data_db_han),
    .data_byte(data_byte),
    .rxd_finish(rxd_finish),
    .rxd_state(rxd_state),
    .data_ab(data_ab),
    .key1_flag(key1_flag)
    );
//qvga显示模块lcd_controlleruut_lcd_conreoller(
    .clk(ext_clk_25m),
    .rst_n(ext_rst_n),
    .lcd_light_en(lcd_light_en),
    .lcd_clk(lcd_clk),
    .lcd_hsy(lcd_hsy),
    .lcd_vsy(lcd_vsy),
    .lcd_r(lcd_r),
    .lcd_g(lcd_g),
    .lcd_b(lcd_b),
    .data_db(data_db),
    .data_ab(data_ab),
    .data_db_han(data_db_han)
    );
endmodule

rxd.v:


modulerxd(clk,rst_n,bps_set,rxd,data_byte,rxd_finish,uart_state    );
inputclk       ;//输入时钟inputrst_n     ;//复位信号input     [1:0] bps_set   ;//波特率选择inputrxd       ;//接收模块output    [7:0] data_byte ;//接收数据outputrxd_finish;//发送完成标志outputuart_state;//串口通信状态reg       [7:0] data_byte ;
regrxd_finish;
reguart_state;
reg [2:0] r_data_byte[7:0];
reg [2:0]Start,Stop;
parameterBPS_4800=16'd324,BPS_9600=16'd162,BPS_19200=16'd80 ,BPS_115200=16'd13 ;//消除亚稳态regrxd_s0,rxd_s1;  //同步寄存器always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginrxd_s0<=1'b0;rxd_s1<=1'b0;endelsebeginrxd_s0<=rxd;
rxd_s1<=rxd_s0;
endendregrxd_temp0,rxd_temp1;//数据寄存器always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginrxd_temp0<=1'b0;rxd_temp1<=1'b0;endelsebeginrxd_temp0<=rxd_s1;
rxd_temp1<=rxd_temp0;
endendwirerxd_negedge=~rxd_temp0&rxd_temp1;
reg [15:0] div_cnt;
reg [15:0] time_div;
//波特率选择模块always@(*)beginif(rst_n==1'b0)begintime_div=BPS_9600;
endelsebegincase(bps_set)
2'b00: time_div = BPS_4800;2'b01: time_div = BPS_9600;2'b10: time_div = BPS_19200;2'b11: time_div = BPS_115200;default:time_div=BPS_9600;
endcaseendend//波特率计数模块always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindiv_cnt<=1'b0;endelseif(uart_state==1'b1)beginif(div_cnt==time_div)begindiv_cnt<=1'b0;endelsebegindiv_cnt<=div_cnt+1'b1;endendelsebegindiv_cnt<=1'b0;endend//波特率时钟模块regbps_clk;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginbps_clk<=1'b0;endelseif(div_cnt==time_div)beginbps_clk<=1'b1;endelsebeginbps_clk<=1'b0;endend//bps计数模块reg [7:0] bps_cnt;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginbps_cnt<=8'd0;endelseif(rxd_finish==1'b1||(bps_cnt==8'd12&& (Start>3'd3)))beginbps_cnt<=8'd0;endelseif(bps_clk==1'b1)beginbps_cnt<=bps_cnt+1'b1;endelsebeginbps_cnt<=bps_cnt;
endendalways@(*)beginif(rst_n==1'b0)beginrxd_finish=1'b0;endelseif(bps_cnt==8'd159)beginrxd_finish=1'b1;endelsebeginrxd_finish=1'b0;endend//数据缓冲区模块always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginStart<=3'd0;r_data_byte[0]<=3'd0;r_data_byte[1]<=3'd0;r_data_byte[2]<=3'd0;r_data_byte[3]<=3'd0;r_data_byte[4]<=3'd0;r_data_byte[5]<=3'd0;r_data_byte[6]<=3'd0;r_data_byte[7]<=3'd0;Stop<=3'd0;endelseif(bps_clk==1'b1)beginif(bps_cnt==1'b0)beginStart<=3'd0;r_data_byte[0]<=3'd0;r_data_byte[1]<=3'd0;r_data_byte[2]<=3'd0;r_data_byte[3]<=3'd0;r_data_byte[4]<=3'd0;r_data_byte[5]<=3'd0;r_data_byte[6]<=3'd0;r_data_byte[7]<=3'd0;Stop<=3'd0;endif(16'd6<=bps_cnt&&bps_cnt<=16'd12)beginStart<=Start+rxd_s1;
endelseif(16'd22<=bps_cnt&&bps_cnt<=16'd28)beginr_data_byte[0]<=r_data_byte[0]+rxd_s1;
endelseif(16'd38<=bps_cnt&&bps_cnt<=16'd44)beginr_data_byte[1]<=r_data_byte[1]+rxd_s1;
endelseif(16'd54<=bps_cnt&&bps_cnt<=16'd60)beginr_data_byte[2]<=r_data_byte[2]+rxd_s1;
endelseif(16'd70<=bps_cnt&&bps_cnt<=16'd76)beginr_data_byte[3]<=r_data_byte[3]+rxd_s1;
endelseif(16'd86<=bps_cnt&&bps_cnt<=16'd92)beginr_data_byte[4]<=r_data_byte[4]+rxd_s1;
endelseif(16'd102<=bps_cnt&&bps_cnt<=16'd108)beginr_data_byte[5]<=r_data_byte[5]+rxd_s1;
endelseif(16'd118<=bps_cnt&&bps_cnt<=16'd124)beginr_data_byte[6]<=r_data_byte[6]+rxd_s1;
endelseif(16'd134<=bps_cnt&&bps_cnt<=16'd140)beginr_data_byte[7]<=r_data_byte[7]+rxd_s1;
endelseif(16'd150<=bps_cnt&&bps_cnt<=16'd156)beginStop<=Stop+rxd_s1;
endendelse;
endalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_byte<=8'd0;endelseif(bps_cnt==8'd159)begindata_byte[0]<=(r_data_byte[0]>3'd3)?1'b1:1'b0;data_byte[1]<=(r_data_byte[1]>3'd3)?1'b1:1'b0;data_byte[2]<=(r_data_byte[2]>3'd3)?1'b1:1'b0;data_byte[3]<=(r_data_byte[3]>3'd3)?1'b1:1'b0;data_byte[4]<=(r_data_byte[4]>3'd3)?1'b1:1'b0;data_byte[5]<=(r_data_byte[5]>3'd3)?1'b1:1'b0;data_byte[6]<=(r_data_byte[6]>3'd3)?1'b1:1'b0;data_byte[7]<=(r_data_byte[7]>3'd3)?1'b1:1'b0;endelsebegindata_byte<=data_byte;
endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginuart_state<=1'b0;endelseif(rxd_negedge==1'b1)beginuart_state<=1'b1;endelseif(rxd_finish==1'b1||(bps_cnt==8'd12&& (Start>3'd3)))beginuart_state<=1'b0;endelsebeginuart_state<=uart_state;
endendendmodule

dat_buf.v:(英文和数字)


moduledat_buf(clk,rst_n,data_db_chars,data_byte,rxd_finish,data_ab,key0_flag    );
inputclk;
inputrst_n;
input [7:0]data_byte;
inputrxd_finish;
input [3:0] data_ab;
inputkey0_flag;
outputreg [79:0]data_db_chars;
reg [127:0]data_db;
regchar1;
parameterS0=4'D0 ,S1=4'D1 ,S2=4'D2 ,S3=4'D3 ,S4=4'D4 ,S5=4'D5 ,S6=4'D6 ,S7=4'D7 ,S8=4'D8 ,S9=4'D9 ,S10=4'D10,CHARS_1=128'H000000E7424222242414141808080000,//VCHARS_2=128'H00000000000000634242424262DC0000,//uCHARS_3=128'H0000003C4242424020100804427E0000,//2CHARS_4=128'H0000000003020272120A0E1222770000,//kCHARS_5=128'H000000000000003C42424242423C0000;//oregfinish_0;
regchar;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginfinish_0<=1'b0;char<=1'b0;endelsebeginfinish_0<=rxd_finish;
char<=char1;
endendregfull_flag;
//英文字符模块always@(*)beginif(rst_n==1'b0)begindata_db=1'b0;char1=1'b0;endelseif(finish_0==1'b0||full_flag==1'b1)begindata_db=data_db;
char1=1'b0;endelseif(data_byte=="V")begindata_db=CHARS_1;
char1=1'd1;endelseif(data_byte=="u")begindata_db=CHARS_2;
char1=1'd1;endelseif(data_byte=="2")begindata_db=CHARS_3;
char1=1'd1;endelseif(data_byte=="k")begindata_db=CHARS_4;
char1=1'd1;endelseif(data_byte=="o")begindata_db=CHARS_5;
char1=1'd1;endelsebegindata_db=data_db;
char1=1'b0;endendreg [79:0]data_db_char[15:0];
//状态转换reg [3:0] state_c;
reg [3:0] state_n;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginstate_c<=S0;
endelsebeginstate_c<=state_n;
endendalways@(*)beginif(rst_n==1'b0)beginstate_n=S0;
endelsebegincase(state_c)
S0:if(char1==1'b1)beginstate_n=S1;
endelsebeginstate_n=S0;
endS1:if(char1==1'b1)beginstate_n=S2;
endelseif(key0_flag==1'b1)beginstate_n=S0;
endelsebeginstate_n=S1;
endS2:if(char1==1'b1)beginstate_n=S3;
endelseif(key0_flag==1'b1)beginstate_n=S1;
endelsebeginstate_n=S2;
endS3:if(char1==1'b1)beginstate_n=S4;
endelseif(key0_flag==1'b1)beginstate_n=S2;
endelsebeginstate_n=S3;
endS4:if(char1==1'b1)beginstate_n=S5;
endelseif(key0_flag==1'b1)beginstate_n=S3;
endelsebeginstate_n=S4;
endS5:if(char1==1'b1)beginstate_n=S6;
endelseif(key0_flag==1'b1)beginstate_n=S4;
endelsebeginstate_n=S5;
endS6:if(char1==1'b1)beginstate_n=S7;
endelseif(key0_flag==1'b1)beginstate_n=S5;
endelsebeginstate_n=S6;
endS7:if(char1==1'b1)beginstate_n=S8;
endelseif(key0_flag==1'b1)beginstate_n=S6;
endelsebeginstate_n=S7;
endS8:if(char1==1'b1)beginstate_n=S9;
endelseif(key0_flag==1'b1)beginstate_n=S7;
endelsebeginstate_n=S8;
endS9:if(char1==1'b1)beginstate_n=S10;
endelseif(key0_flag==1'b1)beginstate_n=S8;
endelsebeginstate_n=S9;
endS10:if(key0_flag==1'b1)beginstate_n=S9;
endelsebeginstate_n=S10;
enddefault:state_n=S0;
endcaseendend//输出模块always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginfull_flag=1'b0;endelseif(state_c==S10)beginfull_flag=1'b1;endelsebeginfull_flag=1'b0;endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_db_char[0] =1'b0;data_db_char[1] =1'b0;data_db_char[2] =1'b0;data_db_char[3] =1'b0;data_db_char[4] =1'b0;data_db_char[5] =1'b0;data_db_char[6] =1'b0;data_db_char[7] =1'b0;data_db_char[8] =1'b0;data_db_char[9] =1'b0;data_db_char[10]=1'b0;data_db_char[11]=1'b0;data_db_char[12]=1'b0;data_db_char[13]=1'b0;data_db_char[14]=1'b0;data_db_char[15]=1'b0;endelseif(char==1'b0)begin            if(state_c==S0)begindata_db_char[0] =1'b0;data_db_char[1] =1'b0;data_db_char[2] =1'b0;data_db_char[3] =1'b0;data_db_char[4] =1'b0;data_db_char[5] =1'b0;data_db_char[6] =1'b0;data_db_char[7] =1'b0;data_db_char[8] =1'b0;data_db_char[9] =1'b0;data_db_char[10]=1'b0;data_db_char[11]=1'b0;data_db_char[12]=1'b0;data_db_char[13]=1'b0;data_db_char[14]=1'b0;data_db_char[15]=1'b0;endelseif(state_c==S1)begindata_db_char[15][79:8]=1'b0;data_db_char[14][79:8]=1'b0;data_db_char[13][79:8]=1'b0;data_db_char[12][79:8]=1'b0;data_db_char[11][79:8]=1'b0;data_db_char[10][79:8]=1'b0;data_db_char[9] [79:8] =1'b0;data_db_char[8] [79:8] =1'b0;data_db_char[7] [79:8] =1'b0;data_db_char[6] [79:8] =1'b0;data_db_char[5] [79:8] =1'b0;data_db_char[4] [79:8] =1'b0;data_db_char[3] [79:8] =1'b0;data_db_char[2] [79:8] =1'b0;data_db_char[1] [79:8] =1'b0;data_db_char[0] [79:8] =1'b0;endelseif(state_c==S2)begindata_db_char[15][79:16]=1'b0;data_db_char[14][79:16]=1'b0;data_db_char[13][79:16]=1'b0;data_db_char[12][79:16]=1'b0;data_db_char[11][79:16]=1'b0;data_db_char[10][79:16]=1'b0;data_db_char[9] [79:16] =1'b0;data_db_char[8] [79:16] =1'b0;data_db_char[7] [79:16] =1'b0;data_db_char[6] [79:16] =1'b0;data_db_char[5] [79:16] =1'b0;data_db_char[4] [79:16] =1'b0;data_db_char[3] [79:16] =1'b0;data_db_char[2] [79:16] =1'b0;data_db_char[1] [79:16] =1'b0;data_db_char[0] [79:16] =1'b0;endelseif(state_c==S3)begindata_db_char[15][79:24]=1'b0;data_db_char[14][79:24]=1'b0;data_db_char[13][79:24]=1'b0;data_db_char[12][79:24]=1'b0;data_db_char[11][79:24]=1'b0;data_db_char[10][79:24]=1'b0;data_db_char[9] [79:24]=1'b0;data_db_char[8] [79:24]=1'b0;data_db_char[7] [79:24]=1'b0;data_db_char[6] [79:24]=1'b0;data_db_char[5] [79:24]=1'b0;data_db_char[4] [79:24]=1'b0;data_db_char[3] [79:24]=1'b0;data_db_char[2] [79:24]=1'b0;data_db_char[1] [79:24]=1'b0;data_db_char[0] [79:24]=1'b0;endelseif(state_c==S4)begindata_db_char[15][79:32]=1'b0;data_db_char[14][79:32]=1'b0;data_db_char[13][79:32]=1'b0;data_db_char[12][79:32]=1'b0;data_db_char[11][79:32]=1'b0;data_db_char[10][79:32]=1'b0;data_db_char[9] [79:32]=1'b0;data_db_char[8] [79:32]=1'b0;data_db_char[7] [79:32]=1'b0;data_db_char[6] [79:32]=1'b0;data_db_char[5] [79:32]=1'b0;data_db_char[4] [79:32]=1'b0;data_db_char[3] [79:32]=1'b0;data_db_char[2] [79:32]=1'b0;data_db_char[1] [79:32]=1'b0;data_db_char[0] [79:32]=1'b0;endelseif(state_c==S5)begindata_db_char[15][79:40]=1'b0;data_db_char[14][79:40]=1'b0;data_db_char[13][79:40]=1'b0;data_db_char[12][79:40]=1'b0;data_db_char[11][79:40]=1'b0;data_db_char[10][79:40]=1'b0;data_db_char[9] [79:40]=1'b0;data_db_char[8] [79:40]=1'b0;data_db_char[7] [79:40]=1'b0;data_db_char[6] [79:40]=1'b0;data_db_char[5] [79:40]=1'b0;data_db_char[4] [79:40]=1'b0;data_db_char[3] [79:40]=1'b0;data_db_char[2] [79:40]=1'b0;data_db_char[1] [79:40]=1'b0;data_db_char[0] [79:40]=1'b0;endelseif(state_c==S6)begindata_db_char[15][79:48]=1'b0;data_db_char[14][79:48]=1'b0;data_db_char[13][79:48]=1'b0;data_db_char[12][79:48]=1'b0;data_db_char[11][79:48]=1'b0;data_db_char[10][79:48]=1'b0;data_db_char[9] [79:48]=1'b0;data_db_char[8] [79:48]=1'b0;data_db_char[7] [79:48]=1'b0;data_db_char[6] [79:48]=1'b0;data_db_char[5] [79:48]=1'b0;data_db_char[4] [79:48]=1'b0;data_db_char[3] [79:48]=1'b0;data_db_char[2] [79:48]=1'b0;data_db_char[1] [79:48]=1'b0;data_db_char[0] [79:48]=1'b0;endelseif(state_c==S7)begindata_db_char[15][79:56]=1'b0;data_db_char[14][79:56]=1'b0;data_db_char[13][79:56]=1'b0;data_db_char[12][79:56]=1'b0;data_db_char[11][79:56]=1'b0;data_db_char[10][79:56]=1'b0;data_db_char[9] [79:56]=1'b0;data_db_char[8] [79:56]=1'b0;data_db_char[7] [79:56]=1'b0;data_db_char[6] [79:56]=1'b0;data_db_char[5] [79:56]=1'b0;data_db_char[4] [79:56]=1'b0;data_db_char[3] [79:56]=1'b0;data_db_char[2] [79:56]=1'b0;data_db_char[1] [79:56]=1'b0;data_db_char[0] [79:56]=1'b0;endelseif(state_c==S8)begindata_db_char[15][79:64]=1'b0;data_db_char[14][79:64]=1'b0;data_db_char[13][79:64]=1'b0;data_db_char[12][79:64]=1'b0;data_db_char[11][79:64]=1'b0;data_db_char[10][79:64]=1'b0;data_db_char[9] [79:64]=1'b0;data_db_char[8] [79:64]=1'b0;data_db_char[7] [79:64]=1'b0;data_db_char[6] [79:64]=1'b0;data_db_char[5] [79:64]=1'b0;data_db_char[4] [79:64]=1'b0;data_db_char[3] [79:64]=1'b0;data_db_char[2] [79:64]=1'b0;data_db_char[1] [79:64]=1'b0;data_db_char[0] [79:64]=1'b0;endelseif(state_c==S9)begindata_db_char[15][79:72]=1'b0;data_db_char[14][79:72]=1'b0;data_db_char[13][79:72]=1'b0;data_db_char[12][79:72]=1'b0;data_db_char[11][79:72]=1'b0;data_db_char[10][79:72]=1'b0;data_db_char[9] [79:72]=1'b0;data_db_char[8] [79:72]=1'b0;data_db_char[7] [79:72]=1'b0;data_db_char[6] [79:72]=1'b0;data_db_char[5] [79:72]=1'b0;data_db_char[4] [79:72]=1'b0;data_db_char[3] [79:72]=1'b0;data_db_char[2] [79:72]=1'b0;data_db_char[1] [79:72]=1'b0;data_db_char[0] [79:72]=1'b0;endendelseif(state_c==S1)begindata_db_char[15][7:0]=data_db[7:0];
data_db_char[14][7:0]=data_db[15:8];
data_db_char[13][7:0]=data_db[23:16];
data_db_char[12][7:0]=data_db[31:24];
data_db_char[11][7:0]=data_db[39:32];
data_db_char[10][7:0]=data_db[47:40];
data_db_char[9] [7:0]=data_db[55:48];
data_db_char[8] [7:0]=data_db[63:56];
data_db_char[7] [7:0]=data_db[71:64];
data_db_char[6] [7:0]=data_db[79:72];
data_db_char[5] [7:0]=data_db[87:80];
data_db_char[4] [7:0]=data_db[95:88];
data_db_char[3] [7:0]=data_db[103:96];
data_db_char[2] [7:0]=data_db[111:104];
data_db_char[1] [7:0]=data_db[119:112];
data_db_char[0] [7:0]=data_db[127:120];
endelseif(state_c==S2)begindata_db_char[15][15:8]=data_db[7:0];
data_db_char[14][15:8]=data_db[15:8];
data_db_char[13][15:8]=data_db[23:16];
data_db_char[12][15:8]=data_db[31:24];
data_db_char[11][15:8]=data_db[39:32];
data_db_char[10][15:8]=data_db[47:40];
data_db_char[9] [15:8]=data_db[55:48];
data_db_char[8] [15:8]=data_db[63:56];
data_db_char[7] [15:8]=data_db[71:64];
data_db_char[6] [15:8]=data_db[79:72];
data_db_char[5] [15:8]=data_db[87:80];
data_db_char[4] [15:8]=data_db[95:88];
data_db_char[3] [15:8]=data_db[103:96];
data_db_char[2] [15:8]=data_db[111:104];
data_db_char[1] [15:8]=data_db[119:112];
data_db_char[0] [15:8]=data_db[127:120];
endelseif(state_c==S3)begindata_db_char[15][23:16]=data_db[7:0];
data_db_char[14][23:16]=data_db[15:8];
data_db_char[13][23:16]=data_db[23:16];
data_db_char[12][23:16]=data_db[31:24];
data_db_char[11][23:16]=data_db[39:32];
data_db_char[10][23:16]=data_db[47:40];
data_db_char[9][23:16] =data_db[55:48];
data_db_char[8][23:16] =data_db[63:56];
data_db_char[7][23:16] =data_db[71:64];
data_db_char[6][23:16] =data_db[79:72];
data_db_char[5][23:16] =data_db[87:80];
data_db_char[4][23:16] =data_db[95:88];
data_db_char[3][23:16] =data_db[103:96];
data_db_char[2][23:16] =data_db[111:104];
data_db_char[1][23:16] =data_db[119:112];
data_db_char[0][23:16] =data_db[127:120];
endelseif(state_c==S4)begindata_db_char[15][31:24]=data_db[7:0];
data_db_char[14][31:24]=data_db[15:8];
data_db_char[13][31:24]=data_db[23:16];
data_db_char[12][31:24]=data_db[31:24];
data_db_char[11][31:24]=data_db[39:32];
data_db_char[10][31:24]=data_db[47:40];
data_db_char[9] [31:24]=data_db[55:48];
data_db_char[8] [31:24]=data_db[63:56];
data_db_char[7] [31:24]=data_db[71:64];
data_db_char[6] [31:24]=data_db[79:72];
data_db_char[5] [31:24]=data_db[87:80];
data_db_char[4] [31:24]=data_db[95:88];
data_db_char[3] [31:24]=data_db[103:96];
data_db_char[2] [31:24]=data_db[111:104];
data_db_char[1] [31:24]=data_db[119:112];
data_db_char[0] [31:24]=data_db[127:120];
endelseif(state_c==S5)begindata_db_char[15][39:32]=data_db[7:0];
data_db_char[14][39:32]=data_db[15:8];
data_db_char[13][39:32]=data_db[23:16];
data_db_char[12][39:32]=data_db[31:24];
data_db_char[11][39:32]=data_db[39:32];
data_db_char[10][39:32]=data_db[47:40];
data_db_char[9] [39:32]=data_db[55:48];
data_db_char[8] [39:32]=data_db[63:56];
data_db_char[7] [39:32]=data_db[71:64];
data_db_char[6] [39:32]=data_db[79:72];
data_db_char[5] [39:32]=data_db[87:80];
data_db_char[4] [39:32]=data_db[95:88];
data_db_char[3] [39:32]=data_db[103:96];
data_db_char[2] [39:32]=data_db[111:104];
data_db_char[1] [39:32]=data_db[119:112];
data_db_char[0] [39:32]=data_db[127:120];
endelseif(state_c==S6)begindata_db_char[15][47:40]=data_db[7:0];
data_db_char[14][47:40]=data_db[15:8];
data_db_char[13][47:40]=data_db[23:16];
data_db_char[12][47:40]=data_db[31:24];
data_db_char[11][47:40]=data_db[39:32];
data_db_char[10][47:40]=data_db[47:40];
data_db_char[9] [47:40]=data_db[55:48];
data_db_char[8] [47:40]=data_db[63:56];
data_db_char[7] [47:40]=data_db[71:64];
data_db_char[6] [47:40]=data_db[79:72];
data_db_char[5] [47:40]=data_db[87:80];
data_db_char[4] [47:40]=data_db[95:88];
data_db_char[3] [47:40]=data_db[103:96];
data_db_char[2] [47:40]=data_db[111:104];
data_db_char[1] [47:40]=data_db[119:112];
data_db_char[0] [47:40]=data_db[127:120];
endelseif(state_c==S7)begindata_db_char[15][55:48]=data_db[7:0];
data_db_char[14][55:48]=data_db[15:8];
data_db_char[13][55:48]=data_db[23:16];
data_db_char[12][55:48]=data_db[31:24];
data_db_char[11][55:48]=data_db[39:32];
data_db_char[10][55:48]=data_db[47:40];
data_db_char[9] [55:48]=data_db[55:48];
data_db_char[8] [55:48]=data_db[63:56];
data_db_char[7] [55:48]=data_db[71:64];
data_db_char[6] [55:48]=data_db[79:72];
data_db_char[5] [55:48]=data_db[87:80];
data_db_char[4] [55:48]=data_db[95:88];
data_db_char[3] [55:48]=data_db[103:96];
data_db_char[2] [55:48]=data_db[111:104];
data_db_char[1] [55:48]=data_db[119:112];
data_db_char[0] [55:48]=data_db[127:120];
endelseif(state_c==S8)begindata_db_char[15][63:56]=data_db[7:0];
data_db_char[14][63:56]=data_db[15:8];
data_db_char[13][63:56]=data_db[23:16];
data_db_char[12][63:56]=data_db[31:24];
data_db_char[11][63:56]=data_db[39:32];
data_db_char[10][63:56]=data_db[47:40];
data_db_char[9] [63:56]=data_db[55:48];
data_db_char[8] [63:56]=data_db[63:56];
data_db_char[7] [63:56]=data_db[71:64];
data_db_char[6] [63:56]=data_db[79:72];
data_db_char[5] [63:56]=data_db[87:80];
data_db_char[4] [63:56]=data_db[95:88];
data_db_char[3] [63:56]=data_db[103:96];
data_db_char[2] [63:56]=data_db[111:104];
data_db_char[1] [63:56]=data_db[119:112];
data_db_char[0] [63:56]=data_db[127:120];
endelseif(state_c==S9)begindata_db_char[15][71:64]=data_db[7:0];
data_db_char[14][71:64]=data_db[15:8];
data_db_char[13][71:64]=data_db[23:16];
data_db_char[12][71:64]=data_db[31:24];
data_db_char[11][71:64]=data_db[39:32];
data_db_char[10][71:64]=data_db[47:40];
data_db_char[9] [71:64]=data_db[55:48];
data_db_char[8] [71:64]=data_db[63:56];
data_db_char[7] [71:64]=data_db[71:64];
data_db_char[6] [71:64]=data_db[79:72];
data_db_char[5] [71:64]=data_db[87:80];
data_db_char[4] [71:64]=data_db[95:88];
data_db_char[3] [71:64]=data_db[103:96];
data_db_char[2] [71:64]=data_db[111:104];
data_db_char[1] [71:64]=data_db[119:112];
data_db_char[0] [71:64]=data_db[127:120];
endelseif(state_c==S10)begindata_db_char[15][79:72]=data_db[7:0];
data_db_char[14][79:72]=data_db[15:8];
data_db_char[13][79:72]=data_db[23:16];
data_db_char[12][79:72]=data_db[31:24];
data_db_char[11][79:72]=data_db[39:32];
data_db_char[10][79:72]=data_db[47:40];
data_db_char[9] [79:72]=data_db[55:48];
data_db_char[8] [79:72]=data_db[63:56];
data_db_char[7] [79:72]=data_db[71:64];
data_db_char[6] [79:72]=data_db[79:72];
data_db_char[5] [79:72]=data_db[87:80];
data_db_char[4] [79:72]=data_db[95:88];
data_db_char[3] [79:72]=data_db[103:96];
data_db_char[2] [79:72]=data_db[111:104];
data_db_char[1] [79:72]=data_db[119:112];
data_db_char[0] [79:72]=data_db[127:120];
endelsebegindata_db_char[0] =data_db_char[0] ;
data_db_char[1] =data_db_char[1] ;
data_db_char[2] =data_db_char[2] ;
data_db_char[3] =data_db_char[3] ;
data_db_char[4] =data_db_char[4] ;
data_db_char[5] =data_db_char[5] ;
data_db_char[6] =data_db_char[6] ;
data_db_char[7] =data_db_char[7] ;
data_db_char[8] =data_db_char[8] ;
data_db_char[9] =data_db_char[9] ;
data_db_char[10]=data_db_char[10];
data_db_char[11]=data_db_char[11];
data_db_char[12]=data_db_char[12];
data_db_char[13]=data_db_char[13];
data_db_char[14]=data_db_char[14];
data_db_char[15]=data_db_char[15];
endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_db_chars<=1'b0;endelsebegincase(data_ab)
0:data_db_chars<=data_db_char[0];
1:data_db_chars<=data_db_char[1];
2:data_db_chars<=data_db_char[2];
3:data_db_chars<=data_db_char[3];
4:data_db_chars<=data_db_char[4];
5:data_db_chars<=data_db_char[5];
6:data_db_chars<=data_db_char[6];
7:data_db_chars<=data_db_char[7];
8:data_db_chars<=data_db_char[8];
9:data_db_chars<=data_db_char[9];
10:data_db_chars<=data_db_char[10];
11:data_db_chars<=data_db_char[11];
12:data_db_chars<=data_db_char[12];
13:data_db_chars<=data_db_char[13];
14:data_db_chars<=data_db_char[14];
15:data_db_chars<=data_db_char[15];
default:data_db_chars<=1'b0;endcaseendendendmodule

dat_buf_han.v:(中文字符)


moduledat_buf_han(clk,rst_n,data_db_chars,data_byte,rxd_finish,rxd_state,data_ab,key1_flag    );
inputclk;
inputrst_n;
input [7:0]data_byte;
inputrxd_finish;
inputrxd_state;
input [3:0] data_ab;
inputkey1_flag;
outputreg [79:0]data_db_chars;
reg [255:0]data_db;
regchar1;
parameterS0=4'D0 ,S1=4'D1 ,S2=4'D2 ,S3=4'D3 ,S4=4'D4 ,S5=4'D5 ,CHECK_S0=5'D7 ,CHECK_S1=5'D8 ,CHECK_S2=5'D9 ,CHECK_S3=5'D10,CHECK_S4=5'D11,CHECK_S5=5'D12,SS1=5'D13,SS2=5'D14,SS3=5'D15,SS4=5'D16,SS5=5'D17,CHARS_6=256'H020002043FE802081FC102027FE200081FC810441FC710441FC4104414440840,//清CHARS_7=256'H001000203E40223C222023203EAE2268226822A83EA4012402220C2170280010,//昶CHARS_8=256'H000000007FFF0020002000200FE0082008200810081008080808080405020201,//万CHARS_9=256'H00103F1021102110217F3F102118213821543F5421122111211021103F102110,//相CHARS_10=256'H004000807FFE4002204100403FFE00200120011000900088044408221FF11020;//宏regfinish;
regfinish_0;
regchar;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginfinish<=1'b0;finish_0<=1'b0;char<=1'b0;endelsebeginfinish_0<=rxd_finish;
finish<=finish_0;
char<=char1;
endendregfull_flag;
//状态转换reg [4:0] state_c_0;
reg [4:0] state_n_0;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginstate_c_0<=CHECK_S0;
endelseif(rxd_state==1'b1)beginstate_c_0<=state_c_0;
endelsebeginstate_c_0<=state_n_0;
endendalways@(*)beginif(rst_n==1'b0)beginstate_n_0=CHECK_S0;
endelsebegincase(state_c_0)
CHECK_S0:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
endCHECK_S1:if(data_byte==8'Hf2)beginstate_n_0=SS1;
endelseif(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endCHECK_S2:if(data_byte==8'he0)beginstate_n_0=SS2;
endelseif(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endCHECK_S3:if(data_byte==8'hea)beginstate_n_0=SS3;
endelseif(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endCHECK_S4:if(data_byte==8'hc6)beginstate_n_0=SS4;
endelseif(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endCHECK_S5:if(data_byte==8'he5)beginstate_n_0=SS5;
endelseif(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endSS1:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
endSS2:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
endSS3:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
endSS4:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
endSS5:if(data_byte==8'HCD)beginstate_n_0=CHECK_S1;
endelseif(data_byte==8'Hcf)beginstate_n_0=CHECK_S2;
endelseif(data_byte==8'Hba)beginstate_n_0=CHECK_S3;
endelseif(data_byte==8'Hea)beginstate_n_0=CHECK_S4;
endelseif(data_byte==8'Hc7)beginstate_n_0=CHECK_S5;
endelsebeginstate_n_0=CHECK_S0;
enddefault:state_n_0=CHECK_S0;
endcaseendend//中文字符模块always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_db=1'b0;char1=1'b0;endelseif(finish==1'b0||full_flag==1'b1)begindata_db=data_db;
char1=1'b0;endelseif(state_c_0==SS1)begindata_db=CHARS_8;
char1=1'b1;endelseif(state_c_0==SS2)begindata_db=CHARS_9;
char1=1'b1;endelseif(state_c_0==SS3)begindata_db=CHARS_10;
char1=1'b1;endelseif(state_c_0==SS4)begindata_db=CHARS_7;
char1=1'b1;endelseif(state_c_0==SS5)begindata_db=CHARS_6;
char1=1'b1;endelsebegindata_db=data_db;
char1=1'b0;endendreg [79:0]data_db_char[15:0];
//状态转换reg [3:0] state_c;
reg [3:0] state_n;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginstate_c<=S0;
endelsebeginstate_c<=state_n;
endendalways@(*)beginif(rst_n==1'b0)beginstate_n=S0;
endelsebegincase(state_c)
S0:if(char1==1'b1)beginstate_n=S1;
endelsebeginstate_n=S0;
endS1:if(char1==1'b1)beginstate_n=S2;
endelseif(key1_flag==1'b1)beginstate_n=S0;
endelsebeginstate_n=S1;
endS2:if(char1==1'b1)beginstate_n=S3;
endelseif(key1_flag==1'b1)beginstate_n=S1;
endelsebeginstate_n=S2;
endS3:if(char1==1'b1)beginstate_n=S4;
endelseif(key1_flag==1'b1)beginstate_n=S2;
endelsebeginstate_n=S3;
endS4:if(char1==1'b1)beginstate_n=S5;
endelseif(key1_flag==1'b1)beginstate_n=S3;
endelsebeginstate_n=S4;
endS5:if(key1_flag==1'b1)beginstate_n=S4;
endelsebeginstate_n=S5;
enddefault:state_n=S0;
endcaseendend//输出模块always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginfull_flag=1'b0;endelseif(state_c==S5)beginfull_flag=1'b1;endelsebeginfull_flag=1'b0;endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_db_char[0] =1'b0;data_db_char[1] =1'b0;data_db_char[2] =1'b0;data_db_char[3] =1'b0;data_db_char[4] =1'b0;data_db_char[5] =1'b0;data_db_char[6] =1'b0;data_db_char[7] =1'b0;data_db_char[8] =1'b0;data_db_char[9] =1'b0;data_db_char[10]=1'b0;data_db_char[11]=1'b0;data_db_char[12]=1'b0;data_db_char[13]=1'b0;data_db_char[14]=1'b0;data_db_char[15]=1'b0;endelseif(char==1'b0)begin            if(state_c==S0)begindata_db_char[0] =1'b0;data_db_char[1] =1'b0;data_db_char[2] =1'b0;data_db_char[3] =1'b0;data_db_char[4] =1'b0;data_db_char[5] =1'b0;data_db_char[6] =1'b0;data_db_char[7] =1'b0;data_db_char[8] =1'b0;data_db_char[9] =1'b0;data_db_char[10]=1'b0;data_db_char[11]=1'b0;data_db_char[12]=1'b0;data_db_char[13]=1'b0;data_db_char[14]=1'b0;data_db_char[15]=1'b0;endelseif(state_c==S1)begindata_db_char[15][79:16]=1'b0;data_db_char[14][79:16]=1'b0;data_db_char[13][79:16]=1'b0;data_db_char[12][79:16]=1'b0;data_db_char[11][79:16]=1'b0;data_db_char[10][79:16]=1'b0;data_db_char[9] [79:16] =1'b0;data_db_char[8] [79:16] =1'b0;data_db_char[7] [79:16] =1'b0;data_db_char[6] [79:16] =1'b0;data_db_char[5] [79:16] =1'b0;data_db_char[4] [79:16] =1'b0;data_db_char[3] [79:16] =1'b0;data_db_char[2] [79:16] =1'b0;data_db_char[1] [79:16] =1'b0;data_db_char[0] [79:16] =1'b0;endelseif(state_c==S2)begindata_db_char[15][79:32]=1'b0;data_db_char[14][79:32]=1'b0;data_db_char[13][79:32]=1'b0;data_db_char[12][79:32]=1'b0;data_db_char[11][79:32]=1'b0;data_db_char[10][79:32]=1'b0;data_db_char[9] [79:32]=1'b0;data_db_char[8] [79:32]=1'b0;data_db_char[7] [79:32]=1'b0;data_db_char[6] [79:32]=1'b0;data_db_char[5] [79:32]=1'b0;data_db_char[4] [79:32]=1'b0;data_db_char[3] [79:32]=1'b0;data_db_char[2] [79:32]=1'b0;data_db_char[1] [79:32]=1'b0;data_db_char[0] [79:32]=1'b0;endelseif(state_c==S3)begindata_db_char[15][79:48]=1'b0;data_db_char[14][79:48]=1'b0;data_db_char[13][79:48]=1'b0;data_db_char[12][79:48]=1'b0;data_db_char[11][79:48]=1'b0;data_db_char[10][79:48]=1'b0;data_db_char[9] [79:48]=1'b0;data_db_char[8] [79:48]=1'b0;data_db_char[7] [79:48]=1'b0;data_db_char[6] [79:48]=1'b0;data_db_char[5] [79:48]=1'b0;data_db_char[4] [79:48]=1'b0;data_db_char[3] [79:48]=1'b0;data_db_char[2] [79:48]=1'b0;data_db_char[1] [79:48]=1'b0;data_db_char[0] [79:48]=1'b0;endelseif(state_c==S4)begindata_db_char[15][79:64]=1'b0;data_db_char[14][79:64]=1'b0;data_db_char[13][79:64]=1'b0;data_db_char[12][79:64]=1'b0;data_db_char[11][79:64]=1'b0;data_db_char[10][79:64]=1'b0;data_db_char[9] [79:64]=1'b0;data_db_char[8] [79:64]=1'b0;data_db_char[7] [79:64]=1'b0;data_db_char[6] [79:64]=1'b0;data_db_char[5] [79:64]=1'b0;data_db_char[4] [79:64]=1'b0;data_db_char[3] [79:64]=1'b0;data_db_char[2] [79:64]=1'b0;data_db_char[1] [79:64]=1'b0;data_db_char[0] [79:64]=1'b0;endendelseif(state_c==S1)begindata_db_char[15][15:0]=data_db[15:0];
data_db_char[14][15:0]=data_db[31:16];
data_db_char[13][15:0]=data_db[47:32];
data_db_char[12][15:0]=data_db[63:48];
data_db_char[11][15:0]=data_db[79:64];
data_db_char[10][15:0]=data_db[95:80];
data_db_char[9] [15:0]=data_db[111:96];
data_db_char[8] [15:0]=data_db[127:112];
data_db_char[7] [15:0]=data_db[143:128];
data_db_char[6] [15:0]=data_db[159:144];
data_db_char[5] [15:0]=data_db[175:160];
data_db_char[4] [15:0]=data_db[191:176];
data_db_char[3] [15:0]=data_db[207:192];
data_db_char[2] [15:0]=data_db[223:208];
data_db_char[1] [15:0]=data_db[239:224];
data_db_char[0] [15:0]=data_db[255:240];
endelseif(state_c==S2)begindata_db_char[15][31:16]=data_db[15:0];
data_db_char[14][31:16]=data_db[31:16];
data_db_char[13][31:16]=data_db[47:32];
data_db_char[12][31:16]=data_db[63:48];
data_db_char[11][31:16]=data_db[79:64];
data_db_char[10][31:16]=data_db[95:80];
data_db_char[9] [31:16]=data_db[111:96];
data_db_char[8] [31:16]=data_db[127:112];
data_db_char[7] [31:16]=data_db[143:128];
data_db_char[6] [31:16]=data_db[159:144];
data_db_char[5] [31:16]=data_db[175:160];
data_db_char[4] [31:16]=data_db[191:176];
data_db_char[3] [31:16]=data_db[207:192];
data_db_char[2] [31:16]=data_db[223:208];
data_db_char[1] [31:16]=data_db[239:224];
data_db_char[0] [31:16]=data_db[255:240];
endelseif(state_c==S3)begindata_db_char[15][47:32]=data_db[15:0]; 
data_db_char[14][47:32]=data_db[31:16];
data_db_char[13][47:32]=data_db[47:32];
data_db_char[12][47:32]=data_db[63:48];
data_db_char[11][47:32]=data_db[79:64];
data_db_char[10][47:32]=data_db[95:80];
data_db_char[9] [47:32]=data_db[111:96]; 
data_db_char[8] [47:32]=data_db[127:112];
data_db_char[7] [47:32]=data_db[143:128];
data_db_char[6] [47:32]=data_db[159:144];
data_db_char[5] [47:32]=data_db[175:160];
data_db_char[4] [47:32]=data_db[191:176];
data_db_char[3] [47:32]=data_db[207:192];
data_db_char[2] [47:32]=data_db[223:208];
data_db_char[1] [47:32]=data_db[239:224];
data_db_char[0] [47:32]=data_db[255:240];
endelseif(state_c==S4)begindata_db_char[15][63:48]=data_db[15:0]; 
data_db_char[14][63:48]=data_db[31:16];
data_db_char[13][63:48]=data_db[47:32];
data_db_char[12][63:48]=data_db[63:48];
data_db_char[11][63:48]=data_db[79:64];
data_db_char[10][63:48]=data_db[95:80];
data_db_char[9] [63:48]=data_db[111:96]; 
data_db_char[8] [63:48]=data_db[127:112];
data_db_char[7] [63:48]=data_db[143:128];
data_db_char[6] [63:48]=data_db[159:144];
data_db_char[5] [63:48]=data_db[175:160];
data_db_char[4] [63:48]=data_db[191:176];
data_db_char[3] [63:48]=data_db[207:192];
data_db_char[2] [63:48]=data_db[223:208];
data_db_char[1] [63:48]=data_db[239:224];
data_db_char[0] [63:48]=data_db[255:240];
endelseif(state_c==S5)begindata_db_char[15][79:64]=data_db[15:0]; 
data_db_char[14][79:64]=data_db[31:16];
data_db_char[13][79:64]=data_db[47:32];
data_db_char[12][79:64]=data_db[63:48];
data_db_char[11][79:64]=data_db[79:64];
data_db_char[10][79:64]=data_db[95:80];
data_db_char[9] [79:64]=data_db[111:96]; 
data_db_char[8] [79:64]=data_db[127:112];
data_db_char[7] [79:64]=data_db[143:128];
data_db_char[6] [79:64]=data_db[159:144];
data_db_char[5] [79:64]=data_db[175:160];
data_db_char[4] [79:64]=data_db[191:176];
data_db_char[3] [79:64]=data_db[207:192];
data_db_char[2] [79:64]=data_db[223:208];
data_db_char[1] [79:64]=data_db[239:224];
data_db_char[0] [79:64]=data_db[255:240];
endelsebegindata_db_char[0] =data_db_char[0] ;
data_db_char[1] =data_db_char[1] ;
data_db_char[2] =data_db_char[2] ;
data_db_char[3] =data_db_char[3] ;
data_db_char[4] =data_db_char[4] ;
data_db_char[5] =data_db_char[5] ;
data_db_char[6] =data_db_char[6] ;
data_db_char[7] =data_db_char[7] ;
data_db_char[8] =data_db_char[8] ;
data_db_char[9] =data_db_char[9] ;
data_db_char[10]=data_db_char[10];
data_db_char[11]=data_db_char[11];
data_db_char[12]=data_db_char[12];
data_db_char[13]=data_db_char[13];
data_db_char[14]=data_db_char[14];
data_db_char[15]=data_db_char[15];
endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begindata_db_chars<=1'b0;endelsebegincase(data_ab)
0:data_db_chars<=data_db_char[0];
1:data_db_chars<=data_db_char[1];
2:data_db_chars<=data_db_char[2];
3:data_db_chars<=data_db_char[3];
4:data_db_chars<=data_db_char[4];
5:data_db_chars<=data_db_char[5];
6:data_db_chars<=data_db_char[6];
7:data_db_chars<=data_db_char[7];
8:data_db_chars<=data_db_char[8];
9:data_db_chars<=data_db_char[9];
10:data_db_chars<=data_db_char[10];
11:data_db_chars<=data_db_char[11];
12:data_db_chars<=data_db_char[12];
13:data_db_chars<=data_db_char[13];
14:data_db_chars<=data_db_char[14];
15:data_db_chars<=data_db_char[15];
default:data_db_chars<=1'b0;endcaseendendendmodule

qvga.v:


modulelcd_controller(clk,rst_n,lcd_light_en,lcd_clk,lcd_hsy,lcd_vsy,lcd_r,lcd_g,lcd_b,data_db,data_ab,data_db_han    );
inputclk;
inputrst_n;
input [79:0] data_db;
input [79:0] data_db_han;
output [3:0]data_ab;
outputlcd_light_en;
outputlcd_clk;
outputreglcd_hsy;
outputreglcd_vsy;
output [4:0] lcd_r;
output [5:0] lcd_g;
output [4:0] lcd_b;
parameterHSY_TH=9'D408-1'D1;//周期parameterHSY_THS=9'D30     ;//脉冲宽度parameterHSY_THB=9'D38     ;//后沿parameterHSY_TEP=9'D320    ;//显示周期parameterHSY_THE=9'D68     ;//同步周期parameterHSY_THF=9'D20     ;//前沿parameterVSY_TV=9'D262-1'D1;//周期parameterVSY_TVS=9'D3      ;//脉冲宽度parameterVSY_TVB=9'D15     ;//后沿parameterVSY_TVD=9'D240    ;//显示周期parameterVSY_TVF=9'D4      ;//前沿//lcd背光常开assignlcd_light_en=1'b1;//配置驱动时钟6.25mHzreg [1:0] lcd_cnt;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginlcd_cnt<=1'b0;endelsebeginlcd_cnt<=lcd_cnt+1'b1;endendassignlcd_clk=lcd_cnt[1];
wiredchange={lcd_cnt==2'd2};//X和Y轴计数器reg[8:0] xcnt;
reg[8:0] ycnt;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginxcnt<=1'b0;endelseif(dchange==1'b1)beginif(xcnt==HSY_TH)beginxcnt<=1'b0;endelsebeginxcnt<=xcnt+1'b1;endendelse;
endalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginycnt<=1'b0;endelseif(dchange&&xcnt==HSY_TH)beginif(ycnt==VSY_TV)beginycnt<=1'b0;endelsebeginycnt<=ycnt+1'b1;endendelsebeginycnt<=ycnt;
endend//lcd显示的有效区域regvalid;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginvalid<=1'b0;endelseif(ycnt>=(VSY_TVS+VSY_TVB)&&ycnt<(VSY_TVS+VSY_TVB+VSY_TVD)&&xcnt>=(HSY_THS+HSY_THB)&&xcnt<(HSY_TEP+HSY_THB+HSY_THE))beginvalid<=1'b1;endelsebeginvalid<=1'b0;endend//LCD驱动行场同步信号产生逻辑always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginlcd_hsy<=1'b1;endelseif(xcnt==1'b0)beginlcd_hsy<=1'b0;endelseif(xcnt>=HSY_THS)beginlcd_hsy<=1'b1;endelsebeginlcd_hsy<=lcd_hsy;
endendalways@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginlcd_vsy<=1'b1;endelseif(ycnt==1'b0)beginlcd_vsy<=1'b0;endelseif(ycnt>=VSY_TVS)beginlcd_vsy<=1'b1;endelsebeginlcd_vsy<=lcd_vsy;
endendassigndata_ab=ycnt-5'd18;reg [8:0]tmp_cnt;
reg [8:0]tmp_cnt_0;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)begintmp_cnt<=1'b0;tmp_cnt_0<=1'b0;endelseif(valid==1'b0)begintmp_cnt<=1'b0;tmp_cnt_0<=1'b0;endelseif(xcnt>=(HSY_THS+HSY_THB)&&xcnt<(HSY_THS+HSY_THB+9'd80)&&dchange)begintmp_cnt<=tmp_cnt+1'b1;endelseif(xcnt>=((HSY_TEP/2'd2)+HSY_THS+HSY_THB)&&xcnt<((HSY_TEP/2'd2)+HSY_THS+HSY_THB+9'd80)&&dchange)begintmp_cnt_0<=tmp_cnt_0+1'b1;endelsebegintmp_cnt<=tmp_cnt;
tmp_cnt_0<=tmp_cnt_0;
endendreg [15:0]lcd_db_rgb;
always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginlcd_db_rgb<=16'd0;endelseif(xcnt==(HSY_TEP/2+HSY_THB+HSY_THS))beginlcd_db_rgb[10:5]<=6'd63;endelseif(ycnt>=(VSY_TVS+VSY_TVB)&&ycnt<(VSY_TVS+VSY_TVB+9'd16)&&xcnt>=(HSY_THS+HSY_THB)&&xcnt<(HSY_THS+HSY_THB+9'd80))beginif(dchange)begin//英文字符区域if(data_db[tmp_cnt]==1'b1)beginlcd_db_rgb<=16'h001f;endelsebeginlcd_db_rgb<=16'hf800;endendelse;
endelseif(ycnt>=(VSY_TVS+VSY_TVB)&&ycnt<(VSY_TVS+VSY_TVB+9'd16)&&xcnt>(HSY_TEP/2+HSY_THS+HSY_THB)&&xcnt<(HSY_TEP/2+HSY_THS+HSY_THB+9'd80))beginif(dchange)begin//中文字符区域if(data_db_han[tmp_cnt_0]==1'b1)beginlcd_db_rgb<=16'h001f;endelsebeginlcd_db_rgb<=16'hf800;endendelse;
endelsebeginlcd_db_rgb<=1'b0;endendassignlcd_r=valid?lcd_db_rgb[15:11]:5'd0;assignlcd_g=valid?lcd_db_rgb[10:5]:6'd0;assignlcd_b=valid?lcd_db_rgb[4:0]:5'd0;endmodule

keys_controller.v:


modulekey_controller(clk,rst_n,key_left,key_righ,key0_flag,key1_flag    );
inputclk;
inputrst_n;
inputkey_left,key_righ;
outputregkey0_flag;
outputregkey1_flag;
//按键抖动判断逻辑wirekey;  //所有的按键相与的结果,用于按键触发判断reg[3:0]keyr ; //按键值key的缓冲寄存器assignkey=key_left&key_righ;
always@(posedgeclkornegedgerst_n)
beginif(!rst_n)
keyr<=4'b1111;elsekeyr<={keyr[2:0],key};
endwirekey_neg=~keyr[2] &keyr [3];//有按键被按下wirekey_pos=keyr[2] &~keyr [3];//有按键被释放//定时器计数逻辑,用于对按键的消抖的判断reg [19:0] cnt;
always@(posedgeclkornegedgerst_n)
beginif(!rst_n)
cnt<=20'd0;elseif(key_pos||key_neg)
cnt<=20'd0;elseif(cnt<20'd999_999)cnt<=cnt+1'b1;elsecnt<=20'd0;endreg[1:0]key_value[1:0];
//定时采取按键值always@(posedgeclkornegedgerst_n)
beginif(!rst_n)
beginkey_value[0] <=2'b11;key_value[1] <=2'b11;endelsebeginkey_value[1] <=key_value[0];
if(cnt==20'd999_999)key_value[0] <={key_righ,key_left};
else ;
endendwire [1:0]key_press=key_value[1] &~key_value[0];
//LED切换控制always@(posedgeclkornegedgerst_n)
beginif(!rst_n)beginkey0_flag<=1'b0;key1_flag<=1'b0;endelseif(key_press[0]==1'b1)beginkey0_flag<=1'b1;endelseif(key_press[1]==1'b1)beginkey1_flag<=1'b1;endelsebeginkey0_flag<=1'b0;key1_flag<=1'b0;endendendmodule
目录
相关文章
|
5月前
|
异构计算
FPGA新起点V1开发板(十)——按键控制LED
FPGA新起点V1开发板(十)——按键控制LED
FPGA新起点V1开发板(十)——按键控制LED
|
机器学习/深度学习 算法 异构计算
m使用FPGA实现基于BP神经网络的英文字母识别,开发平台为vivado2019.2,verilog编程,附带matlab辅助验证
m使用FPGA实现基于BP神经网络的英文字母识别,开发平台为vivado2019.2,verilog编程,附带matlab辅助验证
303 0
m使用FPGA实现基于BP神经网络的英文字母识别,开发平台为vivado2019.2,verilog编程,附带matlab辅助验证
|
异构计算
|
异构计算
实验二 基于FPGA的分频器的设计(基本任务:设计一个分频器,输入信号50MHz,输出信号频率分别为1KHz、500Hz及1Hz。拓展任务1:用按键或开关控制蜂鸣器的响与不响。拓展任务2:用按键或开)
实验二 基于FPGA的分频器的设计(基本任务:设计一个分频器,输入信号50MHz,输出信号频率分别为1KHz、500Hz及1Hz。拓展任务1:用按键或开关控制蜂鸣器的响与不响。拓展任务2:用按键或开)
1310 0
实验二 基于FPGA的分频器的设计(基本任务:设计一个分频器,输入信号50MHz,输出信号频率分别为1KHz、500Hz及1Hz。拓展任务1:用按键或开关控制蜂鸣器的响与不响。拓展任务2:用按键或开)
|
存储 异构计算
FPGA-基于UART的QVGA显示(一)(实现PC端发送字母数字汉字的分别显示)
FPGA-基于UART的QVGA显示(一)(实现PC端发送字母数字汉字的分别显示)
181 0
FPGA-基于UART的QVGA显示(一)(实现PC端发送字母数字汉字的分别显示)
FPGA-状态机的实现实例(按键的消抖)
FPGA-状态机的实现实例(按键的消抖)
226 0
|
C语言 异构计算
FPGA-独立按键的消抖(软件消抖未用状态机)
FPGA-独立按键的消抖(软件消抖未用状态机)
374 0

热门文章

最新文章

下一篇
DataWorks