Altera Code to Demultiplex HC12 Address and Data Busses, and to Generate Output Enable and Write Enable Control Lines
SUBDESIGN demux_oe_we
(
EXP_ENn : INPUT; % Expansion enabled when low %
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 %
A[15..0] : OUTPUT; % Demultiplexed address bits %
)
VARIABLE
demux[15..0] : DFF; % Demuliplexed address internal %
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;
A[15..0] = demux[15..0].q;
% Enable writes when E high and R/W low %
IF (EXP_ENn == GND) & (E == VCC) & (R_W == GND) THEN
WEn = GND;
ELSE
WEn = VCC;
END IF;
% Enable reads when E high and R/W high %
IF (EXP_ENn == GND) & (E == VCC) & (R_W == VCC) THEN
OEn = GND;
ELSE
OEn = VCC;
END IF;
END;