程序说明:1。此程序包括分频,计数控制,显示控制部分。 2。开机显示00。00。00,用户课随时计时,暂停,清零,最大计时可到59分59。99秒。 3。技术时钟为100HZ 4。采用时分复用的方法控制4个数码管的显示,可节省资源。 程序如下: Libraryieee; Useieee。stdlogic1164。all; Useieee。stdlogicarith。all; Useieee。stdlogicunsigned。all; Entitywatchis Port(sel:outstdlogicvector(6downto 1); seg:outstdlogicvector(7downto0); Beginstop:instdlogic; Reset:instdlogic; Cp2:instdlogic); Endwatch; Architecturebehaveofwatchis Signalnum1:stdlogicvector(3downto0); Signalnum2:stdlogicvector(3downto0); Signalnum3:stdlogicvector(3downto0); Signalnum4:stdlogicvector(3downto0); Signalnum5:stdlogicvector(3downto0); Signalnum6:stdlogicvector(3downto0); Signalnum:stdlogicvector(3downto0); Signalnumlet:stdlogicvector(2downto0); Signalcount:stdlogicvector(17downto 1); Signalselsig:stdlogicvector(6downto 1); Signalsegsig:stdlogicvector(7downto0); Signalcp1:stdlogic; Signalcp3:stdlogic; Begin Process(cp 2)分频。 Begin If(cp2eventandcp21)then if(Count1100011010011111)then countlt;00000000000000000;cp1lt;notcp1; elsecountlt;count1; endif; endif; cp3lt;count (10); endprocess; process(cp 1) begin ifreset1thennum1(3downto0)lt;0000; num2(3downto0)lt;0000; num3(3downto0)lt;0000; num4(3downto0)lt;0000; num5(3downto0)lt;0000; num6(3downto0)lt;0000; elseifcp1eventandcp11then ifbeginstop1thennum1lt;num11; ifnum1(3downto0)1001thenifnum2(3downto0)1001then num2(3downto0)lt;0000;num3lt;num31; ifnum3(3downto0)1001then num3(3downto0)lt;0000;num4lt;num41; ifnum4(3downto0)0101then num4(3downto0)lt;0000;num5lt;num51; ifnum5(3downto0)1001then num5(3downto0)lt;0000;num6lt;num61; ifnum6(3downto0)0101then num6(3downto0)lt;0000; endif;endif;endif;endif;endif;endif;endif; endif;endif; endprocess; process(cp 3) begin if(cp3eventandcp31)then if(numlet(2downto0)000)then numlt;num1;selsig(6downto 1)lt;111110;endif; if(numlet(2downto0)001)then numlt;num2;selsig(6downto 1)lt;111101;endif; if(numlet(2downto0)010)then numlt;num3;selsig(6downto 1)lt;111011;endif; if(numlet(2downto0)011)then numlt;num4;selsig(6downto 1)lt;110111;endif; if(numlet(2downto0)100)then numlt;num5;selsig(6downto 1)lt;101111;endif; numlet(2downto0)lt;numlet(2downto0)1; if(numlet(2downto0)101)then numlet(2downto0)lt;011111;endif; endif; if(num(3downto0)0000)then segsig(7downto0)lt;01111111;endif; if(num(3downto0)0001)then segsig(7downto0)lt;00001101;endif; if(num(3downto0)0010)then segsig(7downto0)lt;10110111;endif; if(num(3downto0)0011)then segsig(7downto0)lt;10011111;endif; if(num(3downto0)0100)then segsig(7downto0)lt;11001101;endif; if(num(3downto0)0101)then segsig(7downto0)lt;11011011;endif; if(num(3downto0)0110)then segsig(7downto0)lt;11111011;endif; if(num(3downto0)0111)then segsig(7downto0)lt;00001111;endif; if(num(3downto0)1000)then segsig(7downto0)lt;11111111;endif; if(num(3downto0)1001)then segsig(7downto0)lt;11011111;endif; endprocess; sellt;selsig; seg(7downto0)lt;segsig(7downto0); endbehave;