Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hi-Tech C Compiler Error

Status
Not open for further replies.

5uco

Member
Why do I compile a bit of code, get loads of errors, build the same code immediately afterwards, and it builds with no errors?

I can then load that code into a PIC (16F819) and it works OK.

New to Hi-Tech C, or any other C for that matter.

Seem to have seen this referenced on some forum, but there's so many I can't find it again.

Surely if the code is wrong, it's wrong for all eternity?

D.
 
Pommie you have your crystal ball working ? Mine just stopped

Would be nice to see something LOL
 
Lucky it's only your crystal ball not working :)

The code does nothing I know. Deleted most of it, still leaving error.

So, build was OK. Put in the last comment. Build gave error shown. build again, OK.

First time I've used tags. hope it works...

EDIT Start_up line 49, IF on lines 51, 52,

D.


Code:
#include		<htc.h>

__CONFIG(0x3F10);

#define		run_sw		RA1;
#define		dir_sw		RA2;

int		ctr1			=	0;
int		ctr2			=	0;
int		turns		=	0;

char	st_a_ph		=	1;
char	st_b_ph		=	1;

// ******************************************

char	sta_ph_1	=	0x0A;
char	sta_ph_2	=	0x09;
char	sta_ph_3	=	0x05;
char	sta_ph_4	=	0x06;

char	stb_ph_1	=	0xA0;
char	stb_ph_2	=	0x90;
char	stb_ph_3	=	0x50;
char	stb_ph_4	=	0x60;		

// **************************************

char	sta_mask_1	=	0b00000011;
char	sta_mask_2	=	0b00001100;
char	stb_mask_1	=	0b00110000;
char	stb_mask_2	=	0b11000000;

// *********************************************

char	rate		=	0;
char	b_image	=	0;





void	main ()

	{

// set up sfr's here

start_up:

if	(run_sw  ==	0) 	goto	start_up;
if	(run_sw  ==	1)	goto	start_up;

// Comment	
	
	}
 

Attachments

  • HTC error.JPG
    HTC error.JPG
    66 KB · Views: 165
Last edited:
Your #define statements are wrong. #define run_sw RA1; defines run_sw as RA1; (*with* the semicolon) whereas presumably you want it defined just as RA1. #define statements are not terminated with a semicolon but with an end of line (hence the need to put a \ at the end of each line of a multi-line #define).

So
Code:
if	(run_sw  ==	0) 	goto	start_up;
will be translated as
Code:
if	(RA1;  ==	0) 	goto	start_up;

which is incorrect syntax and the errors are pretty much what I'd expect to see from any compiler. This doesn't explain why the compiler appears to compile the program successfully a second time though. A compiler bug perhaps? But it's anyone's guess what code it's producing.
 
Your #define statements are wrong. #define run_sw RA1; defines run_sw as RA1; (*with* the semicolon) whereas presumably you want it defined just as RA1. #define statements are not terminated with a semicolon but with an end of line (hence the need to put a \ at the end of each line of a multi-line #define).

So
Code:
if	(run_sw  ==	0) 	goto	start_up;
will be translated as
Code:
if	(RA1;  ==	0) 	goto	start_up;

which is incorrect syntax and the errors are pretty much what I'd expect to see from any compiler. This doesn't explain why the compiler appears to compile the program successfully a second time though. A compiler bug perhaps? But it's anyone's guess what code it's producing.

Did actually get it sorted, but did not put a \ at end of each line.

Put:

#define run_sw PORTA, 1
#define dir_sw PORTA, 2

That seemed to work OK. But still got errors. So, copied the original, non-truncated, code to Wordpad, created a new project, pasted the text in, and no more errors. At least, not those.

It appears the project got corrupted in some way.

Now been stuffed into a 16F819, and it seems to do what I require.

I will have to look into the \ on the end.

Thank you for the response.

D.
 
The bit about the backslash applies only to multiline defines (that's defines that take several lines). They do not apply in this case, that was just an aside.

R-ing TFM shows PORTA,1 is special compiler syntax for bit 1 of PORTA
**broken link removed**
HI-TECH C Compiler for PIC10/12/16 MCUs v9.80 User Guide
This is non-standard C, so "if (PORTA,1==1)" in standard C will always evaluate TRUE due to the comma operator and 1==1 being always TRUE.
 
Last edited:
Why do I compile a bit of code, get loads of errors, build the same code immediately afterwards, and it builds with no errors?

I can then load that code into a PIC (16F819) and it works OK.

I've seen this with Hi-Tech PIC18 compiler many times. The reason it "works OK" is because I believe it is used previously compiled code (object code) from when you had something that would compile earlier. Because of this problem with the compiler, you should always use the rebuild all button.
 
Thanks for the replys. Will have some more attempts at this stuff later. Due to family issues will have to park Hi-Tech C for a few weeks now ..

D.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top