View previous topic :: View next topic |
Author |
Message |
circlesod
Joined: 11 May 2007 Posts: 3
|
What am I doing wrong? (help) |
Posted: Fri May 11, 2007 6:38 am |
|
|
As a totally new to CCS Pic-C, I dowloaded the latest demo (4.034 ?) in order to try it out. Used the wizard to create all fuses and such.
Then I just added a variable declaration and compiled it. It wouldn't go thru. I don't understand what I'm doing wrong.
I'll get get this Error everytime I compile:
Quote: |
**** Error 51 "main.c" Line 17(1,5): A numeric expression must appear here
1 Errors, 0 Warning.
|
Pointing to the row where "char text[20];" is located. If I delete this line, the error is gone.
Here is a copy of the simple code:
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
char text[20]; // Testing array for strings --> (causing compile error)
}
|
|
|
|
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Fri May 11, 2007 7:31 am |
|
|
Your are trying to declare a variable after your code, move it to the top of your main loop. |
|
|
circlesod
Joined: 11 May 2007 Posts: 3
|
|
Posted: Fri May 11, 2007 12:11 pm |
|
|
Yes... You're totally right. Stupid me...!
Thank you!
But this one gives me a headache:
Code: |
int porta = 0b111111;
OUTPUT_A(porta); <-- Works fine
OUTPUT_A(0b000000); <-- Error!
|
Compiling this code will generate there two errors because of the line "OUTPUT_A(0b000000);":
Quote: |
*** Error 28 "C:\Projects\Ledseg.c" Line 11(10,11): Expecting an identifier
*** Error 43 "C:\Projects\Ledseg.c"" Line 66(12,13): Expecting a declaration
2 Errors, 0 Warnings.
|
Am I not allowed to put direct values in here? If I first declare a variable for value "0b111111" and then put the value in the OUTPUT_A(x), it works fine. But not with a value.... Why? |
|
|
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Fri May 11, 2007 12:28 pm |
|
|
Those two lines work fine on my system.
Doble check you aren't missing a semicolon above them. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 11, 2007 12:36 pm |
|
|
This is probably what's happening:
Quote: |
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
//==========================
void main()
{
int8 a,b,c;
a = 0x55;
b = 0xAA;
c = a + b;
int porta = 0b111111;
OUTPUT_A(porta);
OUTPUT_A(0b000000);
while(1);
} |
Don't put variable declarations (the line in bold) in the middle of your
code. They must go at the start of the function (or be globals).
Move the line shown in bold so it's just below the declaration for a,b,c. |
|
|
circlesod
Joined: 11 May 2007 Posts: 3
|
|
Posted: Fri May 11, 2007 1:10 pm |
|
|
I don't know. It seems that the compiler isn't consistant.
If I compile this, everything works alright:
Code: |
#include <16F877.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=20000000)
int porta = 0b111111;
OUTPUT_A(porta); <-- Works fine
void main()
{
char text[20]; // Testing array for strings
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
OUTPUT_A(0b000000); <-- Works fine
// TODO: USER CODE!!
}
|
But if I compile the following, I will get the Error messages shown in the post above.
Code: |
#include <16F877.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=20000000)
int porta = 0b111111;
OUTPUT_A(porta); <-- Works fine
OUTPUT_A(0b000000); <-- Gives Error
void main()
{
char text[20]; // Testing array for strings
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
}
|
Sometimes there is a need to alter the ports (for example) outside the main loop. It seems that the only way to do that, is to first put a value into a variable and the make the OUTPUT, which will waste both clock cycles and memory.
Anyone here that do not get errors on the 2nd code above?
(Compiled by Pcw.exe v4.034 for 16F877) |
|
|
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Fri May 11, 2007 1:27 pm |
|
|
Even though the first one compiles with the statment outside of a function, it doesn't generate any code.
You cannot execute code outside of a function. |
|
|
|