⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc8051.vhd

📁 8051 vhdl source code
💻 VHD
📖 第 1 页 / 共 5 页
字号:
--  mc8051.vhd----  This file is a part of the UMR MC8051 VHDL model--  Copyright (C) 2001 University of Missouri-Rolla (UMR)----  The UMR MC8051 VHDL model is free software; you can redistribute it--  and/or modify it under the terms of the GNU General Public License as--  published by the Free Software Foundation; either version 2 of the--  License, or (at your option) any later version.----  This program is distributed in the hope that it will be useful, but--  WITHOUT ANY WARRANTY; without even the implied warranty of--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU--  General Public License for more details.----  You should have received a copy of the GNU General Public License along--  with this program; if not, write to the Free Software Foundation, Inc.,--  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA----  See the file COPYING for the full details of the license.---------------------------------------------------- Model         :  8051 Behavioral Model,--                  Top Level Block---- File          :  mc8051.vhd   (MicroController 8051)---- Author        :  Michael Mayer,--                  Dr. Hardy J. Pottinger, advisor (hjp@ece.ece.edu)--                  Department of Electrical Engineering--                  University of Missouri - Rolla---- Requires      :  pack8051.vhd (Package containing--                  needed procedures, types, etc.)--                  uart.vhd (UART peripheral)--                  (written by Lingfeng Yuan, Prajakta Kurvey)--                  see also LIBRARY and USE clauses below---- Thanks to     :  Dr. Hardy Pottinger and Dr. Daryl Beetner for guidance--                  Kyle Mitchel for much help --                  David Sullins for testing and completing the model--                  Maya Gemini for more testing---- Inspired from :  Sundar Subbarayan--                  UC Riverside CS 122a (lab 3)--                  Professor: Dr.Frank Vahid--                  17th January 1996---- Date Started  :  September 15, 1997---- Features      :  Entire command set--                  Support for Intel Hex format--                  Internal program memory (4Kb)--                  Internal data memory (256 Bytes) - 8052--                  Supports external prog mem up to 64 Kb--                  Supports external data mem up to 64 Kb--                     using MOVX instr. with 16 bit data ptr.--                  Supports I/O through 4 ports when not using--                     above features--                  Interrupts w/ Priority--                  Choice of level / edge sensitive interrupts--                  Serial port--                  Timer 0 and 1 in all four timer modes---- Limitations   :  Interrupt latencies not always accurate--                  (This model allows RETI and instructions accessing--                   IE or IP to be interrupted.  A standard 8051 does not--                   interrupt these instructions).---- REV    DATE       Description-- -----  --------   ----------------------------------------- 1.0    01/17/97   Work from Sundar Subbarayan and--                   Dr. Frank Vahid---- 2.0    11/04/97   Initial implementation of command--                   interpreter for Hex Code set.---- 2.1    11/12/97   Changed memory to separate lo and hi mem--                   and made all access through functions /--                   procedures / aliases to allow for--                   distinction between indirect and direct--                   accessing of upper 128 bytes of data mem--                   (for 8052 compatibility).---- 2.2    11/21/97   Made program memory access only through--                   the process get_pmem and its two--                   signals: pmem_s1_byte and pmem_s4_byte--                   Added state machine sensitive to xtal which--                   governs the machine cycles, port & mem--                   reads, etc.  Built support for external--                   program memory read in process get_pmem.---- 2.3    12/12/97   Corrected bug in get_pmem - resync to pc--                   Moved load_program procedure to pack8051--                   Converted IF..ELSEIF structure to CASE for--                   decoding of opcodes.  Completed any missing--                   commands and verified that all 256 were available---- 3.0    12/13/97   Changed port 3 to a single std_logic_vector--                   Differentiated between commands that read the--                   port and those that read the latch.--                   Added output drivers for port3---- 3.1    12/14/97   Modified procedures in main for accessing--                   data bytes.  All use get_byte_dmem--                   and set_byte_dmem for any data access, unless--                   they access it through aliases (e.g. acc <= val)---- 3.1.1  01/26/98   Added condition of ea_n to the program rom load ---- 3.1.2  02/22/98   Corrected handle_sub's advancing of the pc--                   Corrected JNC to IF cy='0' instead of '1'--                  -- 3.1.3  02/24/98   Corrected MOVX's control of Ports 2 & 3.---- 3.2    07/??/98   Corrections from Kyle Mitchell for--                   0 or L, 1 or H and for initial boot-up---- 4.0    08/30/98   Added serial UART, timer 1 in mode 2, and--                   the serial interrupt---- 4.1    09/02/98   Added more interrupts.---- 4.2    10/06/98   Corrected MOVX's control of ALE and PSEN_n--                   Fixed PC increment on several instructions---- 4.3    10/08/98   Added level / edge sensitive interrupt support--                   Added priority to interrupts (IP)---- 4.4    10/23/98   Fixed interrupt ea---- 4.5    04/06/00   Fixed DIV instruction  --Dave-- -- 4.6    10/03/00   dsulli	Fixed MUL AB instruction---- 4.7    10/04/00   dsulli	Fixed SUBB, MOVC @A+PC, and POP SP---- 4.8    10/20/00   dsulli	Minor changes to startup values of sfrs---- 5.0    12/10/00   dsulli	Support for timers 0 and 1, all modes-- -- 5.1    12/15/00   dsulli--        RST support from original 4.5 merged in.--        MOV A, ACC, divide by zero, and memory overflow now give warnings.--        Reset values of SFRs fixed.  Parity bit fixed.--        External interrupts 0 and 1 fixed.---- 5.2    12/27/00   dsulli      Minor changes, removed unnecessary signals---- 5.3    01/08/01   dsulli      Got rid of warnings at 2250 ns---- 5.4    03/05/01   dsulli      Fixed MOVX bug.  P2 wasn't being reset to Z.---- 5.5    04/08/01   dsulli      Fixed a bug in timer1 overflow causing --                               serial UART not to be triggered.-- -- 5.6    08/01/01   dsulli      Added copyright notice for general release.---- 5.7    08/16/01   dsulli      Changed JB to read from port latch---- 5.8    08/16/01   dsulli      Fixed port 3 alternate function behavior-- ------------------------------------------------------------------------ LIBRARY ieee;USE ieee.std_logic_1164.ALL;USE ieee.std_logic_arith.ALL;    -- Uses type unsigned, the "+" and "-" operators, and the functions    -- conv_integer and conv_unsigned, amongst othersUSE std.textio.ALL;USE work.pack8051.ALL; ENTITY mc8051 IS   GENERIC (      program_filename : string := "code.hex"   );   PORT (      P0      : INOUT std_logic_vector(7 DOWNTO 0);  -- used for data i/o      P1      : INOUT std_logic_vector(7 DOWNTO 0);  -- low-order address byte      P2      : INOUT std_logic_vector(7 DOWNTO 0);  -- high-order address byte      P3      : INOUT std_logic_vector(7 DOWNTO 0);--    These are the other uses for port 3 pins--      rxd     : INOUT std_logic;  --port 3.0, serial port receiver data--      txd     : INOUT std_logic;  --port 3.1, serial port transmitter--      int0_n  : INOUT std_logic;  --port 3.2, interrupt 0 input--      int1_n  : INOUT std_logic;  --port 3.3, interrupt 1 input--      t0      : INOUT std_logic;  --port 3.4, input to counter 0--      t1      : INOUT std_logic;  --port 3.5, input to counter 1--      wr_n    : INOUT std_logic;  --port 3.6, write control, latches port 0 to external--      rd_n    : INOUT std_logic;  --port 3.7, read control, enables external to port 0       rst     : IN    std_logic;  -- low to high causes reset - IGNORED!      xtal1   : IN    std_logic;  -- clock input 1.2 to 12 MHz      xtal2   : OUT   std_logic;  -- output from oscillator (for crystal) - IGNORED!      ale     : OUT   std_logic;  -- provides Address Latch Enable output,      psen_n  : OUT   std_logic;  -- program store enable      ea_n    : IN    std_logic   -- when low, access external prog. mem   );END ENTITY mc8051; ARCHITECTURE behav OF mc8051 IS     -- The following variables hold the program and data memory.    -- Note that the upper 128 byte block of the data memory can    -- only be accessed via indirect addressing.  Direct addressing     -- will instead reach the special function registers, etc.    -- The aliases below are mapped to specific points in the data so that    -- they can be accessed more easily.  All data writes MUST be done    -- through the set_dmem process.    SIGNAL lo_dmem             : data_lomem_T;      -- the lower data memory    SIGNAL direct_hi_dmem      : data_himem_T;      -- the SFR memory space    SIGNAL indirect_hi_dmem    : data_himem_T;      -- the data memory    SIGNAL pc                  : wVec;              -- program counter    SIGNAL pmem_s1_byte, pmem_s4_byte  : bVec;      -- next pmem data if needed     ALIAS  acc  : bvec IS direct_hi_dmem(16#E0#);   -- accumulator    ALIAS  b    : bvec IS direct_hi_dmem(16#F0#);   -- used for mult / div    ALIAS  psw  : bvec IS direct_hi_dmem(16#D0#);   -- program status word    ALIAS  cy   : std_logic IS psw(7);              -- carry flag    ALIAS  ac   : std_logic IS psw(6);              -- auxiliary carry flag    ALIAS  f0   : std_logic IS psw(5);              -- flag 0    ALIAS  rs   : unsigned(1 DOWNTO 0) IS psw(4 DOWNTO 3); -- register bank selector    ALIAS  ov     : std_logic IS psw(2);            -- overflow flag    ALIAS  p      : std_logic IS psw(0);            -- parity - not implemented    ALIAS  sp     : bvec IS direct_hi_dmem(16#81#); -- stack pointer    ALIAS  dpl    : bvec IS direct_hi_dmem(16#82#); -- data pointer low    ALIAS  dph    : bvec IS direct_hi_dmem(16#83#); -- data pointer high    ALIAS  p0_latch : bvec IS direct_hi_dmem(16#80#); -- port 0 in memory    ALIAS  p1_latch : bvec IS direct_hi_dmem(16#90#); -- port 1 in memory    ALIAS  p2_latch : bvec IS direct_hi_dmem(16#A0#); -- port 2 in memory    ALIAS  INT0_n: std_logic is P3(2);    ALIAS  INT1_n: std_logic is P3(3);    ALIAS  T0: std_logic is P3(4);    ALIAs  T1: std_logic is P3(5);    ALIAS  scon   : bvec IS direct_hi_dmem(16#98#); -- serial control reg.    ALIAS  sm     : unsigned(2 DOWNTO 0) IS scon(7 DOWNTO 5); -- serial mode           -- NOT IMPLEMENTED, but would decode as follows:           -- 00 shift reg  (FOSC / 12 Baud)           -- 01 8-Bit UART (Variable Baus)           -- 10 9-Bit UART (Fosc / 64 or Fosc / 32 Baus)           -- 11 9-Bit UART (Variable Baud)           -- sm2 enables multiprocessor communication feature    ALIAS  ren    : std_logic IS scon(4);           -- Reception Enable (active high)    ALIAS  tb8    : std_logic IS scon(3);           -- Transmit Bit 8 (ninth bit)    ALIAS  rb8    : std_logic IS scon(2);           -- Received Bit 8 (ninth bit)    ALIAS  ti     : std_logic IS scon(1);           -- transmit interrupt    ALIAS  ri     : std_logic IS scon(0);           -- receive interrup    ALIAS  sbuf   : bvec IS direct_hi_dmem(16#99#); -- serial data buffer        ALIAS  tcon   : bvec IS direct_hi_dmem(16#88#); -- timer control reg.    ALIAS  timer1_on : std_logic IS tcon(6);    ALIAS  it0    : std_logic IS tcon(0);           -- ext. int. 0 type    ALIAS  IE0    : std_logic IS tcon(1);    ALIAS  it1    : std_logic IS tcon(2);           -- ext. int. 1 type    ALIAS  IE1    : std_logic IS tcon(3);    ALIAS  TR0    : std_logic IS tcon(4);    ALIAS  TR1    : std_logic IS tcon(6);        ALIAS  TMOD   : bvec IS direct_hi_dmem(16#89#); -- timer mode reg.    ALIAS Mode_T0 : unsigned(1 downto 0) IS TMOD(1 downto 0);    ALIAS  CT0    : std_logic IS TMOD(2);    ALIAS  Gate0  : std_logic IS TMOD(3);    ALIAS Mode_T1 : unsigned(1 downto 0) IS TMOD(5 downto 4);    ALIAS  CT1    : std_logic IS TMOD(6);    ALIAS  Gate1  : std_logic IS TMOD(7);        ALIAS  ie     : bvec IS direct_hi_dmem(16#A8#); -- interrupt enable    ALIAS  ea     : std_logic IS ie(7);             -- disable all interrupts    ALIAS  en_serial : std_logic IS ie(4);          -- es bit    ALIAS  en_t1     : std_logic IS ie(3);    ALIAS  en_x1     : std_logic IS ie(2);    ALIAS  en_t0     : std_logic IS ie(1);    ALIAS  en_x0     : std_logic IS ie(0);    ALIAS  ip     : bvec IS direct_hi_dmem(16#B8#); -- interrupt priority    ALIAS  pcon   : bvec IS direct_hi_dmem(16#87#);     -- cycle_state is a signal containing the current state of the    -- machine cycle (s1 through s6), with 2 pulses for each state (p1 and p2).    SIGNAL    cycle_state : machine_cycle_states;    SIGNAL    TCLCL       : TIME := 0 ns;  -- time for a period of XTAL1    SIGNAL    reset_pmem  : std_logic;        -- init_gb is set to true once initialization is done    SIGNAL    init_gb     : boolean := false;     -- port_req is used by the external data memory access (in process main)    -- to halt the output of the external program memory process.    SIGNAL    port_req    : std_logic := '0';    -- These two signals carry addr / data for ports 0 and 2    SIGNAL    p0_addr,  p2_addr  : bvec;    -- When the following ctrl signals are low, then the port will    -- output the value associated with the latch, otherwise it is    -- the value of data / addr or special function.    SIGNAL    p0_ctrl,  p2_ctrl : std_logic;    -- The following signal represents the resolution of the port 3 latch    -- and the port 3 alternate output functions    SIGNAL    p3_resolved : bvec;    SIGNAL    p3_latch : bvec;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -