CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

What am I doing wrong? (help)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
circlesod



Joined: 11 May 2007
Posts: 3

View user's profile Send private message

What am I doing wrong? (help)
PostPosted: Fri May 11, 2007 6:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 11, 2007 7:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 11, 2007 12:11 pm     Reply with quote

Yes... You're totally right. Stupid me...!
Thank you! Embarassed


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

View user's profile Send private message

PostPosted: Fri May 11, 2007 12:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 11, 2007 12:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 11, 2007 1:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 11, 2007 1:27 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group