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 support@ccsinfo.com

shift_left problem

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







shift_left problem
PostPosted: Sun Nov 08, 2009 4:21 pm     Reply with quote

Hi this is my code and I'm having problems when I try to compile it.
The error is:
Quote:

ERROR 66 : previous identifier must be a pointer and it is in this line:


Code:

case 1:
            Output_E(0x03);
            ram = cola1;
            ram = shift_right(ram,1,i);
           
         if (ram[0]==1){        -------------   /////////// here in this line
            output_high(PIN_B0);
            delay_ms(500);
            output_low(PIN_B0);
            bit_clear(ram, 0);
            i = i - 1;
                       }
               break;

As I said I have that error, obviously three times in each case 1 2 4.... and here is the complete code. The program creates a CDC serial comm on the usb port and asks for the PortD status to activate a pin on portB.
Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL2,CPUDIV1,VREGEN

#use delay(clock=48000000)


int indato;
int cola1   = 0;
int ram    = 0;


void main() {

   usb_cdc_init();
   usb_init();                             

   set_tris_B(0x00);                       
   set_tris_E(0x00);
   set_tris_D(0xFF);                       
   
   Output_B(0x00);
   Output_E(0x00);

   while (!usb_cdc_connected()) {}
   while (true)
   {
 inicio:         
      usb_task();
      if(usb_enumerated())         
      {
         if (usb_cdc_kbhit())         
         {           
            indato = usb_cdc_getc();
         }
         }

         Output_E(indato);  // just to verify
         inpulso = input_D();
         
         switch (inpulso) {

    case 1:
            Output_E(0x03);
            ram = cola1;
            ram = shift_right(ram,1,i);
           
         if (ram[0]==1){
            output_high(PIN_B0);
            delay_ms(500);
            output_low(PIN_B0);
            bit_clear(ram, 0);
            i = i - 1;
                       }
               break;

    case 2:
            ram = cola2;
            ram = shift_right(ram,1,i);
           
         if (ram[0]==1){
            output_high(PIN_B1);
            delay_ms(500);
            output_low(PIN_B1);
            bit_clear(ram, 0);
            i = i - 1;
                       }
           break;
           
   case 4:
            ram = cola2;
            ram = shift_right(ram,1,i);
           
         if (ram[0]==1){
            output_high(PIN_B2);
            delay_ms(500);
            output_low(PIN_B2);
            bit_clear(ram, 0);
            i = i - 1;
                       }
           break;

    default:goto sig1;
            break; }

sig1:
switch (indato) {

      case 1:
         bit_set(cola1, 0);
         cola1 = shift_left(cola1, 1, 1);
         cola2 = shift_left(cola2, 1, 1);
         cola3 = shift_left(cola3, 1, 1);
           break;
           
      case 2:   
         bit_set(cola2, 0);
         cola1 = shift_left(cola1, 1, 1);
         cola2 = shift_left(cola2, 1, 1);
         cola3 = shift_left(cola3, 1, 1);
           break;
     
      case 4:   
         bit_set(cola3, 0);
         cola1 = shift_left(cola1, 1, 1);
         cola2 = shift_left(cola2, 1, 1);
         cola3 = shift_left(cola3, 1, 1);
           break;
           
      default: goto inicio;
            break;         
             }
             i = i + 1;
goto inicio;
             
      }
}
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

shift_left problem
PostPosted: Sun Nov 08, 2009 5:55 pm     Reply with quote

Hi,

You are getting the error because you are trying to access the variable ram as an array (ram[0]) but you have defined it as an 8-bit integer. Are you trying to check if bit 0 is a 1 ?
If so you need to replace if ( ram[0] == 1 ) to if ( ram & 1 ).

HTH

Andy
www.sharpcontrols.net :: Free custom controls for .NET
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Nov 09, 2009 3:22 am     Reply with quote

Actually the error relates to line before:-
Code:

ram = shift_right(ram,1,i);

The functions shift_left and shift_right require an address (pointer to memory) where the data to be shifted is.

In this case it is very easy to fix as you are only accessing an 8 bit var.
Put & infront of ram :-
Code:

ram = shift_right(&ram,1,i);

Also the result of the function is not the shifted value but the bit that was shifted out.
So
Code:

shift_right(&ram,1,i);

would work for you.

The var is directly altered!
Also i does not appear to be defined.
Also i can only be 0 or 1 and it is the value of the bit to be shifted in!

andyfraser is also correct in that the conditional statement is wrong.

You have the same issues with the var cola1.
Have a read of the CCS manual/help on the shift functions.

As for the other issues:-
goto inicio; at the end is not required as the while loop does the job for you.
default:goto sig1; is pointless as this is where it goes when it drops off the bottom of the switch anyway!
The only other thing that needs sorting is the
default: goto inicio; within the second switch as this bypasses the
i = i + 1;
Once this is sorted and you can remove the goto's your code would look alot better. According to mine and the majority of C coders. Some people do think it is ok to plaster goto's all around their C code but that is a different matter!
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