Mplab help!!!

nerdegutta

Joined Dec 15, 2009
2,689
I also noticed the V9.60 version...

Last night I tried your code (the code from the quick start guide)in my setup, and it compiled OK, and when I simulated it, it looked like it worked.

Like AlexR said:
I would strongly recommend upgrading
 

t06afre

Joined May 11, 2009
5,934
im kind of a rookie in this stuff but thanks for the help bor i really appreciate it by the way what does #include <htc.h> mean?

ive did what you said and the result got better but still faild to compile here is the error code i got>>

Make: The target "C:\Documents and Settings\Administrator\My Documents\forsundayfinal\srv.p1" is out of date.
.
.
.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" -
.
.

********** Build failed! **********
So in the middle of all this you changed to to HI-Tech version 9.60. But did not say anything to us
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
but im using hi tech c V9.81. where could i find the right .exe file? their are multiple exe files in the bin folder i dont know which to choose? is it .p1 or .picc?
 

t06afre

Joined May 11, 2009
5,934
The example in the manual is using the old config word naming method. However RK17 then you manage to compile a program. How will you program your chip, or what programmer do you use.
This is the new method for the 16f877 chip
Rich (BB code):
// Config Register: CONFIG
#define CONFIG               0x2007
// Oscillator Selection bits
// RC oscillator
#define FOSC_EXTRC           0xFFFF
// HS oscillator
#define FOSC_HS              0xFFFE
// XT oscillator
#define FOSC_XT              0xFFFD
// LP oscillator
#define FOSC_LP              0xFFFC
// Watchdog Timer Enable bit
// WDT enabled
#define WDTE_ON              0xFFFF
// WDT disabled
#define WDTE_OFF             0xFFFB
// Power-up Timer Enable bit
// PWRT disabled
#define PWRTE_OFF            0xFFFF
// PWRT enabled
#define PWRTE_ON             0xFFF7
// FLASH Program Memory Code Protection bits
// Code protection off
#define CP_OFF               0xFFFF
// 1F00h to 1FFFh code protected
#define CP_UPPER_256         0xEFEF
// 1000h to 1FFFh code protected
#define CP_HALF              0xDFDF
// 0000h to 1FFFh code protected
#define CP_All               0xCFCF
// Brown-out Reset Enable bit
// BOR enabled
#define BOREN_ON             0xFFFF
// BOR disabled
#define BOREN_OFF            0xFFBF
// Low Voltage In-Circuit Serial Programming Enable bit
// RB3/PGM pin has PGM function; low-voltage programming enabled
#define LVP_ON               0xFFFF
// RB3 is digital I/O, HV on MCLR must be used for programming
#define LVP_OFF              0xFF7F
// Data EE Memory Code Protection
// Code Protection off
#define CPD_OFF              0xFFFF
// Data EEPROM memory code-protected
#define CPD_ON               0xFEFF
// FLASH Program Memory Write Enable
// Unprotected program memory may be written to by EECON control
#define WRT_ON               0xFFFF
// Unprotected program memory may not be written to by EECON control
#define WRT_OFF              0xFDFF
// In-Circuit Debugger Mode bit
// In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
#define DEBUG_OFF            0xFFFF
// In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
#define DEBUG_ON             0xF7FF
 

AlexR

Joined Jan 16, 2008
732
oh sori bout that...:D i think ive messed up when i was trying to explore on the buid options but still it says error. tnx anyway im already using V9.81 heres the image>>


http://i275.photobucket.com/albums/jj291/xian_19/hitechv981/Untitled-7.jpg

still error is present... :(
Right! Those are the errors I expected to see.
They happen because HiTech have changed the format of configuration bits in their new header files.
What you need to do is replace your existing "__CONFIG" command with the command below that contains the correct config bit names for V9.81 of the compiler.
Rich (BB code):
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF);
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
yes it worked! tnx for the code sir AlexR!:)

and tnx you guys for everything! really much thnks! ill push through by following the manual..

http://i275.photobucket.com/albums/jj291/xian_19/hitechv981/Untitled-8.jpg

but what was wrong about the first code?

Rich (BB code):
__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN &
DEBUGEN & DUNPROT & UNPROTECT);
ive copied it directly from the manual. Is the version of the manual outdated? what does the error mean?
 

t06afre

Joined May 11, 2009
5,934
copied it directly from the manual. Is the version of the manual outdated? what does the error mean?
Not your fault. They have not updated this document for some time. And then they did major changes to the header file system this document(quickstart.pdf) got outdated.
 

AlexR

Joined Jan 16, 2008
732
When you issue the command "#include <htc.h> the compiler looks at the device setting in MPLAB and adds the relevant pic header file to the start of your code. So for example if your device was set to pic16f877 the complier would add the file pic16f877.h to the start of your code.
These pic header files (in the include subdirectory of the HI-TECH installation) contain lists of all the register names and their location in memory, register bit names and what bit number each is, and config bit names and their values.
Now as t06afre said in an earlier post the V9.81 version of the HiTechC compiler introduced new header files with some changed register names and register-bit names. This means that the compiler will no-longer recognise the old config bit names and you will have to use the new names in your code. You can find out what the new names are by reading the relevant header file. Unfortunately the getting started guide was not updated and the examples given still use the old names.
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
:)ok now i understand tnx. Can you please share me links to where i could get a list of updated commands to avoid errors in my program. it would help me so much tnx guys.
 

AlexR

Joined Jan 16, 2008
732
None of the commands have changed.

Some of the register/bit names have changed to make them the same the names used in the PIC data sheets.

I don't know of any list detailing the changes but if you pay close attention to any error messages they will tell you where the errors are, then you can refer to the relevant pic16fxxx,h header file to find out what the new register/bit names should be.
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
hi alexR ive got this new program; ive copied your code;
Rich (BB code):
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF);
im using hi tech c v9.81 but it failed heres the link >>

Rich (BB code):
http://i275.photobucket.com/albums/jj291/xian_19/hitechv981/Untitled-9.jpg
please check it out it says undefined again :(

heres the error message:
Rich (BB code):
Error   [800] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\Tutorials\tutorial3.c; 10. undefined symbol "WRT_OFF"
Error   [800] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\Tutorials\tutorial3.c; 10. undefined symbol "LVP_OFF"
Error   [800] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\Tutorials\tutorial3.c; 10. undefined symbol "BOREN_OFF"
heres the whole program>>

Rich (BB code):
/*  Formula One LED Start Lights */
/*  (c) Perry Andrews Jan. 2002  */

/* use LFSR based algorithm for random   */
/* number generation                     */

#include <htc.h>

__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF);

unsigned char seed = 1 ;

unsigned char random ( void )
{
    unsigned char top, mid ;

    /* get new input bit  */

    if ( seed & 12 )
    {
        mid = 1 ;
    }
    else
    {
        mid = 0 ;
    }

    if ( seed & 0x80 )
    {
        top = 1 ;
    }
    else
    {
        top = 0 ;
    }

    seed = ( seed << 1 ) | ( mid ^ top ) ;

    return seed ;
}

void main (void)
{
    unsigned int i ;
    unsigned int j ;
    unsigned char r;

    /* Select the Register bank 1 */
    set_bit ( STATUS, RP0 ) ;
    /* set all of PORTB for output */
    TRISB = 0x00 ;
    /* set all of PORTA for input */
    TRISA = 0x1f ;
    /* now use Register bank 0    */
    clear_bit ( STATUS, RP0 ) ;

    // set all LEDs off
    for ( j=0; j<5; j=j+1 )
      output_low_port_b(j);

    // Main program loop
    while (1) {
    // Wait for Switch A0
    while ( input_pin_port_a(0)==0 );

    // set the LEDs 1 per second
      for ( j=0; j<5; j=j+1) {
        for ( i=0 ; i < 35200 ; i= i + 1 ) ;
        output_high_port_b ( j ) ;
        }
        for ( i=0 ; i < 35200 ; i= i + 1 ) ;
    // generate a random time period
      r = random () % 4;
      for ( j=0; j<r; j=j+1 )
         for ( i=0 ; i < 35200 ; i= i + 1 ) ;
    // set all LEDs off
      for ( j=0; j<5; j=j+1 )
        output_low_port_b(j);
    }
}
 

AlexR

Joined Jan 16, 2008
732
That's because the PIC16F84 does not support WRT (write protect), LVP (low voltage programming) or BOREN (brown-out detection). Simply delete those from the config command and the errors will go away but what you should be doing is reading the data sheet for the chip you are programming to see if what the various config words do and whether the config suits your program.
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
ive done what you said but another error came up

Rich (BB code):
Error   [500] ; 0. undefined symbols:
    _clear_bit(tutorial3.obj) _set_bit(tutorial3.obj) _input_pin_port_a(tutorial3.obj) _output_low_port_b(tutorial3.obj) _output_high_port_b(tutorial3.obj)
ive checked the datasheet of the 16F84A but where could i find the commands to use in hitech c compiler? i cant find it in the datasheet tnx again alex..:)
 

AlexR

Joined Jan 16, 2008
732
Where did you get that program from?

In the first place it is too advanced for your level of knowledge and in the second I'm not even sure which compiler the program was written for if it was written for HitecC then is was for a very ancient version and thirdly you are either missing the header file that goes with that source code or the old compiler had function that are no longer supported. The most probable answer is that the program was written for a different compiler altogether.

You need to learn the basics of both the PIC chip architecture and programming in C.
I suggest that you go to the tutorials at http://www.gooligum.com.auwork through all of the C based lessons. Once you have done that and understood it all you should be able go back and work out what is going wrong for yourself.
 

t06afre

Joined May 11, 2009
5,934
I am just curious. Say you have a program that compile just fine. What kind of programmer do you plan to use. In order to download the code to a PIC micro.
 

mirrayhan08

Joined Mar 24, 2012
6
hello every body,
I need help on my line follower robot based on PIC 16f877A. i download C source code and try to compile this code in MPLAB. but it show missing error in first 6 line. but i can't find any problem those line. i give the code without header file. plz any body find the error or convert it HEX format.
<><><><><><><><><><><><><><><><><><><><><><><><><<>

#include <16F877A.H>; //declare a PIC header
#device adc=8; //set the bit for ADC
#fuses hs, nowdt, noprotect; //set the PIC protection
#use delay (clock=20000000); //set the clock frequency
#byte porta=5; //assign port a
#byte portd=8; //assign port d

int val1; //ADC value 1 left sensor
int val2; //ADC value 2 center sensor
int val3; //ADC value 3 right sensor
int vref; //voltage reference
void lmotor(int gear); //left motor function
void rmotor(int gear); //right motor function


void main() //main function
{
vref=0x7f; //set voltage reference value
set_tris_d(0); //declare port d as output
setup_port_a(all_analog); //enable port a as ADC port
setup_adc(adc_clock_internal); //set the clock for ADC
setup_ccp1(ccp_pwm); //set enable ccp1
setup_ccp2(ccp_pwm); //set enable ccp2
setup_timer_2(t2_div_by_4,100,1); //set post scaler timer

while(1) //inifinite loop
{
portd=0xaa; //set value for motor
set_adc_channel(0); //ADC at port A0 channel
val1=read_adc(); //read and store A0 value
set_adc_channel(2); //ADC at port A2 channel
val2=read_adc(); //read and store A2 value
set_adc_channel(4); //Adc at port A4
val3=read_adc(); //read and store A4 value

//start condition
//if sensor sense dark then value is greater than Vref
//if sensor sense bright then value is lower than Vref
if(val2>vref) //if sensor 2 is dark
{
if((val1<vref)&&(val3<vref)) //sensor 1&3 is bright
{ //send value to motor ccp
lmotor(70); //both motor moving at same rate
rmotor(70);
}
else if (val1>vref) //sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}
else if (val3>vref) //sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
}
else if ((val1>vref)&&(val3<vref)) //if only sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}





else if ((val3>vref)&&(val1<vref)) //if only sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
else //other than condition above
{
lmotor(60); //left motor move slow
rmotor(60); //right motor move slow
}


}
}
//end program
void lmotor(int gear) //left motor ccp control function
{
set_pwm1_duty(gear); //ccp1 duty cycle

}

void rmotor(int gear) //right motor ccp control function
{
set_pwm2_duty(gear); //ccp2 duty cycle
}

<><><><><><><><><><><><><><><><><><><><><><><>

It is very very emargency in my study.

Plz help me very queckly.

Thanks to all

Mehedi.
 

mirrayhan08

Joined Mar 24, 2012
6
I also noticed the V9.60 version...

Last night I tried your code (the code from the quick start guide)in my setup, and it compiled OK, and when I simulated it, it looked like it worked.

Like AlexR said:
hello every body,
I need help on my line follower robot based on PIC 16f877A. i download C source code and try to compile this code in MPLAB. but it show missing error in first 6 line. but i can't find any problem those line. i give the code without header file. plz any body find the error or convert it HEX format.
<><><><><><><><><><><><><><><><><><><><><><><><><<>

#include <16F877A.H>; //declare a PIC header
#device adc=8; //set the bit for ADC
#fuses hs, nowdt, noprotect; //set the PIC protection
#use delay (clock=20000000); //set the clock frequency
#byte porta=5; //assign port a
#byte portd=8; //assign port d

int val1; //ADC value 1 left sensor
int val2; //ADC value 2 center sensor
int val3; //ADC value 3 right sensor
int vref; //voltage reference
void lmotor(int gear); //left motor function
void rmotor(int gear); //right motor function


void main() //main function
{
vref=0x7f; //set voltage reference value
set_tris_d(0); //declare port d as output
setup_port_a(all_analog); //enable port a as ADC port
setup_adc(adc_clock_internal); //set the clock for ADC
setup_ccp1(ccp_pwm); //set enable ccp1
setup_ccp2(ccp_pwm); //set enable ccp2
setup_timer_2(t2_div_by_4,100,1); //set post scaler timer

while(1) //inifinite loop
{
portd=0xaa; //set value for motor
set_adc_channel(0); //ADC at port A0 channel
val1=read_adc(); //read and store A0 value
set_adc_channel(2); //ADC at port A2 channel
val2=read_adc(); //read and store A2 value
set_adc_channel(4); //Adc at port A4
val3=read_adc(); //read and store A4 value

//start condition
//if sensor sense dark then value is greater than Vref
//if sensor sense bright then value is lower than Vref
if(val2>vref) //if sensor 2 is dark
{
if((val1<vref)&&(val3<vref)) //sensor 1&3 is bright
{ //send value to motor ccp
lmotor(70); //both motor moving at same rate
rmotor(70);
}
else if (val1>vref) //sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}
else if (val3>vref) //sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
}
else if ((val1>vref)&&(val3<vref)) //if only sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}





else if ((val3>vref)&&(val1<vref)) //if only sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
else //other than condition above
{
lmotor(60); //left motor move slow
rmotor(60); //right motor move slow
}


}
}
//end program
void lmotor(int gear) //left motor ccp control function
{
set_pwm1_duty(gear); //ccp1 duty cycle

}

void rmotor(int gear) //right motor ccp control function
{
set_pwm2_duty(gear); //ccp2 duty cycle
}

<><><><><><><><><><><><><><><><><><><><><><><>

It is very very emargency in my study.

Plz help me very queckly.

Thanks to all

Mehedi.
 
Top