如何在去quartus II的基础上设计秒表?(语言-qt)

6、秒表设计
基本要求:最大为1小时,精度要求为0.01秒,具有开始、暂停和清零功能,要求设置能在数码管上面正确显示。
在完成基本要求的基础上,可进一步增加功能、提高性能。

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以看下这个问题的回答https://ask.csdn.net/questions/7552232
  • 你也可以参考下这篇文章:QT框架之翻金币游戏(一),设置主程序界面,实现退出和开始功能。
  • 除此之外, 这篇博客: 07-Qt用代码实现对话框的自适应动态布局(布局跟随窗口大小改变)中的 五、自定义控件源码与本例子源码 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    [

    https://github.com/robert1207/QtVideoPlayDialog]
  • 您还可以看一下 明仕强老师的Qt高级开发视频教程课程中的 Qt鼠标相对位置、绝对位置、窗口位置、控件位置、控件大小、控件绝对位置小节, 巩固相关知识点
  • 以下回答来自chatgpt:

    经过和你的讨论,我了解到你需要设计一个基于Quartus II和QT的秒表,具体要求如下:

    1. 秒表最大时间为1小时,精度为0.01秒
    2. 具备开始、暂停、清零功能
    3. 实现在数码管上的正确显示
    4. 可进一步增加功能和提高性能

    针对第一个需求,我们可以利用计时器(Timer)来达到秒表计时的效果,并且精度可达到0.01秒。对于Quartus II部分,我们可以设计一个计时器电路来实现计时的功能。

    下面是实现的步骤以及代码:

    步骤一:QT界面设计

    1. 创建一个新工程,选择QT Gui Application作为项目模板
    2. 利用QT Designer进行界面设计,需要使用到QLCDNumber、QPushButton、QTimer等控件
    3. 运行程序,观察界面效果

    以下是利用QT Designer进行界面设计的代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>439</width>
        <height>246</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <widget class="QLCDNumber" name="lcdNumber">
        <property name="geometry">
         <rect>
          <x>60</x>
          <y>10</y>
          <width>321</width>
          <height>121</height>
         </rect>
        </property>
        <property name="frameShape">
         <enum>QFrame::NoFrame</enum>
        </property>
        <property name="digitCount">
         <number>10</number>
        </property>
        <property name="segmentStyle">
         <enum>QLCDNumber::Filled</enum>
        </property>
       </widget>
       <widget class="QPushButton" name="btnStart">
        <property name="geometry">
         <rect>
          <x>30</x>
          <y>190</y>
          <width>75</width>
          <height>23</height>
         </rect>
        </property>
        <property name="text">
         <string>Start</string>
        </property>
       </widget>
       <widget class="QPushButton" name="btnPause">
        <property name="geometry">
         <rect>
          <x>180</x>
          <y>190</y>
          <width>75</width>
          <height>23</height>
         </rect>
        </property>
        <property name="text">
         <string>Pause</string>
        </property>
       </widget>
       <widget class="QPushButton" name="btnClear">
        <property name="geometry">
         <rect>
          <x>330</x>
          <y>190</y>
          <width>75</width>
          <height>23</height>
         </rect>
        </property>
        <property name="text">
         <string>Clear</string>
        </property>
       </widget>
      </widget>
      <widget class="QStatusBar" name="statusbar"/>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    步骤二:利用定时器(Timer)实现秒表计时

    1.声明一个变量记录秒表的时间(timeCounter)以及计时器(timer) 2.设置计时器的间隔为10ms,每隔10ms执行一次定时器事件(timeEvent),对timeCounter加1ms 3.在timeEvent()方法中更新数码管显示的时间

    以下是实现的代码:

    //声明变量和对象
    int timeCounter = 0;
    QTimer *timer;
    
    //初始化
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        //创建计时器
        timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(timeEvent()));
    
    }
    
    //定时器事件
    void MainWindow::timeEvent()
    {
        timeCounter++; //记录时间
    
        //计算时间分、秒、毫秒
        int hour = int(timeCounter / 360000);
        int min = int((timeCounter % 360000) / 6000);
        int sec = int((timeCounter % 6000) / 100);
        int msec = timeCounter % 100;
    
        //更新数码管显示
        ui->lcdNumber->display(QString("%1:%2:%3.%4").arg(hour, 2, 10, QLatin1Char('0'))
                                              .arg(min, 2, 10, QLatin1Char('0'))
                                              .arg(sec, 2, 10, QLatin1Char('0'))
                                              .arg(msec, 2, 10, QLatin1Char('0')));
    }
    
    //开始按钮
    void MainWindow::on_btnStart_clicked()
    {
        //开始计时器
        timer->start(10);
    }
    
    //暂停按钮
    void MainWindow::on_btnPause_clicked()
    {
        //暂停计时器
        timer->stop();
    }
    
    //清零按钮
    void MainWindow::on_btnClear_clicked()
    {
        //清零计时器
        timeCounter = 0;
        ui->lcdNumber->display("00:00:00.00");
    }
    

    步骤三:设计Quartus II电路

    1.设计一个计时器电路,利用时钟信号进行计时,每100ms输出一次计数值 2.将计数器的电路和QT界面进行连接 3.使用Verilog语言进行编写,并利用Quartus II进行仿真和烧录

    以下是实现的Verilog代码:

    module counter(clk, clear, out);
    
        input clk, clear;
        output [23:0]out; //24位计数器,可计时1小时
    
        reg [23:0]counter;
    
        always @(posedge clk) begin
            if(clear) begin //复位
                counter <= 0;
            end else begin //计数
                counter <= counter + 1;
            end
        end
    
        assign out = counter;
    
    endmodule
    

    设计好电路后,将计数器的输出与QT界面进行连接。在timeEvent()事件中,需要从FPGA读取计数值并更新数码管显示。

    段落0: 我们可以使用甘特图的语法来绘制一个进度计划:

    gantt
        title 设计秒表进度计划
    
        section 设计
        确定需求:des1, 2021-02-20, 1d
        QT界面设计: des2, after des1, 2d
        Quartus II电路设计: des3, after des2, 3d
    
        section 编写代码
        QT事件编写: code1, after des3, 5d
        Quartus II编写: code2, after code1, 2d
    
        section 测试
        QT界面测试: test1, after code2, 1d
        Quartus II测试: test2, after test1, 1d
        整体测试: test3, after test2, 2d
    
        section 完成
        完成: done, after test3, 1d
    

    按照这个计划,我们需要在2月20日确定需求,然后在接下来的几天内完成QT界面设计和Quartus II电路设计,接着分别编写QT事件和Quartus II的代码,并进行测试。最后,在一个月的时间内完成所有工作。

    希望这个进度计划能够帮助你更好地规划设计秒表的时间。

    综上所述,我们可以通过QT和Quartus II相结合来设计一个秒表,实现计时功能、开始/暂停/清零操作和数码管显示等功能。在设计的过程中,需要进行界面设计和电路设计,同时利用定时器(Timer)实现秒表计时,以及Verilog语言进行计数器电路的编写。最后,通过甘特图来规划进度计划,帮助你更好地完成设计任务。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^