VHDL_3641BS四个7段数码管显示实验

来源:互联网 发布:centos 重启后ip消失 编辑:程序博客网 时间:2024/05/17 09:05

VHDL_3641BS四个7段数码管显示实验

DATE:2016/10/27

CSDN主页

硬件连接图

PIN 七段数码管引脚 七段数码管含义 7 1 E 5 2 D 3 3 DP 1 4 C 143 5 G 141 6 第一个共阳 140 7 B 142 8 第二个共阳 144 9 第三个共阳 2 10 F 4 11 A 6 12 第四个共阳

以上为我开发版的硬件连接图,到手就是这样没办法改.使用的数码管为3641BS(共阳极)
从上图可知,我们使用四个共阳引脚作为每个数码管的片选信号,所以在代码器件里面我写了如下信号

entity led is   port (  clkin:in std_logic;  clkout:out std_logic_vector(7 downto 0);  enout:out std_logic_vector(3 downto 0)  );  
名称 含义 clkin 时钟输入信号 clkout 七段数码管阴极接脚,为了方便,[7-0]对应[DP,G,F,E,D,C,B,A] enout 四个七段数码管的共阳极片选信号线,[3-0]对应[四,三.二,一]

在这个实验当中,我们只能选择使用片选分别选其中某一个数码管来进行显示,所以我们这个是一个大循环,可以分频做也可以不分频做.
对于显示的内容,经过对七段数码管接线和程序管脚定义来看,我们可以算出如下列表

因为是共阳极的数码管,所以当公共脚为0,管脚为1的时候进行点亮

显示字样 clkout值 0 11000000 1 11111001 2 10100100 3 10110000 片选值 选择的数码管 1110 第一个共阳 1101 第二个共阳 1011 第三个共阳 0111 第四个共阳

所以对于实体逻辑代码如下

architecture behave of led is signal mtime:std_logic_vector(15 downto 0);signal me:std_logic_vector(2 downto 0);signal m7_0:std_logic_vector(7 downto 0);signal m7_1:std_logic_vector(7 downto 0);signal m7_2:std_logic_vector(7 downto 0);signal m7_3:std_logic_vector(7 downto 0);begin process(clkin)begin     if(clkin'event and clkin='1')then        mtime<=mtime+1;        if(mtime="1111111111111111")then             mtime<=(others=>'0');            if(me="11")then                 me<=(others=>'0');            else                me<=me+1;            end if;        end if;        m7_0<="11000000";        m7_1<="11111001";        m7_2<="10100100";        m7_3<="10110000";        if(me="00")then            enout<="1110";            clkout<=m7_0;        end if;        if(me="01")then            enout<="1101";            clkout<=m7_1;        end if;        if(me="10")then            enout<="1011";            clkout<=m7_2;        end if;        if(me="11")then            enout<="0111";            clkout<=m7_3;        end if;    end if;    end process;end behave;

完整代码

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity led is port (clkin:in std_logic;clkout:out std_logic_vector(7 downto 0);enout:out std_logic_vector(3 downto 0));end entity;architecture behave of led is signal mtime:std_logic_vector(15 downto 0);signal me:std_logic_vector(2 downto 0);signal m7_0:std_logic_vector(7 downto 0);signal m7_1:std_logic_vector(7 downto 0);signal m7_2:std_logic_vector(7 downto 0);signal m7_3:std_logic_vector(7 downto 0);begin process(clkin)begin     if(clkin'event and clkin='1')then        mtime<=mtime+1;        if(mtime="1111111111111111")then             mtime<=(others=>'0');            if(me="11")then                 me<=(others=>'0');            else                me<=me+1;            end if;        end if;        m7_0<="11000000";        m7_1<="11111001";        m7_2<="10100100";        m7_3<="10110000";        if(me="00")then            enout<="1110";            clkout<=m7_0;        end if;        if(me="01")then            enout<="1101";            clkout<=m7_1;        end if;        if(me="10")then            enout<="1011";            clkout<=m7_2;        end if;        if(me="11")then            enout<="0111";            clkout<=m7_3;        end if;    end if;    end process;end behave;
0 0
原创粉丝点击