logo资料库

某十字路口交通灯.doc

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
设计任务及功能要求: 设计某十字路口交通灯(红黄绿)的指示灯的控制,以达到控制车辆行驶的目的, 如直行绿灯亮 40 秒后黄灯亮 5 秒再到红灯亮 30 秒,红灯亮的同时,左拐或右 拐的绿灯亮也跟着亮。如此循环。 ,,我是小白,写详细点好吗。带注释。 其他回答 共 1 条 2010-6-10 21:51136746386 | 一级 交通灯控制程序 library ieee; use ieee.std_logic_1164.all; entity jtd is port(clk:in std_logic; MR,MY,MG,BR,BY,BG:out std_logic); end jtd; architecture art of jtd is type state_type is (A,B,C,D); signal state: state_type; begin process(clk) variable s:integer range 0 to 45; variable clr,en:bit; begin if(clk'event and clk='1') then if clr='0' then s:=0; elsif en='0' then s:=s; else s:=s+1; end if; case state is when A=>MR<='0';MY<='0';MG<='1'; BR<='1';BR<='0';BG<='0'; if s=45 then state <=B;clr:='0';en:='0';
else state<=A;clr:='1';en:='1'; end if; when B=>MR<='0';MY<='1';MG<='0'; BR<='1';BY<='0';BG<='0'; if s=5 then state<=C;clr:='0';en:='0'; else state<=B;clr:='1';en:='1'; end if; when C=>MR<='1';MY<='0';MG<='0'; BR<='0';BY<='0';BG<='1'; if s=25 then state<=D;clr:='0';en:='0'; else state<=C;clr:='1';en:='1'; end if; when D=>MR<='1';MY<='0';MG<='0'; BR<='0';BY<='1';BG<='0'; if s=5 then state<=A;clr:='0';en:='0'; else state<=D; clr:='1';en:='1'; end if; end case; end if; end process; end art; 45 秒计时程序 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity c45s is port(clk,en45:in std_logic; D45M,D45B:out std_logic_vector(7 downto 0));
end C45s; architecture art of C45s is signal cnt6b:std_logic_vector(5 downto 0); begin process(clk,en45) begin if(clk'event and clk='1')then if en45='1' then cnt6b<=cnt6b+1; elsif en45='0' then cnt6b<=cnt6b-cnt6b-1; end if; end if; end process; process(cnt6b) begin case cnt6b is when"000000"=>D45M<="01000101";D45B<="01010000"; when"000001"=>D45M<="01000100";D45B<="01001001"; when"000010"=>D45M<="01000011";D45B<="01010000"; when"000011"=>D45M<="01000010";D45B<="01010000"; when"000100"=>D45M<="01000001";D45B<="01010000"; when"000101"=>D45M<="01000000";D45B<="01010000"; when"000110"=>D45M<="00111001";D45B<="01010000"; when"000111"=>D45M<="00111000";D45B<="01010000"; when"001000"=>D45M<="00110111";D45B<="01010000"; when"001001"=>D45M<="00110110";D45B<="01010000"; when"001010"=>D45M<="00110101";D45B<="00111001"; when"001011"=>D45M<="00110100";D45B<="00111000"; when"001100"=>D45M<="00110011";D45B<="00110111"; when"001101"=>D45M<="00110010";D45B<="00110110"; when"001110"=>D45M<="00110001";D45B<="00110101";
when"001111"=>D45M<="00110000";D45B<="00110100"; when"010000"=>D45M<="00101001";D45B<="00110011"; when"010001"=>D45M<="00101000";D45B<="00110010"; when"010010"=>D45M<="00100111";D45B<="00110010"; when"010011"=>D45M<="00100110";D45B<="00110001"; when"010100"=>D45M<="00100101";D45B<="00110000"; when"010101"=>D45M<="00100100";D45B<="00101001"; when"010110"=>D45M<="00100011";D45B<="00101000"; when"010111"=>D45M<="00100010";D45B<="00100111"; when"011000"=>D45M<="00100001";D45B<="00100110"; when"011001"=>D45M<="00100000";D45B<="00100101"; when"011010"=>D45M<="00011001";D45B<="00100100"; when"011011"=>D45M<="00011000";D45B<="00100011"; when"011100"=>D45M<="00010111";D45B<="00100010"; when"011101"=>D45M<="00010110";D45B<="00100001"; when"011110"=>D45M<="00010101";D45B<="00100000"; when"011111"=>D45M<="00010100";D45B<="00011001"; when"100000"=>D45M<="00010011";D45B<="00011000"; when"100001"=>D45M<="00010010";D45B<="00010111"; when"100010"=>D45M<="00010001";D45B<="00010110"; when"100011"=>D45M<="00010000";D45B<="00010101"; when"100100"=>D45M<="00001001";D45B<="00010100"; when"100101"=>D45M<="00001000";D45B<="00010011"; when"100110"=>D45M<="00000111";D45B<="00010010"; when"100111"=>D45M<="00000110";D45B<="00010001"; when"101000"=>D45M<="00000101";D45B<="00010000"; when"101001"=>D45M<="00000100";D45B<="00001001"; when"101010"=>D45M<="00000011";D45B<="00001000"; when"101011"=>D45M<="00000010";D45B<="00000111"; when"101100"=>D45M<="00000001";D45B<="00000110";
when others =>D45M<="00000000";D45B<="00000000"; END CASE; end process; end art; 以及类推 40 秒 30 秒 5 秒的都可以写出来 再加上显示程序 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity xianshidanyuan is port(en45,en25,en05m,en05b:in std_logic; A45M,A45B:in std_logic_vector(7 downto 0); A25M,A25B,A05: in std_logic_vector(7 downto 0); DM7,DM6,DM5,DM4,DM3,DM2,DM1,DM0, DB7,DB6,DB5,DB4,DB3,DB2,DB1,DB0:out std_logic); end xianshidanyuan; architecture art of xianshidanyuan is signal X,Y:std_logic_vector(7 downto 0); begin process(en45,en25,en05m,en05b) begin if en45='1' then x<=A45M(7 downto 0);y<=A45B(7 downto 0); elsif en05m='1' then x<=A05(7 downto 0);y<=A05(7 downto 0); elsif en25='1' then x<=A25M(7 downto 0);y<=A25B(7 downto 0); elsif en05b='1' then x<=A05(7 downto 0);y<=A05(7 downto 0); end if; end process; DM7<=X(7); DM5<=X(5); DM6<=X(6); DM4<=X(4);
DM2<=X(2); DB6<=Y(6); DB2<=Y(2); DM1<=X(1); DB5<=Y(5); DB1<=Y(1); DM0<=X(0); DB4<=Y(4); DB0<=Y(0); DM3<=X(3); DB7<=Y(7); DB3<=Y(3); end art; 译码器程序 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity yimaqi is port(A3,A2,A1,A0:in std_logic; D7:out std_logic_vector(6 downto 0)); end yimaqi; architecture art of yimaqi is SIGNAL L:STD_LOGIC_VECTOR(3 DOWNTO 0); begin L<=A3&A2&A1&A0; process(L) begin case L is when"0000"=>D7<="0111111"; when"0001"=>D7<="0000110"; when"0010"=>D7<="1011011"; when"0011"=>D7<="1001111"; when"0100"=>D7<="1100110"; when"0101"=>D7<="1101101"; when"0110"=>D7<="1111101"; when"0111"=>D7<="0000111";
when"1000"=>D7<="1111111"; when"1001"=>D7<="1101111"; when others=>D7<="0000000"; end case; end process; end art; 再用 gdf 图像文件连接起来 这是个有七段数码显示倒计时功能的交通灯控制程 序 前两天课程设计的时候写的 希望对你有所帮助
分享到:
收藏