资源描述:
《刘艳萍_第4章习题答案》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、第四章习题(参考答案)4-3:(1)LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITYcounterISGENERIC(max_value:integer:=15);PORT(clk,clr,en,load,dir:instd_logic;data_in:inintegerrange0tomax_value;Count:outintegerrange0tomax_value;co:outstd_logic);ENDcounter;ARCHITECTUREaOFcounter
2、ISsignalcnt:integerrange0tomax_value;BEGINPROCESS(clr,clk)BEGINifclr=’0’thencnt<=0;elsif(clk’eventandclk='1')thenifload='1'thencnt<=data_in;elsifen='1'thenifdir='1'thenifcnt=max_valuethencnt<=0;elsecnt<=cnt+1;endif;elseifcnt=0thencnt<=max_value;elsecnt<=cnt-1;endif;endif;endif;endif;END
3、PROCESS;count<=cnt;Co<=‘1’when(cnt=max_valueanddir=‘1’)or(cnt=0anddir=‘0’)else‘0’;Enda;(2)计数结果由共阴极七段数码管显示LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITYcounterISGENERIC(max_value:integer:=15);PORT(clk,clr,en,load,dir:instd_logic;data_in:inintegerrange0tomax_val
4、ue;Count:outstd_logic_vector(0to6);co:outstd_logic);ENDcounter;ARCHITECTUREaOFcounterISsignalcnt:integerrange0tomax_value;BEGINPROCESS(clr,clk)BEGINifclr=’0’thencnt<=0;elsif(clk’eventandclk='1')thenifload='1'thencnt<=data_in;elsifen='1'thenifdir='1'thenifcnt=max_valuethencnt<=0;elsecnt<
5、=cnt+1;endif;elseifcnt=0thencnt<=max_value;elsecnt<=cnt-1;endif;endif;endif;endif;ENDPROCESS;Co<=‘1’when(cnt=max_valueanddir=‘1’)or(cnt=0anddir=‘0’)else‘0’;withcntselectcount<=“"when1,--1“"when2,--2“"when3,--3“"when4,--4“"when5,--5“"when6,--6“"when7,--7“"when8,--8“"when9,--9:“”when15,--
6、F“"whenothers;Enda;(3)结果显示为十进制数LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITYcounterISGENERIC(max_value:integer:=15);PORT(clk,clk1,clr,en,load,dir:instd_logic;data_in:inintegerrange0tomax_value;Count:outstd_logic_vector(0to6);Scanout:outstd_logic_vector(0to1);
7、co:outstd_logic);ENDcounter;ARCHITECTUREaOFcounterISsignalcnt:integerrange0tomax_value;signalcnt1:integerrange0to9;signalcnt2:integerrange0to1;signalhex:integerrange0to9;signalscan:std_logic_vector(0to1);BEGINPROCESS(clr,clk)BEGINifclr=‘0’thencnt<=0;elsif(clk’eventandclk='1')th