Code error

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

Code error

Postby anonymous_k87 » Wed Feb 03, 2010 2:41 pm

Do anyone know what wrong with the code?
I cant build it...I'm getting this:

Error [312] C:\Users\Kyran\Documents\C\NEW4\code_rx.c; 10.1 ";" expected
Warning [361] C:\Users\Kyran\Documents\C\NEW4\code_rx.c; 49.8 function declared implicit int
Error [984] C:\Users\Kyran\Documents\C\NEW4\code_rx.c; 94.1 type redeclared
Error [1098] C:\Users\Kyran\Documents\C\NEW4\code_rx.c; 94.1 conflicting declarations for variable "rx_rec"

I have highlighted the showed error..plz help me out..
syntax error or logic error?

CODE: SELECT_ALL_CODE
//   include
//=================================================================
#include <pic.h>

//   configuration
//===================================================================================
__CONFIG (0x3F32)

//   define
//===================================================================================
#define errorflag   RA1
#define errorflag_1   RA2
#define display_1   PORTB
#define display_2   PORTD   

//   function prototype
//===================================================================================
unsigned char rx_rec(void);

//   main function
//===================================================================================
void main(void)
{
   //assign variable
   unsigned char num,num_1,num_2,no, temp;
   unsigned char rx_data[21],rx_act,rx_room,rx_bui,rx_ide,rx_func,rx_sum,checksum;
   unsigned int i;

   //7 segment display
   unsigned char _7seg[16]={0x7f,0x0d,0xb7,0x9f,   //0,1,2,3
                      0xcd,0xdb,0xfb,0x0f,   //4,5,6,7
                      0xff,0xdf,0xef,0xf9,   //8,9,A,B
                      0x73,0xbd,0xf3,0xe3};   //C,D,E,F

   TRISA = 0x00;         //configure PORTA as output
   TRISB = 0x00;         //configure PORTB as output
   TRISD = 0x00;         //configure PORTD as output

   //setup USART
   BRGH = 0;            //baud rate low speed option
   SPBRG= 129;            //set boud rate to 2400bps for 20Mhz crystal
   SPEN = 1;            //enable serial port
   RX9  = 0;            //8-bit reception
   CREN = 1;            //enable reception

   //initialize variable
   num = 0;
   num_1 = 0;
   num_2 = 0;
   no  = 0;
   i=0;

   rx_act = 0xff;

   while(1)                  //infinity loop
   {
      display_2 = _7seg[num_2];   //display 8-bit hexadecimal on 7 segment
      display_1 = _7seg[num_1];

      reset:                  //reset point:
      CREN=1;                  //enable continuos receive
      if(OERR==0)               //receive data if overrun error free
      {
         step1:               
         [color=#BF0000]temp = rx_rec();   [/color]   //store return data to temporary variable
         if(temp == rx_act)      
         {
            rx_data[i]= temp;
            i++;
            if(i==15)
               goto step2;
            goto step1;
         }
         else
         {
            errorflag = 1;      
            goto reset;
         }

         step2:
         for(i=16; i<21; i++)
            rx_data[i]=rx_rec();
         
         rx_sum = rx_data[20];
         rx_room= rx_data[19];
         rx_bui = rx_data[18];
         rx_func= rx_data[17];
         rx_ide = rx_data[16];
         
         checksum = rx_ide+rx_func+rx_bui+rx_room;
   
         if(rx_sum == checksum)
         {   
            num = rx_sum;
            num_2 = num/16;   
            num_1 = num%16;   
            display_2 = _7seg[num_2];   
            display_1 = _7seg[num_1];
         }
         else
         {   
            errorflag_1=1;
            goto reset;
         }
      }
      else CREN=0;
   }
}

[color=#BF0000]unsigned char rx_rec(void)[/color]         //uart subroutine
{
   unsigned char rx_data;
   while(RCIF==0);               //wait for data
   rx_data = RCREG;
   return rx_data;               //return data
}
anonymous_k87
Freshie
 
Posts: 5
Joined: Mon Feb 01, 2010 5:15 pm

Re: Code error

Postby yonghui » Fri Feb 05, 2010 12:09 pm

hi,

pls add a semicolon behind ur __CONFIG(0x3F32)

which will become __CONFIG(0x3F32);

i tested the working code to be like this :

CODE: SELECT_ALL_CODE
// include
//=================================================================
#include <pic.h>

// configuration
//===================================================================================
__CONFIG (0x3F32);

// define
//===================================================================================
#define errorflag RA1
#define errorflag_1 RA2
#define display_1 PORTB
//#define display_2 PORTD

// function prototype
//===================================================================================
unsigned char rx_rec(void);

// main function
//===================================================================================
void main(void)
{
   //assign variable
   unsigned char num,num_1,num_2,no, temp;
   unsigned char rx_data[21],rx_act,rx_room,rx_bui,rx_ide,rx_func,rx_sum,checksum;
   unsigned int i;

   //7 segment display
   unsigned char _7seg[16]={0x7f,0x0d,0xb7,0x9f, //0,1,2,3
   0xcd,0xdb,0xfb,0x0f, //4,5,6,7
   0xff,0xdf,0xef,0xf9, //8,9,A,B
   0x73,0xbd,0xf3,0xe3}; //C,D,E,F

   TRISA = 0x00; //configure PORTA as output
   TRISB = 0x00; //configure PORTB as output
   //TRISD = 0x00; //configure PORTD as output
   
   //setup USART
   BRGH = 0; //baud rate low speed option
   SPBRG= 129; //set boud rate to 2400bps for 20Mhz crystal
   SPEN = 1; //enable serial port
   RX9 = 0; //8-bit reception
   CREN = 1; //enable reception
   
   //initialize variable
   num = 0;
   num_1 = 0;
   num_2 = 0;
   no = 0;
   i=0;
   
   rx_act = 0xff;

   while(1) //infinity loop
   {
      //   display_2 = _7seg[num_2]; //display 8-bit hexadecimal on 7 segment
         display_1 = _7seg[num_1];
         
         reset: //reset point:
         CREN=1; //enable continuos receive
         if(OERR==0) //receive data if overrun error free
         {
            step1:
            temp = rx_rec(); //store return data to temporary variable
            
            if(temp == rx_act)
            {
               rx_data[i]= temp;
               i++;
               if(i==15)
               goto step2;
               goto step1;
            }
            else
            {
               errorflag = 1;
               goto reset;
            }
            
            step2:
            for(i=16; i<21; i++)
            rx_data[i]=rx_rec();
            
            rx_sum = rx_data[20];
            rx_room= rx_data[19];
            rx_bui = rx_data[18];
            rx_func= rx_data[17];
            rx_ide = rx_data[16];
            
            checksum = rx_ide+rx_func+rx_bui+rx_room;
         
            if(rx_sum == checksum)
            {
               num = rx_sum;
               num_2 = num/16;
               num_1 = num%16;
               //display_2 = _7seg[num_2];
               display_1 = _7seg[num_1];
            }
            else
            {
            errorflag_1=1;
            goto reset;
            }
         }
         else CREN=0;
   }

}
unsigned char rx_rec(void) //uart subroutine
{
unsigned char rx_data;
while(RCIF==0); //wait for data
rx_data = RCREG;
return rx_data; //return data
}



yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Code error

Postby anonymous_k87 » Sun Feb 07, 2010 12:59 pm

Thanks dude.....I cant believe I miss that...
anonymous_k87
Freshie
 
Posts: 5
Joined: Mon Feb 01, 2010 5:15 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 10 guests