Author Topic: Code builds in Win 7, but not in XP?  (Read 4392 times)

0 Members and 1 Guest are viewing this topic.

Offline sgonzalezpTopic starter

  • Newbie
  • Posts: 7
Code builds in Win 7, but not in XP?
« on: October 16, 2012, 02:11:56 am »
Code: [Select]
// Program: Pulse Width Modulation Test
// Purpose: The purpose of this program is to test pulse width modulation techniques
//          using a PIC18F4550 microcontroller.

#include <p18f4550.h>
#include <delays.h>

#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
#pragma config WDT = OFF //Disable watchdog timer

#define LEDPin LATAbits.LATA0 //Define LEDPin as PORT A Pin 2
#define LEDTris TRISAbits.TRISA0 //Define LEDTris as TRISA Pin 2
#define LEDPin2 LATAbits.LATA1 //Define LEDPin as PORT A Pin 3
#define LEDTris2 TRISAbits.TRISA1 //Define LEDTris as TRISA Pin 3
#define LEDPin3 LATAbits.LATA2 //Define LEDPin as PORT A Pin 4
#define LEDTris3 TRISAbits.TRISA2 //Define LEDTris as TRISA Pin 4
#define TRIGGER PORTAbits.RA4
#define INPUTPin TRISAbits.TRISA4

int long_pulse_blue();
int short_pulse_blue();
int long_pulse_green();
int short_pulse_green();
int long_pulse_purple();

void main()
{
    ADCON1=0x0F;
    CMCON=0x07;
    INPUTPin = 1;
    TRIGGER = 0;
while(1)
{
            long_pulse_blue();
            long_pulse_green();
            long_pulse_purple();
        }

}

int long_pulse_blue()
{
    LEDTris = 0;//Set LED Pin data direction to OUTPUT
    LEDPin = 0;//Set LED Pin to OFF
    INPUTPin = 1;
    TRIGGER = 0;
    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
        {
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(250 - i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
        {
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(250 - i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    LEDPin = 0;
}

int short_pulse_blue()
{
    LEDTris = 0;//Set LED Pin data direction to OUTPUT
    LEDPin = 0;//Set LED Pin to OFF
    INPUTPin = 1;
    TRIGGER = 0;
    for(int i = 1; i < 150; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
        {
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(150 - i);
            while (TRIGGER == 1){short_pulse_green();}
        }
    for(int i = 1; i < 150; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
        {
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(150 - i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(i);
            while (TRIGGER == 1){short_pulse_green();}
        }
    LEDPin = 0;
}

int long_pulse_green()
{
    LEDTris2 = 0;
    LEDPin2 = 0;
    INPUTPin = 1;
    TRIGGER = 0;
    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
        {
            LEDPin2 = ~LEDPin2;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin2 = ~LEDPin2;//Toggle LED Pin Off
            Delay10TCYx(250 - i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
        {
            LEDPin2 = ~LEDPin2;//Toggle LED Pin On
            Delay10TCYx(250 - i);
            LEDPin2 = ~LEDPin2;//Toggle LED Pin Off
            Delay10TCYx(i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    LEDPin2 = 0;
}

int short_pulse_green()
{
    LEDTris2 = 0;
    LEDPin2 = 0;
    INPUTPin = 1;
    TRIGGER = 0;
    for(int i = 1; i < 150; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
        {
            LEDPin2 = ~LEDPin2;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin2 = ~LEDPin2;//Toggle LED Pin Off
            Delay10TCYx(150 - i);
            if (TRIGGER != 1) { i = 150; }
        }
    for(int i = 1; i < 150; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
        {
            LEDPin2 = ~LEDPin2;//Toggle LED Pin On
            Delay10TCYx(150 - i);
            LEDPin2 = ~LEDPin2;//Toggle LED Pin Off
            Delay10TCYx(i);
            if (TRIGGER != 1) { i = 150; }
        }
    LEDPin2 = 0;
}

int long_pulse_purple()
{
    LEDTris3 = 0;
    LEDPin3 = 0;
    INPUTPin = 1;
    TRIGGER = 0;
    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
        {
            LEDPin3 = ~LEDPin3;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin3 = ~LEDPin3;//Toggle LED Pin Off
            Delay10TCYx(250 - i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
        {
            LEDPin3 = ~LEDPin3;//Toggle LED Pin On
            Delay10TCYx(250 - i);
            LEDPin3 = ~LEDPin3;//Toggle LED Pin Off
            Delay10TCYx(i);
            while (TRIGGER == 1){short_pulse_green();}
        }

    LEDPin3 = 0;
}

Error Message
Quote
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Documents and Settings/Sergio Alonso/MPLABXProjects/DEMO.X'
make  -f nbproject/Makefile-default.mk dist/default/production/DEMO.X.production.hex
make[2]: Entering directory `C:/Documents and Settings/Sergio Alonso/MPLABXProjects/DEMO.X'
"C:\Program Files\Microchip\mplabc18\v3.43\bin\mcc18.exe"  -p18F4550   -I "C:\Program Files\Microchip\mplabc18\v3.43\bin"\\..\\h  -fo build/default/production/LEDBLINK1.o   LEDBLINK1.c
make[2]: *** [build/default/production/LEDBLINK1.o] Error 3
make[1]: *** [.build-conf] Error 2
MPLAB C18 v3.43 (evaluation)
Copyright 2000-2011 Microchip Technology Inc.
Days remaining until evaluation becomes feature limited:  52

WARNING:  The procedural abstraction optimization will not be supported when the evaluation becomes feature limited.

C:\Documents and Settings\Sergio Alonso\MPLABXProjects\DEMO.X\LEDBLINK1.c:47:Error: syntax error
make[2]: Leaving directory `C:/Documents and Settings/Sergio Alonso/MPLABXProjects/DEMO.X'
make[1]: Leaving directory `C:/Documents and Settings/Sergio Alonso/MPLABXProjects/DEMO.X'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 221ms)
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Code builds in Win 7, but not in XP?
« Reply #1 on: October 16, 2012, 02:14:46 am »
in win 7 there is no documents and settings folder. it is stored in the /users folder.
there may be a hardcoded path in a config file somewhere.

win7 stores aliases to retain compatibility. Xp does not have this 'compatibility' and it may not be able to resolve the alieased path
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline sgonzalezpTopic starter

  • Newbie
  • Posts: 7
Re: Code builds in Win 7, but not in XP?
« Reply #2 on: October 16, 2012, 02:27:48 am »
Weird thing is the C source file is in the correct path.. I even made a new project.
 

Online mariush

  • Super Contributor
  • ***
  • Posts: 5017
  • Country: ro
  • .
Re: Code builds in Win 7, but not in XP?
« Reply #3 on: October 16, 2012, 02:48:26 am »
I've had problems in the past with spaces in the path .... you have both "Documents and Settings"  and "Sergio Alonso".

I'd suggest moving your project into a folder that has no spaces in the path ... for example I use  C:\Projects\PIC\[Project Name]

It might not be a solution to your problem but it can't hurt.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9930
  • Country: nz
Re: Code builds in Win 7, but not in XP?
« Reply #4 on: October 16, 2012, 02:59:10 am »
I'm wondering if the error
"C:\Documents and Settings\Sergio Alonso\MPLABXProjects\DEMO.X\LEDBLINK1.c:47:Error: syntax error"

Is due to you declaring the "i" variable inside the for statement.

Line 47:   for(int i = 1; i < 250; i++)

A Google for "Scope of a variable declared in for loop" finds this..
Quote
>A)Is it possible to declare a variable inside for loop like
> for(int i=100;i>=0;i--);
You can do this in C99 and C++, but not in preceding C standards.
Given the low popularity of C99 amongst compiler vendors I recommend
against using its features.

Maybe your Win7 install was using C99/C++ but your XP install is using a preceding standard?

It's easy to check, move the declaration outside the loop for all your functions
Code: [Select]
int i;
for(i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle
{
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(250 - i);
            while (TRIGGER == 1){short_pulse_green();}
}
for(i = 1; i < 250; i++) // Modulate Pulse Width of LED2 decreasing in duty cycle
{
            LEDPin = ~LEDPin;//Toggle LED Pin On
            Delay10TCYx(250 - i);
            LEDPin = ~LEDPin;//Toggle LED Pin Off
            Delay10TCYx(i);
            while (TRIGGER == 1){short_pulse_green();}
}

« Last Edit: October 16, 2012, 03:07:49 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline sgonzalezpTopic starter

  • Newbie
  • Posts: 7
Re: Code builds in Win 7, but not in XP?
« Reply #5 on: October 16, 2012, 04:01:03 pm »
also tried that...weird.

Lol it says syntax error....I guess c no longer works
 

Offline baljemmett

  • Supporter
  • ****
  • Posts: 665
  • Country: gb
Re: Code builds in Win 7, but not in XP?
« Reply #6 on: October 16, 2012, 04:21:42 pm »
Lol it says syntax error....I guess c no longer works

If it doesn't like "for(int i=..." it almost certainly won't like you just moving the "int i;" to the line before -- did you try it there, or did you put it right at the top of the function (before the "LEDTris = 0;")?  Intermingled declarations and code are only supported as of C99, so if the compiler doesn't speak C99 or is configured to strictly observe an earlier standard you'll get an error unless the declarations come before any code in a block.  ("Syntax error" is a rather unhelpful error message, though!)

Technically comments introduced with // aren't valid before C99 either, but it hasn't objected to them on previous lines; alas some compiler vendors allowed them anyway, so it's hard to tell whether or not the compiler is C99-compliant just from that.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9930
  • Country: nz
Re: Code builds in Win 7, but not in XP?
« Reply #7 on: October 16, 2012, 11:16:39 pm »
Intermingled declarations and code are only supported as of C99, so if the compiler doesn't speak C99 or is configured to strictly observe an earlier standard you'll get an error unless the declarations come before any code in a block.

oh true, i didnt think of that. Yeah, he should definitely try it as the first line of the function.

Also, another potential issue with the //.
He should try chancing all comments so there's a space before the first /
It may not like ;// so try ;  //
« Last Edit: October 16, 2012, 11:18:32 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Hypernova

  • Supporter
  • ****
  • Posts: 655
  • Country: tw
Re: Code builds in Win 7, but not in XP?
« Reply #8 on: October 18, 2012, 09:37:31 am »
Until I turned on -pedantic in the options I never knew // was not valid C comment syntex, I was taught to use it from the beginning in uni.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9930
  • Country: nz
Re: Code builds in Win 7, but not in XP?
« Reply #9 on: October 18, 2012, 10:02:51 am »
It will probably accept this fine.

/*
A comment
about stuff
*/
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline ptricks

  • Frequent Contributor
  • **
  • Posts: 671
  • Country: us
Re: Code builds in Win 7, but not in XP?
« Reply #10 on: October 18, 2012, 12:16:30 pm »
While you can initialize a variable in the for statement it can make it harder to read the code later if the function it is used in is a long one. I really like code better that doesn't try to do multiple things in the code into the same statement, it is just easier to read and understand. I have seen code where it looks like the programmer thought he was limited in the number of lines he could have in the code and ouch it is hard to understand.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf