mini2440之--adc程序

本文介绍了一个使用ADC进行实时数据采集的系统,详细解释了如何通过Qt框架实现数据读取、处理和显示的功能。包括启动和停止ADC采集过程,通过LCDNumber和TextLabel组件展示采集的数据。

如图所示,用到的组块:TextLabel,LCDNumber,Pixmap Label,Group Box,PushButton

adc.h

#ifndef MYHELLOFORM_H
#define MYHELLOFORM_H
#include "adc_base.h"
#include <qpixmap.h>

class MyADCForm : public ADCBaseForm
{ 
    Q_OBJECT
	
    public:
        MyADCForm( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
	    virtual ~MyADCForm();
	    //const QPixmap *eddy;
		int fd;
    private slots:
        void startADC();
	void stopADC();


};

#endif // MYHELLOFORM_H

adc.cpp

#include "adc.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qlcdnumber.h>
/*
#include <qtopia/qpeapplication.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.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>

MyADCForm::MyADCForm( QWidget* parent, const char* name, WFlags fl)
	    :ADCBaseForm(parent, name, fl)
{
fd=0;
    connect(PushButton1,SIGNAL(clicked()),this,SLOT(startADC()));
connect(PushButton1,SIGNAL(clicked()),this,SLOT(stopADC()));

}

MyADCForm::~MyADCForm()
{
	::close(fd);
}



void MyADCForm::startADC()
{
    //TextLabel1->setText("System Led is Started");


	fd = ::open("/dev/adc", 0);
	if (fd < 0) {
		::exit(1);
	}
	for(int num=0;num<20;num++) {
		char buffer[30];
		int len = ::read(fd, buffer, sizeof buffer -1);
		if (len > 0) {
			buffer[len] = '\0';
			int value = -1;
			sscanf(buffer, "%d", &value);
			//printf("ADC Value: %d\n", value);
			LCDNumber1->display(value);

		} else	::exit(1);
		usleep(500* 1000);
		LCDNumber2->display(num);
	}
	
	::close(fd);
}void MyADCForm::stopADC()
{
::close(fd);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值