嗨,我的意思是没有确切的信息要写什么数据,因此它没有给出与狗一样的输出,图18。我被要求显示在LCD上传输的数据。但是,因为我不知道数据是什么,所以我不能这样做。可能是地址没有被确认,但我使用的地址是在数据表上为gestIc提供的。以下是示例代码之一:I didextern void lcd_init(void);extern void lcd_putc(无符号int状态);extern void I2C_Master_Init();extern void I2C_Master_Wait();extern void I2C_Master_Start();extern void I2C_Master_Restart();extern void I2C_Master_Stop();extern void I2C_Master_Write(无符号d);无符号的字符数据;无效I2C_Master_Master_Init(){SSPSTAT=0;//b100001SSPMSK=0;//b10000101 SSPSTAT=0;//b10000101 SSPMSK=0;SSPCON 0=0b00101SK=0;SSPCON2=0b001010000000000000000000000;SSPCON2=0;SSPADD=0x4f;TRISC比特.TRISC比特.TRISC3=1;TRISC比特.TRISC比特.TRISC4=1;TRISC比特.TRISC4=1;;}无效I2C_MasMasMasMas串串串串串4=1;}I2C_MasMaster_Wait(){{{//传输正在进行中}无效I2C_Master_S{I2C_Master_Wait(){I2C_Master_Master_Wait();SSP1CON2比特,SSP1CON2比特.SEN=1;}无效I2C_Master_Master_Master_Wait();SSP1CON2C_I2C_Master_Master_Wait();SSP1CON2C_Master_Master_Wait();SSP1CON2C2C_Master_Master_Master_Water_Wait();SSP1CON2C_I2C_Master_Master_Master_Master_Master_Master_Rest2C_Master_Wait();SSP1CON2C_2C_IP1CON2C_2C_Master_Master_Master_Master_Master_}int I2C_Master_Read(无符号短a){无符号shOrtTimp;I2CyMistar WAITE();SSPCON2BITS RCEN=1;I2CyMistar WAITE();TEMP= SSPBUF;I2C.MistMaWaWET();SSPCON2BITS.ACKDT =(a)?0:1;SSPCON2bits.ACKEN=1;返回temp;}vovoidmain(void){OP._REGbits.nWPUEN=0;返回temp;{返回temp;}vovovovoid;{OP._REGbits.void;}void;{OP._REGGGGbits.nWWWPUPU=0;WPUB=1;TRISB=0b11111111111111111111;.//PORTB作为输入TRISD=0b0000000000000000000011;;.//PORTB/PORTB PORTB作为输入TRIRTB=0b00000000000000000000000000000000000000000输入;.//PORTD作为输出(港口)比特.RD2==1) {I2C_Master_Master_Star(){I2C_Master_Star();//启动条件I2C_Master_Master_Writ(0x42|0x4);//7位地址+写入数据=I2C_Master_Master_Master_Master_读出(0);//7位地址+写入数据=I2C_写入数据=I2C_I2C_Master_Master_Master_Master_Master_Wter_写入(0x42|(0x42|0x42|0x42|0x42|0x42|0x42|0x4);//7位地址+写入+写入+写入数据=Is.BF==1) {I2C_Master_Wait();}.{I2C.Mistalm Stutter();} }
以上来自于百度翻译
以下为原文
Hi,
I just mean that there's no information about what exactly the data is to be written, therefore it is not giving the same output as the dongle, pic18. I was asked to display the data transmitted on the LCD . but since I dont know what the data is, I can't do that.
It could be the case that the address in not being acknowledged, but I was using the address that was provided on the datasheet for the gestIc. Here's one of the sample codes I did
extern void lcd_init(void);
extern void lcd_putc(unsigned int status);
extern void I2C_Master_Init();
extern void I2C_Master_Wait();
extern void I2C_Master_Start();
extern void I2C_Master_Restart();
extern void I2C_Master_Stop();
extern void I2C_Master_Write(unsigned d);
unsigned char data;
void I2C_Master_Init()
{
SSPSTAT=0;//b10000101
SSPMSK=0;
SSPCON=0b00101000;
SSPCON2=0;
SSPADD=0x4f;
TRISCbits.TRISC3=1;
TRISCbits.TRISC4=1;
}
void I2C_Master_Wait()
{
while ((SSPSTAT & 0b00000100) || (SSPCON2 & 0b00011111)); //Transmit is in progress
}
void I2C_Master_Start()
{
I2C_Master_Wait();
SSP1CON2bits.SEN = 1;
}
void I2C_Master_Restart()
{
I2C_Master_Wait();
SSP1CON2bits.RSEN = 1;
}
void I2C_Master_Stop()
{
I2C_Master_Wait();
SSP1CON2bits.PEN = 1;
}
void I2C_Master_Write(unsigned d)
{
I2C_Master_Wait();
SSPBUF = d;
}
int I2C_Master_Read(unsigned short a)
{
unsigned short temp;
I2C_Master_Wait();
SSPCON2bits.RCEN = 1;
I2C_Master_Wait();
temp = SSPBUF;
I2C_Master_Wait();
SSPCON2bits.ACKDT = (a)?0:1;
SSPCON2bits.ACKEN = 1;
return temp;
}
void main(void)
{
OPTION_REGbits.nWPUEN=0;
WPUB=1;
TRISB = 0b11111111; //PORTB as input
TRISD = 0b00000000; //PORTD as output
PORTD = 0b00000000;
I2C_Master_Init(100000); //Initialize I2C Master with 100KHz clock
TRISDbits.TRISD2=1;
if(PORTDbits.RD2==1)
{
I2C_Master_Start(); //Start condition
I2C_Master_Write(0x42|0x4); //7 bit address + Write
data=I2C_Master_Read(0);
if(SSPMSK==1)
{
I2C_Master_Read(0);
}
I2C_Master_Wait();
PORTD =I2C_Master_Read(0);
if(SSPSTATbits.BF==1)
{
I2C_Master_Wait();
}
else
{
I2C_Master_Stop();
}
}
}