convert from mickro c to MPLAP

Thread Starter

Afnan_123_

Joined Feb 7, 2013
22
Hi,
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

Rich (BB code):
// Lcd pinout settings
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;
char txt1[] = "ROOM TUMPEATURE";
int x=0;
float temp=0;
char txt[12];
void main() {
lcd_init (); ADC_init (); //analogue and digital converter
lcd_cmd(_lcd_cursor_off);
TRISA.b0=1;
PortA.b0=0;
TRISC.b1=0;
PortC.b1=0;
while (1) {
x=ADC_read (0); // 0 refers to the port number
temp=x*0.489;
floattostr (temp,txt);
lcd_out (1,1,txt1);
lcd_out (2,2,txt);
if (temp<24) { PortC.b0=0; }
else { PortC.b1=1;}
} }
 

Attachments

tshuck

Joined Oct 18, 2012
3,534
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.
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
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?
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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!
 
Top