1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

[HELP] Need to compile and convert this code [mikroC]

Discussion in 'Microcontrollers' started by bluesam, Jul 14, 2010.

  1. bluesam

    bluesam New Member

    Joined:
    May 26, 2010
    Messages:
    59
    Likes:
    0
    Location:
    Indonesia
    Dear all,
    I need to compile and convert this mikroC code for PIC16F877A to get a hex file.
    Since I don't have the software, would you guys help me to get that hex file for me?

    This program is about interfacing lm35dz-pic16f877a-lcd16x2 by Satiesh Kumar.
    note: I use 4MHz Ceramic Resonator on OSC1 and OSC2

    Code (text):
    /*Header******************************************************/

    // 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;                    //
    unsigned int adc_rd;                 // Declare variables
    char *text;                          //
    long tlong;                          //

    void main() {
        INTCON = 0;                      // All interrupts disabled
        ADCON1 = 0x82;                   // A/D voltage reference is VCC
        TRISA = 0xFF;                    // All port A pins are configured as inputs
        Delay_ms(2000);                    // Rest of pins are configured as digital

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

        text = "ADC_Display";       // Define the first message
        Lcd_Out(1,1,text);               // Write the first message in the first line
        text = "LCD example";            // Define the second message
        Lcd_Out(2,1,text);               // Define the first message



        text = "voltage:";               // Define the third message

        while (1) {
            adc_rd = ADC_Read(2);        // A/D conversion. Pin RA2 is an input.
            Lcd_Out(2,1,text);           // Write result in the second line
            tlong = (long)adc_rd * 5000; // Convert the result in millivolts
            tlong = tlong / 1023;        // 0..1023 -> 0-5000mV
            ch = tlong / 1000;           // Extract volts (thousands of millivolts)
                                         // from result
            Lcd_Chr(2,9,48+ch);          // Write result in ASCII format
            Lcd_Chr_CP('.');
            ch = (tlong / 100) % 10;     // Extract hundreds of millivolts
            Lcd_Chr_CP(48+ch);           // Write result in ASCII format
            ch = (tlong / 10) % 10;      // Extract tens of millivolts
            Lcd_Chr_CP(48+ch);           // Write result in ASCII format
            ch = tlong % 10;             // Extract digits for millivolts
            Lcd_Chr_CP(48+ch);           // Write result in ASCII format
            Lcd_Chr_CP('V');
            Delay_ms(1);
        }
    }
    Your help is absolutely thanked.
    bluesam
     
  2. rajbex

    rajbex Member

    Joined:
    Sep 17, 2009
    Messages:
    174
    Likes:
    5
    Location:
    Williamsburg, VA
  3. bluesam

    bluesam New Member

    Joined:
    May 26, 2010
    Messages:
    59
    Likes:
    0
    Location:
    Indonesia
    @Raj: thx, i'll give a try to download it.

    @all: I still need help to convert it as a comparison and a back up. (I have a decent internet connection)
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. bluesam

    bluesam New Member

    Joined:
    May 26, 2010
    Messages:
    59
    Likes:
    0
    Location:
    Indonesia

    Dear Raj and all too,
    I got your link and gave some try.
    I did get a hex file but when I burn it to PIC16f877a, it got this error message:
    a. What is it mean guys?
    b. Can you help me to get that hex file that works?

    Many thanks
    samuel
     
  6. bluesam

    bluesam New Member

    Joined:
    May 26, 2010
    Messages:
    59
    Likes:
    0
    Location:
    Indonesia
    hi guys,
    after i posted the question above, i've finally found the answer

    a. This probably would be because the config word is not set-up correctly for a 16F877A. I would said that the code space did program correctly as microC or your software does not try to program the config word if there is a verify error before hand
    (by someone named newfound and jim)

    Tools: Valid Fuses
    When programming a PIC chip, the fuse settings must be set. For example, if a 20Mhz crystal is used, the fuse must be set to 'HS'. To set "Code Protection from External Reads", the fuse must be set to 'PROTECT'. An sample line of C, included before main() is shown next.
    #fuses HS,PROTECT //fuse settings
    A nice feature of CCS is the ability to find valid fuse settings for a particular micro. Simply select "View >> Valid Fuses" for a list.
    (from CCS C review in PIC micros and C)

    b. Use the fixhex2.exe which is often provided alongside MicroBrn
    this is the link but the old one:http://www.ozitronics.com/download/DIYpack25ep.zip

    hope this will be helpful
    bluesam
     
    Last edited: Jul 15, 2010

Share This Page