Design 2 – Boolean logic

This design sets some of the LED’s to the results of using and, or, xor, and not. The inputs are controlled by the slide switches on the Digilent board. If this were a school lab, you would create a table that predicts the on/off status of each LED for all possible switch settings, and then record the LED statuses for each switch combination. As only two switches are used, there are only four switch combinations.

First, the VHDL version:

-- Logic
--
-- This illustrates the use of ordinary Boolean functions.
-- The LEDs display the results of combining the switch values
--   according to the associated Boolean function (aka operator).

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Logic is
    Port ( sw0 : in std_logic;
           sw1 : in std_logic;
           led0 : out std_logic;
           led1 : out std_logic;
           led2 : out std_logic;
           led3 : out std_logic;
           led4 : out std_logic
    );
end Logic;

architecture Behavioral of Logic is

begin

    led0 <= sw0 and sw1;
    led1 <= sw0  or sw1;
    led2 <= sw0 xor sw1;
    led3 <= sw0;
    led4 <= not sw0;

end Behavioral;

Next, the Verilog version:

// Logic
//
// This illustrates the use of ordinary Boolean functions.
// The LEDs display the results of combining the switch values
//   according to the associated Boolean function (aka operator).

module Logic (
    input  sw0,
    input  sw1,
    output led0,
    output led1,
    output led2,
    output led3,
    output led4
    );

    assign led0 = sw0 & sw1;	// AND function
    assign led1 = sw0 | sw1;	// OR function
    assign led2 = sw0 ^ sw1;	// XOR function
    assign led3 = sw0;
    assign led4 = ~ sw0;    	// NOT function

endmodule