p18_i2c.c

来自「PIC系列单片机的I2C通讯的样例程序」· C语言 代码 · 共 55 行

C
55
字号
#include	<p18f452.h>
#include 	<i2c.h>
//#include 	<stdio.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = ON
#define uchar	unsigned char
#define uint	unsigned int
#define ic_adress1	0xa0
  struct {
    unsigned adress:7;
    unsigned wr:1;
  } EESLAVE;

uchar	EEADDR,EEDAT;

void delay10ms(unsigned int count)  
{ unsigned int i,j,k;

  for (i=0;i<count;i++)
     for (j=0;j<100;j++)
        for (k=0;k<100;k++);
}		


void main()
{
PORTB=0;
TRISB=0;
/*i2c初始化*/ 
SSPSTATbits.SMP=1;
SSPCON1bits.SSPM3=1;
SSPCON1bits.SSPEN=1;
TRISCbits.TRISC3=1;
PORTCbits.RC3=1;
TRISCbits.TRISC4=1;
PORTCbits.RC4=1;
EESLAVE.adress=0xa0;
//start i2c read& write;
delay10ms(3);			//0.5S
PORTB=EEDAT=EEADR=0;
PORTBbits.RB0=1;
delay10ms(4);







while(1);

}

⌨️ 快捷键说明

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