《數(shù)字電子技術與接口技術試驗教程》課件第6章_第1頁
《數(shù)字電子技術與接口技術試驗教程》課件第6章_第2頁
《數(shù)字電子技術與接口技術試驗教程》課件第6章_第3頁
《數(shù)字電子技術與接口技術試驗教程》課件第6章_第4頁
《數(shù)字電子技術與接口技術試驗教程》課件第6章_第5頁
已閱讀5頁,還剩125頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

第6章數(shù)字鐘和頻率計設計

6.1數(shù)字鐘設計6.2數(shù)字頻率計

6.1數(shù)?字?鐘?設?計

數(shù)字鐘設計的關鍵在于產(chǎn)生秒脈沖、對秒脈沖計數(shù)并產(chǎn)生分和小時以及動態(tài)顯示時、分、秒信息。

實驗要求:

(1)在開發(fā)板上運行有關程序。

(2)設計一個完整的數(shù)字鐘,小時和分鐘用數(shù)碼管顯示,秒用發(fā)光二極管閃爍顯示,每秒閃爍一次。如有可能,請增加校時功能。

Basys2板上只有4個數(shù)碼管,因此這里只設計了一個秒和分計時時鐘。6.1.1采用8421BCD碼計數(shù)的Verilog時鐘程序

下面是采用8421BCD計數(shù),并在一個模塊中實現(xiàn)時鐘功能的Verilog程序。時鐘程序比較簡單,可以用一個模塊直接實現(xiàn)。由主時鐘(50MHz)分頻得到秒信號,計秒到60時分加1,秒清零,計分到60時,分清零。請讀者分析,為什么程序從表面上看秒和分都是計到59時就清零了,而不是計到60再清零。

moduleClock_Sec_Min_disp(

inputwireclk,

inputwireclr,

outputSecond_Flash,

outputreg[6:0]a_to_g,

outputreg[3:0]an

);

//中間變量定義

reg[3:0]LED0_num,LED1_num,LED2_num,LED3_num;

reg[1:0]s;

reg[3:0]digit;

reg[16:0]clkdiv; //(1FFFF)*20ns=2.6ms

reg[26:0]q1; //設一足夠長的計數(shù)器

regsec;

reg[3:0]Second_L;

reg[3:0]Second_H;

reg[3:0]Minute_L;

reg[3:0]Minute_H;

//初始化

initialbegin

Second_L=5;

Second_H=5;

Minute_L=8;

Minute_H=5;

LED3_num=Second_L;

LED2_num=Second_H;

LED1_num=Minute_L;

LED0_num=Minute_H;

end

//動態(tài)數(shù)碼管掃描顯示

always@(*)

begin

an=4'b1111; //禁止所有數(shù)碼管顯示

s<=clkdiv[16:15];//間隔2.6ms使能An

an[s]=0;//根據(jù)s使能數(shù)碼管其中之一

case(s)//根據(jù)s取對應的數(shù)碼管上要顯示的數(shù)據(jù)

0:digit<=LED0_num[3:0];

1:digit<=LED1_num[3:0];

2:digit<=LED2_num[3:0];

3:digit<=LED3_num[3:0];

default:digit<=LED3_num[3:0];

endcase

case(digit) //七段譯碼表

0:a_to_g=7'b0000001;

1:a_to_g=7'b1001111;

2:a_to_g=7'b0010010;

3:a_to_g=7'b0000110;

4:a_to_g=7'b1001100;

5:a_to_g=7'b0100100;

6:a_to_g=7'b0100000;

7:a_to_g=7'b0001111;

8:a_to_g=7'b0000000;

9:a_to_g=7'b0000100;

'hA:a_to_g=7'b0001000;

'hB:a_to_g=7'b1100000;

'hC:a_to_g=7'b0110001;

'hD:a_to_g=7'b1000010;

'hE:a_to_g=7'b0110000;

'hF:a_to_g=7'b0111000;

default:a_to_g=7'b0000001;//0

endcase

end

//主時鐘計數(shù):50MHz時鐘,周期20ns,計數(shù)到1FFFFh時長2621420ns,約2.6ms

always@(posedgeclk)

begin

clkdiv<=clkdiv+1;

end

//時鐘程序:計數(shù)到50000000為1s,計秒得分

always@(posedgeclkorposedgeclr)

begin

if(clr==1)

begin

q1<=0;

LED0_num=0;

LED1_num=0;

LED2_num=0;

LED3_num=0;

Second_L<=0;

Second_H<=0;

Minute_L<=0;

Minute_H<=0;

end

elseif(q1==50000000)

begin

q1<=0;

sec=~sec;

LED3_num[3:0]=Second_L[3:0];

LED2_num[3:0]=Second_H[3:0];

LED1_num[3:0]=Minute_L[3:0];

LED0_num[3:0]=Minute_H[3:0];

Second_L<=Second_L+1;

if(Second_L==9)

begin

Second_L<=0;

Second_H<=Second_H+1;

end

if(Second_H==5&&Second_L==9)

begin

Second_L<=0;

Second_H<=0;

Minute_L<=Minute_L+1;

if(Minute_L==9)

begin

Minute_L<=0;

Minute_H<=Minute_H+1;

end

if(Minute_H==5&&Minute_L==9)

begin

Minute_L<=0;

Minute_H<=0;

end

end

end

else

q1<=q1+1;

end

assignSecond_Flash=sec;//1Hz

endmodule約束文件如下:

#Basys2約束文件:

NET“a_to_g[0]”LOC=M12;

NET“a_to_g[1]”LOC=L13;

NET“a_to_g[2]”LOC=P12;

NET“a_to_g[3]”LOC=N11;

NET“a_to_g[4]”LOC=N14;

NET“a_to_g[5]”LOC=H12;

NET“a_to_g[6]”LOC=L14;

NET“an[0]”LOC=K14;

NET"an[1]"LOC=M13;

NET"an[2]"LOC=J12;

NET"an[3]"LOC=F12;

NET"clk"LOC="B8"; //50MHz時鐘

NET"clr"LOC="P11"; //SW0

NET"Second_Flash"LOC="M5"; //LD06.1.2采用模塊化設計Verilog時鐘程序

在數(shù)字系統(tǒng)中一般采用自上而下的設計方法,將系統(tǒng)分成若干個功能模塊,模塊還可繼續(xù)向下劃分成子模塊,直至分成許多最基本的功能模塊。

下面將時鐘程序分為秒脈沖發(fā)生模塊、秒60進制模塊、分60進制模塊以及動態(tài)數(shù)碼管顯示模塊。秒60進制模塊和分60進制模塊的程序是一樣的。一個模塊設計好后,可以在頂層模塊中多次使用,只要改變該模塊例化后的模塊名稱,并給出其相應的輸入輸出連接即可。

//頂層設計:

moduleClock_top(

inputwireclk,

inputwireclr,

outputSecond_Flash,

output[6:0]a_to_g,

output[3:0]an

);

//模塊間連接定義(注意必須是wire)

wire[3:0]Second_L;

wire[3:0]Second_H;

wire[3:0]Minute_L;

wire[3:0]Minute_H;

wirejinwei;

SecondPulseU0(

.clk(clk),

.clr(clr),

.sec(Second_Flash)

);

cnt60U1(

.clk(Second_Flash),

.clr(clr),

.cnt60_L(Second_L),

.cnt60_H(Second_H),

.carry(jinwei)

);

cnt60U2(

.clk(jinwei),

.clr(clr),

.cnt60_L(Minute_L),

.cnt60_H(Minute_H),

.carry(carry)

);

dispU3(

.clk(clk),

.LED0_num(Second_L),

.LED1_num(Second_H),

.LED2_num(Minute_L),

.LED3_num(Minute_H),

.a_to_g(a_to_g),

.an(an)

);

endmodule

//秒脈沖發(fā)生模塊:

moduleSecondPulse(

inputwireclk,

inputwireclr,

outputregsec

);

//中間變量定義

reg[26:0]q1;//設一足夠長的計數(shù)器

//時鐘程序:計數(shù)到25000000輸出sec翻轉一次,翻轉兩次為1s

always@(posedgeclkorposedgeclr)

begin

if(clr==1)

q1<=0;

elseif(q1==25000000)

begin

q1<=0;

sec=~sec;

end

else

q1<=q1+1;

end

endmodule

//60進制計數(shù)模塊:

modulecnt60(

inputwireclk,

inputwireclr,

outputreg[3:0]cnt60_L,

outputreg[3:0]cnt60_H,

outputregcarry

);

//初始化

initialbegin

cnt60_L=8;

cnt60_H=5;

end

//60進制計數(shù)器

always@(posedgeclkorposedgeclr)

begin

if(clr==1)

begin

cnt60_L<=0;

cnt60_H<=0;

end

else

begin

carry<=0;

cnt60_L<=cnt60_L+1;

if(cnt60_L==9)

begin

cnt60_L<=0;

cnt60_H<=cnt60_H+1;

end

if(cnt60_H==5&&cnt60_L==9)

begin

cnt60_L<=0;

cnt60_H<=0;

carry<=1;

end

end

end

endmodule

//數(shù)碼管動態(tài)顯示模塊:

moduledisp(

inputwireclk,

input[3:0]LED0_num,

input[3:0]LED1_num,

input[3:0]LED2_num,

input[3:0]LED3_num,

outputreg[6:0]a_to_g,

outputreg[3:0]an

);

//中間變量定義

reg[1:0]s;

reg[3:0]digit;

reg[16:0]clkdiv;//(1FFFF)*20ns=2.6ms

//動態(tài)數(shù)碼管掃描顯示

always@(*)

begin

an=4'b1111; //禁止所有數(shù)碼管顯示

s<=clkdiv[16:15];//間隔2.6ms使能An

an[s]=0; //根據(jù)s使能數(shù)碼管其中之一

case(s)//根據(jù)s取對應的數(shù)碼管上要顯示的數(shù)據(jù)

0:digit<=LED0_num[3:0];

1:digit<=LED1_num[3:0];

2:digit<=LED2_num[3:0];

3:digit<=LED3_num[3:0];

default:digit<=LED3_num[3:0];

endcase

case(digit) //七段譯碼表

0:a_to_g=7'b0000001;

1:a_to_g=7'b1001111;

2:a_to_g=7'b0010010;

3:a_to_g=7'b0000110;

4:a_to_g=7'b1001100;

5:a_to_g=7'b0100100;

6:a_to_g=7'b0100000;

7:a_to_g=7'b0001111;

8:a_to_g=7'b0000000;

9:a_to_g=7'b0000100;

'hA:a_to_g=7'b0001000;

'hB:a_to_g=7'b1100000;

'hC:a_to_g=7'b0110001;

'hD:a_to_g=7'b1000010;

'hE:a_to_g=7'b0110000;

'hF:a_to_g=7'b0111000;

default:a_to_g=7'b0000001;//0

endcase

end

//主時鐘計數(shù):50MHz時鐘,周期20ns,計數(shù)到1FFFFh時長2621420ns,約2.6ms

always@(posedgeclk)

begin

clkdiv<=clkdiv+1;

end

endmodule

#Basys2約束文件:

NET"a_to_g[0]"LOC=M12;

NET"a_to_g[1]"LOC=L13;

NET"a_to_g[2]"LOC=P12;

NET"a_to_g[3]"LOC=N11;

NET“a_to_g[4]”LOC=N14;

NET“a_to_g[5]”LOC=H12;

NET“a_to_g[6]”LOC=L14;

NET“an[3]”LOC=K14;

NET“an[2]”LOC=M13;

NET“an[1]”LOC=J12;

NET“an[0]”LOC=F12;

NET“clk”LOC=“B8”; //?50?MHz時鐘

NET“clr”LOC=“P11”;//?SW0

NET"Second_Flash"LOC="M5";//?LD0

圖6-1為VerilogHDL設計的數(shù)字鐘的頂層原理圖。圖6-1用VerilogHDL設計的數(shù)字鐘的頂層原理圖

6.1.3采用狀態(tài)機設計動態(tài)數(shù)碼管顯示的時鐘VHDL程序

下面的時鐘VHDL程序分為BCD碼計時模塊和動態(tài)數(shù)碼管顯示模塊。采用狀態(tài)機法設計動態(tài)數(shù)碼管顯示。顯示模塊先將輸入的十進制數(shù)的個位譯碼,加在七段數(shù)碼管的段控制線上,在顯示掃描時鐘的作用下,選通個位上的數(shù)碼管,個位上的數(shù)碼管亮,其他數(shù)碼管滅。然后輸出十位上數(shù)碼管要顯示的內(nèi)容,選通十位上的數(shù)碼管。這樣依次輸出各位的譯碼值,逐個選通數(shù)碼管。由于掃描頻率為1kHz,看起來不會有閃爍的感覺。

--頂層設計:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_unsigned.all;

entityClock_topis

Port(StdClock:inSTD_LOGIC;

Second_Flash:outSTD_LOGIC;

Segments:outSTD_LOGIC_VECTOR(7downto0);

Position:outSTD_LOGIC_VECTOR(3downto0));

endClock_top;

architectureBehavioralofClock_topis

COMPONENTClock_Counter

PORT(

StdClock:INstd_logic;

Second_Flash:OUTstd_logic;

Counter32_16:OUTstd_logic_vector(15downto0)

);

ENDCOMPONENT;

COMPONENTDynamic_Display

PORT(

StdClock:INstd_logic;

DataInput:INstd_logic_vector(15downto0);

Segments:OUTstd_logic_vector(7downto0);

Position:OUTstd_logic_vector(3downto0)

);

ENDCOMPONENT;

signalCounter32_tmp:STD_LOGIC_VECTOR(15downto0);

begin

Inst_Clock_Counter:Clock_CounterPORTMAP(

StdClock=>StdClock,

Second_Flash=>Second_Flash,

Counter32_16=>Counter32_tmp

);

Inst_Dynamic_Display:Dynamic_DisplayPORTMAP(

StdClock=>StdClock,

DataInput=>Counter32_tmp,

Segments=>Segments,

Position=>Position

);

endBehavioral;

--計時模塊:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_unsigned.all;

entityClock_Counteris

Port(StdClock:inSTD_LOGIC;

Second_Flash:outSTD_LOGIC;

Counter32_16:outSTD_LOGIC_VECTOR(15downto0));

endClock_Counter;

architectureBehavioralofClock_Counteris

---信號定義

signalcounter25_reg:STD_LOGIC_VECTOR(25downto0);

signalSecond_L:STD_LOGIC_VECTOR(3downto0):="0101";

signalSecond_H:STD_LOGIC_VECTOR(3downto0):="0101";

signalMintue_L:STD_LOGIC_VECTOR(3downto0):="1000";

signalMintue_H:STD_LOGIC_VECTOR(3downto0):="0101";

begin

process(StdClock)

begin

ifrising_edge(StdClock)then

ifcounter25_reg<50000000then--f?=?50MHz,T?=?20ns,50000000×20ns?=?1s

counter25_reg<=counter25_reg+1;

else

counter25_reg<="00000000000000000000000000";

Second_L<=Second_L+1;

ifSecond_L=9then

Second_L<="0000";

Second_H<=Second_H+1;

endif;

ifSecond_H=5andSecond_L=9then

Second_L<="0000";

Second_H<="0000";

Mintue_L<=Mintue_L+1;

ifMintue_L=9then

Mintue_L<="0000";

Mintue_H<=Mintue_H+1;

endif;

ifMintue_H=5andMintue_L=9then

Mintue_L<="0000";

Mintue_H<="0000";

endif;

endif;

endif;

endif;

endprocess;

Counter32_16(3downto0)<=Second_L;

Counter32_16(7downto4)<=Second_H;

Counter32_16(11downto8)<=Mintue_L;

Counter32_16(15downto12)<=Mintue_H;

Second_Flash<=counter25_reg(25);--50000000?=?2FAF080H

endBehavioral;

--采用狀態(tài)機設計的動態(tài)數(shù)碼管顯示模塊:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

entityDynamic_Displayis

Port(StdClock:inSTD_LOGIC;

DataInput:inSTD_LOGIC_VECTOR(15downto0);

Segments:outSTD_LOGIC_VECTOR(7downto0);

Position:outSTD_LOGIC_VECTOR(3downto0));

endDynamic_Display;

architectureBehavioralofDynamic_Displayis

---狀態(tài)機定義

typestate_typeis(led1,led2,led3,led4);

signalnext_state:state_type;

---信號定義

signalclk1KHz_reg:STD_LOGIC;

signalScanClock_reg:STD_LOGIC;

signaldatacut_reg:STD_LOGIC_VECTOR(3downto0):="0000";

signaldatacut_reg2:STD_LOGIC_VECTOR(3downto0):="0000";

signaldatacut_reg3:STD_LOGIC_VECTOR(3downto0):="0000";

signaldatacut_reg4:STD_LOGIC_VECTOR(3downto0):="0000";

signalposition_reg:STD_LOGIC_VECTOR(3downto0):="1110";

signalsegments_reg:STD_LOGIC_VECTOR(7downto0):="00000000";

---signalDataInput:STD_LOGIC_VECTOR(15downto0):="0101011001111000";---顯示5678

----------------------------------------

begin

---由50MHz標準時鐘信號分頻得到1kHz顯示掃描信號

Clk1KHz_Proc:process(StdClock)

variablecnt1:integerrange0to24999;

begin

ifrising_edge(StdClock)then

ifcnt1=24999then

cnt1:=0;

clk1KHz_reg<=notclk1KHz_reg;

else

cnt1:=cnt1+1;

endif;

endif;

endprocess;

ScanClock_reg<=clk1KHz_reg;

---數(shù)碼管選擇處理

Position_Process:process(ScanClock_reg)

begin

ifrising_edge(ScanClock_reg)then

casenext_stateis

---第一個數(shù)碼管亮

whenled1=>

position_reg<="1110";

datacut_reg<=DataInput(3downto0);

next_state<=led2;

---第二個數(shù)碼管亮

whenled2=>

position_reg<="1101";

datacut_reg2<=DataInput(7downto4);

datacut_reg<=datacut_reg2;

next_state<=led3;

---第三個數(shù)碼管亮

whenled3=>

position_reg<="1011";

datacut_reg3<=DataInput(11downto8);

datacut_reg<=datacut_reg3;

next_state<=led4;

---第四個數(shù)碼管亮

whenled4=>

position_reg<="0111";

datacut_reg4<=DataInput(15downto12);

datacut_reg<=datacut_reg4;

next_state<=led1;

---所有數(shù)碼管全滅

whenothers=>

position_reg<="0000";

datacut_reg<="1100";

next_state<=led1;

endcase;

endif;

endprocess;

withdatacut_regselect

segments_reg<="10000001"when"0000",---0

"11001111"when"0001",---1

"10010010"when"0010",---2

"10000110"when"0011",---3

"11001100"when"0100",---4

"10100100"when"0101",---5

"10100000"when"0110",---6

"10001111"when"0111",---7

"10000000"when"1000",---8

"10000100"when"1001",---9

"10001000"when"1010",---A

"11100000"when"1011",---B

"10110001"when"1100",---C

"11000010"when"1101",---D

"10110000"when"1110",---E

"10111000"when"1111",---F

"11111111"whenothers;---F.

segments<=segments_reg;

position<=position_reg;

endBehavioral;

#Basys2約束文件:

NET"StdClock"LOC="B8"; //50MHz系統(tǒng)標準時鐘引腳

NET"Segments[0]"LOC="M12"; //G

NET"Segments[1]"LOC="L13"; //F

NET"Segments[2]"LOC="P12"; //E

NET"Segments[3]"LOC="N11"; //D

NET"Segments[4]"LOC="N14"; //C

NET"Segments[5]"LOC="H12"; //B

NET“Segments[6]”LOC=“L14”; //A

NET“Segments[7]”LOC=“N13”; //dp

NET“Position[0]”LOC=“F12”; //AN0

NET“Position[1]”LOC=“J12”; //AN1

NET“Position[2]”LOC=“M13”; //AN2

NET“Position[3]”LOC=“K14”; //AN3

NET“Second_Flash”LOC=“M5”; //LD0

用狀態(tài)機設計的數(shù)字鐘的頂層原理圖如圖6-2所示。圖6-2用狀態(tài)機設計的數(shù)字鐘的頂層圖6.1.4采用六十進制計時模塊設計的VHDL時鐘程序

下面的時鐘VHDL程序由頂層設計、時鐘分頻模塊、六十進制計數(shù)器、以及顯示模塊組成。六十進制模塊程序例化后,可在頂層設計中多次使用。這里的秒計數(shù)器和分計數(shù)器都采用的是六十進制計數(shù)器的程序。一個VHDL模塊例化后,在其模板中有兩部分,一部分是COMPONENT(元件)描述部分,另一部分是PORTMAP(端口映射)描述部分。將這兩部分拷貝到頂層模塊中,只要根據(jù)需要進行端口映射(也就是端口連接)即可。

--頂層設計:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

entityclock_sec_min_dispis

Port(clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

second_flash:inoutSTD_LOGIC;

a_to_g:outSTD_LOGIC_VECTOR(6downto0);

an:outSTD_LOGIC_VECTOR(3downto0));

endclock_sec_min_disp;

architectureBehavioralofclock_sec_min_dispis

componentclkdivis

Port(clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

clkout:outSTD_LOGIC);

endcomponent;

componentcnt60is

Port(clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

cnt60_h:outSTD_LOGIC_VECTOR(3downto0);

cnt60_l:outSTD_LOGIC_VECTOR(3downto0);

qc:outSTD_LOGIC);

endcomponent;

componentdisplayis

Port(c60_1_h:inSTD_LOGIC_VECTOR(3downto0);

c60_1_l:inSTD_LOGIC_VECTOR(3downto0);

c60_2_h:inSTD_LOGIC_VECTOR(3downto0);

c60_2_l:inSTD_LOGIC_VECTOR(3downto0);

clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

a_to_g:outSTD_LOGIC_VECTOR(6downto0);

an:outSTD_LOGIC_VECTOR(3downto0));

endcomponent;

signalmclk,qc1,qc2:std_logic;

signalc6011,c6012,c6021,c6022:std_logic_vector(3downto0);

begin

c_div:clkdiv

portmap(clk,clr,mclk);

process(mclk,clr)

begin

if(clr='1')then

second_flash<='0';

elsif(mclk'eventandmclk='1')then

second_flash<=notsecond_flash;

endif;

endprocess;

c_601:cnt60

portmap(mclk,clr,c6011,c6012,qc1);

c_602:cnt60

portmap(qc1,clr,c6021,c6022,qc2);

c_display:display

portmap(c6011,c6012,c6021,c6022,clk,clr,a_to_g,an);

endBehavioral;

--時鐘分頻模塊:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_arith.ALL;

useIEEE.STD_LOGIC_unsigned.ALL;

entityclkdivis

Port(clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

clkout:outSTD_LOGIC);

endclkdiv;

architectureBehavioralofclkdivis

signalq1:std_logic_vector(24downto0);

begin

process(clk,clr)

begin

if(clr='1')then

q1<="0000000000000000000000000";

elsif(clk'eventandclk='1')then

q1<=q1+1;

endif;

endprocess;

clkout<=q1(24);

endBehavioral;

--60進制計數(shù)模塊:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_arith.ALL;

useIEEE.STD_LOGIC_unsigned.ALL;

entitycnt60is

Port(clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

cnt60_h:inoutSTD_LOGIC_VECTOR(3downto0);

cnt60_l:inoutSTD_LOGIC_VECTOR(3downto0);

qc:outSTD_LOGIC);

endcnt60;

architectureBehavioralofcnt60is

begin

process(clr,clk)

begin

if(clr='1')then

cnt60_h<="0000";

cnt60_l<="0000";

elsif(clk'eventandclk='1')then

qc<='0';

if(cnt60_l="1001")then

cnt60_l<="0000";

cnt60_h<=cnt60_h+1;

else

cnt60_l<=cnt60_l+1;

endif;

if(cnt60_l="1001"andcnt60_h="0101")then

cnt60_l<="0000";

cnt60_h<="0000";

qc<='1';

endif;

endif;

endprocess;

endBehavioral;

--顯示模塊:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_arith.ALL;

useIEEE.STD_LOGIC_unsigned.ALL;

entitydisplayis

Port(c60_1_h:inSTD_LOGIC_VECTOR(3downto0);

c60_1_l:inSTD_LOGIC_VECTOR(3downto0);

c60_2_h:inSTD_LOGIC_VECTOR(3downto0);

c60_2_l:inSTD_LOGIC_VECTOR(3downto0);

clk:inSTD_LOGIC;

clr:inSTD_LOGIC;

a_to_g:outSTD_LOGIC_VECTOR(6downto0);

an:outSTD_LOGIC_VECTOR(3downto0));

enddisplay;

architectureBehavioralofdisplayis

signalclksweep:std_logic_vector(19downto0);

signals:std_logic_vector(1downto0);

signaldigit:std_logic_vector(3downto0);

begin

process(clk,clr)

begin

if(clr='1')then

clksweep<="00000000000000000000";

elsif(clk'eventandclk='1')then

clksweep<=clksweep+1;

endif;

endprocess;

s<=clksweep(19downto18);

process(s,c60_1_h,c60_1_l,c60_2_h,c60_2_l)

begin

casesis

when"00"=>an<="1110";digit<=c60_2_h;

when"01"=>an<="1101";digit<=c60_2_l;

when"10"=>an<="1011";digit<=c60_1_h;

when"11"=>an<="0111";digit<=c60_1_l;

whenothers=>null;

endcase;

endprocess;

process(digit)

begin

casedigitis

when"0000"=>a_to_g<="0000001";

when"0001"=>a_to_g<="1001111";

when"0010"=>a_to_g<="0010010";

when"0011"=>a_to_g<="0000110";

when"0100"=>a_to_g<="1001100";

when"0101"=>a_to_g<="0100100";

when"0110"=>a_to_g<="0100000";

when"0111"=>a_to_g<="0001111";

when"1000"=>a_to_g<="0000000";

when"1001"=>a_to_g<="0000100";

when"1010"=>a_to_g<="0001000";

when"1011"=>a_to_g<="1100001";

when"1100"=>a_to_g<="0110001";

when"1101"=>a_to_g<="1000010";

when"1110"=>a_to_g<="0110000";

when"1111"=>a_to_g<="0111000";

whenothers=>a_to_g<="0000001";

endcase;

endprocess;

endBehavioral;

#Basys2約束文件:

NET"a_to_g[0]"LOC=M12;

NET"a_to_g[1]"LOC=L13;

NET"a_to_g[2]"LOC=P12;

NET“a_to_g[3]”LOC=N11;

NET“a_to_g[4]”LOC=N14;

NET“a_to_g[5]”LOC=H12;

NET“a_to_g[6]”LOC=L14;

NET“an[0]”LOC=K14;

NET“an[1]”LOC=M13;

NET“an[2]”LOC=J12;

NET“an[3]”LOC=F12;

NET“clk”LOC=“B8”; //50

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論