Created
November 29, 2016 14:49
-
-
Save nesteruk/0c345468b140682fba6c073d54b97e26 to your computer and use it in GitHub Desktop.
Partial failure in record type update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library ieee; | |
use ieee.std_logic_1164.all; | |
library ps; | |
use ps.hex_conv.all; | |
entity light is | |
port( | |
clock_50 : in std_logic; | |
hex0, hex1, hex2, hex3 : out std_logic_vector(0 to 6); | |
key : in std_logic_vector(0 to 3); | |
sw : in std_logic_vector(0 to 9); | |
ledr : buffer std_logic_vector(0 to 9); | |
ledg : buffer std_logic_vector(0 to 7); | |
btn : in std_logic_vector(0 to 3) | |
); | |
end light; | |
architecture arch of light is | |
subtype hex_digit is std_logic_vector(0 to 6); | |
type hex_digit_array is array(natural range<>) of hex_digit; | |
constant digits : hex_digit_array := | |
( | |
"0000001", "1001111", "0010010", "0000110", "1001100", | |
"0100100", "0100000", "0001111", "0000000", "0000100" | |
); | |
subtype digit is integer range 0 to 9; | |
function get_hex_digit(d:digit) return hex_digit is | |
begin | |
return digits(d); | |
end function; | |
type temp_unit is (celcius, fahrenheit); | |
type hex_temp_array is array(temp_unit range <>) of hex_digit; | |
constant temp_char_array : hex_temp_array(celcius to fahrenheit) := | |
("0110001", "0111000"); | |
type temp_setting is record | |
temp: integer range 0 to 99; | |
unit : temp_unit; | |
end record; | |
signal setting : temp_setting := (25, celcius); | |
begin | |
hex3 <= get_hex_digit(setting.temp / 10); | |
hex2 <= get_hex_digit(setting.temp rem 10); | |
hex1 <= "0011100"; | |
hex0 <= temp_char_array(setting.unit); | |
warmer: process(btn) | |
begin | |
if (btn(0)'event and btn(0) = '1') then | |
setting.temp <= 0; | |
end if; | |
end process; | |
process(sw) | |
begin | |
if (sw(0) = '0') then | |
setting.unit <= celcius; | |
else | |
setting.unit <= fahrenheit; | |
end if; | |
end process; | |
end architecture arch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment