Code builds in Win 7, but not in XP? - Page 1
Forum section: electronics / general

author: sgonzalezp
author_rank: Newbie
timestamp: October 16, 2012, 02:11:56 am
content: Code:// 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.TRISA4int 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 OUTPUTLEDPin = 0;//Set LED Pin to OFFINPUTPin = 1;TRIGGER = 0;for(int i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle{LEDPin = ~LEDPin;//Toggle LED Pin OnDelay10TCYx(i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(250 - i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(i);while (TRIGGER == 1){short_pulse_green();}}LEDPin = 0;}int short_pulse_blue(){LEDTris = 0;//Set LED Pin data direction to OUTPUTLEDPin = 0;//Set LED Pin to OFFINPUTPin = 1;TRIGGER = 0;for(int i = 1; i < 150; i++) // Modulate Pulse Width of LED2 increasing in duty cycle{LEDPin = ~LEDPin;//Toggle LED Pin OnDelay10TCYx(i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(150 - i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(i);LEDPin2 = ~LEDPin2;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(250 - i);LEDPin2 = ~LEDPin2;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(i);LEDPin2 = ~LEDPin2;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(150 - i);LEDPin2 = ~LEDPin2;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(i);LEDPin3 = ~LEDPin3;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(250 - i);LEDPin3 = ~LEDPin3;//Toggle LED Pin OffDelay10TCYx(i);while (TRIGGER == 1){short_pulse_green();}}LEDPin3 = 0;}Error MessageQuote

author: free_electron
author_rank: Super Contributor
timestamp: October 16, 2012, 02:14:46 am
content: 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

author: sgonzalezp
author_rank: Newbie
timestamp: October 16, 2012, 02:27:48 am
content: Weird thing is the C source file is in the correct path.. I even made a new project.

author: mariush
author_rank: Super Contributor
timestamp: October 16, 2012, 02:48:26 am
content: 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.

author: Psi
author_rank: Super Contributor
timestamp: October 16, 2012, 02:59:10 am
content: 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(inti = 1; i < 250; i++)A Google for "Scope of a variable declared in for loop" finds this..QuoteMaybe 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 functionsCode:int i;for(i = 1; i < 250; i++) // Modulate Pulse Width of LED2 increasing in duty cycle{LEDPin = ~LEDPin;//Toggle LED Pin OnDelay10TCYx(i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(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 OnDelay10TCYx(250 - i);LEDPin = ~LEDPin;//Toggle LED Pin OffDelay10TCYx(i);while (TRIGGER == 1){short_pulse_green();}}

author: sgonzalezp
author_rank: Newbie
timestamp: October 16, 2012, 04:01:03 pm
content: also tried that...weird.Lol it says syntax error....I guess c no longer works

author: baljemmett
author_rank: Unknown
timestamp: October 16, 2012, 04:21:42 pm
content: Quote from: sgonzalezp on October 16, 2012, 04:01:03 pmIf 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.

author: Psi
author_rank: Super Contributor
timestamp: October 16, 2012, 11:16:39 pm
content: Quote from: baljemmett on October 16, 2012, 04:21:42 pmoh 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 ; //

author: Hypernova
author_rank: Unknown
timestamp: October 18, 2012, 09:37:31 am
content: 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.

author: Psi
author_rank: Super Contributor
timestamp: October 18, 2012, 10:02:51 am
content: It will probably accept this fine./*A commentabout stuff*/

author: ptricks
author_rank: Frequent Contributor
timestamp: October 18, 2012, 12:16:30 pm
content: 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.