用VHDL語法撰寫的四合一的七段顯示器解碼器原始碼:
ibrary ieee;
use ieee.std_logic_1164.all;
entity seven_seg_4in1 is
port( com_in: in std_logic_vector(1 downto 0);
num_in: in std_logic_vector(3 downto 0);
com_out: out std_logic_vector(3 downto 0);
num_out: out std_logic_vector(7 downto 0)
);
end seven_seg_4in1;
architecture x of seven_seg_4in1 is
begin
with com_in select
com_out <= "0001" when "00",
"0010" when "01",
"0100" when "10",
"1000" when "11",
"0000" when others;
with num_in select
num_out<="11000000" when "0000",
"11111001" when "0001",
"10100100" when "0010",
"10110000" when "0011",
"10011001" when "0100",
"10010010" when "0101",
"10000010" when "0110",
"11111000" when "0111",
"10000000" when "1000",
"10011000" when "1001",
"10001000" when "1010",
"10000011" when "1011",
"11000110" when "1100",
"10100001" when "1101",
"10000110" when "1110",
"10001110" when "1111";
end x;
腳位配置圖(Pin Asignment)
Arduino 端的程式碼:
#define com_in_0 4
#define com_in_1 5
#define num_in_0 8
#define num_in_1 9
#define num_in_2 10
#define num_in_3 11
void setup() {
pinMode(com_in_0, OUTPUT);
pinMode(com_in_1, OUTPUT);
pinMode(num_in_0, OUTPUT);
pinMode(num_in_1, OUTPUT);
pinMode(num_in_2, OUTPUT);
pinMode(num_in_3, OUTPUT);
}
void loop() {
int i, j;
for(j=0; j<4; j++)
{
digitalWrite(com_in_1, (j>>1)&1);
digitalWrite(com_in_0, j&1);
for(i=0; i<16; i++)
{
digitalWrite(num_in_3, (i>>3)&1);
digitalWrite(num_in_2, (i>>2)&1);
digitalWrite(num_in_1, (i>>1)&1);
digitalWrite(num_in_0, i&1);
delay(300);
}
}
}
執行結果:
沒有留言:
張貼留言