搜索
bottom↓
回复: 5

刚写好的VGA 数字时钟

[复制链接]

出0入0汤圆

发表于 2011-7-23 15:00:24 | 显示全部楼层 |阅读模式
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity VGA_MAO is
port(clk50MHz: in std_logic;
            HS,VS: out std_logic;
            R,G,B: out std_logic   
        );
end entity VGA_MAO;       

architecture first of VGA_MAO is
signal clk: std_logic;
signal clk_1Hz: std_logic;

SIGNAL SHI  : INTEGER RANGE 0 TO 23;
SIGNAL FEN  : INTEGER RANGE 0 TO 59;
SIGNAL MIAO : INTEGER RANGE 0 TO 59;

signal count_h: std_logic_vector(9 downto 0);
signal count_v: std_logic_vector(9 downto 0);
signal x,y: integer range 0 to 900;
--signal xx,yy: integer range 0 to 40; --水平方向分成40块,垂直方向分成30块
signal temp: std_logic;
signal RGB: std_logic_vector(0 to 2);
signal HS1,VS1: std_logic;
signal data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11: std_logic_vector(7 downto 0);
signal hour_1,hour_2,min_1,min_2,sec_1,sec_2: integer range 0 to 9;
type mao is array(0 to 199) of std_logic_vector(7 downto 0);
type zi_16_16 is array(0 to 31) of std_logic_vector(7 downto 0);
type shu_8_16 is array(0 to 15) of std_logic_vector(7 downto 0);
--阴码,逐行式,逆向
constant shu_0:shu_8_16:=(        x"00",x"00",x"00",x"38",x"44",x"82",x"82",x"82",
                                                        x"82",x"82",x"82",x"82",x"44",x"38",x"00",x"00");
                                                       
constant shu_1:shu_8_16:=(  x"00",x"00",x"00",x"08",x"0C",x"0E",x"08",x"08",
                                                        x"08",x"08",x"08",x"08",x"08",x"08",x"00",x"00");
                                                       
constant shu_2:shu_8_16:=(        x"00",x"00",x"00",x"18",x"24",x"42",x"42",x"40",
                                                        x"20",x"10",x"08",x"04",x"02",x"7E",x"00",x"00");
                                                                                                               
constant shu_3:shu_8_16:=(        x"00",x"00",x"00",x"3C",x"42",x"42",x"40",x"40",
                                                        x"30",x"40",x"40",x"42",x"42",x"3C",x"00",x"00");
                                                       
constant shu_4:shu_8_16:=(  x"00",x"00",x"00",x"40",x"60",x"50",x"48",x"48",
                                                        x"44",x"42",x"FE",x"40",x"40",x"40",x"00",x"00");
                                                       
constant shu_5:shu_8_16:=(        x"00",x"00",x"00",x"7E",x"02",x"02",x"3E",x"42",
                                                        x"40",x"40",x"40",x"42",x"42",x"3C",x"00",x"00");
                                                       
constant shu_6:shu_8_16:=(        x"00",x"00",x"00",x"38",x"44",x"42",x"02",x"3A",
                                                        x"46",x"42",x"42",x"42",x"44",x"38",x"00",x"00");
                                                       
constant shu_7:shu_8_16:=(        x"00",x"00",x"00",x"7E",x"40",x"40",x"20",x"20",
                                                        x"20",x"10",x"10",x"10",x"08",x"08",x"00",x"00");
                                                       
constant shu_8:shu_8_16:=(        x"00",x"00",x"00",x"38",x"44",x"82",x"82",x"44",
                                                        x"38",x"44",x"82",x"82",x"44",x"38",x"00",x"00");
                                                       
constant shu_9:shu_8_16:=(        x"00",x"00",x"00",x"1C",x"22",x"42",x"42",x"42",
                                                        x"62",x"5C",x"40",x"42",x"22",x"1C",x"00",x"00");
                                                       
constant shu_mh:shu_8_16:=( x"00",x"00",x"00",x"00",x"00",x"00",x"18",x"18",
                                                        x"00",x"00",x"18",x"18",x"00",x"00",x"00",x"00");
                                                       
shared variable shi_shi,shi_ge,fen_shi,fen_ge,miao_shi,miao_ge:shu_8_16;       
                                                                                                                                                               
constant rom:zi_16_16:=( x"00",x"00",x"80",x"0F",
                                             x"FE",x"1F",x"FE",x"00",
                                             x"C0",x"00",x"C0",x"0F",
                                             x"FE",x"0F",x"FE",x"00",
                                             x"C0",x"3F",x"FF",x"3F",
                                             x"FF",x"00",x"C0",x"00",
                                             x"C0",x"30",x"C0",x"3F",
                                             x"80",x"1F",x"00",x"00");--两个数为一行  1为白色  0为黑色
                                       
constant rom1:zi_16_16:=(x"12",x"00",x"DA",x"3B",
                                                 x"CC",x"3B",x"3F",x"33",
                                                 x"3F",x"33",x"4C",x"37",
                                                 x"BE",x"3B",x"3E",x"33",
                                                 x"8C",x"33",x"7F",x"3B",
                                                 x"3F",x"37",x"0C",x"33",
                                                 x"0C",x"33",x"86",x"3B",
                                                 x"83",x"19",x"00",x"00");
               
constant bmp1:mao:=( x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"FC",x"FF",x"00",x"00",
                                        x"00",x"0F",x"C0",x"03",x"00",
                                        x"80",x"01",x"00",x"06",x"00",
                                        x"C0",x"00",x"00",x"0C",x"00",
                                        x"60",x"00",x"00",x"18",x"00",
                                        x"30",x"00",x"00",x"30",x"00",
                                        x"90",x"07",x"80",x"27",x"00",
                                        x"58",x"08",x"40",x"68",x"00",
                                        x"58",x"08",x"40",x"68",x"00",
                                        x"08",x"00",x"00",x"40",x"00",
                                        x"08",x"00",x"00",x"40",x"00",
                                        x"08",x"00",x"00",x"40",x"00",
                                        x"08",x"00",x"00",x"40",x"00",
                                        x"08",x"00",x"00",x"40",x"00",
                                        x"18",x"00",x"00",x"60",x"00",
                                        x"10",x"00",x"00",x"20",x"00",
                                        x"30",x"00",x"03",x"20",x"00",
                                        x"20",x"80",x"07",x"10",x"00",
                                        x"20",x"80",x"04",x"10",x"00",
                                        x"40",x"80",x"04",x"08",x"00",
                                        x"80",x"80",x"04",x"04",x"00",
                                        x"00",x"07",x"83",x"03",x"00",
                                        x"00",x"7C",x"FB",x"00",x"00",
                                        x"00",x"E8",x"5F",x"00",x"00",
                                        x"00",x"28",x"50",x"00",x"00",
                                        x"00",x"28",x"50",x"00",x"00",
                                        x"00",x"24",x"90",x"00",x"00",
                                        x"00",x"E4",x"9F",x"00",x"00",
                                        x"00",x"28",x"53",x"00",x"00",
                                        x"00",x"30",x"33",x"00",x"00",
                                        x"00",x"E0",x"1F",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00");  --bmp 位图40*40
                                       
constant bmp2:mao:=(x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"80",x"FF",x"03",x"00",
                                        x"00",x"E0",x"00",x"0E",x"00",
                                        x"00",x"30",x"00",x"18",x"00",
                                        x"00",x"0C",x"00",x"60",x"00",
                                        x"00",x"76",x"00",x"DC",x"00",
                                        x"00",x"CB",x"00",x"A6",x"01",
                                        x"00",x"DD",x"00",x"6E",x"03",
                                        x"80",x"FD",x"00",x"7E",x"03",
                                        x"80",x"FC",x"00",x"7E",x"02",
                                        x"80",x"78",x"00",x"38",x"02",
                                        x"80",x"00",x"00",x"00",x"02",
                                        x"80",x"00",x"00",x"00",x"02",
                                        x"80",x"00",x"00",x"00",x"02",
                                        x"80",x"00",x"00",x"00",x"02",
                                        x"80",x"00",x"00",x"00",x"02",
                                        x"80",x"01",x"00",x"00",x"03",
                                        x"00",x"01",x"38",x"00",x"01",
                                        x"00",x"03",x"24",x"80",x"01",
                                        x"00",x"06",x"24",x"C0",x"00",
                                        x"00",x"0C",x"38",x"60",x"00",
                                        x"00",x"38",x"00",x"38",x"00",
                                        x"00",x"E0",x"01",x"0F",x"00",
                                        x"00",x"80",x"FF",x"03",x"00",
                                        x"00",x"40",x"01",x"05",x"00",
                                        x"00",x"40",x"01",x"05",x"00",
                                        x"00",x"40",x"01",x"05",x"00",
                                        x"00",x"40",x"FF",x"05",x"00",
                                        x"00",x"C0",x"AA",x"06",x"00",
                                        x"00",x"80",x"AB",x"03",x"00",
                                        x"00",x"00",x"EE",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00",
                                        x"00",x"00",x"00",x"00",x"00");
begin
        p0:process(clk50MHz)
                variable aa: integer range 0 to 25000000;
                begin
                        if clk50MHz'event and clk50MHz='1' then
                                clk<=not clk;
                                if aa<24999900 then aa:=aa+1;
                                        else clk_1Hz<=not clk_1Hz;aa:=0;
                                end if;
                        end if;
                end process p0;
       
        p1:process(clk)  --行像素点计数
                begin
                        if clk'event and clk='1' then
                                if count_h<800 then
                                        count_h<=count_h+1;
                                else count_h<="0000000000";
                                end if;
                        end if;
                end process p1;               
        p2:process(count_h)   --行消隐信号
                begin
                        if count_h<96 then HS1<='0';
                                else HS1<='1';
                        end if;
                end process p2;
               
        p3:process(HS1)  --场像素点计数
                begin
                        if HS1'event and HS1='1' then
                                if count_v<525 then
                                        count_v<=count_v+1;
                                else count_v<="0000000000";
                                end if;
                        end if;
                end process p3;               
        P4:process(count_v)  --场消隐信号
                begin
                        if count_v<2 then VS1<='0';
                                else VS1<='1';
                        end if;
                end process p4;
       
        p5:process(x,clk)  --水平方向上扫描
                begin
                        if clk'event and clk='0' then
                                if count_v>=35 and count_v<=515 then   --行读数时,一定还要场消隐!!!
                                        if y>=0 and y<=480 then
                                                if x>=0 and x<=7 then temp<=data1(x); --八列八列的扫描
                                                        elsif x>=8 and x<=15 then temp<=data2(x-8);
                                                                elsif x>=16 and x<=23 then temp<=data3(x-16);
                                                                        elsif x>=24 and x<=31 then temp<=data4(x-24);
                                                                                elsif x>=32 and x<=39 then temp<=data5(x-32);
                                                                                        elsif x>=40 and x<=47 then temp<=data6(x-40);
                                                                                                elsif x>=48 and x<=55 then temp<=data7(x-48);
                                                                                                        elsif x>=56 and x<=63 then temp<=data8(x-56);
                                                                                                                elsif x>=64 and x<=71 then temp<=data9(x-64);
                                                                                                                        elsif x>=72 and x<=79 then temp<=data10(x-72);
                                                                                                                                elsif x>=80 and x<=87 then temp<=data11(x-80);
                                                else temp<='0';
                                                end if;
                                        end if;
                                else temp<='0';  --场消隐!!!
                                end if;       
                        end if;       
                end process p5;

        p7:process(count_h,count_v,x,y,data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11)          --分配坐标 X,Y
                begin
                        if count_h>143 and count_h<785 then x<=conv_integer(count_h)-144;  --  0~640
                        else x<=900;
                        end if;
                        if count_v>34 and count_v<515 then y<=conv_integer(count_v)-35;    --  0~480
                        else y<=900;
                        end if;
                       
                        if y>=0 and y<=15 then   --确定哪一行显示什么
                                data1<=rom(2*y);
                                data2<=rom(2*y+1);
                                data3<=rom1(2*y);
                                data4<=rom1(2*y+1);
                        elsif y>=16 and y<=55 then
                                data1<=bmp1(5*(y-16));
                                data2<=bmp1(5*(y-16)+1);
                                data3<=bmp1(5*(y-16)+2);
                                data4<=bmp1(5*(y-16)+3);
                                data5<=bmp1(5*(y-16)+4);
                               
                                data6<=bmp2(5*(y-16));
                                data7<=bmp2(5*(y-16)+1);
                                data8<=bmp2(5*(y-16)+2);
                                data9<=bmp2(5*(y-16)+3);
                                data10<=bmp2(5*(y-16)+4);
                                elsif y>=64 and y<=79 then
                                        data1<=shi_shi(y-64);
                                        data2<=shi_ge(y-64);
                                        data3<=shu_mh(y-64);
                                        data4<=fen_shi(y-64);
                                        data5<=fen_ge(y-64);
                                        data6<=shu_mh(y-64);
                                        data7<=miao_shi(y-64);
                                        data8<=miao_ge(y-64);
                        --                data9<=shu_8(y-64);
                        --                data10<=shu_9(y-64);
                        --                data11<=shu_mh(y-64);

                                else
                                        data1<=x"00";
                                        data2<=x"00";
                                        data3<=x"00";
                                        data4<=x"00";
                                        data5<=x"00";
                                        data6<=x"00";
                                        data7<=x"00";
                                        data8<=x"00";
                                        data9<=x"00";
                                        data10<=x"00";       
                                        data11<=x"00";                       
                        end if;
                end process p7;
       
        p8:process(temp)  --1为白色  0为黑色
                begin
                        if temp='0' then RGB<="000";
                                else RGB<="111";
                        end if;                       
                end process p8;
       
--        p9:process(x,y)
--                begin
--                        if x>=0 and x<=7 then xx<=0;
--                        elsif x>=8 and x<=15 then xx<=1;
--                        elsif x>=16 and x<=23 then xx<=2;
--                        elsif x>=24 and x<=31 then xx<=3;
--                        elsif x>=32 and x<=39 then xx<=4;
--                        elsif x>=40 and x<=47 then xx<=5;
--                        elsif x>=48 and x<=55 then xx<=6;
--                        elsif x>=56 and x<=63 then xx<=7;
--                        elsif x>=64 and x<=71 then xx<=8;
                --        else null;
--                        end if;
--                end process p9;
               
        p10:process(clk_1Hz)  --时,分,秒进位进程
                begin
                        if clk_1Hz'event and clk_1Hz='1' then
                                if MIAO<59 then MIAO<=MIAO+1;
                                        elsif MIAO=59 then
                                                MIAO<=0;
                                                if FEN<59 then FEN<=FEN+1;
                                                        elsif FEN=59 then
                                                                FEN<=0;
                                                                if SHI<23 then SHI<=SHI+1;
                                                                        elsif SHI=23 then SHI<=0;
                                                                end if;
                                                end if;
                                end if;
                        end if;
                end process p10;
               
        p11:process(hour_1,hour_2,min_1,min_2,sec_1,sec_2)
                begin
                        case hour_1 is
                                when 0 => shi_shi:=shu_0;
                                when 1 => shi_shi:=shu_1;
                                when 2 => shi_shi:=shu_2;
                                when 3 => shi_shi:=shu_3;
                                when 4 => shi_shi:=shu_4;
                                when 5 => shi_shi:=shu_5;
                                when 6 => shi_shi:=shu_6;
                                when 7 => shi_shi:=shu_7;
                                when 8 => shi_shi:=shu_8;
                                when 9 => shi_shi:=shu_9;
                                when others => null;
                        end case;
                       
                        case hour_2 is
                                when 0 => shi_ge:=shu_0;
                                when 1 => shi_ge:=shu_1;
                                when 2 => shi_ge:=shu_2;
                                when 3 => shi_ge:=shu_3;
                                when 4 => shi_ge:=shu_4;
                                when 5 => shi_ge:=shu_5;
                                when 6 => shi_ge:=shu_6;
                                when 7 => shi_ge:=shu_7;
                                when 8 => shi_ge:=shu_8;
                                when 9 => shi_ge:=shu_9;
                                when others => null;
                        end case;
                       
                        case min_1 is
                                when 0 => fen_shi:=shu_0;
                                when 1 => fen_shi:=shu_1;
                                when 2 => fen_shi:=shu_2;
                                when 3 => fen_shi:=shu_3;
                                when 4 => fen_shi:=shu_4;
                                when 5 => fen_shi:=shu_5;
                                when 6 => fen_shi:=shu_6;
                                when 7 => fen_shi:=shu_7;
                                when 8 => fen_shi:=shu_8;
                                when 9 => fen_shi:=shu_9;
                                when others => null;
                        end case;
                       
                        case min_2 is
                                when 0 => fen_ge:=shu_0;
                                when 1 => fen_ge:=shu_1;
                                when 2 => fen_ge:=shu_2;
                                when 3 => fen_ge:=shu_3;
                                when 4 => fen_ge:=shu_4;
                                when 5 => fen_ge:=shu_5;
                                when 6 => fen_ge:=shu_6;
                                when 7 => fen_ge:=shu_7;
                                when 8 => fen_ge:=shu_8;
                                when 9 => fen_ge:=shu_9;
                                when others => null;
                        end case;
                       
                        case sec_1 is
                                when 0 => miao_shi:=shu_0;
                                when 1 => miao_shi:=shu_1;
                                when 2 => miao_shi:=shu_2;
                                when 3 => miao_shi:=shu_3;
                                when 4 => miao_shi:=shu_4;
                                when 5 => miao_shi:=shu_5;
                                when 6 => miao_shi:=shu_6;
                                when 7 => miao_shi:=shu_7;
                                when 8 => miao_shi:=shu_8;
                                when 9 => miao_shi:=shu_9;
                                when others => null;
                        end case;
                       
                        case sec_2 is
                                when 0 => miao_ge:=shu_0;
                                when 1 => miao_ge:=shu_1;
                                when 2 => miao_ge:=shu_2;
                                when 3 => miao_ge:=shu_3;
                                when 4 => miao_ge:=shu_4;
                                when 5 => miao_ge:=shu_5;
                                when 6 => miao_ge:=shu_6;
                                when 7 => miao_ge:=shu_7;
                                when 8 => miao_ge:=shu_8;
                                when 9 => miao_ge:=shu_9;
                                when others => null;
                        end case;
                end process p11;

        hour_1<=SHI/10;
        hour_2<=SHI mod 10;
        min_1<=FEN/10;
        min_2<=FEN mod 10;
        sec_1<=MIAO/10;
        sec_2<=MIAO mod 10;
       
        HS<=HS1;
        VS<=VS1;
        R<=RGB(2);
        G<=RGB(1);
        B<=RGB(0);
end first;


本来是想把数据存在ROM里的。结果弄了半天不知道写程序了。最后还是把它放在数组里。新手上路,欢迎交流经验。。。

本来想把680*480 分成一块块16*16的,结果写的时候发现会有时延不知道怎么处理,p5进程里的if条件用XX表示就出不图像。




















效果图 (原文件名:图像683.jpg)

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2011-7-23 15:20:36 | 显示全部楼层
不错o

出0入0汤圆

发表于 2011-7-23 16:17:26 | 显示全部楼层
C语言比较难控制时间~~~支持!

出0入0汤圆

发表于 2011-7-24 16:32:12 | 显示全部楼层
我的板子的fpga管脚没有和vga管脚直接相连,接了一个DA纠结。。。

出0入0汤圆

发表于 2011-8-3 10:12:36 | 显示全部楼层
回复【3楼】yvhksovo
-----------------------------------------------------------------------

我服了,看来你就想玩个8色,是电阻网络不?自己改改.

出0入0汤圆

发表于 2011-8-3 18:24:18 | 显示全部楼层
哇!!!mark
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 13:28

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表