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

📄 i2c.c

📁 NIOSII I2C源程序
💻 C
字号:
#include"system.h"
#include"altera_avalon_pio_regs.h"
#include"oc_i2c.h"
#include"alt_types.h"

/******************************************************************
*      与硬件相关的宏定义,用户根据实际情况修改
******************************************************************/
// I2C_MASTER_BASE是用户添加并命名的外设基地址,在SYSTEM中定义,用户需要根据不同的命名来修改此处
#ifndef I2C_BASE             //这是I2C核的设备名称
#define I2C_BASE  0x00005000 //user's definition here
#endif

#if I2C_MASTER_BASE == 0xffffffff
#error "No definition of I2C core.\n"
#endif

int main(void)
{
    alt_u8 w_Data[9]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0x00};
    alt_u8 r_Data[9]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    InitI2C(I2C_BASE,100000,0);
    
    I2CWrite(I2C_BASE,0x15,0x51,w_Data,9);
    I2CRead(I2C_BASE,0x15,0x51,r_Data,9);
    
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE,r_Data[0]);

    return 0;    
}

⌨️ 快捷键说明

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