基于Qt4.7的ADC测试程序

所使用的开发板:友善之臂tiny6140


widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <qlcdnumber.h>


namespace Ui {
    class Widget;
}

class TMainForm : public QWidget
{
    Q_OBJECT

public:
    TMainForm(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0);
    virtual ~TMainForm() {}
protected:
    void timerEvent (QTimerEvent *);
private:
    QLCDNumber* m_label;
    Ui::Widget *ui;
};

#endif // WIDGET_H

widget.cpp
</pre><pre code_snippet_id="1599573" snippet_file_name="blog_20160306_3_265073" name="code" class="cpp">#include "widget.h"
#include "ui_widget.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>


TMainForm::TMainForm(QWidget *parent, const char *name, Qt::WFlags f)
{
    //setCaption( "ADC-Testing" );
    m_label = new QLCDNumber(this);
    m_label->setGeometry(10,10, 100, 50);
    m_label->setSegmentStyle(QLCDNumber::Flat);
    startTimer(500);
}
</pre><pre code_snippet_id="1599573" snippet_file_name="blog_20160306_6_2630841" name="code" class="cpp">void TMainForm::timerEvent ( QTimerEvent * )
{
    int fd = ::open("/dev/adc", 0);
    if (fd < 0)
    {
        return;
    }
    char buffer[30] = "";
    int len = ::read(fd, buffer,
    sizeof buffer -1);
    if(len > 0)
    {
    buffer[len] ='\0';
    int value=-1
                                                                        
    sscanf(buffer,"%d",&value);
    m_label->display(value);
   }
    ::close(fd);
}
</pre><span style="font-family:Microsoft YaHei; font-size:14px"></span><p><span style="font-family:Microsoft YaHei; font-size:14px"></span></p><p><span style="font-family:Microsoft YaHei; font-size:14px">main.cpp</span></p><p><span style="font-family:Microsoft YaHei; font-size:14px"></span></p><p><span style="background-color:rgb(240,240,240)">#include <QtGui/QApplication></span></p><pre code_snippet_id="1599573" snippet_file_name="blog_20160306_8_9401732" name="code" class="cpp">#include "widget.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    TMainForm w;
    w.show();

    return a.exec();
}


亲测可用,如有疑惑,可留言。


                
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值