code conversion micro c to xc8

Status
Not open for further replies.

sahu

Member
i have need code conversion micro c to xc8 .pl help me
Code:
//LCD Module Connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
//End LCD Module Connections
int powerFactor()
{
  int a=0,b=0,t=0,x=0;
  float tm,pf;
  TMR1L=0;
  TMR1H=0;
  do
  {
    if(PORTA.F0 == 1)
    T1CON.F0 = 1;
    else if(PORTA.F0 == 0 && T1CON.F0 == 1)
    {
      T1CON.F0 = 0;
      break;
    }
  }while(1);
  a = (TMR1L | (TMR1H<<8)) * 2;
  TMR1L=0;
  TMR1H=0;
  do
  {
    if(PORTA.F0 == 1)
    {
      T1CON.F0=1;
      if(PORTA.F1==1)
      {
        T1CON.F0=0;
        break;
      }
    }
  }while(1);

  b = TMR1L | (TMR1H<<8);
  tm = (float)b/a;
  pf = cos(tm*2*3.14);
  x=abs(ceil(pf*100));

  return x;
}

void main()
{
  char c[]="0.00";
  int a,b,d,x,f,e;
  float tm,pf;

  Lcd_Init();
  Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

  ADCON1 = 0x08; // To configure PORTA pins as digital
  TRISA.F0 = 1; // Makes First pin of PORTA as input
  TRISA.F1 = 1; //Makes Second pin of PORTA as input
  TRISD.F0 = 0; //Makes Fist pin of PORTD as output
  TRISD.F1 = 0; //Makes Second pin of PORTD as output

  while(1)
  {
    a = powerFactor();
    Delay_us(50);
    b = powerFactor();
    Delay_us(50);
    d = powerFactor();
    Delay_us(50);
    e = powerFactor();
    Delay_us(50);
    f = powerFactor();

    x = (a+b+d+f+e)/5;
    c[3]=x%10 + 0x30;
    x=x/10;
    c[2]=x%10 + 0x30;
    x=x/10;
    c[0]=x%10 + 0x30;

    Lcd_Out(1,1,"Power Factor");
    Lcd_Out(2,1,c);

    if(x<90)
    {
      PORTD.F0 = 1;
      PORTD.F0 = 1;
      Delay_ms(2000);
    }
    else
    {
      PORTD.F0 = 0;
      PORTD.F0 = 0;
    }
    Delay_ms(250);
  }
}
 
hi,
were you able to do the conversion? i need this code compiled but also have demo version of mikroC. can you help?
 
hi,
were you able to do the conversion? i need this code compiled but also have demo version of mikroC. can you help?
The only thing needed is the LCD library!! I wrote a compatible XC version a while back..

C:
#include <xc.h>
#include <math.h>

#define abs(x) ( (x) >= 0 ? (x) : -(x) )

void Delay_Us(int x)
   {
   x>>4;
   while(x--);   
   }
   
void Delay_Ms(int x)
   {
   while(x--) Delay_Us(1000);   
   }

void LCDcmd(char c)
   {
   unsigned char buf;
   buf = c & 0xf0;
   PORTB = buf;
   Delay_Us(100);
   RB3 = 1;     // E
   Delay_Us(100);
   RB3 = 0;     // E
   buf = (c << 4) & 0xf0;
   PORTB = buf;
   Delay_Us(100);
   RB3=1;       // E
   Delay_Us(100);
   RB3=0;       // E
   }

void LCDdata(char c)
   {
   unsigned char buf;
   buf = c & 0xf0;
   PORTB = buf;
   RB2 = 1;     // R/S
   Delay_Us(100);
   RB3 = 1;     // E
   Delay_Us(100);
   RB3 = 0;     // E
   buf = (c << 4) & 0xf0;
   PORTB = buf;
   RB2 = 1;     // R/S
   Delay_Us(100);
   RB3=1;     // E
   Delay_Us(100);;
   RB3 = 0;     // E
   }

void LCDline(char c)
   {
   char addr;
   addr = 0x80;
   if (c == 2) addr += 0x40;
   Delay_Ms(1);
   LCDcmd(addr);
   }

void LCDgoto(char x,char y)
   {
   char addr;
   
   addr = 0x80 + y;
   if(x == 2) addr += 0x40;
   Delay_Ms(1);
   LCDcmd(addr);
   }

void LCDprintC(char x,char y,const char * c)
   {
   LCDgoto( x, y);
   while(*c != '\0')
     {
     Delay_Ms(1);
     LCDdata(*c);
     c++;
     }
   }
void LCDprintR(char x,char y, char * c)
   {
   LCDgoto( x, y);
   while(*c != '\0')
     {
     Delay_Ms(1);
     LCDdata(*c);
     c++;
     }
   }
void LCDinit(char c)
   {
   PORTB = 0;
   TRISB = 3;
   LCDcmd(0x32);
   Delay_Ms(15);
   LCDcmd(0x2c);
   Delay_Ms(5);
   LCDcmd(0x6);
   Delay_Ms(1);
   LCDcmd(0xc);
   Delay_Ms(1);
   LCDcmd(c);
   Delay_Ms(1);
   }


int powerFactor()
{
  int a=0,b=0,t=0,x=0;
  float tm,pf;
  TMR1L=0;
  TMR1H=0;
  do
  {
  if(RA0 == 1)
  TMR1ON = 1;
  else if(RA0 == 0 && TMR1ON == 1)
  {
  TMR1ON = 0;
  break;
  }
  }while(1);
  a = (TMR1L | (TMR1H<<8)) * 2;
  TMR1L=0;
  TMR1H=0;
  do
  {
  if(RA0 == 1)
  {
  TMR1ON=1;
  if(RA1 == 1)
  {
  TMR1ON=0;
  break;
  }
  }
  }while(1);

  b = TMR1L | (TMR1H<<8);
  tm = (float)b/a;
  pf = cos(tm*2*3.14);
  x=abs(ceil(pf*100));

  return x;
}

void main()
{
  char c[]="0.00";
  int a,b,d,x,f,e;
  float tm,pf;

  LCDinit(1);
 
  ADCON1 = 0x07; // To configure PORTA pins as digital
  TRISA0 = 1; // Makes First pin of PORTA as input
  TRISA1 = 1; //Makes Second pin of PORTA as input
  TRISD0 = 0; //Makes Fist pin of PORTD as output
  TRISD1 = 0; //Makes Second pin of PORTD as output

  while(1)
  {
  a = powerFactor();
  Delay_Us(50);
  b = powerFactor();
  Delay_Us(50);
  d = powerFactor();
  Delay_Us(50);
  e = powerFactor();
  Delay_Us(50);
  f = powerFactor();

  x = (a+b+d+f+e)/5;
  c[3]=x%10 + 0x30;
  x=x/10;
  c[2]=x%10 + 0x30;
  x=x/10;
  c[0]=x%10 + 0x30;

  LCDprintC(1,1,"Power Factor");
     LCDprintR(2,1,c);

  if(x<90)
  {
  RD0 = 1;
  RD0 = 1;
  Delay_Ms(2000);
  }
  else
  {
  RD0 = 0;
  RD0 = 0;
  }
  Delay_Ms(250);
  }
}
 
MikroC can't even compile a 20 kB hex LOL I thought it was 2000 kB limit they even said on the forum one of the team that It should but i doesn't.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…