使用51单片机CPLD芯片来扩展的寻址范围
来源:网络收集 作者:佚名 发布时间:2009-05-12 11:39:47 发
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
评论 摘要: 通过CPLD将这些地址位整合起来,并输出到相应的设备,这样,即可实现用单片机的一个八位IO口来实现
多位地址的功能。
关键词:51单片机
4.1 CPLD程序
本例中,采用硬件描述语言VHDL来编写CPLD程序,相关代码如下:
entity mcu_to_flash is
port ( clk : in std_logic;
add : in bit_vector (7 downto 0); --地址输入
flash_add : out bit_vector (17 downto 0); --地址输出(到flash)
oe : out std_logic; --到flash的oe
we : out std_logic ); --到flash的we
end mcu_flash;
architecture func1 of mcu_flash is
signal counter : integer range 0 to 10000; --定义一个计数器
signal add_reg : bit_vector (17 downto 0); --定义寄存器add_reg用于缓存地址
begin
process (clk)
begin
if (clk'event and clk='1') then
case add(7 downto 6) is
when "00" =>
add_reg (5 downto 0) <= add (5 downto 0); --地址0到5
counter <= 0;
when "01" =>
add_reg (11 downto 6) <= add (5 downto 0); --地址6-11
counter <= counter + 1;
if (counter = 5) then --恢复OE,WE到高电平,为后面产生下降沿作准备
oe <= '1';
we <= '1';
end if;
when "10" =>
add_reg (17 downto 12) <= add (5 downto 0); --地址12-17
counter <= 0;
when "11" =>
flash_add <= add_reg; --输出地址
counter <= counter + 1;
if (counter = 5) then --产生OE,WE的下降沿
oe <= '0';
end if;
end case;
end if;
end process;
end func1;
从程序可见,本例中单片机需要写四次P0口进行一次读/写操作,且这四次写入P0的数据的高两位应该分别为“00”;“01”;“10”;“11”,CPLD将该两位作为标志位判断其后六位分别是所需地址的哪几位,将前三次P0口数据的低六位“拼”成FLASH的18位地址,并在第四次写P0口时将该地址输出到FLASH的相应地址位,同时由CPLD产生OE或者WE的下降沿信号,以满足FLASH的读/写时序要求。