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.

[SOLVED] Need help to make .hex file (MPLAB)

Status
Not open for further replies.

Justinho27

Newbie level 5
Joined
Apr 24, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
55
Hello guys!
Im pretty green with microcontrollers and programming, but i need some help with finishing my study project.
So, im using PIC16F877. I have made program code with mikroC PRO, but at the moment program is to big for demo version. So, i want to transfer it from mikroC to MPLAB v8.92. But when im trying to compile it with MPLAB i got a lot of errors, lol. Its my first project, so dont judge me, lol.
Here is the code wich perfectly works with mikroC (except the fact that its too long, lol):


Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned char ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7;
unsigned int adc_rd0, adc_rd1, adc_rd2, adc_rd3;
char *text, *text3, *text1, *text2;
long et0, et1, et2, et3, kg1, kg2;

void main() {
    INTCON = 0;
    ANSELH = 0;

    Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)

    text = "Fuel Balance";               // Define the first message
    Lcd_Out(1,1,text);               // Write the first message in the first line
    text = "System by J.P.";            // Define the second message
    Lcd_Out(2,1,text);               // Define the first message

    ADCON1 = 0x82;                   // A/D voltage reference is VCC
    TRISA = 0xFF;                    // All port A pins are configured as inputs
    Delay_ms(1);
    Lcd_Cmd(_LCD_CLEAR);
    
         text1 = "L/H:";
         text2 = "R/H:";
         Lcd_Cmd(_LCD_CLEAR);

    while (1) {
        Lcd_Out(1,1,text1);
        Lcd_Out(2,1,text2);
        adc_rd0 = ADC_Read(0);
        adc_rd1 = ADC_Read(1);
        adc_rd2 = ADC_Read(2);
        adc_rd3 = ADC_Read(3);
        et0 = (long)adc_rd0 * 1000;
        et1 = (long)adc_rd1 * 1000;
        et2 = (long)adc_rd2 * 1000;
        et3 = (long)adc_rd3 * 1000;
        et0 = et0 / 1023;
        et1 = et1 / 1023;
        et2 = et2 / 1023;
        et3 = et3 / 1023;
        et0 = et1 * 100 / et0;
        et2 = et3 * 100 / et2;
        kg1 = et0 * 4530 / 100;
        kg2 = et2 * 4530 / 100;
        ch4 = et0 / 100;
        ch5 = et2 / 100;
        ch6 = kg1 / 1000;
        ch7 = kg2 / 1000;
        
        Lcd_Out(1,15,"KG");
        Lcd_Out(2,15,"KG");
        
        Lcd_Chr(1,11,48+ch6);
        ch6 = (kg1 / 100) % 10;
        Lcd_Chr(1,12,48+ch6);
        ch6 = (kg1 / 10) & 10;
        Lcd_Chr(1,13,48+ch6);
        ch6 = kg1 % 10;
        Lcd_Chr(1,14,48+ch6);
        
        Lcd_Chr(2,11,48+ch7);
        ch7 = (kg2 / 100) % 10;
        Lcd_Chr(2,12,48+ch7);
        ch7 = (kg2 / 10) & 10;
        Lcd_Chr(2,13,48+ch7);
        ch7 = kg2 % 10;
        Lcd_Chr(2,14,48+ch7);
        
        if (et0 > 99)
        {
        Lcd_Out(1,6,"FULL");
        }
        if (99 > et0 & et0 > 10)
            {
            Lcd_Out(1,6," ");
            ch4 = (et0 / 10) % 10;
            Lcd_Chr(1,7,48+ch4);
            ch4 = et0 % 10;
            Lcd_Chr(1,8,48+ch4);
            Lcd_Chr(1,9,'%');
            }
         if (et0 < 10)
                {
         Lcd_Out(1,6,"LOW!");
                }
                  if (et2 > 99)
        {
        Lcd_Out(2,6,"FULL");
        }
        if (99 > et2 & et2 > 10)
            {
            Lcd_Out(2,6," ");
            ch5 = (et2 / 10) % 10;
            Lcd_Chr(2,7,48+ch5);
            ch5 = et2 % 10;
            Lcd_Chr(2,8,48+ch5);
            Lcd_Chr(2,9,'%');
            }
         if (et2 < 10)
                {
         Lcd_Out(2,6,"LOW!");
                 }
         
                 /*Lcd_Chr(1,11,48+ch0);
        Lcd_Chr_CP('.');
        ch0 = (tlong0 / 100) % 10;
        Lcd_Chr_CP(48+ch0);
        ch0 = (tlong0 / 10) % 10;
        Lcd_Chr_CP(48+ch0);
        ch0 = tlong0 % 10;
        Lcd_Chr_CP(48+ch0);
        Lcd_Chr_CP('V');  */
        Delay_ms(1);
    }
}

How can i make this code work on MPLAB? I mean, how can i get .hex file... Which toolsuite i have to use... HELP!
Any help will be very very appreciated!

- - - Updated - - -

Or just, can anybody tell me how to easily make .hex of this program? Im not making real project, just Proteus simulation. Thank you!
 
Last edited by a moderator:

There's no C-compiler installed with MPLAB 8 by deafult. The recent free compiler solution is MPLAB XC8. But porting your code to any compiler different from mikroC will involve some work. You have to find a replacement for built-in functions, particularly there's no similar LCD library.
 
try the attached file
i used mplabx ide with hitech c compiler
**broken link removed**
 

Attachments

  • lcd_data.X.zip
    160 KB · Views: 83
Thank you! Now i can generate .hex file, nice.
But... Because of lack of my programming skill's, i have another problem, lol. When im trying to write more "if" statements, my LCD start's to blinking. I think, that i have some problem with program code and there is some logical mistakes... So, can anybody tell me better way to write code like this? My controller have to show fuel quantity in each L and R Tank's and if there is difference between them, fuel pumps must transfer fueal from one tank to another. So, here is my code:

Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned char ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8;
unsigned int adc_rd0, adc_rd1, adc_rd2, adc_rd3;
char *text, *text3, *text1, *text2;
long et0, et1, et2, et3, kg1, kg2, skirtumas1, skirtumas2;

void main() {
    INTCON = 0;
    ANSELH = 0;

    Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)

    text = "Fuel Balance";               // Define the first message
    Lcd_Out(1,1,text);               // Write the first message in the first line
    text = "System by J.P.";            // Define the second message
    Lcd_Out(2,1,text);               // Define the first message

    ADCON1 = 0x82;                   // A/D voltage reference is VCC
    TRISA = 0xFF;                    // All port A pins are configured as inputs
    Delay_ms(1);
    Lcd_Cmd(_LCD_CLEAR);

         text1 = "L/H TANK: ";
         text2 = "R/H TANK: ";
         Lcd_Cmd(_LCD_CLEAR);

    while (1) {
        adc_rd0 = ADC_Read(0);
        adc_rd1 = ADC_Read(1);
        adc_rd2 = ADC_Read(2);
        adc_rd3 = ADC_Read(3);
        et0 = (long)adc_rd0 * 1000;
        et1 = (long)adc_rd1 * 1000;
        et2 = (long)adc_rd2 * 1000;
        et3 = (long)adc_rd3 * 1000;
        et0 = et0 / 1023;
        et1 = et1 / 1023;
        et2 = et2 / 1023;
        et3 = et3 / 1023;
        et0 = et1 * 100 / et0;
        et2 = et3 * 100 / et2;
        kg1 = et0 * 4530 / 100;
        kg2 = et2 * 4530 / 100;
        ch4 = et0 / 100;
        ch5 = et2 / 100;
        ch6 = kg1 / 1000;
        ch7 = kg2 / 1000;
        skirtumas1 = et0-et2;
        skirtumas2 = et2-et0;

if ( skirtumas1 >= 15)
   {
            Lcd_Out(2,1,"   ");
            Lcd_Out(2,14,"   ");
            Lcd_Out(2,4,"R/H -> L/H");
            Delay_ms(1);
   }
if ( skirtumas2 >= 15)
{
            Lcd_Out(2,1,"   ");
            Lcd_Out(2,14,"   ");
            Lcd_Out(2,4,"R/H <- L/H");
}
if (skirtumas1 < 15, skirtumas2 < 15)
    {
       if (et0 > 99)
        {
        Lcd_Out(1,1,text1);
        Lcd_Out(1,11,"FULL");
        }
         if (99 > et0 & et0 > 10)
            {
             Lcd_Out(1,1,text1);
            Lcd_Out(1,11," ");
            ch4 = (et0 / 10) % 10;
            Lcd_Chr(1,12,48+ch4);
            ch4 = et0 % 10;
            Lcd_Chr(1,13,48+ch4);
            Lcd_Chr(1,14,'%');
            }
         if (et0 < 10)
                {
         Lcd_Out(1,1,text1);
         Lcd_Out(1,11,"LOW!");
                }
         if (et2 > 99)
        {
        Lcd_Out(2,1,text2);
        Lcd_Out(2,11,"FULL");
        }
        if (99 > et2 & et2 > 10)
            {
            Lcd_Out(2,1,text2);
            Lcd_Out(2,11," ");
            ch5 = (et2 / 10) % 10;
            Lcd_Chr(2,12,48+ch5);
            ch5 = et2 % 10;
            Lcd_Chr(2,13,48+ch5);
            Lcd_Chr(2,14,'%');
            }
          if (et2 < 10)
                {
          Lcd_Out(2,1,text2);
         Lcd_Out(2,11,"LOW!");
                 }
           }
    }
}
I think it's not rigt to use "if" statement... Maybe i can use another? I tried to do it in other way's, but i think my skill's and expierence is to low in this case, lol. Please, guys, show me the right way! :shock:

- - - Updated - - -

Whem im making this part of code like this: https://clip2net.com/s/7i1rhR it's working very nice: https://clip2net.com/s/7i1srl
But when im trying to simulate it with code i just wrote, its blinking and buging: https://clip2net.com/s/7i1v6y
 
Last edited by a moderator:

Anjali had given you MPLAB Hi-Tech C code in post #3 as requested then why are you using mikroC code again in post #4? If you need mikroC code then Zip and post your mikroC project files.

Edit: I have modified the code but it doesn't stop flickering of LCD because there are two if...elseif blocks and if both get executed then lcd data from each if...elseif block will be written to LCD continuously (due to while(1)). So LCD appears flickering.

If you explain in detail what your are trying to achieve then it will be easier to implement it in a better way.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
unsigned char ch[8], i = 0;
char *text[4];
double et[4], kg[2], skirtumas[2];
const double myConst1 = 1.024, myConst2 = 45.3, tenPow2 = 100.0, tenPow3 = 1000.0; //1000 / 1024, 4530 / 100 = 45.3
 
void main() {
 
    INTCON = 0;
    ANSELH = 0;
 
    Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)
 
    text[0] = "Fuel Balance";               // Define the first message
    Lcd_Out(1,1,text[0]);               // Write the first message in the first line
    text[0] = "System by J.P.";            // Define the second message
    Lcd_Out(2,1,text[0]);               // Define the first message
 
    ADCON1 = 0x82;                   // A/D voltage reference is VCC
    TRISA = 0xFF;                    // All port A pins are configured as inputs
    Delay_ms(5);
    Lcd_Cmd(_LCD_CLEAR);
 
    text[1] = "L/H TANK: ";
    text[2] = "R/H TANK: ";
    
    while (1) {
 
    for(i = 0; i < 4; i++) {
 
        et[i] = ADC_Read(i) / myConst1;
    }
 
        
        et[0] = et[1] * tenPow2 / et[0];
        et[2] = et[3] * tenPow2 / et[2];
 
        kg[0] = et[0] * myConst2;
        kg[1] = et[2] * myConst2;
 
        ch[4] = et[0] / tenPow2;
        ch[5] = et[2] / tenPow2;
        ch[6] = kg[0] / tenPow3;
        ch[7] = kg[1] / tenPow3;
 
        skirtumas[0] = et[0] - et[2];
        skirtumas[1] = et[2] - et[0];
 
    if(skirtumas[0] >= 15.0)
    {
            Lcd_Out(2,1,"   ");
            Lcd_Out(2,14,"   ");
            Lcd_Out(2,4,"R/H -> L/H");
        Delay_ms(1);
    }
 
    if(skirtumas[1] >= 15.0)
    {
            Lcd_Out(2,1,"   ");
            Lcd_Out(2,14,"   ");
            Lcd_Out(2,4,"R/H <- L/H");
    }
 
    if((skirtumas[0] < 15.0) || (skirtumas[1] < 15.0))
        {
            if(et[0] > 99.0)
            {
                Lcd_Out(1,1,text[1]);
                Lcd_Out(1,11,"FULL");
            }
        else if((et[0] > 10.0) && (et[0] < 99.0))
                {
                    Lcd_Out(1,1,text[1]);
                    Lcd_Out(1,11," ");
                    ch[4] = (et[0] / 10) % 10;
                    Lcd_Chr(1,12,48+ch[4]);
                    ch[4] = et[0] % 10;
                    Lcd_Chr(1,13,48+ch[4]);
                    Lcd_Chr(1,14,'%');
                }
        else if(et[0] < 10.0)
                {
                Lcd_Out(1,1,text[1]);
                Lcd_Out(1,11,"LOW!");
                }
 
         
        if (et[2] > 99.0)
            {
        
            Lcd_Out(2,1,text[2]);
                Lcd_Out(2,11,"FULL");
            }
        else if ((et[2] > 10.0) && (et[2] < 99.0))
                {
                    Lcd_Out(2,1,text[2]);
                    Lcd_Out(2,11," ");
                    ch[5] = (et[2] / 10) % 10;
                    Lcd_Chr(2,12,48+ch[5]);
                    ch[5] = et[2] % 10;
                    Lcd_Chr(2,13,48+ch[5]);
                    Lcd_Chr(2,14,'%');
                }
        else if (et[2] < 10.0)
                {
                Lcd_Out(2,1,text[2]);
                Lcd_Out(2,11,"LOW!");
                }
        }
    }
}

 
Last edited:
OK, i will try to explain what im trying to achieve:

1. LCD have to show fuel quantity in each tank:
R/H Tank: xxx%
L/H Tank: xxx%


2. When quantity difference between tanks becomes more than 15% (for example), MCU must turn on Fuel Pump (using Proteus i will use just LED to imitate Fuel Pump ON). There is two Fuel Pums, one is pumping from L/H to R/H, ant other is pumping from R/H to L/H Tank. When Fuel Pump ON, LCD have to show:
TRASNEFRING:
R/H -> L/H

or:
TRANSFERING:
R/H <- L/H


3. When quantity difference between tanks becomes lower than 15%, Fuel Pump OFF. And LCD just showing information about quantity in each of tanks:
R/H Tank: xxx%
L/H Tank: xxx%


4. It would be perfect if LCD would show quantity percentage + quanity in kilos. For example:
R/H: xxx% xxxxKG
L/H: xxx% xxxxKG

1% = 45.3KG
100% = 4530KG

5. I have also to make RS323 serial comunication to send all information... But first of all i just want to make everything work properly.
 
Last edited:

Can you use 20X4 LCD? Because R/H Tank: xxx% xxxxKG needs 21 characters and doesn't display on 16X2 but can be displayed on 20X4 LCD using 2 lines, 4 lines for 2 set of data.

Regarding error in https://clip2net.com/s/7i77lf


Code C - [expand]
1
ch[4] = (et[0] / 10.0) % 10.0;

 

Oh, im sorry, i made a mistake: 16x2 LCD have to display "R/H Tank: xxx%" OR "R/H: xxx% xxxxKG". And then there is no need to use 24x4 LCD. I want to make this project as simple as posible :)

- - - Updated - - -

Still got error...

1398512152-clip-26kb.png

its crazy, lol
 
Last edited by a moderator:

Maybe mod operator (%) cannot be applied to float/double. Zip and post your mikroC project files.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top