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

Urgently need help! Anything wrong with the header file?

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







Urgently need help! Anything wrong with the header file?
PostPosted: Wed May 14, 2008 4:20 am     Reply with quote

Guys, can you find anything wrong with the following header file? Im getting a 100 errors, yet i'm confident there's nothing wrong with the code because it compiled in the older version:

#include <16F877a.h>
#USE DELAY(CLOCK=4MHZ,CRYSTAL)
#FUSES HS,NOWDT,Noprotect

#byte port_A=5
#byte port_B=6
#byte port_C=7
#byte port_D=8
#byte port_E=9



//motor control ClockWise direction
#define motorCW_ON output_high(pin_E0)
#define motorCW_OFF output_low(pin_E0)

//motor control Counter ClockWise
#define motorACW_ON output high(pin_E1)
#define motorACW_OFF output low(pin_E1)

//motor speed control
#define PWN_ON output high(pin_E2)
#define PWN_OFF output low(pin_E2)

//horizontal left setting indicator
#define LeftLED_ON output_high(pin_C0)
#define LeftLED_OFF output_low(pin_C0)

//horizontal Right setting indicator
#define RightLED_ON output_high(pin_c1)
#define RightLED_OFF output_low(pin_c1)

//Virtecal Up setting indicator
#define UpLED_ON output_high(pin_c2)
#define UpLED_OFF output_low(pin_c2)

//Virtecal down setting indicator
#define DownLED_ON output_high(pin_c3)
#define DownLED_OFF output_low(pin_c3)

//Automation Control indicator
#define AutoLED_ON output_high(pin_d6)
#define AutoLED_OFF output_low(pin_d6)

//Maual Control Indicator
#define ManualLED_ON output_high(pin_d7)
#define ManualLED_OFF output_low(pin_d7)

//Setting for left or right
#define VerticalSwitch input(pin_b4)

//setting for up or down
#define HorizontalSwitch input(pin_b5)

//Manual Control button
#define StartSwitchinput(pin_b6)

#define UpButton input(pin_c4)
#define DownButton input(pin_c5)
#define LeftButton input(pin_c6)
#define RightButton input(pin_c7)

//Pneumatic Vacuum System
#define ValveConL_ON output_high(pin_d0)
#define ValveConL_OFF output_low(pin_d0)

#define ValveConL_ON output_high(pin_d1)
#define ValveConL_OFF output_low(pin_d1)

//left Suction Detector
#define Stick_DetectorL input(pin_d2)
//Right Suction Detector
#define Stick_DetectorR input(pin_d3)

//left Suction Indicator
#define SolenoidLEDL_ON output_high(pin_d4)
#define SolenoidLEDL_OFF output_low(pin_d4)

//Right Suction Indicator
#define SolenoidLEDR_ON output_high(pin_d5)
#define SolenoidLEDR_OFF output_low(pin_d5)

//Optical Sensor
#define OpticalEncoder input(pin_b7)

void move Up()
{
ValveConR_OFF;
ValveConL_ON;
motorCW_OFF;
motorACW_ON;
if(OpticalEncoder)
{
ValveConR_ON;
}
if(Stick_DetectorR)
{
int count1 = 0;
While(count1 == 2)
{
if(input(OpticalEncoder))
{
count1++;
}
else
{
ValveConR_ON;
ValveConL_OFF;
motorCW_ON;
motorACW_OFF;
if(OpticalEncouder)
{
ValveConL_ON;
}
}
}
}
else if(Stick_DetectorL)
{
int count2 = 0;
while(count2 == 2)
{
if(input(OpticalEncouder))
{
count2++
}
else
{
ValveConR_OFF;
ValveConL_ON;
motorCW_OFF;
motorACW_ON;
if(OpticalEncoder)
{
ValveConR_ON;
}
}
}
}
}





void main()
{
set_tris_a(0x00);
set_tris_b(0xff);
set_tris_c(0xf0);
set_tris_d(0x0c);
set_tris_e(0x00);
port_a = 0x00;
port_c = 0xf0;
port_d = 0x0c;
port_e = 0x00;
PreSetting();
switch (port_d);
{
case 0x04:
{
switch (port_c)
{
case 0x0a:
{
while (StartSwitch)
{
if(bumber3 || bumber4)
{
moveright();
}
else
{
moveDown();
}
}
break;
}
case 0x06:
{
if(bumber1 || bumber2)
{
moveright();
}
else
{
moveUp();
}
}
break;
}
case 0x09:
{
while (StartSwitch)
{
if(bumber3 || bumber4)
{
moveleft();
}
else
{
moveDown();
}
}
break;
}
case 0x05:
{
while(StartSwitch)
{
if(bumber1 || bumber2)
{
moveleft();
}
else
{
moveUp();
}
}
break;
}
default:
{

}
}
}
case: 0x08:
{
while(startswitch)
{
if(UpButton)
{
moveUp();
}
else if(DownButton)
{
moveDown();
}
else if(Leftbutton)
{
moveleft();
}
else if(RightButton)
{
movright();
}
}
}
}
Ttelmah
Guest







PostPosted: Wed May 14, 2008 4:43 am     Reply with quote

Without looking very far. First line in move_Up, you call ValveConR_OFF, but don't have this defined (instead you have the ConL version defined twice....).
Other obvious thing, you are mixing case in some places. Now the default for CCS, is for case significance to be turned off, but if you are compiling in (for example) ANSI mode, then the case becomes important. Your switch/case syntax in the main is completely wrong.
Further comment, you are setting the TRIS registers, but have not selected FAST_IO, so the effects won't be what you expect.

Best Wishes
ckielstra



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

View user's profile Send private message

PostPosted: Wed May 14, 2008 6:15 am     Reply with quote

Besides everything mentioned by Ttelmah:
- Add the NOLVP fuse to make your system more stable (now it will stall at a logic high on the PGM (B3) pin).

Code:
 int count1 = 0;
While(count1 == 2)      <-- this will never be true
mKm
Guest







problem with case?
PostPosted: Wed May 14, 2008 10:05 pm     Reply with quote

Thanks so much for the help. Down from 100 to 4 errors.
For each case statement in my main function, i'm getting the error message 'A numeric expression must appear here'. Any idea what's up?



void main()
{
set_tris_a(0x00);
set_tris_b(0xff);
set_tris_c(0xf0);
set_tris_d(0x0c);
set_tris_e(0x00);
port_a = 0x00;
port_c = 0xf0;
port_d = 0x0c;
port_e = 0x00;
PreSetting();
switch (port_d)
{
case 0X40:
{
switch (port_c)
{
case 0X0a:
{
while (StartSwitch)
{
if(bumper3 || bumper4)
{
moveright();
}
else
{
moveDown();
}
}
break;
}
case 0X06:
{
if(bumper1 || bumper2)
{
moveright();
}
else
{
moveUp();
}
}
break;
}
case 0X09:
{
while (StartSwitch)
{
if(bumper3 || bumper4)
{
moveleft();
}
else
{
moveDown();
}
}
break;
}
case 0X05:
{
while(StartSwitch)
{
if(bumper1 || bumper2)
{
moveleft();
}
else
{
moveUp();
}
}
break;
}
default:
{

}
}
}
case 0X08:
{
while(StartSwitch)
{
if(UpButton)
{
moveUp();
}
else if(DownButton)
{
moveDown();
}
else if(Leftbutton)
{
moveleft();
}
else if(RightButton)
{
moveright();
}
}
}
}
Matro
Guest







PostPosted: Thu May 15, 2008 1:42 am     Reply with quote

In your "case 0x06", you don't have any "while" like in other cases so you have to remove one of the 2 brackets that are just after call to "moveUp()".
After that a bracket will be missing at the end of "main()" to close the function.

Matro
Ttelmah
Guest







PostPosted: Thu May 15, 2008 2:07 am     Reply with quote

As a 'comment', use brackets, and indenting, to help you see how things are laid out (and use the code buttons when posting here so that we can see this). So (for example):
Code:

   switch (something) {

   case xxx :
       //Indent to show that this is for this case
       code here;
       break;

  case yyy:
       //again indent for the case
       switch (something else) {
       
       case aaa :
           code for inner switch;
           break;
       
       case bbb :
           code for next inner switch;
           break;
       
       default:
           default code for inner switch;
           break;

       }//Remark here if you want that this is for the 'something else'
       break;

   case zzz :
       //See how the layout tells you that this is for the first case
       break;

   }//remark here that this is for the 'something' switch.

Done properly, this reduces the probability of getting 'lost' as to which switch/while the brackets etc., refer to.

Best Wishes
mKm
Guest







Thank you
PostPosted: Thu May 15, 2008 2:57 am     Reply with quote

I really appreciate the help guys. The program's finally error-free. Thanks.
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