:
: 特权 franchises3
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
// Company
// Engineer
// Create Date : 2009.05.27
// Design Name
// Module Name
// Project Name
// Target Device: Cyclone EP1C3T144C8
// Tool versions: Quartus II 8.1
// Description : 连接 SF-EP1C6 开发板的 VGA 接口和电脑液晶屏,
//
// Revision
: V1.0
// Additional Comments :
//
////////////////////////////////////////////////////////////////////////////////
module vga_char(
: vga_char
: vga_char
: vga_char
显示字符"EDN"
clk_25m,rst_n,//系统控制
hsync,vsync,vga_r,vga_g,vga_b
// VGA 控制
);
input clk_25m;
input rst_n;
// 25MHz
//低电平复位
// FPGA 与 VGA 接口信号
//行同步信号
//场同步信号
output hsync;
output vsync;
output[2:0] vga_r;
output[2:0] vga_g;
output[1:0] vga_b;
//--------------------------------------------------
// 坐标计数
reg[9:0] x_cnt;
reg[9:0] y_cnt;
//行坐标
//列坐标
always @ (posedge clk_25m or negedge rst_n)
if(!rst_n) x_cnt <= 10'd0;
else if(x_cnt == 10'd799) x_cnt <= 10'd0;
else x_cnt <= x_cnt+1'b1;
always @ (posedge clk_25m or negedge rst_n)
if(!rst_n) y_cnt <= 10'd0;
else if(y_cnt == 10'd599) y_cnt <= 10'd0;
else if(x_cnt == 10'd799) y_cnt <= y_cnt+1'b1;
//产生 hsync 信号
//产生 vsync 信号
//--------------------------------------------------
// VGA 场同步,行同步信号
reg hsync_r,vsync_r;
//同步信号
always @ (posedge clk_25m or negedge rst_n)
if(!rst_n) hsync_r <= 1'b1;
else if(x_cnt == 10'd0) hsync_r <= 1'b0;
else if(x_cnt == 10'd96) hsync_r <= 1'b1;
always @ (posedge clk_25m or negedge rst_n)
if(!rst_n) vsync_r <= 1'b1;
else if(y_cnt == 10'd0) vsync_r <= 1'b0;
else if(y_cnt == 10'd2) vsync_r <= 1'b1;
assign hsync = hsync_r;
assign vsync = vsync_r;
//--------------------------------------------------
//有效显示标志位产生
reg valid_yr;
always @ (posedge clk_25m or negedge rst_n)
//行显示有效信号
if(!rst_n) valid_yr <= 1'b0;
else if(y_cnt == 10'd32) valid_yr <= 1'b1;
else if(y_cnt == 10'd512) valid_yr <= 1'b0;
wire valid_y = valid_yr;
reg valid_r;
always @ (posedge clk_25m or negedge rst_n)
// VGA 有效显示区标志位
if(!rst_n) valid_r <= 1'b0;
else if((x_cnt == 10'd141) && valid_y) valid_r <= 1'b1;
else if((x_cnt == 10'd781) && valid_y) valid_r <= 1'b0;
wire valid = valid_r;
wire[9:0] x_dis;
wire[9:0] y_dis;
//横坐标显示有效区域相对坐标值 0-639
//竖坐标显示有效区域相对坐标值 0-479
assign x_dis = x_cnt - 10'd142;
assign y_dis = y_cnt - 10'd33;
//--------------------------------------------------
//--------------------------------------------------
// VGA 色彩信号产生
/*
RGB = 000 黑色
= 001 蓝色
= 010 绿色
= 011 青色
*/
RGB = 100 红色
= 101 紫色
= 110 黄色
= 111 白色
/*EDN 字模参数*/
parameter char_line0 = 64'h0100000000000040,
char_line1 = 64'h01007FF821F02040,
char_line2 = 64'h0100001011101040,
char_line3 = 64'h3FF8002011101040,
char_line4 = 64'h2108004001100040,
char_line5 = 64'h21080180020E0040,
char_line6 = 64'h21080100F400F7FE,
char_line7 = 64'h3FF8FFFE13F81040,
char_line8 = 64'h2108010011081040,
char_line9 = 64'h2108010011101040,
char_linea = 64'h2108010010901040,
char_lineb = 64'h3FF8010014A01040,
char_linec = 64'h210A010018401440,
char_lined = 64'h0102010010A01840,
char_linee = 64'h0102050003181040,
char_linef = 64'h00FE02000C060040;
reg[6:0] char_bit;
//显示位计算
always @(posedge clk_25m or negedge rst_n)
if(!rst_n) char_bit <= 5'h1f;
else if(x_cnt == 10'd400) char_bit <= 7'd63; //显示最高位数据
else if(x_cnt > 10'd400 && x_cnt < 10'd529) char_bit <= char_bit-1'b1;
// 依 次 显 示 后 面
的数据
reg[7:0] vga_rgb;
// VGA 色彩显示寄存器
always @ (posedge clk_25m)
if(!valid) vga_rgb <= 8'd0;
else if(x_cnt > 10'd400 && x_cnt < 10'd529) begin
case(y_dis)
10'd231: if(char_line0[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_11100;
//绿色
10'd232: if(char_line1[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd233: if(char_line2[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd234: if(char_line3[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd235: if(char_line4[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd236: if(char_line5[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd237: if(char_line6[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd238: if(char_line7[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd239: if(char_line8[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd240: if(char_line9[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd241: if(char_linea[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd242: if(char_lineb[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd243: if(char_linec[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd244: if(char_lined[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd245: if(char_linee[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
10'd246: if(char_linef[char_bit]) vga_rgb <= 8'b111_000_01;
//红色
else vga_rgb <= 8'b001_111_00; //绿色
default: vga_rgb <= 8'h03;
endcase
end
vga_rgb <= 8'h1C;
else if (x_cnt > 10'd0 && x_cnt < 10'd101)
else if(x_cnt > 10'd100 && x_cnt < 10'd201) vga_rgb <= 8'hE0;
else if(x_cnt > 10'd200 && x_cnt < 10'd301) vga_rgb <= 8'h03;
else if(x_cnt > 10'd300 && x_cnt < 10'd401) vga_rgb <= 8'h1C;
else if(x_cnt > 10'd528 && x_cnt < 10'd628) vga_rgb <= 8'h1C;
else if(x_cnt > 10'd627 && x_cnt < 10'd728) vga_rgb <= 8'hAB;
else if(x_cnt > 10'd727 && x_cnt < 10'd782) vga_rgb <= 8'hE0;
//r,g,b 控制液晶屏颜色显
assign vga_r = vga_rgb[7:5];
assign vga_g = vga_rgb[4:2];
assign vga_b = vga_rgb[1:0];
endmodule