u13653 自动化1105班 骆攀Word下载.docx
《u13653 自动化1105班 骆攀Word下载.docx》由会员分享,可在线阅读,更多相关《u13653 自动化1105班 骆攀Word下载.docx(51页珍藏版)》请在冰豆网上搜索。
二、实验要求
1.能显示小时、分钟、秒钟(小时以24进制,时、分用显示器,秒用LED)
2.能调整小时、分钟的时间
3.复位
三、实验仪器
QUARTUSII软件PCDEO实验板
四、需求分析与系统设计说明
数字钟由2个60进制计数器和1个24进制计数器和两个2选1数据选择器共5个模块构成,3个计数器公用一个时钟信号CP。
2个选择器分别用于选择分计数器和时计数器的使能控制信号,对时间进行校正时,在控制器的作用下,使能信号接高电平,此时每来一个时钟信号,计数器加一计数,从而实现对小时和分钟的校正.正常计时时,使能信号来自低位计数器的输出,即秒计数器达到59秒时,产生输出信号使分计数器加1,分秒计数器同时计到最大值时即59分59秒时,产生输出信号使小时计数器加一。
主要模块如下:
顶层模块:
moduletime_counter(
inputCLK,
inputRESET,
input[2:
0]SWITCH,
inputGrimSelect,
input[1:
0]KEY,
output[31:
0]SEG,
output[7:
0]LED
);
parameterFCLK=50_000_000;
//设定时钟频率
wireclk_1hz,clk_4hz,clk_10hz,clk_100hz;
wireadd_cmd,sub_cmd;
wirecarry_in_minute,carry_in_hour;
wire[2:
0]mode;
wiregrim_select;
wire[5:
0]sec_value,min_value,hour_value;
wire[3:
0]min_out_ones,min_out_tens,hour_out_ones,hour_out_tens;
0]alarm_min,alarm_hour;
0]alarm_min_ones,alarm_min_tens,alarm_hour_ones,alarm_hour_tens;
wire[6:
0]stop_sec,stop_mill;
0]stop_sec_ones,stop_sec_tens,stop_mill_ones,stop_mill_tens;
reg[3:
0]led_in_1,led_in_2,led_in_3,led_in_4;
wire[7:
0]led_out_1,led_out_2,led_out_3,led_out_4;
/*assignclk_1hz=CLK;
assignclk_4hz=CLK*4;
assignclk_10hz=CLK*10;
assignclk_100hz=CLK*100;
*/
assignmode=SWITCH;
assigngrim_select=GrimSelect;
/************************************************/
/*开关模式选择*/
always@(posedgeCLK)
begin
if(mode==3'
b000)
begin
led_in_1=min_out_ones;
led_in_2=min_out_tens;
led_in_3=hour_out_ones;
led_in_4=hour_out_tens;
end
elseif(mode==3'
b001)
begin
b010)
end
b101)
led_in_1=alarm_min_ones;
led_in_2=alarm_min_tens;
led_in_3=alarm_hour_ones;
led_in_4=alarm_hour_tens;
b110)
b100)
b111)
led_in_1=stop_mill_ones;
led_in_2=stop_mill_tens;
led_in_3=stop_sec_ones;
led_in_4=stop_sec_tens;
else
end
freq_dividerinst_freq_divider
(
.CLK(CLK),
.clk_1hz(clk_1hz),
.clk_4hz(clk_4hz),
.clk_10hz(clk_10hz),
.clk_100hz(clk_100hz)
KeyDetectinst_KeyDetect(
.Key(KEY),
.add_cmd(add_cmd),
.sub_cmd(sub_cmd)
SecondCountinst_SecondCount(
.clk_1hz(clk_1hz),
.reset(RESET),
.carry_in_minute(carry_in_minute),
.sec_value(sec_value)
MinuteCountinst_MinuteCount(
.mode(mode),
.sub_cmd(sub_cmd),
.carry_in_hour(carry_in_hour),
.min_value(min_value)
HourCountinst_HourCount(
.grim_select(grim_select),
.hour_value(hour_value)
SEG7_OUTinst_SEG7_OUT1(
.in_seg_value(led_in_1),
.out_seg_value(led_out_1[6:
0])
SEG7_OUTinst_SEG7_OUT2(
.in_seg_value(led_in_2),
.out_seg_value(led_out_2[6:
SEG7_OUTinst_SEG7_OUT3(
.in_seg_value(led_in_3),
.out_seg_value(led_out_3[6:
SEG7_OUTinst_SEG7_OUT4(
.in_seg_value(led_in_4),
.out_seg_value(led_out_4[6:
LED_OUTinst_LED_OUT(
.in_led_value(sec_value),
.out_led_value(LED[5:
//change
ConvertToBCDinst_ConvertToBCD1(
.bin_in(min_value),
.ones(min_out_ones),
.tens(min_out_tens)
ConvertToBCDinst_ConvertToBCD2(
.bin_in(hour_value),
.ones(hour_out_ones),
.tens(hour_out_tens)
ConvertToBCDinst_ConvertToBCD3(
.bin_in(alarm_min),
.ones(alarm_min_ones),
.tens(alarm_min_tens)
ConvertToBCDinst_ConvertToBCD4(
.bin_in(alarm_hour),
.ones(alarm_hour_ones),
.tens(alarm_hour_tens)
SharpClockinst_SharpClock(
.mode(mode),
.min_value(min_value),
.hour_value(hour_value),
.sharp_led(LED[6])
Alarm_Setinst_Alarm_Set(
.alarm_min(alarm_min),
.alarm_hour(alarm_hour)
Alarm_Ringinst_Alarm_Ring(
.alarm_hour(alarm_hour),
.alarm_led(LED[7])
Stop_Watchinst_Stop_Watch(
.stop(add_cmd),
.start(sub_cmd),
.stop_mill(stop_mill),
.stop_sec(stop_sec)
assignSEG={led_out_4,led_out_3,led_out_2,led_out_1};
assign{led_out_4[7],led_out_3[7],led_out_2[7],led_out_1[7]}=((mode==3'
b0)||(mode==3'
b100))?
4'
b1011:
b1111;
assignstop_sec_ones=stop_sec%10;
assignstop_sec_tens=stop_sec/10;
assignstop_mill_ones=stop_mill%10;
assignstop_mill_tens=stop_mill/10;
endmodule
计数模块:
//时分秒分别计时
moduleSecondCount(
inputclk_1hz,
inputreset,
outputcarry_in_minute,
output[5:
0]sec_value
regcarry_in_minute_temp;
reg[5:
0]sec_value_temp;
initial
sec_value_temp=6'
b0;
carry_in_minute_temp=1'
always@(posedgeclk_1hzornegedgereset)
if(!
reset)
sec_value_temp<
=6'
if(sec_value_temp==6'
d59)
sec_value_temp<
else
=sec_value_temp+6'
b1;
carry_in_minute_temp<
=1'
elseif(sec_value_temp==6'
d58)
else
assigncarry_in_minute=carry_in_minute_temp;
assignsec_value=sec_value_temp;
moduleMinuteCount(
inputclk_10hz,
inputcarry_in_minute,
0]mode,
inputadd_cmd,
inputsub_cmd,
outputcarry_in_hour,
0]min_value
0]min_value_temp;
regcarry_in_hour_temp;
regcarry_in_min_last;
regcarry_in_min_temp;
min_value_temp<
carry_in_hour_temp<
carry_in_min_last<
carry_in_min_temp<
always@(posedgeclk_10hzornegedgereset)
carry_in_min_temp<
carry_in_min_last<
carry_in_min_last=carry_in_min_temp;
carry_in_min_temp=carry_in_minute;
min_value_temp<
if(mode==3'
b0)//mode=2'
b00)
begin
if((carry_in_min_temp==1'
b0)&
&
(carry_in_min_last==1'
b1))
begin
if(min_value_temp==6'
min_value_temp<
else
=min_value_temp+6'
end
end
elseif(mode==3'
b001)//mode=2'
b01
if(add_cmd)
elseif(sub_cmd)
b0)
d59;
=min_value_temp-6'
carry_in_hour_temp<
elseif(min_value_temp==6'
d59&
carry_in_minute&
mode==3'
assigncarry_in_hour=carry_in_hour_temp;
assignmin_value=min_value_temp;
moduleHourCount(
inputcarry_in_hour,
inputgrim_select,
0]hour_value
0]hour_value_temp;
regcarry_in_hour_last;
0]Hour_MAX;
hour_value_temp=6'
carry_in_hour_last=1'
carry_in_hour_temp=1'
Hour_MAX=6'
d24;
always@(posedgeclk_10hz)
if(grim_select)
Hour_MAX=6'
d23;
d12;
carry_in_hour_last<
carry_in_hour_last=carry_in_hour_temp;
carry_in_hour_temp=carry_in_hour;
hour_value_temp<
if(mode==3'
b00
if((carry_in_hour_temp==1'
(carry_in_hour_last==1'
if(hour_value_temp>
=Hour_MAX)
hour_value_temp<
=hour_value_temp+6'
elseif(mode==3'
b010)//mode=2'
b01,add_cmdandsub_cmdvalid
if(sub_cmd)
if(hour_value_temp==6'
=Hour_MAX;
=