convert from mickro c to MPLAP

Discussion in 'Embedded Systems and Microcontrollers' started by Afnan_123_, Apr 2, 2013.

  1. Afnan_123_

    Thread Starter New Member

    Feb 7, 2013
    i have code in mickro C ,but i want to work in MPLAP c18 compiler
    can any one know how to convert from Mickro C to MPLAP C18??i attached my file

    Code ( (Unknown Language)):
    1. // Lcd pinout settings
    2. sbit LCD_RS at RD4_bit;
    3. sbit LCD_EN at RD5_bit;
    4. sbit LCD_D7 at RD3_bit;
    5. sbit LCD_D6 at RD2_bit;
    6. sbit LCD_D5 at RD1_bit;
    7. sbit LCD_D4 at RD0_bit;
    9. // Pin direction
    10. sbit LCD_RS_Direction at TRISD4_bit;
    11. sbit LCD_EN_Direction at TRISD5_bit;
    12. sbit LCD_D7_Direction at TRISD3_bit;
    13. sbit LCD_D6_Direction at TRISD2_bit;
    14. sbit LCD_D5_Direction at TRISD1_bit;
    15. sbit LCD_D4_Direction at TRISD0_bit;
    16. char txt1[] = "ROOM TUMPEATURE";
    17. int x=0;
    18. float temp=0;
    19. char txt[12];
    20. void main() {
    21. lcd_init (); ADC_init (); //analogue and digital converter
    22. lcd_cmd(_lcd_cursor_off);
    23. TRISA.b0=1;
    24. PortA.b0=0;
    25. TRISC.b1=0;
    26. PortC.b1=0;
    27. while (1) {
    28. x=ADC_read (0); // 0 refers to the port number
    29. temp=x*0.489;
    30. floattostr (temp,txt);
    31. lcd_out (1,1,txt1);
    32. lcd_out (2,2,txt);
    33. if (temp<24) { PortC.b0=0; }
    34. else { PortC.b1=1;}
    35. } }
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    I believe the compiler you are referring to is Microchip's C18 compiler, not "MPLAP".

    MPLAB is the programming environment.

    As far as converting between the two, I think you may need to bite the bullet (the brute force method) and transcribe it yourself. Luckily, your program is pretty simple and you should view this as a learning exercise as how to use the C18 compiler.
  3. Afnan_123_

    Thread Starter New Member

    Feb 7, 2013
    yes i mean C18 compiler
  4. JohnInTX


    Jun 26, 2012
    Agreed, but why not XC8? That's where things at uCHIP are going. C18 is going away. Microchip is now kind of suggesting that C18 projects stay on C18 rather than try to rebuild with XC8. Kind of indicates how much difference there is between the two. So, as long as you are rewriting, might as well go to the new stuff?
  5. Afnan_123_

    Thread Starter New Member

    Feb 7, 2013
    No my teacher told me " i should use C18 compiler, no Mickro C"
  6. JohnInTX


    Jun 26, 2012
    But tshuck is still right, you'll be doing a lot of rewriting.

    Your basic C should compile pretty well under C18. All of your library routines for the LCD display (the pin declarations, names of functions etc.) will be different and the code using them will need to be rewritten. Consult the compiler libraries documentation DS51297F and have at it. For starters, section 3.2 describes the Hitachi-compatible LCD libraries.

    In a large program, you can sometimes use #define to rename and reformat things to save some labor but on something small it can just add confusion. Time for a rewrite.
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    The big thing you are up against here is Mikro C and C18 have a ton of incompatibilities built in, starting with the way they define single bits and continuing along with code libraries.

    C18 has the same functions in it's libraries (even for LCD displays if you look hard enough) so there is nothing you can do in Mikro C you cannot do on C18.

    I would not look to translate from one language to another... I would look at the code you have as a template, and write each line in C18 style. We can help you over the humps (and everyone has a big hump getting the LCD to work the first time).

    After all, if your instructor tells you you're a C18 programmer, then you're a C18 programmer. Go forth and program!