3.主体模块(包含计时和设置闹钟)

这是一个基于VHDL的数字时钟系统设计,包括时间显示、设置时间及多个闹钟功能。通过EN信号控制不同的操作模式,如显示时间、设置时间和闹钟。key输入信号用于调整和确认时间,输出包括数码管位选信号、蜂鸣器控制和状态指示。

library IEEE;
use IEEE.std_logic_1164.ALL;
use IEEE.std_logic_unsigned.ALL;
use IEEE.std_logic_arith.ALL;
----EN是各个功能块的使能信号,EN(0)=‘1’时是显示时间,EN(1)=‘1’时是设置时间,EN(2)='1'时是闹钟1,EN(3)='1'时是闹钟2,EN(4)='1'时是闹钟3
---key0是用来调整用的
---key_1是设置时间后按下确认键时的电平
---key1是用来调整时间或闹钟的,和key0配合使用。
---key2是用来切换调整的是时还是分,在显示时间的时候,还可以作为切换显示时,分或者秒
---choise输出信号值,可以为秒,分,时,
---output输出数码管的位选信号,和choise配合使用来实现动态显示
---bell输到蜂鸣器中,当bell=‘0’时蜂鸣器响,这里是用作闹钟响或者整点报时的
---dot是数码管上的e口,即显示的是那一点,主要是用来显示时,分时显示如下12.01
---setm0---seth1这四个是用作输入设置的时间
---set_en设置时间block(块)的使能信号
---e懒人模式块的使能信号
entity clock is
 port(clk_1s,clk_5us,clk_100ms:in std_logic;
  EN:in std_logic_vector(4 downto 0); 
  key0:in std_logic; 
  key_1:in std_logic;
  key1:in std_logic;
  key2:in std_logic;
  choise:out std_logic_vector(3 downto 0);
  output:out std_logic_vector(3 downto 0);
  bell:out std_logic;
  dot:out std_logic;
  setm0:in std_logic_vector(3 downto 0);
  setm1:in std_logic_vector(3 downto 0);
  seth0:in std_logic_vector(3 downto 0);
  seth1:in std_logic_vector(3 downto 0);
  set_en:out std_logic;
  e:out std_logic);  
end clock;
architecture behav of clock is
---s0秒值的个位,s1秒值的十位,m0分值的个位,m1分值的十位,h0时的个位,h1时的十位,其他的类推
signal  s0:std_logic_vector(3 downto 0):="0000";
signal s1:std_logic_vector(3 downto 0):="0000";
signal  m0:std_logic_vector(3 downto 0):="0000";
signal m1:std_logic_vector(3 downto 0):="0000";
signal h0:std_logic_vector(3 downto 0):="0000";
signal h1:std_logic_vector(3 downto 0):="0000";
signal setm00:std_logic_vector(3 downto 0):="0011";
signal setm01:std_logic_vector(3 downto 0):="0000";
signal seth00:std_logic_vector(3 downto 0):="0000";
signal seth01:std_logic_vector(3 downto 0):="0000";
signal setm10:std_logic_vector(3 downto 0):="0011";
signal setm11:std_logic_vector(3 downto 0):="0000";
signal seth10:std_logic_vector(3 downto 0):="0000";
signal seth11:std_logic_vector(3 downto 0):="0000";
signal setm20:std_logic_vector(3 downto 0):="0011";
signal setm21:std_logic_vector(3 downto 0):="0000";
signal seth20:std_logic_vector(3 downto 0):="0000";
signal seth21:std_logic_vector(3 downto 0):="0000";
signal put:integer:=1;
signal if_alarm:std_logic:='1';
begin
 JISHI:process(key1,clk_1s)  -----------set_clock and set_alarm
 begin
  if (EN(1)='1' AND key_1='0') then ----按下确认键(key_1=0)时把设置好的时间输入,
   m0<=setm0;
   m1<=setm1;
   h0<=seth0;
   h1<=seth1;
  elsif rising_edge(clk_1s) then  ----1s钟计时
   if s0="1001" then
    s0<="0000";
    if s1="0101" then
     s1<="0000";
     if m0="1001" then
      m0<="0000";
      if m1="0101" then
       m1<="0000";
       if h1="0010" then
        if h0="0011" then
         h0<="0000";
         h1<="0000";
        else h0<=h0+1;
        end if;
       elsif h0="1001" then
        h0<="0000";
        h1<=h1+1;
       else h0<=h0+1;
       end if;
      else m1<=m1+1;
      end if;
     else m0<=m0+1;
     end if;
    else s1<=s1+1;
    end if;
   else s0<=s0+1;
   end if;
  END IF;
 END PROCESS JISHI;
 setalarm:PROCESS(key1,key0) ---设置闹钟
 begin
 if rising_edge(key0) then
  if EN(2)='1' then  ---set_bell_1
   if key1='0' then
    if key2='0' then  ---min-1
     IF setm00="0000" THEN
      setm00<="1001";
      IF setm01="0000" THEN
       setm01<="0101";
      ELSE setm01<=setm01-1;
      END IF;
     ELSE setm00<=setm00-1;
     END IF;
    elsif key2='1' then  ---hour-1
     if seth01="0000" then
      IF seth00="0000" THEN
       seth00<="0011";
       seth01<="0010";
      ELSE seth00<=seth00-1;
      END IF;
     elsif seth00="0000" then
      seth00<="1001";
      seth01<=seth01-1;
     else seth00<=seth00-1;
     end if; 
    end if;
   elsif key1='1' then
    if key2='0' then  ---min+1
     IF setm00="1001" THEN
      setm00<="0000";
      IF setm01="0101" THEN
       setm01<="0000";
      ELSE setm01<=setm01+1;
      END IF;
     ELSE setm00<=setm00+1;
     END IF;
    elsif key2='1' then  ---hour+1
     if seth01="0010" then
      if seth00="0011" then
       seth00<="0000";
       seth01<="0000";
      else seth00<=seth00+1;
      end if;
     elsif seth00="1001" then
      seth00<="0000";
      seth01<=seth01+1;
     else seth00<=seth00+1;
     end if;
    end if;
   end if;
  elsif EN(3)='1' then  ---set_bell_2
   if key1='0' then
    if key2='0' then  ---min-1
     IF setm10="0000" THEN
      setm10<="1001";
      IF setm11="0000" THEN
       setm11<="0101";
      ELSE setm11<=setm11-1;
      END IF;
     ELSE setm10<=setm10-1;
     END IF;
    elsif key2='1' then  ---hour-1
     if seth11="0000" then
      IF seth10="0000" THEN
       seth10<="0011";
       seth11<="0010";
      ELSE seth10<=seth10-1;
      END IF;
     elsif seth10="0000" then
      seth10<="1001";
      seth11<=seth11-1;
     else seth10<=seth10-1;
     end if; 
    end if;
   elsif key1='1' then
    if key2='0' then   ---min+1
     IF setm10="1001" THEN
      setm10<="0000";
      IF setm11="0101" THEN
       setm11<="0000";
      ELSE setm11<=setm11+1;
      END IF;
     ELSE setm10<=setm10+1;
     END IF;
    elsif key2='1' then  ---hour+1
     if seth11="0010" then
      if seth10="0011" then
       seth10<="0000";
       seth11<="0000";
      else seth10<=seth10+1;
      end if;
     elsif seth10="1001" then
      seth10<="0000";
      seth11<=seth11+1;
     else seth10<=seth10+1;
     end if;
    end if;
   end if;
   elsif EN(4)='1' then  ---set_bell_3
   if key1='0' then
    if key2='0' then  ---min-1
     IF setm20="0000" THEN
      setm20<="1001";
      IF setm21="0000" THEN
       setm21<="0101";
      ELSE setm21<=setm21-1;
      END IF;
     ELSE setm20<=setm20-1;
     END IF;
    elsif key2='1' then  ---hour-1
     if seth21="0000" then
      IF seth20="0000" THEN
       seth20<="0011";
       seth21<="0010";
      ELSE seth20<=seth20-1;
      END IF;
     elsif seth20="0000" then
      seth20<="1001";
      seth21<=seth21-1;
     else seth20<=seth20-1;
     end if; 
    end if;
   elsif key1='1' then
    if key2='0' then   ---min+1
     IF setm20="1001" THEN
      setm20<="0000";
      IF setm21="0101" THEN
       setm21<="0000";
      ELSE setm21<=setm21+1;
      END IF;
     ELSE setm20<=setm20+1;
     END IF;
    elsif key2='1' then  ---hour+1
     if seth21="0010" then
      if seth20="0011" then
       seth20<="0000";
       seth21<="0000";
      else seth20<=seth20+1;
      end if;
     elsif seth20="1001" then
      seth20<="0000";
      seth21<=seth21+1;
     else seth20<=seth20+1;
     end if;
    end if;
   end if;
  end if;
 end if;
 end process setalarm;
 out_put:process(clk_5us) ---动态显示,利用5us的时钟
 begin
  if rising_edge(clk_5us) then
   if EN(2)='1' THEN ---显示闹钟1
    CASE put is
     when 1 =>
      output<="1110";
      choise<=setm00;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=setm01;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1011";
      choise<=seth00;
      dot<='0';
      put<=4;
     when 4 =>
      output<="0111";
      choise<=seth01;
      dot<='1';
      put<=1;
     when others => put<=1;
    end case;
   elsif EN(3)='1' THEN ---显示闹钟2
    CASE put is
     when 1 =>
      output<="1110";
      choise<=setm10;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=setm11;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1011";
      choise<=seth10;
      dot<='0';
      put<=4;
     when 4 =>
      output<="0111";
      choise<=seth11;
      dot<='1';
      put<=1;
     when others => null;
    end case;
   elsif EN(4)='1' THEN ---显示闹钟3
    CASE put is
     when 1 =>
      output<="1110";
      choise<=setm20;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=setm21;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1011";
      choise<=seth20;
      dot<='0';
      put<=4;
     when 4 =>
      output<="0111";
      choise<=seth21;
      dot<='1';
      put<=1;
     when others => null;
    end case;
   elsif (EN(0)='1' AND key2='0') then ---显示时和分
    CASE put is
     when 1 =>
      output<="1110";
      choise<=m0;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=m1;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1011";
      choise<=h0;
      dot<='0';
      put<=4;
     when 4 =>
      output<="0111";
      choise<=h1;
      dot<='1';
      put<=1;
     when others => null;
    end case;
   elsif (key2='1' and EN(0)='1') then ---显示秒
    CASE put is
     when 1 =>
      output<="1110";
      choise<=s0;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=s1;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1110";
      choise<=s0;
      dot<='1';
      put<=4;
     when 4 =>
      output<="1101";
      choise<=s1;
      dot<='1';
      put<=1;
     when others => put<=1;
    end case;
   elsif EN(1)='1' then ---显示设置的时间
    case put is
     when 1 =>
      output<="1110";
      choise<=setm0;
      dot<='1';
      put<=2;
     when 2 =>
      output<="1101";
      choise<=setm1;
      dot<='1';
      put<=3;
     when 3 =>
      output<="1011";
      choise<=seth0;
      dot<='0';
      put<=4;
     when 4 =>
      output<="0111";
      choise<=seth1;
      dot<='1';
      put<=1;
     when others => put<=1;
    end case;
   end if;
  end if;
 end process out_put;
 alarm:process(clk_100ms) ---闹铃响的判断进程
 begin
  if rising_edge(clk_100ms) then  ---整点报时
   if (s1="0000" and m1="0000" and m0="0000" and h0="0000" and h1="0000") then
    if(s0="0000") then if_alarm<='0';
    elsif(s0="0011") then if_alarm<='1';
    end if;
   elsif EN(0)='1' THEN ---闹钟响
    if ((setm00=m0 AND setm01=m1 and seth00=h0 and seth01=h1) or (setm10=m0 AND setm11=m1 and seth10=h0 and seth11=h1) or (setm20=m0 AND setm21=m1 and seth20=h0 and seth21=h1)) THEN
     if (s0="0000" and s1="0000") then if_alarm<='0';e<='1';
     elsif (s1="0001") then if_alarm<='1';
     end if;
    end if;
   elsif(EN(0)='0') then if_alarm<='1';e<='0'; ---其他情况下闹铃不响
   end if;
  end if;
 end process alarm;
 bell<=if_alarm;

图片

 


 set_en<=EN(1);
 end behav;   

 

实验四 基于STM32的数字时钟 【实验学时】 6学时 【实验目的】 1.了解STM32的定时器原理及其在时钟设计中的应用。 2.学习数码管动态显示的实现方法。 3.掌握SysTick定时器的使用,生成精准的时间基准。 4.熟悉按键中断的处理机制,实现时钟调整功能 【实验器材】、 1.STM32F103 核心板(M3 内核) 2.数码管模块(共阳极) 3.按键模块 4.Keil 开发环境 5.ST-Link 下载器 【实验原理】 1.时间基准的产生 STM32 的SysTick定时器用于产生0.1s的中断,通过计数10次形成1s基准。 2.按键调整原理 使用两个按键,一个作为功能键,另一个作为调整键: 第 1 次按下功能键:调整秒 第 2 次按下功能键:调整分 第 3 次按下功能键:调整时 第 4 次按下功能键:恢复正常计时模式 按键采用 EXTI 外部中断方式,确保快速响应。 3.数码管动态显示 采用扫描显示技术,每次点亮一个数码管,减少 I/O 资源占用。 【基于STM32的数字时钟】 1.实验描述 设计一个基于 STM32 的数字时钟,利用数码管模块进行动态显示,同时支持按键调整时间功能。 2.硬件连接 1.数码管连接 段选端口:显示模块的 J7 接口,按照 A、B、C、D、E、F、G、DP 的顺序,分别与 STM32 的 PA0-PA7 连接。 位选端口: PB10-PB13 分别连接 S1-S4 PC6-PC9 分别连接 S5-S8 2.按键连接 KEY1(功能键):PB5(用于切换调整模式) KEY2(调整键):PB6(用于增减调整数值) 电路连接主体与动态数码管实验相同。另外,需要把PB5引出来,模拟按键Key2。也可以把PB5接到键盘模块的COL4上,同时键盘模块的ROW0接地,此时,键盘模块的“项目1”按键就是Key2。给出代码
04-29
数据集介绍:垃圾分类检测数据集 一、基础信息 数据集名称:垃圾分类检测数据集 图片数量: 训练集:2,817张图片 验证集:621张图片 测试集:317张图片 总计:3,755张图片 分类类别: - 金属:常见的金属垃圾材料。 - 纸板:纸板类垃圾,如包装盒等。 - 塑料:塑料类垃圾,如瓶子、容器等。 标注格式: YOLO格式,包含边界框类别标签,适用于目标检测任务。 数据格式:图片来源于实际场景,格式为常见图像格式(如JPEG/PNG)。 二、适用场景 智能垃圾回收系统开发: 数据集支持目标检测任务,帮助构建能够自动识别分类垃圾材料的AI模型,用于自动化废物分类回收系统。 环境监测与废物管理: 集成至监控系统或机器人中,实时检测垃圾并分类,提升废物处理效率环保水平。 学术研究与教育: 支持计算机视觉与环保领域的交叉研究,用于教学、实验论文发表。 三、数据集优势 类别覆盖全面: 包含三种常见垃圾材料类别,覆盖日常生活中主要的可回收物类型,具有实际应用价值。 标注精准可靠: 采用YOLO标注格式,边界框定位精确,类别标签准确,便于模型直接训练使用。 数据量适中合理: 训练集、验证集测试集分布均衡,提供足够样本用于模型学习评估。 任务适配性强: 标注兼容主流深度学习框架(如YOLO等),可直接用于目标检测任务,支持垃圾检测相关应用。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值