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 2
Joined
Oct 7, 2017
Messages
44
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
329
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??
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,031
Helped
4,716
Reputation
9,448
Reaction score
5,089
Trophy points
1,393
Activity points
152,587
Hi,

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

Klaus
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
50,804
Helped
14,603
Reputation
29,481
Reaction score
13,687
Trophy points
1,393
Location
Bochum, Germany
Activity points
290,907
If this is your full code, it also misses the definition of I2C registers. They are not defined in mikroC.
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,957
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

Top