(1)实验目标:在5寸显示屏(800 * 480 @ 60)中央显示汉字(黄色),且背景颜色为青色。
(2)代码编写:
- tft_ctrl模块:
module tft_ctrl(
input clk_33M ,
input reset_n ,
input [15:0] data_in ,
output [9:0] hang ,
output [9:0] lie ,
output hsync ,
output vsync ,
output [15:0] rgb_tft ,
output tft_bl ,
output tft_clk ,
output tft_DE
);
reg [10:0] hang_cnt ;
reg [9:0] v_cnt ;
wire data_vaild ;
parameter H_SYNC = 128 ;
parameter H_BACK = 88 ;
parameter H_VAILD = 800 ;
parameter H_FRONT = 40 ;
parameter H_TOTAL = 1056 ;
parameter V_SYNC = 2 ;
parameter V_BACK = 33 ;
parameter V_VAILD = 480 ;
parameter V_FRONT = 10 ;
parameter V_TOTAL = 525 ;
//行计数器设计
always@(posedge clk_33M or negedge reset_n)
if(!reset_n)
hang_cnt <= 11'd0;
else if(hang_cnt == H_TOTAL - 11'd1)
hang_cnt <= 11'd0;
else
hang_cnt <= hang_cnt + 11'd1;
//场计数器设计
always@(posedge clk_33M or negedge reset_n)
if(!reset_n)
v_cnt <= 10'd0;
else if ((v_cnt == V_TOTAL - 10'd1) && (hang_cnt == H_TOTAL - 11'd1))
v_cnt <= 10'd0;
else if(hang_cnt == H_TOTAL - 11'd1)
v_cnt <= v_cnt + 10'd1;
else
v_cnt <= v_cnt;
//数据有效信号设计
assign data_vaild = (hang_cnt >= H_SYNC + H_BACK) && (hang_cnt < H_SYNC + H_BACK + H_VAILD)
&& (v_cnt >= V_SYNC + V_BACK) && (v_cnt < V_SYNC + V_BACK + V_VAILD);
//行、列信号设计
assign hang = ( data_vaild ) ? (hang_cnt - H_SYNC - H_BACK + 10'd1) : 10'd0;
assign lie = ( data_vaild ) ? (v_cnt - V_SYNC - V_BACK + 10'd1) : 10'd0;
//行同步、场同步信号设计
assign hsync = (hang_cnt >= H_SYNC);
assign vsync = (v_cnt >= V_SYNC);
//rgb_tft、tft_bl、tft_clk、tft_DE信号设计
assign rgb_tft = (data_vaild) ? data_in : 16'd0;
assign tft_bl = 1'd1;
assign tft_clk = clk_33M;
assign tft_DE = data_vaild;
endmodule
- char_gen模块:
module char_gen(
input clk_33M ,
input reset_n ,
input [9:0] hang ,
input [9:0] lie ,
output reg [15:0]data
);
wire char_dis ;
wire [9:0] char_x ;
wire [9:0] char_y ;
//位宽为384的寄存器,深度为96
reg [575:0] char_r[95:0];
//色彩定义
parameter CYAN = 16'h07F9;
parameter YELLOW = 16'hFFE0;
//字符有效显示区域信号
assign char_dis = (hang >= 112)&&(hang < 688)&&(lie >= 193)&&(lie < 289);
//字符显示区域坐标信号
assign char_x = char_dis ? (hang - 10'd112):10'h3FF ;
assign char_y = char_dis ? (lie - 10'd193):10'h3FF ;
//char_r信号赋值
always@(posedge clk_33M )
begin
char_r[0] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[1] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[2] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[3] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[4] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[5] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F00000000000000000000000000000000000;
char_r[6] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FC0000000000000000000000000000000000;
char_r[7] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000FE0000000000000000000000000000000000;
char_r[8] <= 576'h0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007C0000FE0000000000000000000000000000000000;
char_r[9] <= 576'h0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007E0000FC0000000000000000000000000000000000;
char_r[10] <= 576'h00000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000000007E0000F80780000000000000000000000000000000;
char_r[11] <= 576'h00000000000000000000000000000000000F8000000000000000000000000000000000000000000000000000000000000000007C0001F0FFC0000000000000000000000000000000;
char_r[12] <= 576'h00000000000000000000000000000000000FC00000000000000000000001FE0000000000000000000000007FF8000000000000F81F01FFFFC0000000000000000000000000000000;
char_r[13] <= 576'h00000000000000000000000000000000000FE0000000000000000000001FFF80000000000000000000001FFFFE000000000000FFFF83FFFF00000000000000000000000000000000;
char_r[14] <= 576'h00000000000000000000000000000000000FC000000000000000000001FFFF800000000000000000000FFFFFFF000000000001FFFF83C00000000000000000000000000000000000;
char_r[15] <= 576'h000000000000FF800000000000000000000FC00000000000000000007FFFFE00000000000000000007FFFFFFFF800000000001FFFE07800000000000000000000000000000000000;
char_r[16] <= 576'h00000000003FFFC0000000000000001E001F8000000000000000003FFFFFC0000000000000000003FFFFFFFFFF800000000003E0000F000000000000000000000000000000000000;
char_r[17] <= 576'h000000001FFFFFF000000000000001FF001F000000000000000000FFFFF8000000000000000007FFFFFFFE000C000000000003C0000E1E0000000000000000000000000000000000;
char_r[18] <= 576'h0000003FFFFFFFE00000000000001FFF001F0000000000000000007FFE0000000000000001FFFFFFFFE00000000000000000079C001C1FC000000000000000000000000000000000;
char_r[19] <= 576'h00000FFFFFFFFF80000000000001FFFE003E0000000000000000001F3E0000000000000000FFFFFFDF8000000000000000000F1F00380FE000000000000000000000000000000000;
char_r[20] <= 576'h000007FFFFFFF00000000000001FFFF8003E000000000000000000003E0000000000000000FFFFF00FC000000000000000001E0FC07007E000000000000000000000000000000000;
char_r[21] <= 576'h000001FFFFF800000000000000FFFFC0003C000000000000000000003F00000000000000003FFC000FC000000000000000003C0FC06003E000000000000000000000000000000000;
char_r[22] <= 576'h0000007FF80000000000000000FFFC00007C000000000000000000003F00000000000000000F000007E000000000000000003807C08001E000000000000000000000000000000000;
char_r[23] <= 576'h000000000000000000000000001F78000078000000000000000000003F000000000000000000000007E000000000000000007003C000000000000000000000000000000000000000;
char_r[24] <= 576'h00000000000000000000000000003C0000F81C0000000000000000003F000000000000000000000007C00000000000000000E00000003E0000000000000000000000000000000000;
char_r[25] <= 576'h00000000000000000000000000003E0000F03F0000000000000000003F000000000000000000000007C00000000000000001C0000003FF0000000000000000000000000000000000;
char_r[26] <= 576'h00000000000000000000000000003F0000F0FFC000000000000000003E000000000000000000000007C00000000000000003000000FFFFC000000000000000000000000000000000;
char_r[27] <= 576'h00000000000000000000000000003E0001E7FFC000000000000000003E000000000000000000000003C000000000000000000003FFFFFFE000000000000000000000000000000000;
char_r[28] <= 576'h00000000000000000000000000001E0001FFFFC000000000000000003E000000000000000000000003C0000000000000000001FFFFE03FC000000000000000000000000000000000;
char_r[29] <= 576'h00000000000000000000000000001E0003FE3F8000000000000000003E000000000000000000000003C0000000000000000000FFFE003F8000000000000000000000000000000000;
char_r[30] <= 576'h00000000000000000000000000001E0003803F0000000000000000003E000FE0000000000000000003C00000000000000000003C07803F0000000000000000000000000000000000;
char_r[31] <= 576'h00000000000000000000000000001E0007803E0000000000000000003E01FFF8000000000000000003C00000000000000000000007C03E0000000000000000000000000000000000;
char_r[32] <= 576'h00000000000000000000000000001E0007003E0000000000000000003E1FFFFC000000000000000003C00000000000000000000007C03C0000000000000000000000000000000000;
char_r[33] <= 576'h00000000000000000000000000001E380E003C0000000000000000003FFFFFFC000000000000000003C00000000000000000000007C03C0000000000000000000000000000000000;
char_r[34] <= 576'h00000000000000000000000000001EFC0E007C000000000000000000FFFFFFC0000000000000000003FE000000000000000000000780380000000000000000000000003FF8000000;
char_r[35] <= 576'h00000000000000000000000000001FFC1C007C00000000000000003FFFFF0000000000000000000003FFF80000000000000000000783FC00000000000000000000000FFFFE000000;
char_r[36] <= 576'h00000000001FFC000000000000007FF8180078000000000000007FFFFFC00000000000000000000003DFFF00000000000000000007FFFE0000000000000000000003FFFFFF800000;
char_r[37] <= 576'h0000000007FFFF00000000000007FFE03000F800000000000000FFFFFC000000000000000000000003C7FFC00000000000003C01FFFFFC00000000000000000001FFFFFFFFC00000;
char_r[38] <= 576'h00000001FFFFFF0000000000003FFF006000F0000000000000003FFE3C000000000000000000000003C1FFE00000000000001FFFFFE000000000000000000000FFFFFFFFFFE00000;
char_r[39] <= 576'h000003FFFFFFFF0000000000007FFE000001F0000000000000000FC03C000000000000000000000003C0FFE00000000000001FFF8780000000000000000001FFFFFFFFFFFFE00000;
char_r[40] <= 576'h000003FFFFFFF0000000000000001E000001F00000000000000000007C000000000000000000000003C03FF00000000000000E00078000000000000003FFFFFFFFFFC00003800000;
char_r[41] <= 576'h0000007FFF8000000000000000001E000001E00000000000000000007C000000000000000000000003C00FF00000000000000E00078000000000000001FFFFFFFC00000000000000;
char_r[42] <= 576'h00000007800000000000000000001E000003E00000000000000000007C000000000000000000000003C003F00000000000000E00078000FF0000000000FFFFFC0000000000000000;
char_r[43] <= 576'h00000000000000000000000000001E000003C00000000000000000007E000000000000000000000003C000F00000000000000E0007801FFFC0000000007FFF000000000000000000;
char_r[44] <= 576'h00000000000000000000000000001E000007C00000000000000000007F000000000000000000000003C000000000000000000E00078FFFFFE0000000001FE0000000000000000000;
char_r[45] <= 576'h00000000000000000000000000001E000007C0000000000000000000FB800000000000000000000003C000000000000000000E0007FFFF1FF0000000000000000000000000000000;
char_r[46] <= 576'h00000000000000000000000000001E00000FE0000000000000000000F9C00000000000000000000003C000000000000000001E01FFFF0007F0000000000000000000000000000000;
char_r[47] <= 576'h00000000000000000000000000001E00001F70000000000000000000F0E00000000000000000000003C000000000000000001FFFFF800007E0000000000000000000000000000000;
char_r[48] <= 576'h00000000000000000000000000001E00801E38000000000000000001F0F00000000000000000000003C000000000000000003FFFDF800007C0000000000000000000000000000000;
char_r[49] <= 576'h00000000000000000000000000001E0F003E1C000000000000000001F0780000000000000000000003C000000000000000007FF03F800007C0000000000000000000000000000000;
char_r[50] <= 576'h00000000000000000000000000001E3E007C0E000000000000000003E03C0000000000000000000003C000000000000000007F007F80000780000000000000000000000000000000;
char_r[51] <= 576'h00000000000000000000000000001FF800F80E000000000000000003E01E0000000000000000000003C000000000000000007C00FF80000780000000000000000000000000000000;
char_r[52] <= 576'h00000000000000000000000000001FE000F807000000000000000007C01F0000000000000000000007C000000000000000003000FF80000F80000000000000000000000000000000;
char_r[53] <= 576'h00000000000000000000000000007FC001F00380000000000000000F800F8000000000000000000007C000000000000000000001F780000F00000000000000000000000000000000;
char_r[54] <= 576'h0000000000000000000000000001FF0003E003C0000000000000000F8007C000000000000000000007C000000000000000000003E780001F00000000000000000000000000000000;
char_r[55] <= 576'h000000000000000000000000000FFC0007C001F0000000000000001F0003E000000000000000000007C000000000000000000007C780601F00000000000000000000000000000000;
char_r[56] <= 576'h00000000000000FFFE00000001FFF0000F8000F8000000000000003E0001F000000000000000000007C00000000000000000000F87803FFF00000000000000000000000000000000;
char_r[57] <= 576'h000000000000FFFFFF8000000FFFC0001F0000FC000000000000007E0001FC00000000000000000007C00000000000000000001F07800FFE00000000000000000000000000000000;
char_r[58] <= 576'h0000000001FFFFFFFFC0000007FF00003E00007F00000000000000FC0000FE00000000000000000007C00000000000000000003E078007FE00000000000000000000000000000000;
char_r[59] <= 576'h00000003FFFFFFFFFFE0000003FE00007800003F80000000000001F800007F00000000000000000007C0000000000000000000FC078003FC00000000000000000000000000000000;
char_r[60] <= 576'h00000FFFFFFFFFFFFFF0000000F80001F000003FE0000000000003F000003FC0000000000000000007C0000000000000000001F8078001FC00000000000000000000000000000000;
char_r[61] <= 576'h003FFFFFFFFC0000FFF0000000300003E000001FF800000000000FE000001FE0000000000000000007C0000000000000000003E0078001F800000000000000000000000000000000;
char_r[62] <= 576'h1FFFFFFFC000000000E00000000000078000000FFE00000000001F8000000FF8000000000000000007C0000000000000000007C0078000F000000000000000000000000000000000;
char_r[63] <= 576'h0FFFFFC000000000000000000000001E00000007FFC0000000007F0000000FFC00000000000000000FC000000000000000001F00078000E000000000000000000000000000000000;
char_r[64] <= 576'h07FFF00000000000000000000000003800000007FFF800000001FC00000007FF00000000000000000FC000000000000000003E000780000000000000000000000000000000000000;
char_r[65] <= 576'h01FC00000000000000000000000000E000000001FFF000000007F000000003FFE0000000000000000F800000000000000000F8000780000000000000000000000000000000000000;
char_r[66] <= 576'h000000000000000000000000000000000000000000000000003FC000000001FFFC000000000000000F800000000000000001E0000780000000000000000000000000000000000000;
char_r[67] <= 576'h00000000000000000000000000000000000000000000000000FC0000000000FFFFC00000000000001F80000000000000000780000F80000000000000000000000000000000000000;
char_r[68] <= 576'h000000000000000000000000000000000000000000000000000000000000007FFFE00000000000001F80000000000000001C00000F80000000000000000000000000000000000000;
char_r[69] <= 576'h000000000000000000000000000000000000000000000000000000000000001FFFE00000000000000F80000000000000000000000F80000000000000000000000000000000000000;
char_r[70] <= 576'h0000000000000000000000000000000000000000000000000000000000000003E0000000000000000F80000000000000000000000F80000000000000000000000000000000000000;
char_r[71] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000F80000000000000000000000F80000000000000000000000000000000000000;
char_r[72] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000780000000000000000000000F00000000000000000000000000000000000000;
char_r[73] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000F00000000000000000000000000000000000000;
char_r[74] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000700000000000000000000000000000000000000;
char_r[75] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000;
char_r[76] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000;
char_r[77] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[78] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[79] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[80] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[81] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[82] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[83] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[84] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[85] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[86] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[87] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[88] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[89] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[90] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[91] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[92] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[93] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[94] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
char_r[95] <= 576'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
end
//data信号输出
always@(posedge clk_33M or negedge reset_n)
if(!reset_n)
data <= CYAN ;
else if(!char_dis)
data <= CYAN ;
else if(char_r[char_y][10'd575-char_x] == 1'd1) //让扫描从高位到低位
data <= YELLOW;
else
data <= CYAN ;
endmodule
- 顶层模块:
module tft_char(
input clk ,
input reset_n ,
output hsync ,
output vsync ,
output [15:0] rgb_tft ,
output tft_bl ,
output tft_clk ,
output tft_DE
);
wire locked ;
wire clk_33M ;
wire [15:0] data_in ;
wire [9:0] hang ;
wire [9:0] lie ;
wire [15:0] data ;
assign data_in = data ;
pll_33M pll_33M_inst (
.areset ( ~reset_n ),
.inclk0 ( clk ),
.c0 ( clk_33M ),
.locked ( locked )
);
tft_ctrl tft_ctrl_inst
(
.clk_33M (clk_33M ),
.reset_n (locked ),
.data_in (data_in ),
.hang (hang ),
.lie (lie ),
.hsync (hsync ),
.vsync (vsync ),
.rgb_tft (rgb_tft ),
.tft_bl (tft_bl ),
.tft_clk (tft_clk ),
.tft_DE (tft_DE )
);
char_gen char_gen(
.clk_33M (clk_33M),
.reset_n (locked),
.hang (hang),
.lie (lie),
.data (data)
);
endmodule
(2)引脚绑定:
(3)实验现象: