aswin p ajayan
Member
hi ,
recently i switched to pic 18f
i cant get the program for i2c correct can any body help
when i simulate in proteus i get the following outputs.
it doesnt make any sense .
recently i switched to pic 18f
i cant get the program for i2c correct can any body help
C:
#include<htc.h>
__CONFIG(2, PWRTDIS & WDTPS1 & WDTEN &WDTDIS);
__CONFIG(4, STVRDIS);
#define _XTAL_FREQ 16000000
void _delay(unsigned long cycles);
void i2c_init(void);
bit i2c_write_byte(unsigned char byte);
unsigned char i2c_read_byte(void);
void i2c_send_ack(void);
void i2c_send_nack(void);
void i2c_start(void);
void i2c_stop(void);
void i2c_repstart(void);
void main()
{
unsigned char byte;
byte = 0xff;
TRISB =0XFF;
i2c_init();
while(1)
{
i2c_start();
i2c_write_byte(0xD0);
i2c_repstart();
i2c_write_byte(0x00);
i2c_write_byte(0x55);
i2c_write_byte(0x02);
i2c_stop();
_delay(10000);
}
}
void i2c_init()
{
SMP = 1;
SSPCON1 = 0X3B;
}
void i2c_start(void)
{
SEN = 1;
while(!SSPIF);
SSPIF=0;
}
void i2c_repstart(void)
{
RSEN = 1;
while(!SSPIF);
SSPIF = 0;
return;
}
void i2c_stop(void)
{
PEN = 1;
while(!SSPIF);
SSPIF =0 ;
}
void i2c_send_ack(void)
{
ACKDT = 0;
ACKEN = 1;
while(!SSPIF);
SSPIF =0;
}
void i2c_send_nack(void)
{
ACKDT =1;//Not Acknowledged
ACKEN = 1;
while(!SSPIF);
SSPIF =0;
}
bit i2c_write_byte(unsigned char byte)
{
SSPBUF = byte;
while(!SSPIF);
SSPIF = 0;
return ACKSTAT;
}
unsigned char i2c_read_byte(void)
{
RCEN =1;
while(!SSPIF);
SSPIF = 0;
return SSPBUF;
}
when i simulate in proteus i get the following outputs.
it doesnt make any sense .
Attachments
Last edited by a moderator: