example.c

来自「I2c驱动」· C语言 代码 · 共 50 行

C
50
字号
/****************************************************************************/
/* Copyright (c) 1999-2007  Digital Core Design  DCD                        */
/****************************************************************************/
/* Please review the terms of the license agreement before using this file. */
/* If you are not an authorized user, please destroy this source code file  */
/* and notify DCD immediately that you inadvertently received an            */
/* unauthorized copy.                                                       */
/****************************************************************************/
/*                                                                          */
/*--------------------------------------------------------------------------*/
/* Project name         : DI2CS                                             */
/* Project description  : DI2CS - I2C BUS INTERFACE-SLAVE                   */
/*                                                                          */
/* File name            : example.c                                         */
/* File contents        : DI2CS C compiler interface functions              */
/*                        sample test.                                      */
//--------------------------------------------------------------------------
// Design Engineer      : T.K.
// Version              : 1.37
// Last modification    : 2007-01-24
//----------------------------------------------------------------------------
// Functions body are defined in "di2cs.h" file for DP80390/DP8051
//****************************************************************************

#include "di2cs.h"

volatile unsigned char slave_address, datain;
// very simple DI2CS interface test
int main()
{
 slave_address=0xAA;
 datain=0x20;
 
 
 ownaddr_di2cs( slave_address ); // Set Own address
 enable_di2cs(); // Enable DI2CS module
 
 while(1){
   if (read_di2cs(DI2CS_SR)& SR_RREQ) // Read received byte
     datain=readbuf_di2cs();
   if (read_di2cs(DI2CS_SR)& SR_TREQ){ // Submit byte
     writebuf_di2cs(datain);
	 datain++;
   }
 }

 return 0;
}

⌨️ 快捷键说明

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