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

Function prototype issue?

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







Function prototype issue?
PostPosted: Sun Aug 02, 2009 11:45 am     Reply with quote

I am trying to compile a program made up of snippets of working code from previous projects...

void SerialReceive(void); // apprears earlier in code.

void main()

// bunch of configuration
// etc/

//*************************************
// Main Loop
//**************************************
while (1)
{
//When a packet is received on the tool bus, NewPacket is set.
//Process received packet and reply.

if(NewPacket)
{
disable_interrupts(INT_RDA); //disable serial port interrupts
NewPacket = FALSE; //clear flag
SerialReceive(); //get received packet
enable_interrupts(INT_RDA); //enable serial port interrupts
}
if (Tick)
{
Tick = 0;
output_toggle(PIN_D7); //Show that Timer0 is generating a 1/2 sec timer
fputs( " | HI ! | ",HOST_PC );
output_toggle(PIN_D0); //Toggle the D0 D1 pin pattern
output_toggle(PIN_D1); //
rs232_errors = 0; // clear errors just to clear warning...
}
}//end of MAIN LOOP

void SerialReceive(void) // compiler does not like this line and
// focuses on the "void" ...
{
Checksum = 0;

delay_us(50); //short dead time to allow bus master to get ready to receive
if(SerialError) //received an error in packet
{
CREN = 0; //turn off receiver
putc(Buff[0]); //echo board address
while(!TRMT); //wait for transmit buffer to finish

when I try to compile this I get the DREADED non-specific, utterly confusing; " A numeric expression must appear here..." pointing to the first line of code

This funtion comiles noprmally in other code...and I have looked for obvious missing braces etc. Actually no funtions will compile after my brief main section...So something is hosed in there...but I can't find it.

Any help appreciated...from reading other posts, I see you can get this message from a host of arcane sources...Hoo Boy, what fun!

JPR
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

Re: Funtion prototype issue?
PostPosted: Sun Aug 02, 2009 11:51 am     Reply with quote

JohnP wrote:
I am trying to compile a program mad eup of snippets of working code from previous projects...

when I try to compile this I get the DREADED non-specific, utterly confusing; " A numeric expression must appear here..." pointing to the first line of code

This funtion comiles noprmally in other code...and I have looked for obvious missing braces etc. Actually no funtions will compile after my brief main section...So something is hosed in there...but I can't find it.

Any help appreciated...from reading other posts, I see you can get this message from a host of arcane sources...Hoo Boy, what fun!

JPR

Paste complete code. You probably overlooked something and use CODE for pasting a source it is easier to "debug" Wink
JohnP
Guest







Reply
PostPosted: Sun Aug 02, 2009 11:56 am     Reply with quote

Here is the code...implements a ninth bit serial RX funtion...

Works great in other uses...I am clearly missing something simple?

Code:


#define RecvTimeout 20000  // increased for debug 6/7/06
// define legal addresses
#define PMTAddress1 70       
#define PMTAddress2 80
#define PMTAddress3 90

//  Need to find where these come from?????
#byte  RCSTA2 = 0xF6B    //Receive status control register


#bit  SPEN = 0xF6B.7    //Serial Port Enable
#bit  RX9 = 0xF6B.6     //9-bit receive enable
#bit  CREN = 0xF6B.4    //Receive Enable
#bit  ADDEN = 0xF6B.3   //Address detect enable
#bit  FERR = 0xF6B.2    //framing error
#bit  OERR = 0xF6B.1    //overrun error
#bit  RX9D = 0xF6B.0    //9th bit of received data
#byte TXSTA2 = 0xF6C     //Transmit status and control register
#bit  TX9 = 0xF6C.6     //9-bit transmit enable
#bit  TXEN = 0xF6C.5    //Transmit enable
#bit  TRMT = 0xF6C.1    //Transmit buffer is empty
#bit  TX9D = 0xF6C.0    //9th bit of transmit data
#byte RCREG2 = 0xF6E     //receive register
#byte  PIR1 = 3998
#bit RCIF= 3998.5    //usart receive interrupt flag

int1  NewPacket;
int1  PMT_changed;
int16 Tout;
int8 RecvPacketSize;
int8 PacketSize;
int16 TotPacketSize;
int8 H;
int8 L;
int8 Checksum;
int8 RecvPointer;
int8 Adr;
int8 SerialError;
int8 Status, TempCount;
int1 Tick, toggle;
int16 temperature, temptemp;
unsigned int16 dac_value, pmt_set_value, buf_value, temp_value;
unsigned int16 default_PMT = 44239;  // initialize to 1350 volts
int8 PowerOnTimer;

                     //ready to be xmited
int8  Rcmd;          //received command

int8  Buff[30];      //serial communications buffer
int8  CB;
int8  CL;
int8  CH;
int8  ReceivedAddress;     //value read from serial port with 9th bit set
int   *pntr;
int16 CVsetpoint;
int16 Timer0_Clk;
//int8  B1, B2, B3, B4, B5, B6, B7, B8;    // temporary variables


void ReadTemp(void);
void SerialReceive(void);
void SendStatus(void);
void SetSerialNumber(void);
void SendReport(void);
void ChangePMT(void);
void IncrementPMT(void);
void DecrementPMT(void);
void WriteCalDate(void);
void WritePMTVoltage(void);
void Write_new_SN(void);
void WriteMfgDate(void);
void WriteFirmwareVersion(void);
void WriteHardwareVersion(void);
void SetMfgDate(void);
void SetFirmwareRev(void);
void SetHardwareRev(void);
void SendPMTVoltage(void);

/********************************************************************
*  RTCC - Timer 0 Interrupt                                         *
********************************************************************/
#int_TIMER0
TIMER0_ISR()
{
set_timer0(15536);     // reload for 10 msec tick, based on value from above number
                       // = 655356 - (.01/(8 /40,000,000))
//  this gives a 94.67 hz pulse so a lot closer than the previous value
Timer0_Clk++;           // 10 msec clock event counter
if (Timer0_Clk > 50)
   {
   Tick = 1;      //500 msec clock tick
   }
}// end of Timer0 ISR

#int_RDA
void  RDA_isr(void)
{
// handler for input commands from the Host PC would go here...
}


//**************************************************************************
// STB Serial ISR
//
//  Receive Interrupt - when address bit is set                       
//    in 1st xmission matches the BoardAddress                       
//**************************************************************************
#int_RDA2
void  RDA2_isr(void)
{
int CS;

NewPacket = 0;
SerialError = 0;
ReceivedAddress = RCREG2;      //get byte from receive buffer
if ( (ReceivedAddress == PMTAddress1) || (ReceivedAddress == PMTAddress2) || (ReceivedAddress == PMTAddress3) )
   {
   //output_high(PIN_B6);     // for debug!!!! Set while wating for next byte
   NewPacket = 1;       //set flag for new packet is coming
   ADDEN = 0;           //allow receiver to get the rest of the packet
   //output_low(PIN_B6);
   Buff[0] = ReceivedAddress;  //shove address into 1st slot...
//Receive packet size High Byte
   Tout = RecvTimeout;
   while(RCIF == 0)        //wait for next byte in receiver
     {
     Tout--;
     //output_high(PIN_B6);     // for debug!!!!Set while wating for next byte
     if(Tout == 0)
         {
         SerialError = 130;           //Timeout error
         goto ErrorTest;
         }
     }
   //output_low(PIN_B6);              // for debug!!!! 2nd byte arrived
   Buff[1] = RCREG2;                  //get size byte from serial port
// Receive packet size Low byte   
   Tout = RecvTimeout;
   while(RCIF == 0)                    //wait for next byte in receiver
     {
     Tout--;
     //output_high(PIN_B6);     // for debug!!!!Set while wating for next byte
     if(Tout == 0)
         {
         SerialError = 130;           //Timeout error
         goto ErrorTest;
         }
     }
   //output_low(PIN_B6);     // for debug!!!!last size byte arrived
   Buff[2] = RCREG2;                    //get byte from serial port
   RecvPacketSize = Buff[2];       //add size and checksum to packet size
// --- receive packet
   RecvPointer = 3;       //position pointer at first byte
// receive rest of packet past the packet size bytes.....   
   while(RecvPointer < (RecvPacketSize+1))
     {
     Tout = RecvTimeout;
     while(RCIF == 0)
       {
       Tout--;
    //   output_high(PIN_B6);     // for debug!!!!Set while wating for next byte
       if(Tout == 0)
          {
          SerialError = 130;            //Timeout error = 0x82
          goto ErrorTest;
          }
       }
   //  output_low(PIN_B6);            // for debug!!!! next byte here
     Buff[RecvPointer] = RCREG2;     //save packet data in buffer array
     RecvPointer++;
     }// end of while RCVpointer <= RecvPacetsize
     CS = 0;
     RecvPointer = 1;
     while(RecvPointer < Buff[2])
      {
      CS = CS + Buff[RecvPointer];
      RecvPointer++;
      }
   CS = ~(CS) + 1;       //CheckSum is now 2's complement     
   RecvPacketSize = Buff[2];
   if (CS != Buff[RecvPacketSize])
      {
      SerialError = 129;                  //checksum error = 0x81
      }
   }// End of IF Rc'd addr = Board Address

ErrorTest:
ADDEN = 1;                    //enable interrupt when address bit is set

}// end of RDA2 ISR


void main()
{

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_20);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED, 0,1);
   setup_timer_3(T3_DISABLED);
   setup_timer_4(T4_DISABLED, 0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   TX9D = 0;                        //9th bit of transmitted data is always low
   TX9 = 1;                         //Enable 9-bit transmits
   RX9 = 1;                         //Enable 9-bit receives   

   setup_low_volt_detect(FALSE);
   set_tris_a(0xFF);    // all inputs
   set_tris_b(0xFF);    // all inputs
   set_tris_c(0x80);    //Set up for UART1 = HOST_PC on C7(Rx)Input and C6 (TX) and all others are outputs
   set_tris_d(0);       //All outputs to drive diodes and diagnostics
   set_tris_e(0xFF);    // all inputs
   set_tris_f(0xFF);    // all inputs
   set_tris_g(0xFF);    // all inputs
   set_tris_h(0x80);    //Set up for UART2 = STB on H7 (Rx)Input and H6 (TX) and all others are outputs
   set_tris_j(0xFF);    // all inputs

//   setup_uart(115200, HOST_PC);
//   setup_uart(115200, STB);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// Crive pin D0 high to turn on diode D1   
   output_high(PIN_D0);       //Turn on D1 to signify we made it this far!!!
   output_high(PIN_D1);
   output_high(PIN_D2);
   output_high(PIN_D3); 
   output_high(PIN_D4);
   output_high(PIN_D5);
   output_high(PIN_D6);
   output_high(PIN_D7);
   delay_ms(1000);
   output_low(PIN_D1);
   output_low(PIN_D2);   
   output_low(PIN_D3);   
   output_low(PIN_D4);
   output_low(PIN_D5);
   output_low(PIN_D6); 
   output_low(PIN_D7);   
   Timer0_Clk = 0; 
   enable_interrupts(INT_RDA);;
   enable_interrupts(INT_RDA2);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   Checksum = 0;

//*************************************
//  Main Loop
//**************************************
   while (1)
   {
//When a packet is received on the tool bus, NewPacket is set.
//Process received packet and reply.

   if(NewPacket)
      {
      disable_interrupts(INT_RDA);  //disable serial port interrupts
      NewPacket = FALSE;            //clear flag
      SerialReceive();              //get received packet
      enable_interrupts(INT_RDA);   //enable serial port interrupts
      }
  if (Tick)
      {
      Tick = 0;
      output_toggle(PIN_D7);       //Show that Timer0 is generating a 1/2 sec timer
      fputs( " |   HI !  | ",HOST_PC );
      output_toggle(PIN_D0);       //Toggle the D0 D1 pin pattern
      output_toggle(PIN_D1);       //
      rs232_errors = 0;            // clear errors just to clear warning...
      }
   }//end of MAIN LOOP



void SerialReceive(void)
   {
   Checksum = 0;
   
   delay_us(50);     //short dead time to allow bus master to get ready to receive
   if(SerialError)              //received an error in packet
      {
      CREN = 0;                  //turn off receiver
      putc(Buff[0]);             //echo board address
      while(!TRMT);              //wait for transmit buffer to finish
      putc(0);                   // high byte of num. of bytes
      while(!TRMT);              //wait for transmit buffer to finish     
      putc(4);                   //1 byte command
      while(!TRMT);              //wait for transmit buffer to finish     
      putc(SerialError);         //error code
      while(!TRMT);              //wait for transmit buffer to finish     
      Checksum = ~(4 + SerialError) + 1;  // CS now 2's complement
      putc(Checksum);                    //checksum
      goto SerialEnd;
   }
   else
        {
        switch (Buff[3])           //sort the received command...USES 4th BYTE FOR CHLS FORMAT
           {
           case 's':
               //SendStatus();
               break;
                     
           case 'm':   
               //SetMfgDate();  // write mfg date to eeprom
               break;
                     
           case 'n':   
               //SetSerialNumber();
               break;
                     
           case 'f':   
               //SetFirmwareRev(); // write firmware date to eeprom
               break;
                     
           case 'H':   
               //SetHardwareRev(); //write hardware version to eeprom
               break;
                     
           case 50:   
               Buff[2] = 50;              //error command
               break;
                     
           case 'r':   
               //SendReport();
               break;
           case 'i':   
               //IncrementPMT();
               break;
               
           case 'l':   
               //DecrementPMT();
               break;
               
           case 'c':   
               //WriteCalDate();
               break;
           case 'P':   
               WritePMTVoltage();
               break;
               
           case 'V':   
               //SendPMTVoltage();
               break;
               
           default:   
               Buff[1] = 0;  //(1 byte reply) received command is
                              //not supported
               Buff[2] = 4;   // low byte of # bytes in block
               Buff[3] = 131;  //bad command received
               break;
           }
// Command selection/action done
// Send response
      PacketSize = Buff[2];       
      Checksum = 0;
      for(RecvPointer = 1; RecvPointer < PacketSize; RecvPointer++)
         {
         Checksum = Checksum + Buff[RecvPointer];
         }
      Buff[Buff[2]] = ~(Checksum) + 1;
      CREN = 0;                  //turn off receiver
      for(RecvPointer = 0; RecvPointer <= PacketSize; RecvPointer++)
         {
         putc(Buff[RecvPointer]);
         while(!TRMT);              //wait for transmit buffer to finish
         }
     
SerialEnd:     
      delay_us(50);     //short dead time to allow bus master to get ready to receive
      CREN = 1;                  //turn on receiver
      setup_wdt(WDT_ON);
      restart_wdt();     
      }
   } //end of SerialReceive

}// Program end

JohnP
Guest







Prototype problem wa BRAIN problem
PostPosted: Sun Aug 02, 2009 12:16 pm     Reply with quote

Found it...

I had the added functions stuck in before the final ending curly brace of main...stupid error...wonderfully non-specific compiler error...

Sorry to bother the Illuminati with this triffle...

JPR
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