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.

Help me convert PIC16F877A to hex

Status
Not open for further replies.

aizzaidi

Newbie level 6
Joined
Apr 20, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,387
hallo,can u help me? how to convert this language to hex file?


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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#define sw_up         PORTE.F0
#define sw_down       PORTE.F1
#define sw_enter      PORTE.F2
 
#define relay_in      PORTD.F0
#define relay_out     PORTD.F1
#define led    PORTC.F4
#define buzzer PORTC.F5
 
#define sec_flag flag.F0
#define start_flag flag.F1
 
 
char txt[6];
char msec,sec,minutes;
char flag;
int level,setting;
int level1;
int diff;
char value;
 
void beep();
 
 
 
//******************************
 void interrupt(){
 
  if  (INTCON.T0IF){
      asm{clrwdt}
      msec++;
      if (msec >100){
         msec = 0;
         sec++;
         sec_flag=1;
           if (sec >=60){
             sec = 0;
             minutes++;
           }
       }
  }
}
 
 
void main()
{
  ADCON1=0x82;
  TRISA  = 0b00000011;              // PORTA is input
  TRISB  = 0x00;
  TRISC  = 0b00001111;              //
  TRISD  = 0x00;
  TRISE  = 0b00000111;
  PORTA=PORTB=PORTC=PORTD=0x00;
  LCD_Config(&PORTB,4,5,6,3,2,1,0);
  Lcd_Init(&PORTB);                        // Lcd_Init_EP4, see Autocomplete
  LCD_Cmd(LCD_CURSOR_OFF);                 // send command to LCD (cursor off)
  LCD_Cmd(LCD_CLEAR);                      // send command  to LCD (clear LCD)
  Lcd_Out(1,1, "Water Level");
  Lcd_Out(2,1, "  System");
  Usart_init(9600);
  Delay_ms(2000);
  LCD_Cmd(LCD_CLEAR);
  Delay_ms(2000);
  OPTION_REG = 0b00000010;        // Assign prescaler to TMR0
  INTCON = 0xA0;       // Enable TMRO interrupt
  start_flag=0;
  setting=eeprom_read(0x00);
 do
 {
 
    if(usart_data_ready())
    {
     value = Usart_read();
     if(value=='U')
     {
      setting++;
      if(setting>=200)
      setting=200;
     }
     if(value=='D')
     {
      if(setting<=1)
      setting = 1;
      setting--;
     }
     
     if(value=='K')
     {
      start_flag=1;
      led=1;
      beep();
     }
     
     if(value=='X')
     {
      start_flag=0;
      led=0;
      beep();
      beep();
      relay_in=0;
      relay_out=0;
     }
     
     lcd_out(2,1,"Set:");
     inttostr(setting,txt);
     lcd_chr_cp(txt[2]);
     lcd_chr_cp(txt[3]);
     lcd_chr_cp(txt[4]);
     lcd_chr_cp(txt[5]);
     lcd_chr_cp('C');
     lcd_chr_cp('m');
    }
 
     if(sec_flag && start_flag)
    {
     LCD_Cmd(LCD_CLEAR);
     level = (adc_read(1) - 20)*0.8;
     lcd_out(1,1,"Value:");
     level1=level;
     inttostr(level,txt);
     lcd_chr_cp(txt[2]);
     lcd_chr_cp(txt[3]);
     lcd_chr_cp(txt[4]);
     lcd_chr_cp(txt[5]);
     lcd_chr_cp('C');
     lcd_chr_cp('m');
     lcd_out(2,1,"Set:");
     inttostr(setting,txt);
     lcd_chr_cp(txt[2]);
     lcd_chr_cp(txt[3]);
     lcd_chr_cp(txt[4]);
     lcd_chr_cp(txt[5]);
     lcd_chr_cp('C');
     lcd_chr_cp('m');
     usart_write('x');
     usart_write(level1);
     usart_write('y');
     usart_write(setting);
 
     if(level1>setting)
     {
      diff=level1-setting;
      if(diff>1)
      {
       relay_in=1;
       relay_out=0;
      beep();
      }
      else
      {
       relay_in=0;
       relay_out=0;
      }
     }
     
     else if(level1<setting)
     {
      diff=setting-level1;
      if(diff>1)
      {
       relay_in=0;
       relay_out=1;
      beep();
      }
      else
      {
       relay_in=0;
       relay_out=0;
      }
     }
     
     else
     {
      relay_in=0;
      relay_out=0;
     }
     sec_flag=0;
    }
 
//******************************************************************************
 
    while(!sw_up)
    {
     setting++;
     if(setting>=200)
     setting=200;
     lcd_out(2,1,"Set:");
     inttostr(setting,txt);
     lcd_chr_cp(txt[2]);
     lcd_chr_cp(txt[3]);
     lcd_chr_cp(txt[4]);
     lcd_chr_cp(txt[5]);
     lcd_chr_cp('C');
     lcd_chr_cp('m');
     delay_ms(50);
     eeprom_write(0x00,setting);
    }
    
    while(!sw_down)
    {
     if(setting<=1)
     setting = 1;
     setting--;
     lcd_out(2,1,"Set:");
     floattostr(setting,txt);
     lcd_chr_cp(txt[2]);
     lcd_chr_cp(txt[3]);
     lcd_chr_cp(txt[4]);
     lcd_chr_cp(txt[5]);
     lcd_chr_cp('C');
     lcd_chr_cp('m');
     delay_ms(50);
     eeprom_write(0x00,setting);
    }
    
    if(!sw_enter)
    {
     if(!start_flag)
     {
      start_flag=1;
      led=1;
      beep();
 
     }
     else
     {
      start_flag=0;
      led=0;
      beep();
      beep();
      relay_in=0;
      relay_out=0;
     }
     while(!sw_enter);
    }
 
 
 }while(1);
 
}
 
//****************************************************************************
 
void beep(void)
{
 buzzer=1;
 delay_ms(50);
 buzzer=0;
 delay_ms(50);
}
 
//*****************************************************************************
********************************************

 
Last edited by a moderator:

Re: Please some help me.

hallo,can u help me? how to convert this language to hex file?
You would need to buy MikroC compiler, as the code is too big to fit the free version.

Then you would need to make changes to make it work with the latest compiler. That code was for an old compiler version.
 
Re: Please some help me.

the language is correct or not? i dun have the compiler,which compiler is suitable for this. Untitled.png
 

Re: Please some help me.

The compiler that you show is the correct one.

You will need to make a few changes to your code to make it work with this compiler
 
Re: Please some help me.

i dun hv any idea, can u help me, thanks.
 

Re: Please some help me.

You will have to tell me which PIC you are using first, then I can help you
 
Re: Please some help me.

im using PIC16F877A. thank you very much.
 

Re: Please some help me.

Here is my attempt at updating your code.

It compiles, but I have no idea whether it would work in real life

Code:
#define sw_up PORTE.F0
#define sw_down PORTE.F1
#define sw_enter PORTE.F2

#define relay_in PORTD.F0
#define relay_out PORTD.F1
#define led PORTC.F4
#define buzzer PORTC.F5

#define sec_flag flag.F0
#define start_flag flag.F1

// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;


char txt[6];
char msec,sec,minutes;
char flag;
int level,setting;
int level1;
int diff;
char value;

void beep();



//******************************
void interrupt(){

    if (INTCON.T0IF){
        asm{clrwdt}
        msec++;
        if (msec >100){
            msec = 0;
            sec++;
            sec_flag=1;
            if (sec >=60){
                sec = 0;
                minutes++;
            }
        }
    }
}


void main()
{
    ADCON1=0x82;
    TRISA = 0b00000011; // PORTA is input
    TRISB = 0x00;
    TRISC = 0b00001111; //
    TRISD = 0x00;
    TRISE = 0b00000111;
    PORTA=PORTB=PORTC=PORTD=0x00;
    Lcd_Init(); // Lcd_Init_EP4, see Autocomplete
    Lcd_Cmd(_LCD_CURSOR_OFF); // send command to LCD (cursor off)
    Lcd_Cmd(_LCD_CLEAR); // send command to LCD (clear LCD)
    Lcd_Out(1,1, "Water Level");
    Lcd_Out(2,1, " System");
    UART1_Init(9600);
    Delay_ms(2000);
    Lcd_Cmd(_LCD_CLEAR);
    Delay_ms(2000);
    OPTION_REG = 0b00000010; // Assign prescaler to TMR0
    INTCON = 0xA0; // Enable TMRO interrupt
    start_flag=0;
    setting=EEPROM_Read(0x00);
    do
    {

        if(UART1_Data_Ready())
        {
            value = UART1_Read();
            if(value=='U')
            {
                setting++;
                if(setting>=200)
                setting=200;
            }
            if(value=='D')
            {
                if(setting<=1)
                    setting = 1;
                setting--;
            }

            if(value=='K')
            {
                start_flag=1;
                led=1;
                beep();
            }

            if(value=='X')
            {
                start_flag=0;
                led=0;
                beep();
                beep();
                relay_in=0;
                relay_out=0;
            }

            Lcd_Out(2,1,"Set:");
            IntToStr(setting,txt);
            Lcd_Chr_CP(txt[2]);
            Lcd_Chr_CP(txt[3]);
            Lcd_Chr_CP(txt[4]);
            Lcd_Chr_CP(txt[5]);
            Lcd_Chr_CP('C');
            Lcd_Chr_CP('m');
        }

        if(sec_flag && start_flag)
        {
            Lcd_Cmd(_LCD_CLEAR);
            level = (ADC_Read(1) - 20)*0.8;
            Lcd_Out(1,1,"Value:");
            level1=level;
            IntToStr(level,txt);
            lcd_chr_cp(txt[2]);
            lcd_chr_cp(txt[3]);
            lcd_chr_cp(txt[4]);
            lcd_chr_cp(txt[5]);
            lcd_chr_cp('C');
            lcd_chr_cp('m');
            lcd_out(2,1,"Set:");
            inttostr(setting,txt);
            lcd_chr_cp(txt[2]);
            lcd_chr_cp(txt[3]);
            lcd_chr_cp(txt[4]);
            lcd_chr_cp(txt[5]);
            lcd_chr_cp('C');
            lcd_chr_cp('m');
            uart1_write('x');
            uart1_write(level1);
            uart1_write('y');
            uart1_write(setting);

            if(level1>setting)
            {
            diff=level1-setting;
            if(diff>1)
            {
            relay_in=1;
            relay_out=0;
            beep();
            }
            else
            {
                relay_in=0;
                relay_out=0;
                }
            }

            else if(level1<setting)
            {
                diff=setting-level1;
                if(diff>1)
                {
                relay_in=0;
                relay_out=1;
                beep();
                }
                else
                {
                relay_in=0;
                relay_out=0;
                }
            }

            else
            {
                relay_in=0;
                relay_out=0;
            }
               sec_flag=0;
        }

//************************************************** ****************************

        while(!sw_up)
        {
            setting++;
            if(setting>=200)
            setting=200;
            lcd_out(2,1,"Set:");
            inttostr(setting,txt);
            lcd_chr_cp(txt[2]);
            lcd_chr_cp(txt[3]);
            lcd_chr_cp(txt[4]);
            lcd_chr_cp(txt[5]);
            lcd_chr_cp('C');
            lcd_chr_cp('m');
            delay_ms(50);
            eeprom_write(0x00,setting);
        }

        while(!sw_down)
        {
              if(setting<=1)
                  setting = 1;
              setting--;
              lcd_out(2,1,"Set:");
              floattostr(setting,txt);
              lcd_chr_cp(txt[2]);
              lcd_chr_cp(txt[3]);
              lcd_chr_cp(txt[4]);
              lcd_chr_cp(txt[5]);
              lcd_chr_cp('C');
              lcd_chr_cp('m');
              delay_ms(50);
              eeprom_write(0x00,setting);
        }

        if(!sw_enter)
        {
            if(!start_flag)
            {
                start_flag=1;
                led=1;
                beep();

            }
            else
            {
                start_flag=0;
                led=0;
                beep();
                beep();
                relay_in=0;
                relay_out=0;
            }
            while(!sw_enter);
         }


    }while(1);

}

//************************************************** **************************

void beep(void)
{
    buzzer=1;
    delay_ms(50);
    buzzer=0;
    delay_ms(50);
}

//************************************************** ***************************
//********************************************
 
Re: Please some help me.

thanks dude, i hope it can operate.

---------- Post added at 22:32 ---------- Previous post was at 22:31 ----------

im sorry, what kind of software that will use to convert that to hex file. im the beginner.

---------- Post added at 22:36 ---------- Previous post was at 22:32 ----------

got it.thanks! already with hex file!
 

Hex file too large"

Pls help me! I was converted that code to hex using MikroC, but when i want put it into PIC. HEX FILE TOO LARGE. Pls someone tell me what is hapenning?


Code:
#define sw_up PORTE.F0
#define sw_down PORTE.F1
#define sw_enter PORTE.F2

#define relay_in PORTD.F0
#define relay_out PORTD.F1
#define led PORTC.F4
#define buzzer PORTC.F5

#define sec_flag flag.F0
#define start_flag flag.F1

// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;


char txt[6];
char msec,sec,minutes;
char flag;
int level,setting;
int level1;
int diff;
char value;

void beep();



//******************************
void interrupt(){

   if (INTCON.T0IF){
       asm{clrwdt}
       msec++;
       if (msec >100){
           msec = 0;
           sec++;
           sec_flag=1;
           if (sec >=60){
               sec = 0;
               minutes++;
           }
       }
   }
}


void main()
{
   ADCON1=0x82;
   TRISA = 0b00000011; // PORTA is input
   TRISB = 0x00;
   TRISC = 0b00001111; //
   TRISD = 0x00;
   TRISE = 0b00000111;
   PORTA=PORTB=PORTC=PORTD=0x00;
   Lcd_Init(); // Lcd_Init_EP4, see Autocomplete
   Lcd_Cmd(_LCD_CURSOR_OFF); // send command to LCD (cursor off)
   Lcd_Cmd(_LCD_CLEAR); // send command to LCD (clear LCD)
   Lcd_Out(1,1, "Water Level");
   Lcd_Out(2,1, " System");
   UART1_Init(9600);
   Delay_ms(2000);
   Lcd_Cmd(_LCD_CLEAR);
   Delay_ms(2000);
   OPTION_REG = 0b00000010; // Assign prescaler to TMR0
   INTCON = 0xA0; // Enable TMRO interrupt
   start_flag=0;
   setting=EEPROM_Read(0x00);
   do
   {

       if(UART1_Data_Ready())
       {
           value = UART1_Read();
           if(value=='U')
           {
               setting++;
               if(setting>=200)
               setting=200;
           }
           if(value=='D')
           {
               if(setting<=1)
                   setting = 1;
               setting--;
           }

           if(value=='K')
           {
               start_flag=1;
               led=1;
               beep();
           }

           if(value=='X')
           {
               start_flag=0;
               led=0;
               beep();
               beep();
               relay_in=0;
               relay_out=0;
           }

           Lcd_Out(2,1,"Set:");
           IntToStr(setting,txt);
           Lcd_Chr_CP(txt[2]);
           Lcd_Chr_CP(txt[3]);
           Lcd_Chr_CP(txt[4]);
           Lcd_Chr_CP(txt[5]);
           Lcd_Chr_CP('C');
           Lcd_Chr_CP('m');
       }

       if(sec_flag && start_flag)
       {
           Lcd_Cmd(_LCD_CLEAR);
           level = (ADC_Read(1) - 20)*0.8;
           Lcd_Out(1,1,"Value:");
           level1=level;
           IntToStr(level,txt);
           lcd_chr_cp(txt[2]);
           lcd_chr_cp(txt[3]);
           lcd_chr_cp(txt[4]);
           lcd_chr_cp(txt[5]);
           lcd_chr_cp('C');
           lcd_chr_cp('m');
           lcd_out(2,1,"Set:");
           inttostr(setting,txt);
           lcd_chr_cp(txt[2]);
           lcd_chr_cp(txt[3]);
           lcd_chr_cp(txt[4]);
           lcd_chr_cp(txt[5]);
           lcd_chr_cp('C');
           lcd_chr_cp('m');
           uart1_write('x');
           uart1_write(level1);
           uart1_write('y');
           uart1_write(setting);

           if(level1>setting)
           {
           diff=level1-setting;
           if(diff>1)
           {
           relay_in=1;
           relay_out=0;
           beep();
           }
           else
           {
               relay_in=0;
               relay_out=0;
               }
           }

           else if(level1<setting)
           {
               diff=setting-level1;
               if(diff>1)
               {
               relay_in=0;
               relay_out=1;
               beep();
               }
               else
               {
               relay_in=0;
               relay_out=0;
               }
           }

           else
           {
               relay_in=0;
               relay_out=0;
           }
              sec_flag=0;
       }

//************************************************** ****************************

       while(!sw_up)
       {
           setting++;
           if(setting>=200)
           setting=200;
           lcd_out(2,1,"Set:");
           inttostr(setting,txt);
           lcd_chr_cp(txt[2]);
           lcd_chr_cp(txt[3]);
           lcd_chr_cp(txt[4]);
           lcd_chr_cp(txt[5]);
           lcd_chr_cp('C');
           lcd_chr_cp('m');
           delay_ms(50);
           eeprom_write(0x00,setting);
       }

       while(!sw_down)
       {
             if(setting<=1)
                 setting = 1;
             setting--;
             lcd_out(2,1,"Set:");
             floattostr(setting,txt);
             lcd_chr_cp(txt[2]);
             lcd_chr_cp(txt[3]);
             lcd_chr_cp(txt[4]);
             lcd_chr_cp(txt[5]);
             lcd_chr_cp('C');
             lcd_chr_cp('m');
             delay_ms(50);
             eeprom_write(0x00,setting);
       }

       if(!sw_enter)
       {
           if(!start_flag)
           {
               start_flag=1;
               led=1;
               beep();

           }
           else
           {
               start_flag=0;
               led=0;
               beep();
               beep();
               relay_in=0;
               relay_out=0;
           }
           while(!sw_enter);
        }


   }while(1);

}

//************************************************** **************************

void beep(void)
{
   buzzer=1;
   delay_ms(50);
   buzzer=0;
   delay_ms(50);
}

//************************************************** ***************************
//********************************************
 

Re: Hex file too large"

what is your target PIC
what is the Flash size of your PIC
what is size of your hex file
 

Re: Hex file too large"

what is your target PIC
what is the Flash size of your PIC
what is size of your hex file

my PIC is PIC16F877A
i dont know what is flashsize.
the size of hex file is 48kb

hope can help me.. tq
 

Re: Please some help me.

the size of PIC16F877A Flash memory if 8K
thats what the problem is .. 48KB hex cant fit into your 8KB flash
you need to optimise your code .. are you including some some files you dont need
or do you have some functions that are never called ?
 

Re: Please some help me.

this is my circuit, hope u can help me,thank you very much Circuit.jpg
 

Re: Please some help me.

I donot have this MicroC compiler - so shall be unable to provide direct pre-compiled modifications ..
but what i can guess from the code above is that your LCD routines take most part of your code

Do you use an LCD in your design ?
Do you have any hardware at hand .. shall be useful if you post the schematic here
what programmer do you use
 
Re: Please some help me.

thanks. i doing this project based on the internet. :(
 

Re: Please some help me.

OK - your were posting the schematic while i was typing :)
But i donot see how this schematic relates to water tank level project using pressure sensor
Or am i getting something wrong ?
 

Re: Please some help me.

act im using two aquarium waterpumps for replaced the normal waterpump. Im used relay to cut off the waterpump.
 

Re: Please some help me.

can someone help me how to convert the code into hex file, because when i convert to hex,it become large file
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top