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

Why does my code not compile?

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



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

Why does my code not compile?
PostPosted: Mon May 17, 2010 5:06 am     Reply with quote

Hi, i wrote this code and I don't know what can I do to compile it.

Code:

#include <16f628.h>
#fuses xt,nowdt,put,noprotect
// xt=crystal; nowdt=no watchdog timer
// put=powerup timer; noprotect=memory protection off
#use delay(clock=12000000)
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte PORTA = 0x05
#byte PORTB = 0x06

byte const A[] = {
         0x1F,
         0x24,
         0x24,
         0x24,
         0x1F
      };
byte const R[] = {
         0x3F,
         0x28,
         0x2C,
         0x2A,
         0x29
      };

letra(char varlet) {
   BYTE i;
     for(i=0; i<=5; ++i) {
       set_tris_b(0x00);
       PORTB = varlet[i];
      }
}

void main(void) {
   BYTE i;

   /////////////MAIN LOOP
   while (1) {
      for (i = 0; i<=5; i++){
         PORTB=A[i];
      }
   delay_us(20);
   }

}


Compiler outputs:
Code:

Executing: "C:\Program Files (x86)\PICC\Ccsc.exe" +FM "main.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 66 "C:\Users\Rafa\Documents\MPLAB\POV\main.c" Line 30(20,21): Previous identifier must be a pointer
      1 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Mon May 17 13:00:09 2010



Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon May 17, 2010 5:14 am     Reply with quote

First some faults that won't stop it compiling.

You have XT selected as the oscillator fuse, but then 12MHz as the operating frequency. What is the maximum for XT?.....

Then in your 'main', you output to PORTB, without setting the TRIS, so nothing will happen...


The reason for the failure though, is 'varlet'. You declare that varlet is a single character, then try to use it in the 'letra' routine, as a pointer/array. Won't work, so the compiler complains.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 17, 2010 6:24 am     Reply with quote

Another common mistake:
Code:
      for (i = 0; i<=5; i++){
         PORTB=A[i];
How many items are in A[]?
And how many times is this loop going to executed?
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Mon May 17, 2010 7:38 am     Reply with quote

Ttelmah wrote:
First some faults that won't stop it compiling.

You have XT selected as the oscillator fuse, but then 12MHz as the operating frequency. What is the maximum for XT?.....

Then in your 'main', you output to POPRTB, without setting the TRIS, so nothing will happen...


The reason for the failure though, is 'varlet'. You declare that varlet is a single character, then try to use it in the 'letra' routine, as a pointer/array. Won't work, so the compiler complains.

Best Wishes

Thanks. It's working now, leds are "blinking"!
The only thing left is.. how can I select wich array is going to be put in PORTB? In the "letra" routine I mean.

@ckielstra: Thanks for pointing this out.

Btw, my code is now:
Code:
#include <16f628.h>
#fuses HS,nowdt,put,noprotect
// xt=crystal; nowdt=no watchdog timer
// put=powerup timer; noprotect=memory protection off
#use delay(clock=12000000)
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte PORTA = 0x05
#byte PORTB = 0x06

byte const A[] = {
         0x1F,
         0x24,
         0x24,
         0x24,
         0x1F
      };
byte const R[] = {
         0x3F,
         0x28,
         0x2C,
         0x2A,
         0x29
      };
byte const F[] = {
         0b11111,
         0b11100,
         0b10100,
         0b10100,
         0b10100
      };

/*letra(char varlet) {
   BYTE i;
     for(i=0; i<=5; ++i) {
       set_tris_b(0x00);
       PORTB = varlet[i];
      }
}*/

void main(void) {
   BYTE i;

   /////////////MAIN LOOP
   while (1) {
      set_tris_b(0x00);
      for (i = 0; i<=4; i++){
         PORTB=R[i];
      }
      delay_us(20);

      for (i = 0; i<=4; i++){
         PORTB=A[i];
      }
      delay_us(20);

      for (i = 0; i<=4; i++){
         PORTB=F[i];
      }
      delay_us(20);

      for (i = 0; i<=4; i++){
         PORTB=A[i];
      }
      delay_us(20);
   }

}


The only thing left to do is to make the letra routine work, and reading a IR sensor to receive instructions from it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon May 17, 2010 9:24 am     Reply with quote

Get rid of the 'const' declarations on your arrays.

Declare 'letra' as:
Code:

void letra(char * varlet) {
   BYTE i;
   for(i=0; i<5; ++i) {
     set_tris_b(0x00);
     PORTB = varlet[i];
   }
}

Note the '*' this now says that 'varlet' is a _pointer_ to a character.

Then call with:
Code:

   letra(A);

   letra(F);

   letra(R);

as required

Now the reason for getting rid of the 'const', is that in the PIC, program memory, and RAM, are two different memory spaces. It is very hard because of this to construct 'pointers' to ROM. The compiler has got ways of doing this now, but the overheads involved, are more than are worthwhile for three 5 element arrays. Much simpler to just declare them as arrays in normal memory...

Best Wishes
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Mon May 17, 2010 1:28 pm     Reply with quote

It seems like its working now.
There is a little hardware problem... it only works if i touch the oscillator pin. I'm using a 4MHz (XT mode) crystal with 22pF caps, but it does the same with 12MHz (HS Mode) with 27pF, and 16MHz (HS) with 27pF caps.

Any idea?
Thanks.

EDIT: And it does not work with IntRC oscillator.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2010 1:44 pm     Reply with quote

1. Add the NOLVP fuse.
2. Make sure you have a pull-up resistor on your MCLR pin.
Use 10K if your programmer is the Microchip ICD2, etc.
Use 47K if you are using the CCS ICD-U40, etc.
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Mon May 17, 2010 2:20 pm     Reply with quote

PCM programmer wrote:
1. Add the NOLVP fuse.
2. Make sure you have a pull-up resistor on your MCLR pin.
Use 10K if your programmer is the Microchip ICD2, etc.
Use 47K if you are using the CCS ICD-U40, etc.

Done two thing. Same result, the Pull-up is 10K.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2010 2:46 pm     Reply with quote

Try to make a very simple program work. The program below will blink
an LED on Pin B0. This assumes your PIC is running at +5 volts.
It assumes you have a series resistor (approx. 470 ohms) going to from
pin B0 to the Anode of the LED, and the Cathode of the LED is connected
to ground.
Code:

#include <16F628.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

//=======================
void main()
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Mon May 17, 2010 3:14 pm     Reply with quote

I've resolved it. Too short delays and too low POV speed to see the letters.
Thanks for the help, and sorry Embarassed
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