View previous topic :: View next topic |
Author |
Message |
mKm Guest
|
Urgently need help! Anything wrong with the header file? |
Posted: Wed May 14, 2008 4:20 am |
|
|
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
|
|
Posted: Wed May 14, 2008 4:43 am |
|
|
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
|
|
Posted: Wed May 14, 2008 6:15 am |
|
|
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? |
Posted: Wed May 14, 2008 10:05 pm |
|
|
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
|
|
Posted: Thu May 15, 2008 1:42 am |
|
|
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
|
|
Posted: Thu May 15, 2008 2:07 am |
|
|
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 |
Posted: Thu May 15, 2008 2:57 am |
|
|
I really appreciate the help guys. The program's finally error-free. Thanks. |
|
|
|