Altera Code for 8-bit Input Port


SUBDESIGN ea_input
(
    E               :  INPUT;   % E-Clock %
    R_W             :  INPUT;   % R/W Line %

    PA[7..0]        :  BIDIR;   % Address and Data (15-8) from HC12 %
    PB[7..0]        :  BIDIR;   % Address and Data (7-0) from HC12 %

    WEn             :  OUTPUT;  % Write Enable to memory %
    OEn             :  OUTPUT;  % Output Enable to memory %
    
    EA[7..0]        :  INPUT;   % Expansion Port A %
)


VARIABLE
    demux[15..0]    :  DFF;    % Demuliplexed address internal %

    PA_OE           ;  NODE;   % Tells when to drive data onto Port A %

BEGIN

% ***********************************************************************%
% Address decoding and demultiplexing                                    %
% Latch address on rising edge of E clock                                %
% ***********************************************************************%

    demux[15..8].d = PA[7..0];
    demux[7..0].d = PB[7..0];
    demux[15..0].clk = E; 
    
% ***********************************************************************%
% Start of expansion ports                                               %
% ***********************************************************************%


%  A read from address 0x0400 reads the expansion port A %

    IF (demux[15..0].q == H"0400") & (R_W == VCC) & (E==VCC) THEN
            PA_OE = VCC;
    ELSE
            PA_OE = GND;
    END IF;

%  Here we put the input values on exp port A onto Port A %

    PA[7] = TRI(EA[7], PA_OE);
    PA[6] = TRI(EA[6], PA_OE);
    PA[5] = TRI(EA[5], PA_OE);
    PA[4] = TRI(EA[4], PA_OE);
    PA[3] = TRI(EA[3], PA_OE);
    PA[2] = TRI(EA[2], PA_OE);
    PA[1] = TRI(EA[1], PA_OE);
    PA[0] = TRI(EA[0], PA_OE);

END;