北邮数电综合实验 加油机的设计_第1页
北邮数电综合实验 加油机的设计_第2页
北邮数电综合实验 加油机的设计_第3页
北邮数电综合实验 加油机的设计_第4页
北邮数电综合实验 加油机的设计_第5页
已阅读5页,还剩33页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数字电路与逻辑设计实验学院:班级:学号:姓名:时间:一任务要求3二系统设计3设计思路3总体框图3分块说明4三仿真波形41.投币计数模块4100元投币的计数52.加油计数模块63.数码管显示模块74.点阵显示模块8四VHDL源程序141.2k分频器142.投币计数器153.加油计数器164.数码管显示205.点阵显示246.音乐模块307.总体布线36五完成功能说明36六资源利用情况37七故障及问题分析37八实验总结与心得体会37一任务要求设计并实现一个简易加油机控制系统,能够完成定值加油、加油至油箱满等功能,并显示所加油量和钱数。 基本要求: 1、 油价固定设为5元/升。 2、 用2个按键(b

2、tn7、btn6)分别表示一百元、十元,用btn5做加油开始键,用btn0做系统复位键。用3个数码管(disp2、disp1、disp0)显示钱数,以元为单位,上限990元;用数码管(disp5、disp4、disp3)显示加油量,精确到0.1升,最大显示99.9升。 3、 定值加油时,先输入钱币,数码管同时显示钱数,按加油键,开始加油。加油过程中,钱数及加油量的显示从零开始递增,直到钱数到达预定值。并用发光二极管表示购买成功。加油过程中,所有按键按下无效。 4、 加油至油箱满:在钱币数为零的状态下,按加油键,钱数及加油量的显示从零开始递增,直到油箱加满。自行设计一个随机数发生器,控制加油量自

3、动停止在30升至50升之间,精确到0.1升。加油过程中,所有按键按下无效。 5、 复位键(btn0)按下后,系统复位,此时数码管显示钱币数及加油量均为零。 提高要求: 1、 用小键盘输入价格,用点阵显示加油机各种状态及动画。 2、 设定不同的油品、油价。 3、 油库管理功能。4、 自拟其它功能。二系统设计设计思路自动加油机的程序主要的难点在于计数器的实现与不同状态的控制,先让投币计数器器计数投入的钱数,并用数码管显示出来,当加油键按下时,数码管显示归零,并让左右三个数码管同时开始从零计数,由于是五元一升,即当油量加两个数时,价钱加一个数,当价钱等于投币计数器传过来的值时,停止计数,显示动画,提

4、示加油成功。总体框图2k分频器投币计数器加油计数器数码管显示器10元100元Cpclkclkclkjiayoumoney点阵音乐chooseoil对每个模块都有一个复位,所以省略。分块说明(1) 输入部分:输入部分有六个输入端,分别为时钟输入,10元按键,100元按键,加油键,复位键,以及附加功能中的选择油品的开关。复位信号为高电平有效,当reset=1时,所以都清为0。(2) 处理部分:主要处理的部分为加油计数器部分,当有reset=1信号后,投币计数器向加油计数器传入及时的钱数值,当有jiayou=1信号后,加油计数器的输出钱数值归零,并开始计数,直到钱数等于预定钱数。在加满油的功能上,设

5、定一个用时钟控制的计数器,当加油键按下且输入的钱数等于零时,加油键按下的时机就从计数器中把值赋给钱数,然后开始加油,后面的类似。(3) 输出部分:输出的部分不单单只有数码管的输出,还有点阵与音乐的输出,在数码管的输出中,我通过六个数来控制六个数码管的值并输出,而点阵则是通过复位与加油键的控制输出三种不同状态的动画(我姑且把它起名为欢迎加油,正在加油,谢谢加油三种状态),音乐在加油成功后播放音乐,为我国经典的小提琴曲梁祝,让人在愉悦的心情中付钱。三仿真波形1.投币计数模块10元投币计数,其中mpo3,mpo2,mpo1分别表示moneypayout的缩写,为钱输出的百位十位与个位。100元投币的

6、计数从10元计数器可以看出,最多钱可记到990:2.加油计数模块首先,chooseoil=0当加油键没有按时,money3out=mpi3,money2out=mpi2,money1out=mpi1,这个是把付钱给用户看,而oil3out,oil2out,oil1out为9,5,0,这个意思是95号油的显示,95号油的油价为5元一升,当加油键按下时,moneyout3,moneyout2,moneyout1,oilout3,oilout2,oilout1归零并开始计数。当计数到规定钱数时,停止计数,给点阵与音乐控制一个不同的信号,让他们改变状态。这里为了仿真方便起见,只选择输入10元时。(mp

7、i为moneypayin的缩写)当chooseoil=1时,加的即为97号油,97号油我设定是十元一升,此时,moneyout与oilout计数是同步的。并且注意到开始加油键没有按下时,oil3out,oil2out为9,7.说明此时已经变成了97号油。加油至邮箱满:当moneypayin=0时,设定一个计数器,在加油过程中通过加油键的按下瞬间把值传给钱数,接着就是与上面一样的加油计数方式。3.数码管显示模块我用了六个数值同时控制六个数码管的显示。具体我们可以看到不同的为显示我想让它显示的地方,不妨把oil3in,oil2in,oilin设为123,money3in,money2in,mone

8、y1in设为246.4.点阵显示模块点阵在前面已经提到分为状态一:欢迎加油;状态二:正在加油;状态三:谢谢加油三种状态。状态一,在点阵上显示英文字母HELLO和一个_的笑脸的动画,为了让LL区分开,我把它做成闪烁的形式。HELO笑脸当加油机正在加油时,此时en1传入1,en2传入0,在点阵上显示“加油”两个字的动画。“加”字:“油”字:当en1=“0”且en2=“1”时,进入第三状态:谢谢加油,此时,点阵显示动画的“THANKS”和一个笑脸,其中笑脸与欢迎加油一样,故略去。THANKS音乐模块由于控制过于简单且仿真波形没有实质性意义,故略去。四VHDL源程序1.2k分频器library iee

9、e;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity div2k isport(clk_in : in std_logic;clk_out : out std_logic);end;architecture fenpin of div2k issignal cnt :integer range 0 to 999; -当记到999时反转signal clk_tmp : std_logic;beginprocess(clk_in)beginif(clk_in'event and clk_in='1&

10、#39;)thenif cnt=999 thencnt<=0; clk_tmp<=not clk_tmp;elsecnt<=cnt+1;end if;end if;end process;clk_out<=clk_tmp;end;2.投币计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity pay isport(clk : in std_logic;reset :in std_logic;pay100,pay10 :in std_logic;money : o

11、ut integer range 0 to 990;mpo3,mpo2,mpo1: out std_logic_vector(3 downto 0);end pay;architecture paymoney of pay issignal moneypay : integer range 0 to 990;signal money3,money2,money1 :std_logic_vector(3 downto 0);beginmpo3<=money3;mpo2<=money2;mpo1<=money1;process(clk)beginif(clk'event

12、and clk='1') then if reset='1' then moneypay<=0; money3<="0000"money2<="0000"money1<="0000" -复位 elsif(pay100='1' and pay10='0') then if(moneypay<=890) then moneypay<=moneypay + 100; -投100元 money3<=money3+1; end if; el

13、sif(pay100='0' and pay10='1') then if(moneypay<=980) then if(money2="1001") then money3<=money3+1;money2<="0000" moneypay<=moneypay + 10; -投10元 else money2<=money2+1; moneypay<=moneypay + 10; end if; end if; else moneypay<=moneypay; money3<

14、=money3;money2<=money2; end if; else moneypay<=moneypay; end if; money<=moneypay;end process;end paymoney;3.加油计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jiayoucount isport(reset: in std_logic;jiayou,clk:in std_logic;chooseoil: in std_logic;dianzhenout

15、1 :out std_logic;dianzhenout2 :out std_logic;moneypayin :in integer range 0 to 990;mpi3,mpi2,mpi1 :in std_logic_vector(3 downto 0);money3out,money2out,money1out : out std_logic_vector(3 downto 0);oil3out,oil2out,oil1out : out std_logic_vector(3 downto 0);musiccontrol : out std_logic);end jiayoucount

16、;architecture simple of jiayoucount issignal deng : integer range 0 to 1999;signal money3,money2,money1 : std_logic_vector(3 downto 0);signal oil3,oil2,oil1 :std_logic_vector(3 downto 0);signal cnt2 :integer range 0 to 1;signal mpc : integer range 0 to 990;signal xiaobiao :std_logic;signal moneyrd1,

17、moneyrd2 : integer range 0 to 990;signal cnt100 : integer range 150 to 250;signal cnt200 : integer range 300 to 500;beginprocess(clk)beginif (clk'event and clk='1' ) thenif cnt100 = 250 thencnt100<=150;elsecnt100<=cnt100+1; -95号油的加满油的计数器end if;if cnt200 = 500 thencnt200<=300;els

18、ecnt200<=cnt200+1; -97号油的加满油计数器end if;end if;end process;process(clk,reset)beginif(reset='1') then -复位 xiaobiao<='0' -状态转换信号 money3<="0000"money2<="0000"money1<="0000" oil3<="0000"oil2<="0000"oil1<="0000&q

19、uot; deng<=0;cnt2<=0;mpc<=0;dianzhenout1<='0'dianzhenout2<='0'musiccontrol<='1' elsif clk'event and clk ='1' then if(jiayou='1')then xiaobiao<='1' -状态改变,让其他键对加油进程无影响 if(moneypayin=0) then -如果输入钱等于零,则用计数器随机3050升 moneyrd1<=cnt

20、100; moneyrd2<=cnt200; else -传入钱数值 moneyrd1<=moneypayin; moneyrd2<=moneypayin; end if; end if; if(xiaobiao='0') thenif(chooseoil='0') then -95号油 money3out<=mpi3; money2out<=mpi2; money1out<=mpi1; oil3out<="1001" oil2out<="0101" oil1out<=

21、"0000"elsif(chooseoil='1') then -97号油 money3out<=mpi3; money2out<=mpi2; money1out<=mpi1; oil3out<="1001" oil2out<="0111" oil1out<="0000"end if; end if; if(xiaobiao='1') thencase chooseoil is -95号油的分支计数when '0' => if

22、 deng = 1999 then cnt2<=cnt2+1; if(mpc<moneyrd1) then dianzhenout1<='1'dianzhenout2<='0'musiccontrol<='1' if( oil3="1001" and oil2="1001" and oil1="1001") then oil3<="1001" oil2<="1001" oil1<="1001

23、" elsif(oil2="1001" and oil1="1001") then oil3<=oil3+1; oil2<="0000"oil1<="0000" elsif(oil1="1001") then oil2<=oil2+1; oil1<="0000" else oil1<=oil1+1; end if; if( money3="0101" and money2="0000" an

24、d money1="0000" and cnt2=1) then -此时设置cnt2,让oil+2时,money+1. money3<="0101" money2<="0000" money1<="0000"mpc<=mpc+1; elsif(money2="1001" and money1="1001" and cnt2=1) then money3<=money3+1; money2<="0000"money1<

25、;="0000" ;mpc<=mpc+1; elsif(money1="1001" and cnt2=1) then money2<=money2+1; money1<="0000"mpc<=mpc+1; elsif(cnt2=1) then money1<=money1+1;mpc<=mpc+1; else money3<=money3; money2<=money2; money1<=money1; end if; else dianzhenout1<='0

26、9;dianzhenout2<='1' -点阵输出 musiccontrol<='0' money3<=money3; money2<=money2; money1<=money1; oil3<=oil3; oil2<=oil2; oil1<=oil1; mpc<=mpc; end if; deng <=0; else deng<=deng+1;money3out<=money3;money2out<=money2;money1out<=money1;oil3out<=oi

27、l3;oil2out<=oil2;oil1out<=oil1; end if;when '1' => -97号油的分支计数 if deng = 1999 then if(mpc<moneyrd2) then dianzhenout1<='1'dianzhenout2<='0'musiccontrol<='1' if( oil3="1001" and oil2="1001" and oil1="0000") then oil3<

28、;="1001" oil2<="1001" oil1<="0000" elsif(oil2="1001" and oil1="1001") then oil3<=oil3+1; oil2<="0000"oil1<="0000" elsif(oil1="1001") then oil2<=oil2+1; oil1<="0000" else oil1<=oil1+1; en

29、d if; if( money3="1001" and money2="1001" and money1="0000") then -此时不用设置cnt2,oil计数与money计数同步。 money3<="1001" money2<="1001" money1<="0000"mpc<=mpc+1; elsif(money2="1001" and money1="1001") then money3<=mo

30、ney3+1; money2<="0000"money1<="0000" ;mpc<=mpc+1; elsif(money1="1001") then money2<=money2+1; money1<="0000"mpc<=mpc+1; else money1<=money1+1;mpc<=mpc+1; end if; else dianzhenout1<='0'dianzhenout2<='1' musiccontrol

31、<='0' money3<=money3; money2<=money2; money1<=money1; oil3<=oil3; oil2<=oil2; oil1<=oil1; mpc<=mpc; end if; deng <=0; else deng<=deng+1;money3out<=money3;money2out<=money2;money1out<=money1;oil3out<=oil3;oil2out<=oil2;oil1out<=oil1; end if;end

32、case; end if; end if; end process;end simple;4.数码管显示library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity shumaguanxianshi isport(clk :in std_logic;-jiayou : in std_logic;money3in,money2in,money1in :in std_logic_vector(3 downto 0);oil3in,oil2in,oil1in : in std_logic_vector(

33、3 downto 0);-moneypayin : in integer range 0 to 990;sg:out std_logic_vector(7 downto 0);bt:out std_logic_vector(5 downto 0);end;architecture xianshi of shumaguanxianshi issignal cnt6 : integer range 0 to 5;signal wei :integer range 0 to 5;signal clk_tmp :std_logic;signal money3,money2,money1 : std_l

34、ogic_vector(3 downto 0);signal oil3,oil2,oil1 : std_logic_vector(3 downto 0);beginmoney3<=money3in;money2<=money2in;money1<=money1in;oil3<=oil3in;oil2<=oil2in;oil1<=oil1in;clk_tmp<=clk;p1:process(cnt6)begincase cnt6 is -数码管扫描when 0 =>bt<="011111" wei<=5;when 1

35、 =>bt<="101111" wei<=4;when 2 =>bt<="110111" wei<=3;when 3 =>bt<="111011" wei<=2;when 4 =>bt<="111101" wei<=1;when 5 =>bt<="111110" wei<=0;when others => null;end case;end process p1;p2:process(clk_tmp)

36、beginif (clk_tmp'event and clk_tmp='1' )thenif cnt6 = 5 thencnt6<=0;else cnt6 <= cnt6 + 1;end if;end if;end process p2;p3:process(wei)begincase wei is when 5 => case oil3(3 downto 0) is -油量十位 when "0000" => sg(7 downto 0) <="11111100" when "0001&qu

37、ot; => sg(7 downto 0) <="01100000" when "0010" => sg(7 downto 0) <="11011010" when "0011" => sg(7 downto 0) <="11110010" when "0100" => sg(7 downto 0) <="01100110" when "0101" => sg(7 downto 0)

38、 <="10110110" when "0110" => sg(7 downto 0) <="10111110" when "0111" => sg(7 downto 0) <="11100000" when "1000" => sg(7 downto 0) <="11111110" when "1001" => sg(7 downto 0) <="11110110&quo

39、t; when others => sg(7 downto 0) <="11111100" end case; when 4 => case oil2(3 downto 0) is -油量个位 when "0000" => sg(7 downto 0) <="11111101" when "0001" => sg(7 downto 0) <="01100001" when "0010" => sg(7 downto 0) <

40、;="11011011" when "0011" => sg(7 downto 0) <="11110011" when "0100" => sg(7 downto 0) <="01100111" when "0101" => sg(7 downto 0) <="10110111" when "0110" => sg(7 downto 0) <="10111111" w

41、hen "0111" => sg(7 downto 0) <="11100001" when "1000" => sg(7 downto 0) <="11111111" when "1001" => sg(7 downto 0) <="11110111" when others => sg(7 downto 0) <="11111101" end case;when 3 => case oil1(3 d

42、ownto 0) is -油量十分位 when "0000" => sg(7 downto 0) <="11111100" when "0001" => sg(7 downto 0) <="01100000" when "0010" => sg(7 downto 0) <="11011010" when "0011" => sg(7 downto 0) <="11110010" when

43、"0100" => sg(7 downto 0) <="01100110" when "0101" => sg(7 downto 0) <="10110110" when "0110" => sg(7 downto 0) <="10111110" when "0111" => sg(7 downto 0) <="11100000" when "1000" => s

44、g(7 downto 0) <="11111110" when "1001" => sg(7 downto 0) <="11110110" when others => sg(7 downto 0) <="11111100" end case;when 2 => case money3(3 downto 0) is -钱百位 when "0000" => sg(7 downto 0) <="11111100" when &quo

45、t;0001" => sg(7 downto 0) <="01100000" when "0010" => sg(7 downto 0) <="11011010" when "0011" => sg(7 downto 0) <="11110010" when "0100" => sg(7 downto 0) <="01100110" when "0101" => sg(7

46、downto 0) <="10110110" when "0110" => sg(7 downto 0) <="10111110" when "0111" => sg(7 downto 0) <="11100000" when "1000" => sg(7 downto 0) <="11111110" when "1001" => sg(7 downto 0) <="111

47、10110" when others => sg(7 downto 0) <="11111100" end case;when 1 => case money2(3 downto 0) is -钱十位 when "0000" => sg(7 downto 0) <="11111100" when "0001" => sg(7 downto 0) <="01100000" when "0010" => sg(7 down

48、to 0) <="11011010" when "0011" => sg(7 downto 0) <="11110010" when "0100" => sg(7 downto 0) <="01100110" when "0101" => sg(7 downto 0) <="10110110" when "0110" => sg(7 downto 0) <="1011111

49、0" when "0111" => sg(7 downto 0) <="11100000" when "1000" => sg(7 downto 0) <="11111110" when "1001" => sg(7 downto 0) <="11110110" when others => sg(7 downto 0) <="11111100" end case;when 0 => case

50、 money1(3 downto 0) is -钱个位 when "0000" => sg(7 downto 0) <="11111100" when "0001" => sg(7 downto 0) <="01100000" when "0010" => sg(7 downto 0) <="11011010" when "0011" => sg(7 downto 0) <="11110010&qu

51、ot; when "0100" => sg(7 downto 0) <="01100110" when "0101" => sg(7 downto 0) <="10110110" when "0110" => sg(7 downto 0) <="10111110" when "0111" => sg(7 downto 0) <="11100000" when "1000"

52、; => sg(7 downto 0) <="11111110" when "1001" => sg(7 downto 0) <="11110110" when others => sg(7 downto 0) <="11111100" end case;when others =>null;end case;end process p3;end xianshi;5.点阵显示library ieee;use ieee.std_logic_1164.all;use ieee.

53、std_logic_unsigned.all;entity dianzhen isport(clk : in std_logic;en1,en2: in std_logic;lie : out std_logic_vector(7 downto 0);com : out std_logic_vector(7 downto 0);end dianzhen;architecture behave of dianzhen issignal cnt8 :integer range 0 to 7;signal wei :integer range 0 to 7;signal jydianzhen : i

54、nteger range 0 to 55999;beginp1:process(cnt8)begincase cnt8 is -点阵扫描when 0 =>com<="01111111" wei<=0;when 1 =>com<="10111111" wei<=1;when 2 =>com<="11011111" wei<=2;when 3 =>com<="11101111" wei<=3;when 4 =>com<="11

55、110111" wei<=4;when 5 =>com<="11111011" wei<=5;when 6 =>com<="11111101" wei<=6;when 7 =>com<="11111110" wei<=7;when others => null;end case;end process p1;p2:process(clk)beginif (clk'event and clk='1' )thenif cnt8 = 7 th

56、encnt8<=0;else cnt8 <= cnt8 + 1;end if;if(jydianzhen = 55999 ) thenjydianzhen<=0;else jydianzhen<=jydianzhen+1;end if;end if;end process p2;p3:process(wei,en1,en2)begincase en2 is when '0' =>case en1 iswhen '0' =>if(jydianzhen<6999) then -“H”case wei iswhen 0=>

57、;lie<="11000011"when 1=>lie<="11000011"when 2=>lie<="11000011"when 3=>lie<="11111111"when 4=>lie<="11111111"when 5=>lie<="11000011"when 6=>lie<="11000011"when 7=>lie<="11000011&quo

58、t;end case;elsif( jydianzhen>=6999 and jydianzhen<9999) then -NULLcase wei iswhen 0=>lie<="00000000"when 1=>lie<="00000000"when 2=>lie<="00000000"when 3=>lie<="00000000"when 4=>lie<="00000000"when 5=>lie<=&qu

59、ot;00000000"when 6=>lie<="00000000"when 7=>lie<="00000000"end case;elsif(jydianzhen>=9999 and jydianzhen<16999) then -Ecase wei iswhen 0=>lie<="11111111"when 1=>lie<="11111111"when 2=>lie<="00000011"when 3=>

60、;lie<="11111111"when 4=>lie<="11111111"when 5=>lie<="00000011"when 6=>lie<="11111111"when 7=>lie<="11111111"end case;elsif( jydianzhen>=16999 and jydianzhen<19999) then -NULLcase wei iswhen 0=>lie<="0000000

61、0"when 1=>lie<="00000000"when 2=>lie<="00000000"when 3=>lie<="00000000"when 4=>lie<="00000000"when 5=>lie<="00000000"when 6=>lie<="00000000"when 7=>lie<="00000000"end case;elsif(jydia

62、nzhen>=19999 and jydianzhen<26999)then -Lcase wei iswhen 0=>lie<="00000011"when 1=>lie<="00000011"when 2=>lie<="00000011"when 3=>lie<="00000011"when 4=>lie<="00000011"when 5=>lie<="00000011"when 6=&

63、gt;lie<="11111111"when 7=>lie<="11111111"end case;elsif( jydianzhen>=26999 and jydianzhen<29999) then -NULLcase wei iswhen 0=>lie<="00000000"when 1=>lie<="00000000"when 2=>lie<="00000000"when 3=>lie<="00000

64、000"when 4=>lie<="00000000"when 5=>lie<="00000000"when 6=>lie<="00000000"when 7=>lie<="00000000"end case;elsif(jydianzhen>=29999 and jydianzhen<36999) then -Lcase wei iswhen 0=>lie<="00000011"when 1=>lie<="00000011"wh

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论