• 沒有找到結果。

致中板VHDL

N/A
N/A
Protected

Academic year: 2021

Share "致中板VHDL"

Copied!
121
0
0

加載中.... (立即查看全文)

全文

(1)

致中板

(2)
(3)
(4)
(5)
(6)

kout

kin

(7)

kout

kin

(8)
(9)
(10)

七段解碼

a

b

c

d

e

f

g

A

VCC

B

C

D

Segin[3:0]

Segout[6:0]

library ieee; use ieee.std_logic_1164.all; entity v_7seg is

port (segin : in std_logic_vector(3 downto 0); segout : out std_logic_vector (6 downto 0)); end entity;

architecture rtl of v_7seg is begin

with segin select

segout <= "1000000" when x"0", "1111001" when x"1", "0100100" when x"2", "0110000" when x"3", "0011001" when x"4", "0010010" when x"5", "0000010" when x"6", "1111000" when x"7", "0000000" when x“8", "0010000" when x"9", "0001000" when x"a", "0000011" when x"b", "1000110" when x"c", "0100001" when x"d", "0000110" when x"e", "0001110" when x"f"; end rtl;

(11)

七段解碼

a

b

c

d

e

f

g

A

VCC

B

C

D

Segin[3:0]

Segout[6:0]

library ieee; use ieee.std_logic_1164.all; entity v_7seg is

port (segin : in std_logic_vector(3 downto 0); segout : out std_logic_vector (6 downto 0)); end entity;

architecture rtl of v_7seg is begin

with segin select

segout <= "1000000" when x"0", "1111001" when x"1", "0100100" when x"2", "0110000" when x"3", "0011001" when x"4", "0010010" when x"5", "0000010" when x"6", "1111000" when x"7", "0000000" when x“8", "0010000" when x"9", "0001000" when x"a", "0000011" when x"b", "1000110" when x"c", "0100001" when x"d", "0000110" when x"e", "0001110" when others; end rtl;

(12)

library ieee;

use ieee.std_logic_1164.all; entity v_7seg is

port (segin : in std_logic_vector(3 downto 0); segout : out std_logic_vector (6 downto 0)); end entity;

architecture rtl of v_7seg is begin

with segin select

segout <= "1000000" when x"0", "1111001" when x"1", "0100100" when x"2", "0110000" when x"3", "0011001" when x"4", "0010010" when x"5", "0000010" when x"6", "1111000" when x"7", "0000000" when x“8", "0010000" when x"9", "0001000" when x"a", "0000011" when x"b", "1000110" when x"c", "0100001" when x"d", "0000110" when x"e", "0001110" when x"f"; end rtl;

v_7seg

0~f字形

Tools

Netlist viewers

RTL

viewer

(13)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component;

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

(14)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component;

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

end

rtl;

(15)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component;

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

end

rtl;

(16)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component;

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

(17)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component

;

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

(18)

七段顯示(componernt

instantiation

)

library ieee

;

use ieee.std_logic_1164.all

;

use work

.my_pkg.

all

;

entity

c_7seg

is port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end entity

;

architecture

rtl

of

c_7seg

is

begin

v_7seg0 : v_7seg

port map

(segin => segin,segout => segout);

(19)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity m_7seg is port

( segin : in std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of v_4disp is

begin

v_7seg0 : v_7seg port map (segin =>segin, segout => segout);

end rtl;

component

package

component

(20)

建立package程式,不須compile

add入project內

七段顯示(

package)

library ieee;

use ieee.std_logic_1164.all;

package

my_pkg

is

component

v_7seg

port

(

segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0)

);

end component

;

end

my_pkg;

無entity

(21)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity m_7seg is port

( segin : in std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of v_4disp is

begin

v_7seg0 : v_7seg port map (segin =>segin, segout => segout);

end rtl;

component

package

component

(22)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity m_7seg is port

( segin : in std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of v_4disp is

begin

v_7seg0 : v_7seg port map (segin =>segin, segout => segout);

end rtl;

com

(23)
(24)
(25)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity m_7seg is port

( segin : in std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of v_4disp is

begin

v_7seg0 : v_7seg port map (segin =>segin, segout => segout);

qout <= "0001" ;

end rtl;

0

|

F

com

個位數常亮

其餘常滅

(26)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity m_7seg is port

( segin : in std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of v_4disp is

begin

v_7seg0 : v_7seg port map (segin =>segin, segout => segout);

qout <= "0001" ;

end rtl;

0

|

F

com

注意!

七段個位數

固定常久顯示

未接限流電阻

可能燒毀七段

顯示器

(27)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_7seg is port

(ck : in std_logic;

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of m_7seg is

signal fd : std_logic_vector(24 downto 0);

begin

v_7seg0 : v_7seg port map (segin => fd(24 downto 21),segout => segout);

qout <= "0001" when fd(1 downto 0)="00" else "0000";

process(ck) begin

if rising_edge(ck) then

fd <= fd+1;

end if;

end process;

end rtl;

0

|

F

25%

(28)
(29)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity v_4disp is port

(d_in : in std_logic_vector(15 downto 0);

sin : in std_logic_vector(1 downto 0);

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of v_4disp is

signal data : std_logic_vector(3 downto 0);

begin

v_7seg0 : v_7seg port map (segin => data,segout => segout);

with sin select

qout <= "1000" when "00" ,

"0100" when "01",

"0010" when "10",

"0001" when "11";

with sin select

data <= d_in(15 downto 12) when "00",

d_in(11 downto 8) when "01",

d_in(7 downto 4) when "10",

d_in(3 downto 0) when "11";

end rtl;

v_4disp

29

(30)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity v_4disp is port

(d_in : in std_logic_vector(15 downto 0);

sin : in std_logic_vector(1 downto 0);

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of v_4disp is

signal data : std_logic_vector(3 downto 0);

begin

v_7seg0 : v_7seg port map (segin => data,segout => segout);

with sin select

qout <= "1000" when "00" ,

"0100" when "01",

"0010" when "10",

"0001" when others;

with sin select

data <= d_in(15 downto 12) when "00",

d_in(11 downto 8) when "01",

d_in(7 downto 4) when "10",

d_in(3 downto 0) when others ;

end rtl;

v_4disp

29

(31)

package

(my_pkg)

加入一個

component

計2個

component

v_7seg

v_4disp

library ieee

;

use ieee

.

std_logic_1164

.

all

;

package

my_pkg

is

component

v_7seg

port

(segin :

in std_logic_vector

(3

downto

0);

segout :

out std_logic_vector

(6

downto

0));

end component

;

component

v_4disp

port

(d_in :

in std_logic_vector

(15

downto

0);

sin :

in std_logic_vector

(1

downto

0);

segout :

out std_logic_vector

(6

downto

0);

qout :

out std_logic_vector

(3

downto

0));

end component

;

(32)

m_4disp

1234

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_4disp is port

(

clk : in std_logic;

qout : out std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0) );

end entity;

architecture rtl of m_4disp is

signal fd : std_logic_vector(1 downto 0);

begin

v_4disp0 : v_4disp port map (d_in=>(x"1234"),sin=>fd(1 downto 0),qout=>qout,segout=>segout);

process (clk) begin if rising_edge(clk) then fd<=fd+1; end if; end process; end rtl;

(33)

m_7seg

(34)

v_4disp

RTL view

v_7seg

(35)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_4disp is port

(

clk : in std_logic;

qout : out std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0) );

end entity;

architecture rtl of m_4disp is

signal fd : std_logic_vector(20 downto 0);

signal

cnt :

std_logic_vector

(15

downto

0);

begin

v_4disp0 : v_4disp port map (d_in=>cnt,sin=>fd(1 downto 0),qout=>qout,segout=>segout);

process (clk) begin if rising_edge(clk) then fd<=fd+1; end if; end process;

process

(fd(20))

begin

if rising_edge

(fd(20))

then

cnt<=cnt+1;

end if

;

end process

;

end rtl;

m_4disp

(36)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_4disp is port

(

clk : in std_logic;

qout : out std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0) );

end entity;

architecture rtl of m_4disp is

signal fd : std_logic_vector(20 downto 0);

signal

cnt :

std_logic_vector

(15

downto

0);

begin

v_4disp0 : v_4disp port map (d_in=>cnt,sin=>fd(1 downto 0),qout=>qout,segout=>segout);

process (clk) begin if rising_edge(clk) then fd<=fd+1; end if; end process;

process

(fd(20))

begin

if rising_edge

(fd(20))

then

cnt<=cnt+1;

end if

;

end process

;

end rtl;

m_4disp

(37)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_4disp is port

(

clk : in std_logic;

qout : out std_logic_vector(3 downto 0);

segout : out std_logic_vector(6 downto 0) );

end entity;

architecture rtl of m_4disp is

signal fd : std_logic_vector(20 downto 0);

signal

cnt :

std_logic_vector

(15

downto

0);

begin

v_4disp0 : v_4disp port map (d_in=>cnt,sin=>fd(1 downto 0),qout=>qout,segout=>segout);

process (clk) begin if rising_edge(clk) then fd<=fd+1; end if; end process;

process

(fd(20))

begin

if rising_edge

(fd(20))

then

cnt<=cnt+1;

end if

;

end process

;

end rtl;

m_4disp

(38)
(39)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity key_ci is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic; pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : buffer std_logic);

end entity;

architecture rtl of key_ci is

signal Scnt : std_logic_vector(1 downto 0);

signal keyin: std_logic;

begin

keyin <= kin0 or kin4 or kin8; ken <= '1' when pcnt=6 else '0'; key <= kin8 & kin4 & Scnt;

with Scnt select

kout <= "0001“ when "00", "0010" when "01“, "0100“ when "10“, "1000" when "11";

process (pck,keyin) begin if keyin='0' then

pcnt <= "000"

elsif rising_edge (pck) then if pcnt /=7 then pcnt <= pcnt+1; end if; end if; end process; process (clk) begin if rising_edge (clk) then if keyin='0' then Scnt <= Scnt+1; end if; end if; end process; end rtl;

Key_ci

ken=1時按鍵有效(已防彈跳)

key為鍵值

(40)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity key_ci is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic; pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : buffer std_logic);

end entity;

architecture rtl of key_ci is

signal Scnt : std_logic_vector(1 downto 0);

signal keyin: std_logic;

begin

keyin <= kin0 or kin4 or kin8; ken <= '1' when pcnt=6 else '0'; key <= kin8 & kin4 & Scnt;

with Scnt select

kout <= "0001“ when "00", "0010" when "01“, "0100“ when "10“, "1000" when others;

process (pck,keyin) begin if keyin='0' then

pcnt <= "000"

elsif rising_edge (pck) then if pcnt /=7 then pcnt <= pcnt+1; end if; end if; end process; process (clk) begin if rising_edge (clk) then if keyin='0' then Scnt <= Scnt+1; end if; end if; end process; end rtl;

Key_ci

ken=1時按鍵有效(已防彈跳)

key為鍵值

(41)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity key_ci is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic; pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : buffer std_logic);

end entity;

architecture rtl of key_ci is

signal Scnt : std_logic_vector(1 downto 0);

signal keyin: std_logic;

begin

keyin <= kin0 or kin4 or kin8; ken <= '1' when pcnt=6 else '0'; key <= kin8 & kin4 & Scnt;

process (Scnt) begin case Scnt is when "00" => kout <= "0001"; when "01" => kout <= "0010"; when "10" => kout <= "0100"; when "11" => kout <= "1000"; end case; end process;

process (pck,keyin) begin if keyin='0' then

pcnt <= "000"

elsif rising_edge (pck) then if pcnt /=7 then pcnt <= pcnt+1; end if; end if; end process; process (clk) begin if rising_edge (clk) then if keyin='0' then Scnt <= Scnt+1; end if; end if; end process; end rtl;

Key_ci

ken=1時按鍵有效(已防彈跳)

key為鍵值

(42)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity key_ci is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic; pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : buffer std_logic);

end entity;

architecture rtl of key_ci is

signal Scnt : std_logic_vector(1 downto 0);

signal keyin: std_logic;

begin

keyin <= kin0 or kin4 or kin8; ken <= '1' when pcnt=6 else '0'; key <= kin8 & kin4 & Scnt;

process (Scnt) begin case Scnt is

when "00" => kout <= "0001";

when "01" => kout <= "0010";

when "10" => kout <= "0100";

when others => kout <= "1000";

end case;

end process;

process (pck,keyin) begin if keyin='0' then

pcnt <= "000"

elsif rising_edge (pck) then if pcnt /=7 then pcnt <= pcnt+1; end if; end if; end process; process (clk) begin if rising_edge (clk) then if keyin='0' then Scnt <= Scnt+1; end if; end if; end process; end rtl;

Key_ci

ken=1時按鍵有效(已防彈跳)

key為鍵值

(43)
(44)
(45)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity m_key is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic;

kout : out std_logic_vector(3 downto 0);

seg7_code : out std_logic_vector(6 downto 0));

end entity;

architecture rtl of m_key is

signal key,segin : std_logic_vector(3 downto 0);

signal fd : std_logic_vector(10 downto 0);

signal ken : std_logic;

begin

key_ci0 : key_ci port map(clk=>clk, pck=>fd(10), kin0=>kin0,kin4=>kin4,kin8=>kin8,kout=>kout,key=>key,ken=>ken); v_7seg0 : v_7seg port map(segin=>segin,segout=>seg7_code);

segin <= key when ken='1';

process (clk) begin if rising_edge (clk) then fd <= fd+1; end if; end process; end rtl;

m_Key

(栓鎖)

按鍵,七段顯示

(46)
(47)

VHDL

(48)

七段解碼

a

b

c

d

e

f

g

A

VCC

B

C

D

Segin[3:0]

Segout[6:0]

library ieee; use ieee.std_logic_1164.all; entity v_7seg is

port (segin : in std_logic_vector(3 downto 0); segout : out std_logic_vector (6 downto 0)); end entity;

architecture rtl of v_7seg is begin

with segin select

segout <= "1000000" when x"0", "1111001" when x"1", "0100100" when x"2", "0110000" when x"3", "0011001" when x"4", "0010010" when x"5", "0000010" when x"6", "1111000" when x"7", "0000000" when x“8", "0010000" when x"9", "0001000" when x"a", "0000011" when x"b", "1000110" when x"c", "0100001" when x"d", "0000110" when x"e", "0001110" when others; end rtl;

(49)

library ieee;

use ieee.std_logic_1164.all;

use work.my_pkg.all;

entity v_4disp is port

(d_in : in std_logic_vector(15 downto 0);

sin : in std_logic_vector(1 downto 0);

segout : out std_logic_vector(6 downto 0);

qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of v_4disp is

signal data : std_logic_vector(3 downto 0);

begin

v_7seg0 : v_7seg port map (segin => data,segout => segout);

with sin select

qout <= "1000" when "00" ,

"0100" when "01",

"0010" when "10",

"0001" when others;

with sin select

data <= d_in(15 downto 12) when "00",

d_in(11 downto 8) when "01",

d_in(7 downto 4) when "10",

d_in(3 downto 0) when others ;

end rtl;

v_4disp

29

(50)

library ieee

;

use ieee

.

std_logic_1164

.

all

;

use work

.my_pkg.

all

;

entity

v_2disp

is port

(d_in :

in std_logic_vector

(7

downto

0);

sin :

in std_logic

;

segout :

out std_logic_vector

(6

downto

0);

qout :

out std_logic_vector

(1

downto

0));

end entity

;

architecture

rtl

of

v_2disp

is

signal

data :

std_logic_vector

(3

downto

0);

begin

v_7seg0 : v_7seg

port map

(segin => data,segout => segout);

with

sin

select

qout <= "10"

when

‘0’ ,

"01"

when

others

;

with

sin

select

data <= d_in(7

downto

4)

when

‘0’,

d_in(3

downto

0)

when

others

;

end

rtl;

v_4disp

(51)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity key_ci is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic; pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : buffer std_logic);

end entity;

architecture rtl of key_ci is

signal Scnt : std_logic_vector(1 downto 0);

signal keyin: std_logic;

begin

keyin <= kin0 or kin4 or kin8; ken <= '1' when pcnt=6 else '0'; key <= kin8 & kin4 & Scnt;

with Scnt select

kout <= "0001“ when "00", "0010" when "01“, "0100“ when "10“, "1000" when others;

process (pck,keyin) begin if keyin='0' then

pcnt <= "000"

elsif rising_edge (pck) then if pcnt /=7 then pcnt <= pcnt+1; end if; end if; end process; process (clk) begin if rising_edge (clk) then if keyin='0' then Scnt <= Scnt+1; end if; end if; end process; end rtl;

Key_ci

ken=1時按鍵有效(已防彈跳)

key為鍵值

(52)

package

(my_pkg)

4個

component

v_7seg

v_4disp

v_2disp

key_ci

library ieee;

use ieee.std_logic_1164.all;

package my_pkg is component v_7seg port

(segin : in std_logic_vector(3 downto 0); segout : out std_logic_vector(6 downto 0));

end component;

component v_4disp port

(d_in : in std_logic_vector(15 downto 0); sin : in std_logic_vector(1 downto 0); qout : out std_logic_vector(3 downto 0); segout : out std_logic_vector(6 downto 0));

end component;

component v_2disp port

(d_in : in std_logic_vector(7 downto 0); sin : in std_logic;

qout : out std_logic_vector(1 downto 0); segout : out std_logic_vector(6 downto 0));

end component;

component key_ci port

(clk,kin0,kin4,kin8,pck : in std_logic;

kout,key : out std_logic_vector(3 downto 0); ken : out std_logic);

end component;

(53)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數,

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(54)

• 當按0~9鍵時,

移位:(

異步載入

)(

順序載入

)

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

(55)

• 當按0~9鍵時,十位<=個位

load1

移位:(

異步載入

)(

順序載入

)

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

(56)

• 當按0~9鍵時,十位<=個位

load1

個位<=按鍵值

load2

移位:(

異步載入

)(

順序載入

)

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

(57)

• 當按0~9鍵時,十位<=個位

load1

個位<=按鍵值

load2

移位:(

異步載入

)(

順序載入

)

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

process

(pck)

begin

if rising_edge

(pck)

then

if

key<=9

then

load1<=ken;

end if;

load2<=load1;

end if

;

end process

;

load1,load2皆是cnt的敏感源;

敏感源不適合用組合邏輯產生,

用正反器防雜訊

(58)

• 當按0~9鍵時,十位<=個位

load1

個位<=按鍵值

load2

移位:(

異步載入

)(

順序載入

)

process

(pck)

begin

if rising_edge

(pck)

then

if

key<=9

then

load1<=ken;

end if;

load2<=load1;

if

key=x”b”

then

clr<=ken;

end if;

end if

;

end process

;

p ck

k en

lo ad1

lo ad2

clr

clr亦是cnt的敏感源;

敏感源不適合用組合邏輯產生,

用正反器防雜訊

(59)

process

(pck)

begin

if rising_edge

(pck)

then

if

key<=9

then

load1 <= ken;

end if

;

load2<=load1;

if

key=x”b”

then

clr <= ken;

end if

;

end if

;

end process

;

clr,load1,load2皆是cnt的敏感源;

敏感源不適合用組合邏輯產生,

用正反器防雜訊

CLK D Q lo ad1 CLK D Q lo ad2 0 1 CLK D Q clr 0 1 k en k en p ck p ck k ey <=9 k ey =x"b "

p ck

k en

lo ad1

lo ad2

clr

(60)

• 當按0~9鍵時,

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數,

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(61)

• 當按0~9鍵時,十位<=個位

load1

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數,

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(62)

• 當按0~9鍵時,十位<=個位

load1

個位<=按鍵值

load2

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數,

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(63)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數,

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(64)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(65)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)(

ck2

)

再按一次b鍵,停止下數,

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(66)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)(

ck2

)

再按一次b鍵,停止下數, (

dec=0

)

再按一次b鍵,開始下數。

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(67)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)(

ck2

)

再按一次b鍵,停止下數, (

dec=0

)

再按一次b鍵,開始下數。 (

dec=1

)

下數時,下數至0時,停止下數

• 當按 a鍵時,顯示清除為0。

(68)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)(

ck2

)

再按一次b鍵,停止下數, (

dec=0

)

再按一次b鍵,開始下數。 (

dec=1

)

下數時,下數至0時,停止下數 (

zero=1

,

dec=0

)

• 當按 a鍵時,顯示清除為0。

(69)

• 當按0~9鍵時,十位<=個位

個位<=按鍵值

移位:(

異步載入

)(

順序載入

)

• 當按b鍵時,開始下數, (

dec=1

)(

ck2

)

再按一次b鍵,停止下數, (

dec=0

)

再按一次b鍵,開始下數。 (

dec=1

)

下數時,下數至0時,停止下數 (

zero=1

,

dec=0

)

• 當按 a鍵時,顯示清除為0。 (

clr=1

)

(70)
(71)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity key_asy is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic;

kout : out std_logic_vector(3 downto 0); segout : out std_logic_vector(6 downto 0); qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of key_asy is

signal key : std_logic_vector(3 downto 0);

signal fd : std_logic_vector(12 downto 0);

signal ck2,pck,dec,ken,load1,load2: std_logic;

signal dec_en,clr,zero: std_logic;

signal cnt : std_logic_vector(7 downto 0):=x"00";

signal q : std_logic_vector(1 downto 0);

begin

key_ci0 : key_ci port map(clk=>clk,kin0=>kin0,kin4=>kin4,kin8=>kin8,pck=>pck,kout=>kout,key=>key,ken=>ken); v_2disp0 : v_2disp port map(d_in=>cnt,sin=>fd(0),qout=>q,segout=>segout);

qout<=(”00” & q);

dec_en <= ken when key=x“b” else ‘0’; --是否按b鍵,每按一次b鍵時ken為產生一個正脈波,寬度為pck週期

pck <= fd(15);

zero <= ‘1’when dig=x“0000” else ‘0’; --計數顯示是否為0

(72)

process

(ck2)

begin

if

clr='1'

then

cnt <= x"00";

elsif

load1=‘1’

then

cnt(7

downto

4) <= cnt(3

downto

0);

elsif

load2=‘1’

then

cnt(3

downto

0) <= key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=x"0"

then

cnt(3

downto

0) <= x"9";

cnt(7

downto

4) <= cnt(7

downto

4)-1;

else

cnt(3

downto

0) <= cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

當按 a鍵時,顯示清除為0 (

clr=1

)

CLK

clr

D

Q

lo ad

in

cnt[7 :4 ]

CLK

clr

D

Q

lo ad

in

cnt[3 :0 ]

- 1

0

1

dec

loa d1

loa d2

c k2

key

c lr

(73)

process

(ck2)

begin

if

clr='1'

then

cnt <= x"00";

elsif

load1=‘1’

then

cnt(7

downto

4) <= cnt(3

downto

0);

elsif

load2=‘1’

then

cnt(3

downto

0) <= key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=x"0"

then

cnt(3

downto

0) <= x"9";

cnt(7

downto

4) <= cnt(7

downto

4)-1;

else

cnt(3

downto

0) <= cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

當按 a鍵時,顯示清除為0 (

clr=1

)

CLK

clr

D

Q

lo ad

in

cnt[7 :4 ]

CLK

clr

D

Q

lo ad

in

cnt[3 :0 ]

- 1

0

1

dec

loa d1

loa d2

c k2

key

c lr

(74)

CLK

clr

D

Q

lo ad

in

cnt[7 :4 ]

CLK

clr

D

Q

lo ad

in

cnt[3 :0 ]

- 1

0

1

dec

loa d1

loa d2

c k2

key

c lr

process

(ck2)

begin

if

clr='1'

then

cnt <= x"00";

elsif

load1=‘1’

then

cnt(7

downto

4) <= cnt(3

downto

0);

elsif

load2=‘1’

then

cnt(3

downto

0) <= key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=x"0"

then

cnt(3

downto

0) <= x"9";

cnt(7

downto

4) <= cnt(7

downto

4)-1;

else

cnt(3

downto

0) <= cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

當按 a鍵時,顯示清除為0 (

clr=1

)

(75)

CLK

clr

D

Q

lo ad

in

cnt[7 :4 ]

CLK

clr

D

Q

lo ad

in

cnt[3 :0 ]

- 1

0

1

dec

loa d1

loa d2

c k2

key

c lr

process

(ck2)

begin

if

clr='1'

then

cnt <= x"00";

elsif

load1=‘1’

then

cnt(7

downto

4) <= cnt(3

downto

0);

elsif

load2=‘1’

then

cnt(3

downto

0) <= key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=x"0"

then

cnt(3

downto

0) <= x"9";

cnt(7

downto

4) <= cnt(7

downto

4)-1;

else

cnt(3

downto

0) <= cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

當按 a鍵時,顯示清除為0 (

clr=1

)

(76)

CLK

clr

D

Q

lo ad

in

cnt[7 :4 ]

CLK

clr

D

Q

lo ad

in

cnt[3 :0 ]

- 1

0

1

dec

loa d1

loa d2

c k2

key

c lr

當按 a鍵時,顯示清除為0 (

clr=1

)

process

(ck2,clr,load1,load2)

begin

if

clr='1'

then

cnt <= x"00";

elsif

load1=‘1’

then

cnt(7

downto

4) <= cnt(3

downto

0);

elsif

load2=‘1’

then

cnt(3

downto

0) <= key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=x"0"

then

cnt(3

downto

0) <= x"9";

cnt(7

downto

4) <= cnt(7

downto

4)-1;

else

cnt(3

downto

0) <= cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

(77)

p ck

k en

lo ad1

lo ad2

clr

process

(pck)

begin

if rising_edge

(pck)

then

if

key<=9

then

load1 <= ken;

end if

;

load2<=load1;

if

key=x”b”

then

clr <= ken;

end if

;

end if

;

end process

;

clr,load1,load2皆是cnt的敏感源;

敏感源不適合用組合邏輯產生,

用正反器防雜訊

CLK D Q lo ad1 CLK D Q lo ad2 0 1 CLK D Q clr 0 1 k en k en p ck p ck k ey <=9 k ey =x"b "

(78)

process

(pck)

begin

if rising_edge

(pck)

then

if

key<=9

then

load1 <= ken;

end if

;

load2<=load1;

if

key=x”b”

then

clr <= ken;

end if

;

end if

;

end process

;

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

clr,ioad1,load2皆是cnt的敏感源;

敏感源不適合用組合邏輯產生,

用正反器防雜訊

CLK D Q lo ad1 CLK D Q lo ad2 0 1 CLK D Q clr 0 1 k en k en p ck p ck k ey <=9 k ey =x"b "

(79)

process (pck) begin

if (load1='1' or zero=‘1’) then dec <= '0';

elsif falling_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

k en

鍵碼

=b

d ec_ en

p ck

1

b

一次反相一次

zero

ken2

CLK

D Q

clr

ena

d ec

load1

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

下數至0000時,

dec設為0(停止下數)

load1

(80)

process (pck) begin

if (load1='1' or zero=‘1’) then dec <= '0';

elsif falling_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

k en

鍵碼

=b

d ec_ en

p ck

1

b

一次反相一次

zero

ken2

CLK

D Q

clr

ena

d ec

load1

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

當按b鍵時,

load1

(81)

process (pck) begin

if (load1='1' or zero=‘1’) then dec <= '0';

elsif falling_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

k en

鍵碼

=b

d ec_ en

p ck

1

b

一次反相一次

zero

ken2

CLK

D Q

clr

ena

d ec

load1

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

當按b鍵時,

load1

(82)

process (pck) begin

if (load1='1' or zero=‘1’) then dec <= '0';

elsif falling_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

k en

鍵碼

=b

d ec_ en

p ck

1

b

一次反相一次

zero

ken2

CLK

D Q

clr

ena

d ec

load1

p ck

k en

lo ad1

lo ad2

d ec

反相

p ck

負緣

d ec_ en

ck2

正緣

p ck

負緣

當按b鍵時,

dec設為反相

(下數變為停止下數,

停止下數變為下數)

load1

(83)

process (pck) begin if rising_edge (pck) then if key<=9 then load1 <= ken; end if; load2 <= load1; if key=x”b” then clr <= ken; end if; end if; end process; process (clk) begin if rising_edge (clk) then fd <= fd+1; end if; end process; process (pck) begin

if (load1=‘1’ or zero='1‘) then dec <= '0';

elsif rising_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

按數字鍵

產生移位脈波

load1及load2

按數字鍵或下數至00時,

Dec設為0(停止下數)

當按b鍵時,

dec設為反相

(下數變為停止下數,

停止下數變為下數)

除頻電路

process (ck2,clr,load1,loaq2) begin if clr='1' then cnt <= x"00";

elsif load1=‘1')then

cnt(7 downto 4) <= cnt(3 downto 0);

elsif load2=‘1')then

cnt(3 downto 0) <= key;

elsif rising_edge (ck2) then if dec='1' then if cnt(3 downto 0)=x"0" then cnt(3 downto 0) <= x"9"; cnt(7 downto 4) <= cnt(7 downto 4)-1; else cnt(3 downto 0) <= cnt(3 downto 0)-1; end if; end if; end if; end process; end rtl;

(84)

process (pck) begin if rising_edge (pck) then if key<=9 then load1 <= ken; end if; load2 <= load1; if key=x”b” then clr <= ken; end if; end if; end process; process (clk) begin if rising_edge (clk) then fd <= fd+1; end if; end process; process (pck) begin

if (load1=‘1’ or zero='1‘) then dec <= '0';

elsif rising_edge (pck) then if dec_en='1' then

dec <= not dec;

end if; end if; end process;

按數字鍵

產生移位脈波

load1及load2

按數字鍵或下數至00時,

Dec設為0(停止下數)

當按b鍵時,

dec設為反相

(下數變為停止下數,

停止下數變為下數)

除頻電路

process (ck2,clr,load1,loaq2) begin if clr='1' then cnt <= x"00";

elsif load1=‘1')then

cnt(7 downto 4) <= cnt(3 downto 0);

elsif load2=‘1')then

cnt(3 downto 0) <= key;

elsif rising_edge (ck2) then if dec='1' then if cnt(3 downto 0)=x"0" then cnt(3 downto 0) <= x"9"; cnt(7 downto 4) <= cnt(7 downto 4)-1; else cnt(3 downto 0) <= cnt(3 downto 0)-1; end if; end if; end if; end process; end rtl;

(85)

library ieee

;

use ieee

.

std_logic_1164

.

all

;

use ieee

.

std_logic_unsigned

.

all

;

use work

.my_pkg.

all

;

entity

key43_asy

is

port

(clk,kin0,kin4,kin8 :

in std_logic

;

--5

kout :

out std_logic_vector

(3

downto

0);

--4,9

qout :

out std_logic_vector

(3

downto

0);

--4,13

segout :

out std_logic_vector

(6

downto

0);

--7,20

end entity

;

architecture

rtl

of

key43_asy

is

signal

key :

std_logic_vector

(3

downto

0);

signal

cnt :

std_logic_vector

(7

downto

0):=x"00";

signal

fd :

std_logic_vector

(21

downto

0):="0000000000000000000000";

signal

pck,ck2,ken,dec_en,zero :

std_logic

;

signal

clr,dec,load1,load2 :

std_logic

:='0';

(86)

Begin

key43_0 : key43 port map(clk=>clk,pck=>pck,kin0=>kin0,kin4=>kin4,kin8=>kin8,kout=>kout,key=>key,ken=>ken); v_2disp0 : v_2disp port map(d_in=>cnt,sin=>fd(0),qout=>q,segout=>segout);

qout<=("00" & q);

zero<='1' when cnt=0 else '0'; pck<=fd(15);ck2<=fd(20);

process (pck) begin

if rising_edge(pck) then

if key<=9 then load1<=ken; end if;

load2<=load1;

if key=x"b" then clr<=ken; end if; end if; end process; process (clk) begin if rising_edge(clk) then fd <= fd+1; end if; end process;

process (pck,load1,zero) begin

if (zero='1'or load1='1') then dec<='0'; elsif load1='1' then dec<='0';

elsif falling_edge (pck) then

if dec_en='1' then dec<=not dec; end if;

end if;

(87)

process

(ck2,clr,load1,load2)

begin

if

clr='1'

then

cnt<=(

others

=>'0');

elsif

load1='1'

then

cnt(7

downto

4)<=cnt(3

downto

0);

elsif

load2='1'

then

cnt(3

downto

0)<=key;

elsif rising_edge

(ck2)

then

if

dec='1'

then

if

cnt(3

downto

0)=0

then

cnt(3

downto

0)<=x"9";

cnt(7

downto

4)<=cnt(7

downto

4)-1;

else

cnt(3

downto

0)<=cnt(3

downto

0)-1;

end if

;

end if

;

end if

;

end process

;

end

rtl;

(88)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use work.my_pkg.all;

entity key_asy is port

(clk : in std_logic;

kin0,kin4,kin8 : in std_logic;

kout : out std_logic_vector(3 downto 0); segout : out std_logic_vector(6 downto 0); qout : out std_logic_vector(3 downto 0));

end entity;

architecture rtl of key_asy is

signal key : std_logic_vector(3 downto 0);

signal fd : std_logic_vector(12 downto 0);

signal ck2,pck,ken,dec_en,zero : std_logic;

signal dec,clr,load1,load2 : std_logic :=‘0’;

signal cnt : std_logic_vector(7 downto 0):=x"00";

signal q: std_logic_vector(1 downto 0);

begin

key_ci0 : key_ci port map(clk=>clk,kin0=>kin0,kin4=>kin4,kin8=>kin8,pck=>pck,kout=>kout,key=>key,ken=>ken); v_2disp0 : v_2disp port map(d_in=>cnt,sin=>fd(0),qout=>qout,segout=>segout);

qout<=(“00” & q);

dec_en <= ken when key=x"b" else '0'; pck <= fd(15);ck2<=fd(20);

zero <= '1'when cnt=x"00" else '0';

process (pck) begin

ifrising(pck) then ken2 <= '1';

if key<=9 then load1 <= ken;

end if; load2<=load1;

if key=x”b” then clr <= ken;

end if;

end if;

end process;

process (clk) begin

if rising_edge (clk) then fd <= fd+1;

end if; end process;

process (pck) begin

if (zero='1' or load1=‘1’) then dec <= '0';

elsif falling_edge (pck) then if dec_en='1' then dec <= not dec;

end if;

end if;

end process;

process (ck2,clr,load1,loaq2) begin if clr='1' then cnt <= x"00";

elsif load1=‘1')then

cnt(7 downto 4) <= cnt(3 downto 0);

elsif load2=‘1')then cnt(3 downto 0) <= key;

elsif rising_edge (ck2) then if dec='1' then if cnt(3 downto 0)=x"0" then cnt(3 downto 0) <= x"9"; cnt(7 downto 4) <= cnt(7 downto 4)-1; else cnt(3 downto 0) <= cnt(3 downto 0)-1; end if; end if; end if; end process; end rtl;

(89)
(90)
(91)
(92)
(93)

同步載入

• 移位

• 同步載入(同時載入)

• 下數與移位用同一觸發源(ck2)

• 每一按鍵祇能載入一次

(94)

ken and key<=9

pck

ck2

ken_pr

ken1

ken_clr

ken_pr

ken1

ken_clr

ken_pr

ken1

ken_clr

參考文獻

相關文件

能督導工程人員依施 工圖說之規定完成模 板材料之選用及模板

左邊有一個平面紙板圖形,右邊有數個立體圖型,左邊的紙板可合成右

200kW PAFC power plant built by UTC Fuel Cells.. The Solar

目錄的字型不一致 不一致 不一致 不一致 縮排格式.

FUNCTION ODD_par8 (DI: STD_LOGIC_VECTOR(7 DOWNTO 0) ) RETURN STD_LOGIC;. FUNCTION ODD_par81 (DI: BIT_VECTOR(7 DOWNTO 0))

1.分離板塊邊界(Divergent Plate Boundary) 2.聚合板塊邊界 (Convergent Plate Boundary).. Ch2 造岩礦物及板塊構造學說 Ch2

iTunes Course Manager. It act like

回顧樣本背光模組中的導光板設計,其 Face6 散射點佈放面,由 大小不同的散射點控制。Face1 光源入射面有 V 型槽結構,其 V 型 槽方向為平行 X 軸方向;Face5 導光板出光面亦有