免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 924 | 回复: 0
打印 上一主题 下一主题

读写24c08 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-30 18:14 |只看该作者 |倒序浏览
hello.h---------------------------
#include
#include
#include
#include
#include
#include
#include
#include
class myMainWindow : public QWidget
{
    Q_OBJECT
    public:
        myMainWindow();
        void write2eeprom(void);
        void readFromEEprom();
    public slots:
        void bEvent(); //按钮事件
    private:
        bool flag; //启动/停止指示
        QPushButton *b_on1,*bExit;
        QMultiLineEdit *editTop;
        QMultiLineEdit *editBtm;
        QProgressBar *bar;
        QLabel *label;
        QVBoxLayout *vbox;
};
hello.cpp--------------------------
#include "hello.h"
myMainWindow::myMainWindow()
{
    setMinimumSize(200,200);
//    setMaximumSize(200,200);
    label = new QLabel(this);
    label->setMinimumSize(150,30);
    label->setMaximumSize(240,200);
    label->setFont(QFont("san",10,QFont::Black));
    label->setText("press the top button to\n"
                    "read/write the text to the eeprom");
    label->setAlignment(AlignLeft);
    flag = 0; //0:表示当前是读操作
    b_on1 = new QPushButton("read",this);
    b_on1->setMinimumSize(30,20);
    b_on1->setFont(QFont("Times",15,QFont::Bold));
    bExit = new QPushButton("exit",this);
    bExit->setMinimumSize(30,20);
    bExit->setFont(QFont("Times",15,QFont::Bold));
    editTop = new QMultiLineEdit(this);
    editTop->setMinimumSize(200,60);
    editTop->setText(QString("long long ago ...\n"
                            "a king die\n"
                            "and another king die\n"
                            "and the rest king die\n"));
    editBtm = new QMultiLineEdit(this);
    editBtm->setMinimumSize(200,60);
    editBtm->setText(QString(""));
    bar = new QProgressBar(1024,this);
    bar->setMinimumSize(100,20);
    QVBoxLayout *vbox = new QVBoxLayout(this); //没有这个this,布局管理器将不能工作
    vbox->addWidget(b_on1);
    vbox->addWidget(editTop);
    vbox->addWidget(bar);
    vbox->addWidget(editBtm);
    vbox->addWidget(label);
    vbox->addWidget(bExit);
    connect(b_on1,SIGNAL(clicked()),this,SLOT(bEvent()));
    connect(bExit,SIGNAL(clicked()),qApp,SLOT(quit()));
//    setWindowTitle("ad convert"); //这个东东在qte2.2.0版本里没有
}
#include
#include
#include
#include
#include
#include
#include
#define I2C_RETRIES    0x0701
#define I2C_TIMEOUT    0x0702
#define I2C_SLAVE    0x0703
#define  BUF_SIZE    1024
//要实现读出24c08的所有内容,并显示在multilineedit里面
void myMainWindow::readFromEEprom(void)
{
    int fd;
    unsigned char *buf;
    buf = (unsigned char *)malloc(BUF_SIZE);
    memset(buf,0x98,BUF_SIZE);
    fd = open("/dev/i2c/0",O_RDWR);
    if(fd >1 = 0x50,驱动里面会把最地位补全的(读或者写)
    ioctl(fd,I2C_TIMEOUT,1);
    ioctl(fd,I2C_RETRIES,1);
    int block,i;
    for(block=0;blocksetProgress(i+(block*256)+1);
        }
    }
    editBtm->setText(QString((const char*)buf));
    free(buf);
    ::close(fd);
}
void myMainWindow::write2eeprom()
{
    int fd;
    char *buf;
    union data{
        unsigned short addr;
        char byte[2];
    }my_data;
    QString qbuf;
    qbuf = editTop->text();
    buf = (char *)malloc(BUF_SIZE);
    memset(buf,0x98,BUF_SIZE);
    ::strcpy(buf,qbuf.ascii());
    fd = open("/dev/i2c/0",O_RDWR);
    if(fd >1 = 0x50,驱动里面会把最地位补全的(读或者写)
    ioctl(fd,I2C_TIMEOUT,1);
    ioctl(fd,I2C_RETRIES,1);
    int block,i;
    for(block=0;blocksetProgress(i+(block*256)+1);
        }
    }
    free(buf);
    ::close(fd);
}
void myMainWindow::bEvent()
{
    flag = (flag?false:true); //读写操作改变
    if(flag){ //这里表示开始读操作
        b_on1->setText(QString("write"));
        readFromEEprom();
    }else{ //这里是关闭pwm
        b_on1->setText(QString("read"));
        write2eeprom();
    }
}
int main(int argc,char **argv)
{
    QApplication a(argc,argv);
    myMainWindow w;
    a.setMainWidget(&w);
    w.show();
    a.exec();
}
helloworld.desktop---------------------
[Translation]
File=QtopiaApplications
Context=helloworld
Comment[Desktop Entry/Name]=Use soft hyphen (char U00AD) to indicate hyphenation
[Desktop Entry]
Comment[]=helloworld program
Exec=helloworld
Icon=helloworld
Type=Application
Name[]=helloworld


   

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93291/showart_2107597.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP