Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm a beginner of vhdl. And now i'm

Status
Not open for further replies.

shayh

ISP
Jun 1, 2003
1
IL
I'm a beginner of vhdl. And now i'm trying to realize the chip 8254 with vhdl,but i have met some troubles when i compile my .vhd file.
I hope i can get the vhd code of 8254. Thank you!
Below is my .vhd code.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity chip8254 is
port(
clk: in std_logic;--ʱÖÓ
gate: in std_logic;--ÃÅÐźÅ
wr: in std_logic;--¶ÁÐźÅ
cs: in std_logic;--Ƭѡ
cout: buffer std_logic;--Êä³ö
data: inout std_logic_vector(7 downto 0)--Êý¾Ý¶Ë
);
end chip8254;

architecture behave of chip8254 is
signal pcr:std_logic_vector(7 downto 0):="00000000";--³õÖµ¼Ä´æ»º³å
signal cr:std_logic_vector(7 downto 0):="00000000";--³õÖµ¼Ä´æÆ÷
signal ce:std_logic_vector(7 downto 0):="00000000";--¼ÆÊýÖ´Ðе¥Ôª
signal cnr:std_logic_vector(7 downto 0):="00000000";--¿ØÖÆ×ּĴæÆ÷
signal nullcount: std_logic:='1';--ÊÇ·ñÖÃÈë³õÖµ
signal stopcount: std_logic:='0';--ÊÇ·ñÍ£Ö¹¼ÆÊý
begin
process(wr)--¶ÁÊý
begin
if rising_edge(wr) then--¶ÁÐźŵÄÉÏÉýÑØ
if cnr=0 then--»¹Ã»ÓÐдÈë¿ØÖÆ×Ö
cnr<=data;--дÈë¿ØÖÆ×Ö
case cnr(3 downto 1) is--дÈë¿ØÖÆ×ÖºóµÄcout±ä»¯
when &quot;000&quot;=>cout<='0';
when &quot;001&quot;=>cout<='1';
when &quot;010&quot;=>cout<='1';
when &quot;011&quot;=>cout<='0';
when &quot;100&quot;=>cout<='1';
when &quot;101&quot;=>cout<='1';
when others=>null;
end case;
else--дÈë³õÖµ
pcr<=data;
if cnr(3 downto 1)=&quot;000&quot; or cnr(3 downto 1)=&quot;100&quot; then
cr<=pcr;--ÔÚ·½Ê½0ºÍ·½Ê½4ÖУ¬³õÖµËæʱ±ä»¯
end if;
end if;
end if;
end process;

process(gate)--ÃÅÐźŵĴ¥·¢×÷ÓÃ
begin
if rising_edge(gate) then--ÉÏÉýÑØ
if cnr(3 downto 1)=&quot;000&quot; then--·½Ê½0
stopcount<='0';--¼ÌÐø¼ÆÊý
elsif cnr(3 downto 1)=&quot;001&quot; then--·½Ê½1
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
ce<=cr;--¿ªÊ¼¼ÆÊý
nullcount<='0';
cout<='0';
elsif cnr(3 downto 1)=&quot;010&quot; then--·½Ê½2
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
ce<=cr;--¿ªÊ¼¼ÆÊý
nullcount<='0';
elsif cnr(3 downto 1)=&quot;011&quot; then--·½Ê½3
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
if cr(0)='0' then--³õֵΪżÊý
ce<=cr;--³õÖµ×°Èëce
else
ce<=cr-1;--³õֵΪÆæÊý£¬³õÖµ¼õÒ»×°Èëce
end if;
nullcount<='0';--¿ªÊ¼¼ÆÊý
elsif cnr(3 downto 1)=&quot;100&quot; then--·½Ê½4
ce<=cr;--¿ªÊ¼¼ÆÊý
nullcount<='0';
elsif cnr(3 downto 1)=&quot;101&quot; then--·½Ê½5
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
ce<=cr;--¿ªÊ¼¼ÆÊý
nullcount<='0';
else
null;
end if;
end if;
end process;

process(gate)--ÃÅÐźŴ¥·¢
begin
if falling_edge(gate) then --ϽµÑØ
if cnr(3 downto 1)=&quot;000&quot; then--·½Ê½0
stopcount<='1';--Í£Ö¹¼ÆÊý
elsif cnr(3 downto 1)=&quot;001&quot; then--·½Ê½1
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
elsif cnr(3 downto 1)=&quot;010&quot; then--·½Ê½2
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
stopcount<='1';--Í£Ö¹¼ÆÊý
elsif cnr(3 downto 1)=&quot;011&quot; then--·½Ê½3
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
stopcount<='1';--Í£Ö¹¼ÆÊý
elsif cnr(3 downto 1)=&quot;100&quot; then--·½Ê½4
stopcount<='1';--Í£Ö¹¼ÆÊý
elsif cnr(3 downto 1)=&quot;101&quot; then--·½Ê½5
if pcr/=cr then--¸üгõÖµ
cr<=pcr;
end if;
else
null;
end if;
end if;
end process;

process(clk)--ʱÖÓ
begin
if rising_edge(clk) then--ʱÖÓÉÏÉýÑØ
if cnr(3 downto 1)=&quot;000&quot; then--·½Ê½0
if cs='1'and gate='1' and stopcount='0'and nullcount='0'
then
if ce/=0 then--¼ÆÊýδ½áÊø
ce<=ce-1;
else--¼ÆÊý½áÊø
cout<='1';
nullcount<='1';
end if;
end if;
elsif cnr(3 downto 1)=&quot;001&quot; then--·½Ê½1
if cs='1' and nullcount='0' then
if ce/=0 then
ce<=ce-1;
else
cout<='1';
nullcount<='1';
end if;
end if;
elsif cnr(3 downto 1)=&quot;010&quot; then--·½Ê½2
if cs='1' and nullcount='0' and stopcount='0' and
gate='1' then
if ce/=0 then--¼ÆÊýδ½áÊø
if ce=1 then--¼ÆÊýֵΪ1
cout<='0';
if cr/=pcr then--¸üгõÖµ
cr<=pcr;
end if;
else
ce<=ce-1;
end if;
else--¼ÆÊý½áÊø
cout<='1';
ce<=cr;--ÖØÐÂ×°Èë³õÖµ£¬¿ªÊ¼¼ÆÊý
nullcount<='0';
end if;
end if;
elsif cnr(3 downto 1)=&quot;011&quot; then--·½Ê½3
if cs='1' and nullcount='0' and stopcount='0' and
gate='1' then
if cr(0)='0' then--³õֵΪżÊý
if ce/=0 then--¼ÆÊýδ½áÊø
ce<=ce-2;
else--¼ÆÊý½áÊø
cout<= not cout;--cout·´Ïò
if cr/=pcr then--¸üгõÖµ
cr<=pcr;
end if;
if cr(0)='0' then--³õֵΪżÊý
ce<=cr;--×°Èë³õÖµ
else--³õֵΪÆæÊý
ce<=cr-1;--×°Èë³õÖµ¼õÒ»
end if;
nullcount<='0';--ÖØмÆÊý
end if;
else--³õֵΪÆæÊý
if cout='1' then--coutΪ¸ßµçƽ
if ce/=-2 then
ce<=ce-2;
else--¼ÆÊýµ½-2
if cr/=pcr then--¸üгõÖµ
cr<=pcr;
end if;
cout<='0';
ce<=cr-1;--³õÖµ¼õÒ»×°Èëce
nullcount<='0';--ÖØпªÊ¼¼ÆÊý
end if;
else--coutΪµÍµçƽ
if ce/=0 then
ce<=ce-2;
else--¼ÆÊý½áÊø
if cr/=pcr then--¸üгõÖµ
cr<=pcr;
end if;
cout<='1';
ce<=cr-1;--³õÖµ¼õÒ»×°Èëce
nullcount<='0';--ÖØпªÊ¼¼ÆÊý
end if;
end if;
end if;
end if;
elsif cnr(3 downto 1)=&quot;100&quot; then--·½Ê½4
if cs='1' and nullcount='0' and stopcount='0' and
gate='1' then
if ce/=0 then
ce<=ce-1;
else--¼ÆÊý½áÊø
cout<='0';
nullcount<='1';
end if;
elsif cout='0' and nullcount='1' and ce=0
then--ÈüÆÊý½áÊøºócoutÖµ±£³ÖÒ»¸öʱÖӵĵ͵çƽ
cout<='1';
end if;
elsif cnr(3 downto 1)=&quot;101&quot; then--·½Ê½5
if cs='1' and nullcount='0' then
if ce/=0 then
ce<=ce-1;
else--¼ÆÊý½áÊø
cout<='0';
nullcount<='1';
end if;
elsif cout='0' and nullcount='1' and ce=0 then
cout<='1';--ÈüÆÊý½áÊøºócoutÖ»±£³ÖÒ»¸öʱÖӵĵ͵çƽ
end if;
else
null;
end if;
end if;

end process;
end behave;
 
plz i need the code of 8254 urgent.
if any one have it correctly plz send it to me: haytham79@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top