基础:
由PC通过UART发送数据在VGA显示。数据可以为字母,数字,汉字(任选10个字),VGA分为左右两个区域,输入字母或者数字时在VGA左边显示,输入汉字时在VGA右边显示。
发挥:有删除功能,可通过按键删除显示的数字,字母或者汉字。左边的按键按下字母或者数字删除,右边的按键按下汉字删除。每次仅可删除一个字符。举例:VGA左侧显示FPGA 时,按下左边的键,VGA显示FPG,再按一下,显示FP。
这个思想其实很简单:
大致三个模块:
1、串口通信的接收端模块
2、字符的缓冲区
3、qvga显示屏的驱动模块
但是实现起来却不是很容易
首先我们可以知道qvga其实显示的话和数码管的显示原理差不多,这里只不过把屏幕看做一个二维的数组在每个位置写0或者1标志显示的字模。通过bgr通道进行调色。
但是这里的关键点在于如何读取到这样一个内存区域的数据
这里我想到了两个方法但是感觉工程量都很大,让我跟大家扯一下:
1、利用ip核生成一些ROM模块用于存储这几个字符的数据,然后在PC串口发送后接收到不同的标志信号然后在不同的区域读取相应的字符数据
这个方法比较省定义字符缓冲区(我自己随便叫的,就是用于存取字符的地方)的工程量,但是在不同的地方进行读取的时候觉得工程量也不小,而且自己思路比较迷没有想好如何处理,尤其是在发挥部分删除的时候,觉得思路和第二种差不多甚至更麻烦所以我个人处理的办法是第二种。
2、直接写一个字符存储的区域当接收处理端,当收到相应的字符时将相应的值传到寄存器中,然后在显示屏幕的中固定读取相应位置的数据实现字符的显示。
这里其实qvga和uart的模块早就调试好了主要问题出现在字符缓冲区中,各种小bug,真是有点让人头大·····
个人觉得自己的这个方法有点蠢,,菜鸟级别的,缺点:
1、只能显示确定的大小是字符
2、存储空间太小
3、浪费了大量的寄存器
高人指点说存储器可以用ram进行动态处理,过段时间看看ram看自己可不可以升级下自己这个蠢方案。
大致思路就是这样了:
利用发送完成位进行判断数据是否是想要的将数据写入一系列 reg中qvga模块中返回一个算是地址进行对y行扫描的时候进行寻址查码
暂时更新一份只可以读英文和数字的代码,明天估计就可以把余下的功能完善了
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 ); inputext_clk_25m; inputext_rst_n; inputuart_rx; 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; //接收模块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) ); //汉字字符缓冲区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) ); //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
qvga_controller.v:
`timescale1ns/1ps////Company: //Engineer: ////CreateDate: 14:05:5901/20/2019//DesignName: //ModuleName: lcd_controller//ProjectName: //TargetDevices: //Toolversions: //Description: ////Dependencies: ////Revision: //Revision0.01-FileCreated//AdditionalComments: ////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
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; 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//数据缓冲区模块reg [2:0] r_data_byte[7:0]; reg [2:0]Start,Stop; 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 ); inputclk; inputrst_n; input [7:0]data_byte; inputrxd_finish; input [3:0] data_ab; 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,/*V*/CHARS_2=128'H00000000000000634242424262DC0000,//uCHARS_3=128'H0000003C4242424020100804427E0000,//2CHARS_4=128'H0000000003020272120A0E1222770000,//kCHARS_5=128'H000000000000003C42424242423C0000;//oregchar; regfinish_0; always@(posedgeclkornegedgerst_n)beginif(rst_n==1'b0)beginchar<=1'b0;finish_0<=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; endelsebeginstate_n=S1; endS2:if(char1==1'b1)beginstate_n=S3; endelsebeginstate_n=S2; endS3:if(char1==1'b1)beginstate_n=S4; endelsebeginstate_n=S3; endS4:if(char1==1'b1)beginstate_n=S5; endelsebeginstate_n=S4; endS5:if(char1==1'b1)beginstate_n=S6; endelsebeginstate_n=S5; endS6:if(char1==1'b1)beginstate_n=S7; endelsebeginstate_n=S6; endS7:if(char1==1'b1)beginstate_n=S8; endelsebeginstate_n=S7; endS8:if(char1==1'b1)beginstate_n=S9; endelsebeginstate_n=S8; endS9:if(char1==1'b1)beginstate_n=S10; endelsebeginstate_n=S9; endS10: state_n=S10; default: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 data_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]; endelseif(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 ); inputclk; inputrst_n; input [7:0]data_byte; inputrxd_finish; inputrxd_state; input [3:0] data_ab; 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; endelsebeginstate_n=S1; endS2:if(char1==1'b1)beginstate_n=S3; endelsebeginstate_n=S2; endS3:if(char1==1'b1)beginstate_n=S4; endelsebeginstate_n=S3; endS4:if(char1==1'b1)beginstate_n=S5; endelsebeginstate_n=S4; endS5:state_n=S5; default: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 data_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]; endelseif(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