/*
*
*	University of Oregon PHYS 432 - Lab 5 PAL Example 1
*	This example shows how CUPL can be used to create
*       non-trivial decoders and other combinatoric logic.
*
*	This program decodes a 3-bit input word to make
*       a bar display for LEDs.
*
*/

Name            ledenc;
Partno          PHYS432;
Revision        01;
Date            20/03/2006;
Designer        E. Torrence;
Company         University of Oregon;
Location        None;
Assembly        None;
Device          g16v8;

/** Inputs **/

/* Note, in simple mode, pin 1 can be used as a regular input.
* In registered mode (state machine) pin 1 has to be the clock.
*/
pin  [1..3] = [in0..2];		/* 3-bit input lines */

/** Outputs **/

/* We're driving LEDs and need a low voltage to make them light up.
   So make all the outputs active low */
pin [16..19] = ![led0..3];	/* Output LED lines */

/* Declarations and Intermediate Variable Definitions **/

/* Note I have defined these MSB -> LSB */
field input  = [in2..0];		/* Shorthand for input lines */
field output = [led3..0];	/* Shorthand for output lines */

/* Make this more readable by defining on/off macros for LED states.
* Note that this is assertion-level logic.  CUPL will automatically
* invert the actual voltage levels since we defined the outputs to
* be negative true.  $define statements do not end with semi-colons!
*/
$define on  'b'1
$define off 'b'0

/* Define the decoder operations by anding specific input patterns
* with the desired output pattern.  By ORing together all possibilities,
* we get the correct output code depending upon the input received.
*/
output = 
	[ off, off, off, off ] & input:0 #
	[ on,  off, off, off ] & input:1 #
	[ on,  on,  off, off ] & input:2 #
	[ on,  on,  on,  off ] & input:3 #
	[ on,  on,  on,  on  ] & input:4 #
	[ on,  on,  on,  off ] & input:5 #
	[ on,  on,  off, off ] & input:6 #
	[ on,  off, off, off ] & input:7;