VHDL Codes For Thermometer Projects Using Leds & LCD Display
VHDL Codes For Thermometer Projects Using Leds & LCD Display
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity TopLevel is
port (
kelvin: in std_logic;
HexDec: in std_logic;
SystemClock: in std_logic;
ClockOut: out std_logic;
Power: out std_logic;
CS: out std_logic;
MISO: in std_logic;
An: out std_logic_vector (5 downto 0);
Ca, Cb, Cc, Cd, Ce, Cf, Cg: out std_logic;
SFD: out std_logic_vector (3 downto 0);
LCDE, LCDRS, LCDRW: out std_logic);
end TopLevel;
component PULLDOWN
port ( O : out std_ulogic);
end component;
component Max6675
port ( SystemClock: in std_logic;
ClockOut: out std_logic;
Power: out std_logic;
MISO: in std_logic;
DataOut: out std_logic_vector (15 downto 0);
CS: out std_logic);
end component;
--component D4to7
-- port ( Q: in std_logic_vector (3 downto 0);
-- Seg: out std_logic_vector (6 downto 0));
--end component;
component Converter
port ( kelvin: in std_logic;
Hexdec : in std_logic;
q : in STD_LOGIC_VECTOR (15 downto 0);
seg1 : out STD_LOGIC_VECTOR (6 downto 0);
seg2 : out STD_LOGIC_VECTOR (6 downto 0);
1
seg3 : out STD_LOGIC_VECTOR (6 downto 0);
seg4 : out STD_LOGIC_VECTOR (6 downto 0);
seg5 : out STD_LOGIC_VECTOR (6 downto 0);
seg6 : out STD_LOGIC_VECTOR (6 downto 0);
lcd1 : out STD_LOGIC_VECTOR (3 downto 0);
lcd2 : out STD_LOGIC_VECTOR (3 downto 0);
lcd3 : out STD_LOGIC_VECTOR (3 downto 0);
lcd4 : out STD_LOGIC_VECTOR (3 downto 0));
end component;
component Scan4Digit
port ( Digit5, Digit4, Digit3, Digit2, Digit1, Digit0: in std_logic_vector(6 downto 0);
Clock: in std_logic; An : out std_logic_vector(5 downto 0);
Ca, Cb, Cc, Cd, Ce, Cf, Cg: out std_logic);
end component;
component LCD
port ( SystemClock: in std_logic;
lcd1: in STD_LOGIC_VECTOR (3 downto 0);
lcd2: in STD_LOGIC_VECTOR (3 downto 0);
lcd3: in STD_LOGIC_VECTOR (3 downto 0);
lcd4: in STD_LOGIC_VECTOR (3 downto 0);
LCDE : out std_logic;
LCDRS : out std_logic;
LCDRW : out std_logic;
SFD : out std_logic_vector (3 downto 0));
end component;
begin
--process (SystemClock)
-- begin
-- if rising_edge(SystemClock) then
-- if
-- iCount9 = "101001111101100011000000" then -- the divider is 11000000
-- iCount9 <= (others=>'0');
-- Clock123 <=
-- else iCount9 <= iCount9 + '1';
-- end if;
-- end if;
--
2
-- if rising_edge(SystemClock) then
-- if
-- iCount = "101000101" then -- the divider is 325, or "101000101"
-- iCount <= (others=>'0');
-- else iCount <= iCount + '1';
-- end if;
-- end if;
--end process;
3
U3: scan4digit port map (
Digit5 => iDigitOut5,
Digit4 => iDigitOut4,
Digit3 => iDigitOut3,
Digit2 => iDigitOut2,
Digit1 => iDigitOut1,
Digit0 => iDigitOut0,
Clock => SystemClock,
An => An,
Ca => Ca,
Cb => Cb,
Cc => Cc,
Cd => Cd,
Ce => Ce,
Cf => Cf,
Cg => Cg);
end Behavioral;
MAX 6675
entity Max6675 is
port ( SystemClock, MISO: in std_logic;
ClockOut: out std_logic;
Power: out std_logic;
DataOut: out std_logic_vector (15 downto 0);
CS: out std_logic);
end Max6675;
4
signal iClkDiv: std_logic_vector (3 downto 0);
signal iSClk: std_logic;
signal NoBits: std_logic_vector (3 downto 0);
signal iEnableDataOut: std_logic;
signal iDataOut: std_logic_vector (15 downto 0);
signal iShiftRegister: std_logic_vector (15 downto 0);
signal iCount9: std_logic_vector (23 downto 0);
begin
--CS Clock
--process (Clock1m, iReset)
--begin
-- if Clock1m'event and Clock1m = '0' then
-- iCS <= '0';
-- elsif Clock1m'event and Clock1m = '0' then
-- iCS<= '1';
-- end if;
-- end if;
--end process;
5
iCSEnable <= '1';
end if;
CS <= iCS;
--process (Clock1m)
--begin
-- if rising_edge(Clock1m) then
--
-- end if;
--end process;
6
end process;
case presState is
when stIdle =>
if iCSEnable = '1' then
nextState <= stData;
else
nextState <= stIdle;
end if;
when stData =>
if NoBits = "1110" then
iEnableDataOut <= '1';
nextState <= stStop;
else
iEnableDataOut <= '0';
nextState <= stData;
end if;
when stStop =>
nextState <= stRxdCompleted;
when stRxdCompleted =>
iReset <= '1';
nextState <= stIdle;
end case;
end process;
end Behavioral;
CONVERTER
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Converter is
Port ( --hexdec : in std_logic;
kelvin: in std_logic;
Hexdec: in std_logic;
q : in STD_LOGIC_VECTOR (15 downto 0);
7
seg1 : out STD_LOGIC_VECTOR (6 downto 0);
seg2 : out STD_LOGIC_VECTOR (6 downto 0);
seg3 : out STD_LOGIC_VECTOR (6 downto 0);
seg4 : out STD_LOGIC_VECTOR (6 downto 0);
seg5 : out STD_LOGIC_VECTOR (6 downto 0);
seg6 : out STD_LOGIC_VECTOR (6 downto 0);
lcd1: out STD_LOGIC_VECTOR (3 downto 0);
lcd2: out STD_LOGIC_VECTOR (3 downto 0);
lcd3: out STD_LOGIC_VECTOR (3 downto 0);
lcd4: out STD_LOGIC_VECTOR (3 downto 0));
end Converter;
begin
8
"1000111" when d1 = "01111" else
"0000000";
9
"0111101" when d4 = "01101" else
"1001111" when d4 = "01110" else
"1000111" when d4 = "01111" else
"0000000";
-- DEGREE CELCIUS --
deci2 <= 1 when deci>9 and deci<20 else
2 when deci>19 and deci<30 else
3 when deci>29 and deci<40 else
4 when deci>39 and deci<50 else
0;
10
"0111" when deci1 = 7 else
"1000" when deci1 = 8 else
"1001" when deci1 = 9 else
"0000";
c3 <= "0000";
c4 <= "0000";
-- KELVIN --
kelvin3 <= 1 when kelvin0>99 and kelvin0<200 else
2 when kelvin0>199 and kelvin0<300 else
3 when kelvin0>299 and kelvin0<400 else
4 when kelvin0>399 and kelvin0<500 else
5 when kelvin0>499 and kelvin0<600 else
6 when kelvin0>599 and kelvin0<700 else
7 when kelvin0>699 and kelvin0<800 else
8 when kelvin0>799 and kelvin0<900 else
9 when kelvin0>899 and kelvin0<1000 else
0;
11
"1011011" when kelvin1 = 5 else
"1011111" when kelvin1 = 6 else
"1110000" when kelvin1 = 7 else
"1111111" when kelvin1 = 8 else
"1111011" when kelvin1 = 9 else
"0000000";
12
"0111" when kelvin2 = 7 else
"1000" when kelvin2 = 8 else
"1001" when kelvin2 = 9 else
"0000";
k4 <= "0000";
process (hexdec)
begin
if kelvin = '0' then
if hexdec = '0' then
else
13
iSeg5 <= decseg5;
end if;
else
14
-- "0110000" when d2 = "000001" else
-- "1101101" when d2 = "000010" else
-- "1111001" when d2 = "00011" else
-- "0110011" when d2 = "00100" else
-- "1011011" when d2 = "00101" else
-- "1011111" when d2 = "00110" else
-- "1110000" when d2 = "00111" else
-- "1111111" when d2 = "01000" else
-- "1111011" when d2 = "01001" else
-- "1110111" when d2 = "01010" else
-- "0011111" when d2 = "01011" else
-- "1001110" when d2 = "01100" else
-- "0111101" when d2 = "01101" else
-- "1001111" when d2 = "01110" else
-- "1000111" when d2 = "01111" else
-- "0000000";
--
-- iSeg5 <= "1111110" when d3 = "00000" else
-- "0110000" when d3 = "000001" else
-- "1101101" when d3 = "000010" else
-- "1111001" when d3 = "00011" else
-- "0110011" when d3 = "00100" else
-- "1011011" when d3 = "00101" else
-- "1011111" when d3 = "00110" else
-- "1110000" when d3 = "00111" else
-- "1111111" when d3 = "01000" else
-- "1111011" when d3 = "01001" else
-- "1110111" when d3 = "01010" else
-- "0011111" when d3 = "01011" else
-- "1001110" when d3 = "01100" else
-- "0111101" when d3 = "01101" else
-- "1001111" when d3 = "01110" else
-- "1000111" when d3 = "01111" else
-- "0000000";
--
-- iSeg6 <= "1111110" when d4 = "00000" else
-- "0110000" when d4 = "000001" else
-- "1101101" when d4 = "000010" else
-- "1111001" when d4 = "00011" else
-- "0110011" when d4 = "00100" else
-- "1011011" when d4 = "00101" else
-- "1011111" when d4 = "00110" else
-- "1110000" when d4 = "00111" else
-- "1111111" when d4 = "01000" else
-- "1111011" when d4 = "01001" else
-- "1110111" when d4 = "01010" else
-- "0011111" when d4 = "01011" else
-- "1001110" when d4 = "01100" else
-- "0111101" when d4 = "01101" else
-- "1001111" when d4 = "01110" else
-- "1000111" when d4 = "01111" else
-- "0000000";
15
-- else
--
-- deci2 <= deci / 10;
-- deci1 <= deci mod 10;
--
-- Seg1 <= "1001110";
--
-- Seg2 <= "1100011";
--
-- Seg3 <= "1111110" when deci1 = 0 else
-- "0110000" when deci1 = 1 else
-- "1101101" when deci1 = 2 else
-- "1111001" when deci1 = 3 else
-- "0110011" when deci1 = 4 else
-- "1011011" when deci1 = 5 else
-- "1011111" when deci1 = 6 else
-- "1110000" when deci1 = 7 else
-- "1111111" when deci1 = 8 else
-- "1111011" when deci1 = 9 else
-- "0000000";
--
-- Seg4 <= "1111110" when deci2 = 0 else
-- "0110000" when deci2 = 1 else
-- "1101101" when deci2 = 2 else
-- "1111001" when deci2 = 3 else
-- "0110011" when deci2 = 4 else
-- "1011011" when deci2 = 5 else
-- "1011111" when deci2 = 6 else
-- "1110000" when deci2 = 7 else
-- "1111111" when deci2 = 8 else
-- "1111011" when deci2 = 9 else
-- "0000000";
--
-- Seg5 <= "0000000";
--
-- Seg6 <= "0000000";
end if;
end process;
16
end Behavioral;
SCAN4DIGIT
entity Scan4Digit is
Port ( digit0 : in STD_LOGIC_VECTOR (6 downto 0);
digit1 : in STD_LOGIC_VECTOR (6 downto 0);
digit2 : in STD_LOGIC_VECTOR (6 downto 0);
digit3 : in STD_LOGIC_VECTOR (6 downto 0);
digit4 : in STD_LOGIC_VECTOR (6 downto 0);
digit5 : in STD_LOGIC_VECTOR (6 downto 0);
clock : in STD_LOGIC;
an : out STD_LOGIC_VECTOR (5 downto 0);
ca : out STD_LOGIC;
cb : out STD_LOGIC;
cc : out STD_LOGIC;
cd : out STD_LOGIC;
ce : out STD_LOGIC;
cf : out STD_LOGIC;
cg : out STD_LOGIC);
end scan4Digit;
17
Cc <= iDigitOut(4);
Cd <= iDigitOut(3);
Ce <= iDigitOut(2);
Cf <= iDigitOut(1);
Cg <= iDigitOut(0);
end Behavioral;
LCD
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity LCD is
port ( SystemClock: in std_logic;
lcd1: in STD_LOGIC_VECTOR (3 downto 0);
lcd2: in STD_LOGIC_VECTOR (3 downto 0);
lcd3: in STD_LOGIC_VECTOR (3 downto 0);
lcd4: in STD_LOGIC_VECTOR (3 downto 0);
LCDE : out std_logic;
LCDRS : out std_logic;
LCDRW : out std_logic;
SFD : out std_logic_vector (3 downto 0));
end LCD;
signal iData1, iData2, iData3, iData4 : STD_LOGIC_VECTOR (7 downto 0):= (others=>'0'); -- Data to be
displayed
signal Startup : std_logic := '0'; -- Power-On Initialization ready
signal displayconfig : std_logic := '0'; -- Display configuration ready
signal startcount : std_logic_vector (20 downto 0):= (others=>'0');
signal colours : std_logic_vector (5 downto 0):= (others=>'0');
signal iLCDE, iLCDRS : std_logic := '0';
signal iSFD : std_logic_vector (3 downto 0):= (others=>'0');
signal changers1, changers2: std_logic := '0';
signal systemstart: std_logic:= '0';
signal systemstartup : std_logic_vector (25 downto 0):= (others=>'0');
signal iLCDEfake : std_logic := '0';
signal iSFDfake : std_logic_vector (3 downto 0);
18
-- variable timing : integer;
-- begin
-- timing <= 0;
-- if click'event and click = '1' then
-- timing <= timing + 1;
-- end if;
-- if timing>0 and timing<45 then
-- iSFD <= dataout(7 downto 4);
-- elsif timing>46 and timing<90 then
-- iSFD <= dataout (3 downto 0);
-- else
-- iSFD <= "0000";
-- end if;
-- if timing>3 and timing<18 then
-- iLCDE <= '1';
-- elsif timing>70 and timing<85 then
-- iLCDE <= '1';
-- else
-- iLCDE <= '0';
-- end if;
begin
19
"00111001" when lcd2 = "1001" else
"01000001" when lcd2 = "1010" else
"01000010" when lcd2 = "1011" else
"01000011" when lcd2 = "1100" else
"01000100" when lcd2 = "1101" else
"01000101" when lcd2 = "1110" else
"01000110" when lcd2 = "1111" else
"00110000";
-- START SYSTEM --
process (SystemClock)
begin
if Systemstart = '1' then
Systemstart <= '1';
systemstartup <= (others=>'0');
20
iSFDfake <= "0000";
iLCDEfake <= '0';
else
if SystemClock'event and SystemClock = '1' then
systemstartup <= systemstartup + '1';
end if;
if systemstartup = "10110111000110110000" then
iLCDEfake <= '1';
iSFDfake <= "0011";
elsif systemstartup = "10110111000110111100" then
iLCDEfake <= '0';
iSFDfake <= "0000";
elsif systemstartup = "11101001001010000100" then
iLCDEfake <= '1';
iSFDfake <= "0011";
elsif systemstartup = "11101001001010010000" then
iLCDEfake <= '0';
iSFDfake <= "0000";
elsif systemstartup = "11101010011000011000" then
iLCDEfake <= '1';
iSFDfake <= "0011";
elsif systemstartup = "11101010011000100100" then
iLCDEfake <= '0';
iSFDfake <= "0000";
elsif systemstartup = "11101010110111110100" then
iLCDEfake <= '1';
iSFDfake <= "0011";
elsif systemstartup = "11101010111000000000" then
iLCDEfake <= '0';
iSFDfake <= "0000";
-- function set
elsif systemstartup = "11101011010111010000" then
iSFDfake <= "0010";
elsif systemstartup = "111010110101110100101" then
iLCDEfake <= '1';
elsif systemstartup = "11101011010111011111" then
iLCDEfake <= '0';
elsif systemstartup = "11101011010111100000" then
iSFDfake <= "1000";
elsif systemstartup = "11101011011000010110" then
iLCDEfake <= '1';
elsif systemstartup = "11101011011000100010" then
iLCDEfake <= '0';
21
elsif systemstartup = "11101011110111111111" then
iLCDEfake <= '0';
elsif systemstartup = "11101011111000000000" then
iSFDfake <= "0110";
elsif systemstartup = "11101011111000110010" then
iLCDEfake <= '1';
elsif systemstartup = "11101011111000111110" then
iLCDEfake <= '0';
elsif systemstartup = "11101011111000111111" then
iSFDfake <= "0000";
-- display on/off
elsif systemstartup = "11101100011000001111" then
iLCDEfake <= '1';
elsif systemstartup = "11101100011000011011" then
iLCDEfake <= '0';
elsif systemstartup = "11101100011000011100" then
iSFDfake <= "1100";
elsif systemstartup = "11101100100000010000" then
iLCDEfake <= '1';
elsif systemstartup = "11101100100000011100" then
iLCDEfake <= '0';
elsif systemstartup = "11101100100000011101" then
iSFDfake <= "0000";
-- Clear display
elsif systemstartup = "11101100111111101101" then
iLCDEfake <= '1';
elsif systemstartup = "11101100111111111001" then
iLCDEfake <= '0';
elsif systemstartup = "11101100111111111001" then
iSFDfake <= "0001";
elsif systemstartup = "11101101000000101100" then
iLCDEfake <= '1';
elsif systemstartup = "11101101000000111000" then
iLCDEfake <= '0';
elsif systemstartup = "100000001000010001000" then
Systemstart <= '1';
-- else
-- iLCDEfake <= iLCDEfake;
-- iSFDfake <= iSFDfake;
-- Systemstart <= Systemstart;
end if;
end if;
end process;
-- SET COLOURS --
process (SystemClock)
begin
if Systemstart = '1' then
if SystemClock'event and SystemClock = '1' then
22
if colours="0" or colours ="10" or colours ="100" or colours ="110" or colours ="1000"
or colours ="1010" or colours ="1100" or colours ="1110" or colours ="10000" or colours ="10010" then
startcount <= startcount + '1';
iLCDRS <= '1';
if startcount = "10110" then -- 22 cycles / 440
ns
colours <= colours + '1';
startcount <= (others=>'0');
end if;
--end if;
23
-- SEND LCD_E --
process (Colours, startcount, iLCDEfake)
begin
if SystemStart = '1' then
if colours="0" or colours ="10" or colours ="100" or colours ="110" or colours ="1000" or colours
="1010" or colours ="1100" or colours ="1110" or colours ="10000" or colours ="10010" then
if startcount = "100" then
iLCDE <= '1';
end if;
if startcount = "10100" then
iLCDE <= '0';
end if;
end if;
else
iLCDE <= iLCDEfake;
end if;
end process;
-- SEND DATAS --
process (Colours, iSFDfake)
begin
if Systemstart = '1' then
if colours="0" then
iSFD <= iData1(7 downto 4);
changers1 <= '1';
end if;
if colours ="10" then
iSFD <= iData1(3 downto 0);
changers1 <= '1';
end if;
if colours ="100" then
iSFD <= iData2(7 downto 4);
changers1 <= '1';
end if;
if colours ="110" then
iSFD <= iData2(3 downto 0);
changers1 <= '1';
end if;
if colours ="1000" then
iSFD <= iData3(7 downto 4);
changers1 <= '1';
end if;
if colours ="1010" then
iSFD <= iData3(3 downto 0);
changers1 <= '1';
end if;
if colours ="1100" then
iSFD <= iData4(7 downto 4);
changers1 <= '1';
24
end if;
if colours ="1110" then
iSFD <= iData4(3 downto 0);
changers1 <= '1';
end if;
if colours ="10000" then
iSFD <= "0000";
changers1 <= '0';
end if;
if colours ="10010" then
iSFD <= "0001";
changers1 <= '0';
end if;
else
iSFD <= iSFDfake;
end if;
end process;
end Behavioral;
D4TO7
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
25
--use UNISIM.VComponents.all;
entity D4to7 is
Port ( q : in STD_LOGIC_VECTOR (3 downto 0);
seg : out STD_LOGIC_VECTOR (6 downto 0));
end D4to7;
26