Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Showing error while initializing I2C Function in MIKROC

Status
Not open for further replies.

khatus

Member level 3
Member level 3
Joined
Oct 7, 2017
Messages
64
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,754
Hello guys I am getting the following error in mikroc.I am trying to convert a code written for MPLAB. While declaring and defining i2c function in mikroc.Here is the error message

I2c erorrr.PNG

here is my full code

Code:
#define   _XTAL_FREQ 8000000

void I2C_Initialize(const unsigned long feq_K) //Begin IIC as master
{
  TRISC.F3 = 1;  TRISC.F4 = 1;  //Set SDA and SCL pins as input pins

  SSPCON  = 0b00101000;    //pg84/234
  SSPCON2 = 0b00000000;    //pg85/234

  SSPADD = (_XTAL_FREQ/(4*feq_K*100))-1; //Setting Clock Speed pg99/234
  SSPSTAT = 0b00000000;    //pg83/234
}
void I2C_Hold()
{
    while ((SSPCON2 & 0b00011111)||(SSPSTAT & 0b00000100)) ; //check the this on registers to make sure the IIC is not in progress
}
void I2C_Begin()
{
  I2C_Hold();  //Hold the program is I2C is busy
  SSPCON2.SEN = 1;     //Begin IIC pg85/234
}
unsigned short I2C_Rd(unsigned short ack)
{
  unsigned short incoming;
  I2C_Hold();
  SSPCON2.RCEN = 1;

  I2C_Hold();
  incoming = SSPBUF;      //get the data saved in SSPBUF

  I2C_Hold();
  SSPCON2.ACKDT = (ack)?0:1;    //check if ack bit received
  SSPCON2.ACKEN = 1;          //pg 85/234

  return incoming;
}

void I2C_End()
{
  I2C_Hold(); //Hold the program is I2C is busy
  SSPCON2.PEN = 1;    //End IIC pg85/234
}

Void I2C_Wrt(unsigned int dat)
{
  I2C_Hold(); //Hold the program is I2C is busy
  SSPBUF=dat;//pg82/234
}

void main()
{
  ADCON1.PCFG3=1;
  ADCON1.PCFG2=1;
  ADCON1.PCFG1=1 ;
  ADCON1.PCFG0=0 ;
  PORTB = 0;
  TRISB = 0;                 // Configure PORTB as output
  I2C_Initialize(100); //Initialize I2C Master with 100KHz clock
  
  while(1)
  {
   I2C_Begin();
   I2C_Wrt(0xD0);
   I2C_Wrt(0x88);
   I2C_Wrt(0xFF);
   I2C_End();
   delay_ms(1000); 
  }

 }

What is the problem in my code??
 

Hi,

Try to write "void" without capital "V".
Without knowing about your compiler .... I just see this is the difference to other lines.

Klaus
 

If this is your full code, it also misses the definition of I2C registers. They are not defined in mikroC.
 

Review reply #2...the C language is case-sensitive, and void is a reserved word necessary at the line where compilator complains.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top