-- Behavioural model of a simple 8-bit CPU
-- download from: www.fpga.com.cn & www.pld.com.cn
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE work.bv_math.ALL;
USE work.cpu8pac.ALL;
ENTITY cpu IS
GENERIC(cycle_time : TIME := 200 ns); --must be divisible by 8
PORT(reset : IN std_logic;
memrd, memwr : OUT std_logic;
address : OUT std_logic_vector(11 DOWNTO 0);
data : INOUT std_logic_vector(7 DOWNTO 0));
END cpu;
ARCHITECTURE version1 OF cpu IS
--internal clock signal
SIGNAL clock : std_logic;
BEGIN
clock_gen : PROCESS
BEGIN
clock <= '1','0' AFTER cycle_time/2;
WAIT FOR cycle_time;
END PROCESS;
main_sequence : PROCESS
VARIABLE inst_reg : BIT_VECTOR(3 DOWNTO 0);
VARIABLE mar : BIT_VECTOR(11 DOWNTO 0);
VARIABLE acca, accb : BIT_VECTOR(7 DOWNTO 0);
VARIABLE pc : BIT_VECTOR(11 DOWNTO 0);
BEGIN
IF reset = '1' THEN
--initialisation
memrd <= '1';
memwr <= '1';
pc := (OTHERS => '0');
address <= (OTHERS => 'Z');
data <= (OTHERS => 'Z');
WAIT UNTIL rising_edge(clock);
ELSE
--fetch phase
address <= To_StdlogicVector(pc);
WAIT FOR cycle_time/4;
memrd <= '0';
WAIT FOR cycle_time/2;
memrd <= '1';
--read instruction
inst_reg := To_bitvector(data(7 DOWNTO 4));
--load page address
mar(11 DOWNTO 8) := To_bitvector(data(3 DOWNTO 0));
--increment program counter
pc := inc_bv(pc);
--wait until end of cycle
WAIT UNTIL rising_edge(clock);
--execute
CASE inst_reg IS
WHEN add =>
--add and sub use overloaded functions from bv_math package
acca := acca + accb;
WHEN subr =>
acca := acca - accb;
WHEN inc =>
acca := inc_bv(acca);
WHEN dec =>
acca := dec_bv(acca);
WHEN land =>
acca := acca AND accb;
WHEN lor =>
acca := acca OR accb;
WHEN cmp =>
acca := NOT acca;
WHEN lxor =>
acca := acca XOR accb;
WHEN lita =>
acca := acca;
WHEN litb =>
acca := accb;
WHEN clra =>
acca := (OTHERS => '0');
WHEN lda|ldb|sta|stb =>
address <= To_StdlogicVector(pc);
WAIT FOR cycle_time/4;
memrd <= '0';
WAIT FOR cycle_time/2;
memrd <= '1';
--read page offset address
mar(7 DOWNTO 0) := To_bitvector(data);
--increment program counter
pc := inc_bv(pc);
--wait until end of cycle
WAIT UNTIL rising_edge(clock);
--output address of operand
address <= To_StdlogicVector(mar);
IF ((inst_reg = lda) OR (inst_reg = ldb)) THEN
WAIT FOR cycle_time/4;
memrd <= '0';
WAIT FOR cycle_time/2;
memrd <= '1';
IF inst_reg = lda THEN
--load accumulator a from bus
acca := To_bitvector(data);
ELSE
--load accumulator b from bus
accb := To_bitvector(data);
END IF;
--wait until end of cycle
WAIT UNTIL rising_edge(clock);
ELSE
WAIT FOR cycle_time/8;
IF inst_reg = sta THEN
--ouput data
data <= To_StdlogicVector(acca);
ELSE
--ouput data
data <= To_StdlogicVector(accb);
END IF;
WAIT FOR cycle_time/8;
memwr <= '0';
WAIT FOR cycle_time/2;
memwr <= '1';
WAIT FOR cycle_time/8;
data <= (OTHERS => 'Z');
--wait until end of cycle
WAIT UNTIL rising_edge(clock);
END IF;
WHEN jmp =>
address <= To_StdlogicVector(pc);
--transfer page address to pc from mar
pc(11 DOWNTO 8) := mar(11 DOWNTO 8);
--read in offset address
WAIT FOR cycle_time/4;
memrd <= '0';
WAIT FOR cycle_time/2;
memrd <= '1';
pc(7 DOWNTO 0) := To_bitvector(data);
--wait until end of cycle
WAIT UNTIL rising_edge(clock);
END CASE;
END IF;
END PROCESS main_sequence;
END version1;
没有合适的资源?快使用搜索试试~ 我知道了~
vhdl红绿灯控制代码
共64个文件
txt:41个
vhd:21个
transcript:1个
5星 · 超过95%的资源 需积分: 10 28 下载量 5 浏览量
2009-04-08
10:05:41
上传
评论 1
收藏 59KB RAR 举报
温馨提示
交通灯信号控制器用于主干道与支道公路的交叉路口,要求是优先保证主干道的畅通。因此,平时处于“主干道绿灯,支道红灯”状态,只有在支道有车辆要穿行主干道时,才将交通灯切向“主干道红灯,支道绿灯”,一旦支道无车辆通过路口,交通灯又回到“主干道绿灯,支道红灯”的状态。此外,主干道和支道每次通行的时间不得短于30 s,而在两个状态交换过程出现的“主黄,支红”和“主红,支黄”状态,持续时间都为4 s。
资源推荐
资源详情
资源评论
收起资源包目录
WinRAR 压缩文件.rar (64个子文件)
红绿灯控制
adder_nbit_generate.txt 1KB
priority_encoder_highest.txt 1KB
traffic_ls.vhd 3KB
fifo.txt 2KB
address_decoder_m68008.txt 2KB
counters_altera.vhd 6KB
condsigm.vhd 545B
multiplier_booth.txt 5KB
dc_motor.vhd 10KB
multiplexer_ifelse.txt 782B
cpu_core.txt 7KB
vhdl_example.html 14KB
shift_register_164.txt 657B
hamming_decoder.txt 2KB
comparetor_magnitude.txt 2KB
mealy1.txt 3KB
mancala.vhd 19KB
cpu_3rd_package.txt 7KB
CPU_system.txt 2KB
counter_conversion.txt 2KB
d-filp-flop_hct175.txt 853B
reg12.vhd 405B
uart_ls.vhd 10KB
selsigen.vhd 614B
counter_mod16_jk.txt 2KB
state_variable.txt 2KB
smart_waveform.vhd 2KB
counter_generate.txt 1KB
comparator8.txt 411B
decoder_hct139.txt 1KB
universal_register.txt 2KB
moor1.txt 3KB
register_374.txt 721B
counter_wait.txt 1014B
decoder_bcd_to_7segment.txt 874B
priority_encoder_ls.vhd 2KB
ram_16x8.txt 1KB
counter_pload.txt 922B
State_areset.txt 1KB
transcript 109B
ram_LS.vhd 1KB
hct245.txt 722B
random_generator.txt 2KB
moor2.txt 2KB
state_classic.txt 3KB
testadder.vhd 4KB
step_motor.vhd 3KB
CPU_ram.txt 1KB
conversion_altera.vhd 427B
condsig.vhd 374B
hamming_encoder.txt 893B
majority_voter.txt 2KB
adder.vhd 3KB
compinst.vhd 717B
CPU_rom.txt 3KB
pseudorandom.vhd 8KB
statmach_altera.vhd 773B
adder_variety_style.txt 3KB
counter_nbit.txt 859B
pelian_contrller.txt 5KB
chess_clock.txt 6KB
state_moor_mealy.txt 3KB
latchinf.vhd 419B
reginf.vhd 2KB
共 64 条
- 1
资源评论
- renzku2015-09-02挺有用,可以作为参考,然后自己动手写。。
songwenchaodehao
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课程设计项目:python+QT实现的小型编译器.zip
- (源码)基于AVR ATmega644的智能卡AES解密系统.zip
- (源码)基于C++插件框架的计算与打印系统.zip
- (源码)基于Spring Boot和Vue的苍穹外卖管理系统.zip
- (源码)基于wxWidgets库的QMiniIDE游戏开发环境管理系统.zip
- 通过C++实现原型模式(Prototype Pattern).rar
- 学习记录111111111111111111111111
- 通过java实现原型模式(Prototype Pattern).rar
- 通过python实现原型模式(Prototype Pattern).rar
- xiefrnsdklmkds
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功