convert from mplab ide to mikroc compiler

Status
Not open for further replies.

h.sharma

Junior Member level 3
Joined
Jun 16, 2012
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,455
Hey, I have to convert this code to mikroc compiler. It is compiled successfully in mplab but it shows many errors in mikroc .
please help me..!!!
thanx in advance.
Code:
#define LCD PORTB
#define RS portd.f0
#define EN portd.f1
#define _XTAL_FREQ 4000000
void cmd(void);

void temp_sens();




void main(){
int j=0;
char ldg[12]=" Loading...";
TRISD=0X00;
PORTD=0X00;
TRISC=0X00;
TRISA=0XFF;
TRISB=0X00;
PORTD=0X00;
LCD_init();
for(j=0;j<=9;j++)
{
        LCD=ldg[j];
        data();
}
while(1){
speed();
temp_sens();
press_sens();
car_temp();
}
}

void LCD_init(){
         LCD=0X38;        //using5*8dots
         cmd();
         LCD=0X0C;        //display ON
     cmd();
         LCD=0X01;        //clear lcd//
         cmd();
     LCD=0X80;        //intial cursor position//
     cmd();
}
void cmd(void){
RS=0;
EN=1;
delay_us(100);
EN=0;
delay_us(100);
}

void data(void){
RS=1;
EN=1;
delay_us(100);
EN=0;
delay_us(100);
}
void temp_sens(){
ADCON0=0b00000101;  //channel 1 AN0
ADCON1=0b11000000;

        int ii=0,j=0;
        float f;
        char t[21]=" Coolant Temperature ",disp[2];
        long h;
        ADGO=1;
        while(ADGO==1);
        h=ADRESH;
        h<<=8;
        h|=ADRESL;

        f = ((h*5.0)/1023)*100;
        float2string(disp,f);
LCD=0X94;   //3rd line cursor position
cmd();
for(j=0;j<=20;j++)
{
        LCD=t[j];
        data();
}     LCD=0XD4;        //4th line cursor position//
     cmd();
             while(disp[ii]!=0){
                     LCD=disp[ii];
                     data();
                         ii++;
            }
         ii=0;
}


void second(s){
for(i=0;i<=s;i++){
for(i=0;i<=10;i++){
delay_ms(100);
}
}
}
void float2string(char *str,float f)
 {
         int d=0,i=0,j=0; char *t;
         d =(int)f;

         while(d!=0)
          {
                  j=d%10;
                  //cout<<j<<endl;
                  i++;
                  d-=j;
                  d/=10;
          for(int m=i;m>0;m--)
                          str[m]=str[m-1];

                  str[0]=j+'0';
      }
        str[i]='.';
        i++;
        f=f-(float)((int)f);
        f=f*100;
        d=(int)f;
        t = &str[i];
        i=0;
        while(d!=0)
          {
                  j=d%10;
                  i++;
                  d-=j;
                  d/=10;
                  for(int m=i;m>0;m--)
                          t[m]=t[m-1];
                  t[0]=j+'0';

                  }
 }


void press_sens(){
ADCON0=0b00001101;  //channel 2 AN1
ADCON1=0b11000000;

        int ii=0;
        float f;
        char t[]="    Fuel(%) ",disp1[2];
        long h;
        ADGO=1;
        while(ADGO==1);
        h=ADRESH;
        h<<=8;
        h|=ADRESL;

        f =100-(((h*5.0)/1023)/5)*100;   //100-(% out of 5.0)

        float2string(disp1,f);

   //  LCD=0X94;        //intial cursor position//
   //  cmd();
for(j=0;j<=10;j++)
{
        LCD=t[j];
        data();
}
             while(disp1[ii]!=0){
                     LCD=disp1[ii];
                     data();
                         ii++;
            }
         ii=0;
}



speed(){
int j=0,ii=0;
float f;
char t[]=" speed(rev/min) ",o[]="overdrive",disp[3];
TMR0=0X00;
//TOCS=1;
//TOSE=0;
//PSA=0;
OPTION_REG=0b00000001;
second(1);
f=60*TMR0;   //REV/MIN
float2string(disp,f);
    LCD_init();
for(j=0;j<=14;j++)
{
        LCD=t[j];
        data();
}
             while(disp[ii]!=0){
                     LCD=disp[ii];
                     data();
                         ii++;
            }
         ii=0;
        LCD=0XC0;      //2nd line cursor  position
        cmd();
if(f>60){
for(j=0;j<=8;j++){
        LCD=o[j];
        data();
}
}

}





void car_temp(){
ADCON0=0b00010101; //channel 2 AN2
ADCON1=0b11000000;

        int ii=0,f;
        long h;
        ADGO=1;
        while(ADGO==1);
        h=ADRESH;
        h<<=8;
        h|=ADRESL;

        f = ((h*5.0)/1023)*100;
if(f>=25)
RD2=1;
else
RD2=0;

}


##############Here are the errors shown....############3


0 1139 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
0 126 All files Preprocessed in 94 ms
0 122 Compilation Started automotive sensors.c
26 315 Invalid expression automotive sensors.c
25 402 ; expected, but 'data' found automotive sensors.c
26 424 '}' expected ';' found automotive sensors.c
27 424 '}' expected '}' found automotive sensors.c
34 371 Specifier needed automotive sensors.c
34 396 Invalid declarator expected'(' or identifier automotive sensors.c
45 1503 Result is not defined in function: '' automotive sensors.c
54 396 Invalid declarator expected'(' or identifier automotive sensors.c
55 300 Syntax Error: ')' expected, but '=' found automotive sensors.c
55 402 ; expected, but '1' found automotive sensors.c
55 393 '' Identifier redefined automotive sensors.c
55 312 Internal error '' automotive sensors.c
0 102 Finished (with errors): 17 Jul 2012, 18:06:46 automotive sensors.mcppi
 

Code:
#define LCD PORTB
#define RS portd.f0
#define EN portd.f1
#define _XTAL_FREQ 4000000
#define ADGO ADCON0.GO

void cmd(void);
void temp_sens();
void speed(void);
void lcd_data(void);
void LCD_init(void);
void press_sens(void);
void car_temp(void);
void float2string(char *str,float f);
void second(char nsecs);

void main(){
int j=0;
char ldg[12]=" Loading...";
    TRISD=0X00;
    PORTD=0X00;
    TRISC=0X00;
    TRISA=0XFF;
    TRISB=0X00;
    PORTD=0X00;
    LCD_init();
    for(j=0;j<=9;j++)
    {
            LCD=ldg[j];
            lcd_data();
    }
    while(1){
        speed();
        temp_sens();
        press_sens();
        car_temp();
    }
}

void LCD_init(void){
     LCD=0X38;        //using5*8dots
     cmd();
     LCD=0X0C;        //display ON
     cmd();
     LCD=0X01;        //clear lcd//
     cmd();
     LCD=0X80;        //intial cursor position//
     cmd();
}

void cmd(void){
    RS=0;
    EN=1;
    delay_us(100);
    EN=0;
    delay_us(100);
}

void lcd_data(void){
    RS=1;
    EN=1;
    delay_us(100);
    EN=0;
    delay_us(100);
}

void temp_sens(){
int ii=0,j=0;
float f;
char t[23]=" Coolant Temperature ";
char disp[2];
long h;

    ADCON0=0b00000101;  //channel 1 AN0
    ADCON1=0b11000000;
    ADGO=1;
    while(ADGO==1);
    h=ADRESH;
    h<<=8;
    h|=ADRESL;

    f = ((h*5.0)/1023)*100;
    float2string(disp,f);
    LCD=0X94;   //3rd line cursor position
    cmd();
    for(j=0;j<=20;j++)
    {
            LCD=t[j];
            lcd_data();
    }     LCD=0XD4;        //4th line cursor position//
    cmd();
    while(disp[ii]!=0){
        LCD=disp[ii];
        lcd_data();
        ii++;
    }
    ii=0;
}


void second(char nsecs){
char i;

    for(i=0;i<=nsecs;i++){
        for(i=0;i<=10;i++){
            delay_ms(100);
        }
    }
}

void float2string(char *str,float f){
int d=0,i=0,j=0; char *t;
int m;

    d =(int)f;

    while(d!=0)
    {
        j=d%10;
        //cout<<j<<endl;
        i++;
        d-=j;
        d/=10;
        for(m=i;m>0;m--)
                          str[m]=str[m-1];

        str[0]=j+'0';
    }
    str[i]='.';
    i++;
    f=f-(float)((int)f);
    f=f*100;
    d=(int)f;
    t = &str[i];
    i=0;
    while(d!=0)
    {
        j=d%10;
        i++;
        d-=j;
        d/=10;
        for(m=i;m>0;m--)
            t[m]=t[m-1];
        t[0]=j+'0';

    }
}

void press_sens(void){
int ii=0;
float f;
char t[]="    Fuel(%) ",disp1[2];
long h;
char j;
        
    ADCON0=0b00001101;  //channel 2 AN1
    ADCON1=0b11000000;
    ADGO=1;
    while(ADGO==1);
    h=ADRESH;
    h<<=8;
    h|=ADRESL;

    f =100-(((h*5.0)/1023)/5)*100;   //100-(% out of 5.0)

    float2string(disp1,f);

    //  LCD=0X94;        //intial cursor position//
    //  cmd();
    for(j=0;j<=10;j++)
    {
            LCD=t[j];
            lcd_data();
    }
    while(disp1[ii]!=0){
        LCD=disp1[ii];
        lcd_data();
        ii++;
    }
    ii=0;
}

void speed(void){
int j=0,ii=0;
float f;
char t[]=" speed(rev/min) ",o[]="overdrive",disp[3];

    TMR0=0X00;
    //TOCS=1;
    //TOSE=0;
    //PSA=0;
    OPTION_REG=0b00000001;
    second(1);
    f=60*TMR0;   //REV/MIN
    float2string(disp,f);
    LCD_init();
    for(j=0;j<=14;j++)
    {
        LCD=t[j];
        lcd_data();
    }
    while(disp[ii]!=0){
        LCD=disp[ii];
        lcd_data();
        ii++;
    }
    ii=0;
    LCD=0XC0;      //2nd line cursor  position
    cmd();
    if(f>60){
        for(j=0;j<=8;j++){
            LCD=o[j];
            lcd_data();
        }
    }
}


void car_temp(void){
int ii=0,f;
long h;

    ADCON0=0b00010101; //channel 2 AN2
    ADCON1=0b11000000;
    ADGO=1;
    while(ADGO==1);
    h=ADRESH;
    h<<=8;
    h|=ADRESL;

    f = ((h*5.0)/1023)*100;
    if(f>=25)
        PORTB.RD2=1;
    else
        PORTB.RD2=0;
}
Adjust the following line to suit your processor

#define ADGO ADCON0.GO
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…