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;