⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpio_i2c.h

📁 在Wince环境下面的用 gpio 来模拟 i2c的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
 关于wince下I2C控制的参考代码收藏
/////////////////////////////////////////////////////////////
//title:关于I2C控制的一些注意问题
//descrpit:分析I2C总线工作原理和实现方法
//author:Mercury Xu
//date:2008-09-20
/////////////////////////////////////////////////////////////
//阅读本文前请先阅读完I2C协议手册,下载地址如下:
//http://download.csdn.net/source/315355

//最近的开发一直与I2C有关系。以前写过I2C通讯相关东西。但是用的是别人的封装函数。所以没有怎么仔细看。
//这次通过开发MTV335这款芯片自己参考了原厂提供的代码写了一个I2C通讯的程序。没有做成类的形式,也是普通的函数调用。应该比较容易理解和使用。具体的操作如下,另外要提得一点是,在做I2C程序之前一定要硬件工程师帮你检查下或者你自己检查下线路是否通畅,上拉电阻是否使用正确,I2C两线的电压是否正常3.3-5V。检查完这些后,尝试送一组值给芯片,看下波型是否正确,如果正确就放心大胆的写东西吧,多话不说了,大家看参考代码吧。其中我使用了一些伪代码来替代一些操作,不同的芯片用不同的方式去替换就好了。

//另,参考程序是基于wince5.0下流设备驱动形式编写,请按照各自不同的芯片进行修改。


#ifndef _DEMO_H_ 
#define _DEMO_H_

#define DELAY_CNT   50         //Delay 50 us

#define DEMO_WriteID  0x4A     //[DEMO] Write address
#define DEMO_ReadID   0x4B     //[DEMO] Read  address

#define   TIMERTICK    (v_pDriverGlobals->sysclk.dwSystemClock/(1000000*2))       //delay basic num

#define   NTSC       1        //set show type

typedef enum OPERA_MODE {
    READ = 1,
    WRITE = 2
} T_OPERA_MODE;


unsigned char DEMOTable[] = {
    
                                

0x08,0xC0,0x33,0x00,0x00,0xE9,0x0D,0xB8,0x01,0x80,0x47,0x40,0x00,0x01,0x2A,0x38,
                                

0x0C,0xf7,0x01,0x3E,0x00,0x00,0x02,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                                

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x07,
                                0x80,0x00
                                
                             }; 

unsigned char DEMOAddress[] = { 
    
                                 

0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,
                                 

0x11,0x12,0x13,0x15,0x16,0x17,0x40,0x41,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,
                                 

0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,
                                 0x5B,0x5E
                                 
                                };

////////////////////////////////////////////////////////////////////
// Copyright Mercury's CO.,LTD.2007-2008
// Author : Mercury Xu
// Descript: this file for DEMO chip,it's a dll entry function 
// in this file include the DEMO_XXX function for driver the chip
// as a stream device.At the same time,in the bsp package we define
// other function for make suer that this device can reset.use 
// centrality define function from gpio.h head file.
////////////////////////////////////////////////////////////////////
//update log
//create by : 2008-03-21 mercury xu 
//add by : 2008-04-03 mercury xu add define into the file change old file struct.
//add by : 2008-04-04 mercury xu add some variables for ioctr function
//modify by : 2008-07-30 mercury xu change it for DEMO
/////////////////////////////////////////////////////////////////////

        //=============================================================================
        //Title : WrToDEMO
        //Detail: Write Data To DEMO
        //Input : addr data
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        void WrToDEMO(unsigned char addr,unsigned char data);

        //=============================================================================
        //Title : initial_DEMO
        //Detail: initial DEMO chip
        //Input : none
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        void initial_DEMO();

        //=============================================================================
        //Title : ReceiveAck
        //Detail: Receive Ack from DEMO chip
        //Input : none
        //Output: int
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        int ReceiveAck();

        //=============================================================================
        //Title : StopBit
        //Detail: StopBit  from DEMO chip
        //Input : none
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        void StopBit();

        //=============================================================================
        //Title : StartBit
        //Detail: StartBit  from DEMO chip
        //Input : none
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        void StartBit();

        //=============================================================================
        //Title : WrData
        //Detail: WrData to DEMO chip
        //Input : none
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

        void WrData(unsigned char data);

        //=============================================================================
        //Title : DEMO_reset
        //Detail: DEMO_reset to DEMO chip
        //Input : none
        //Output: none
        //Author: Mercury Xu
        //Data  : 2008-07-30
        //=============================================================================

              //  void DEMO_reset();
///////////////////////////////////////////////////////////////////////////
//modify by mercury xu  Mercury's 20080401
//this segment for define some useful little function.usually use in the program.
//there are including some functions as following words
//sdio_high()
//sdio_low()
//sclk_high()
//sclk_low()
//sdio_output_enable()
//sdio_input_enable()
//sdio_getdata()
///////////////////////////////////////////////////////////////////////////
//update log
//create by mercury xu  20070401
///////////////////////////////////////////////////////////////////////////

void sleepGPIO(long usVal);

///////////////////////////////////////////////////////////////////////////

void sdio_high();

///////////////////////////////////////////////////////////////////////////

void sdio_low();

///////////////////////////////////////////////////////////////////////////

void sclk_high();

///////////////////////////////////////////////////////////////////////////

void sclk_low();

//////////////////////////////////////////////////////////////////////////

void sdio_output_enable();

//////////////////////////////////////////////////////////////////////////

void sdio_input_enable();

//////////////////////////////////////////////////////////////////////////

int sdio_getdata();

//end segment
///////////////////////////////////////////////////////////////////////////////
void sdio_reset();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -