Help for Start 1st project with HI-TECH C

Embedded Systems Topics
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Help for Start 1st project with HI-TECH C

Post by Nandika » Sat May 12, 2012 2:15 pm

Hi Friends,
I have started to coding with HI-TECH C compiler.I have used MPLAB IDE.
Please,tell
1.Is HI-TECH C a compiler? And,Is MPLAB a IDE?(don't write more,please tell Yes or No ;) )

2.Am i correct that compiler settings in MPLAB?(tell more about this :) )
SetCompiler.PNG
SetCompiler.PNG (23.53 KiB) Viewed 11595 times
3.I coded small project like this.But,Compiler give me "Build Faild" :cry:

Code: Select all

void main(){
	TRISB=0;
	PORTB=0;
	
	do{
		PORTB=~PORTB;
		Delay_ms(500);
		
		}while(1)
		
	}
Build Failed
Build Failed
OutPut.PNG (24.71 KiB) Viewed 11595 times
Please,give me some example code or links.
Fox
Sergeant
Sergeant
Posts: 11
Joined: Fri Jul 22, 2011 9:22 am

Re: Help for Start 1st project with HI-TECH C

Post by Fox » Sat May 12, 2012 4:05 pm

1. Yes and yes
2. Seems correct. Not sure since I normally use C18 compiler.

3. Seems like you didn't include the header file.
Under the projects tab in MPLAB expand your project. Then right click on header files and select "add existing item". Navigate to where you installed your compiler (not sure about hi-tech compiler but for C18, it's C:\Program Files\Microchip\mplabc18\v3.40)
Then there will be a folder full of files with the .h extension( header)
Find the file that says - PIC16F877A.h or something similar and add it. It should compile fine.

Nadeeja.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Help for Start 1st project with HI-TECH C

Post by SemiconductorCat » Sat May 12, 2012 8:05 pm

There is no problem with the include file,

Normally in a IDE we setup include path for give the support to the interlaser

Code: Select all

 and debugger.
Compiler is a very standalone program, it could work without even include path was not set.
Since using it's default include path. I'm pretty sure it's default include path contains "p16F877.h" file

So just include it.
like this:

[code]
#include <16F877.h>
or if you keeping 16F877.h in your project, [when you add it to the project , I think it MPLAB will copy it to
your project working source directory, or pass the include path the the directory, in that case.

Code: Select all

#include "16F877.h"
will work.

So use try the first choice I have given. Then it will search default include directory.
I'm pretty sure you lack this line.

These things are non magic. your compiler is already working. Only thing is when you didn't add that include
file as a project file, the second choice won't work.

Anyway read the manual, manual is not to forcefully to keep in mind like periodic table, it's for reference.
Manual describes how to setup the include path,library path ,linker scripts , templates and etc. When you
got some time read it.


Contaz, your compiler is working fine , otherwise it won't give this error messages like this, note your
simple mistake on ';' thing. After the while.
User avatar
SevenZero
Major
Major
Posts: 263
Joined: Sun Nov 01, 2009 8:37 pm

Re: Help for Start 1st project with HI-TECH C

Post by SevenZero » Sat May 12, 2012 10:31 pm

1.Is HI-TECH C a compiler? And,Is MPLAB a IDE?(don't write more,please tell Yes or No ;) )
Yes
2.Am i correct that compiler settings in MPLAB?(tell more about this :) )
Correct. See Neo's great Microcontroller tutorial How to start with Microcontrollers.
3.I coded small project like this.But,Compiler give me "Build Faild" :cry:
Two problems.
1. You need to put, #include <pic.h>. In some HI-TECH compilers, you need to use #include <htc.h> instead.
2. Loop has a syntax error. You need to put a semicolon after while(1).

Your corrected code will look like below.

Code: Select all

#include <pic.h>

void main(){

	TRISB = 0;
	PORTB = 0;

	do{
		PORTB = ~PORTB;
		Delay_ms(500);
	} while(1);
}
Please note that I hate to see codes with bad indents (correct tabs). So please be kind enough to maintain indents correctly as pasted in my code.
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: Help for Start 1st project with HI-TECH C

Post by Nandika » Sun May 13, 2012 9:50 am

Fox,SemiconducterCat and ZevenZero,thanks all for help me... :D :D :D

According to Fox said,I could found .h folder of HI-TECH C Compiler.In my machine,path of it is "C:\Program Files\HI-TECH Software\PICC\9.70\include".This folder has lot of header files(189) and one text file(readme.exe).
But,pic16f877a.h or pic16f877.h not exist. :(
in readme.txt has this text.

Code: Select all

PLEASE NOTE: 
	Some devices share the same header file, therefore you will not find 
	one header file per device. 
	You need only to include HTC.H in order to get the Special Function
	Register (SFR) definitions. The HTC.H header file will automatically
	include the header file for the device you have selected.


[/color]
Therefore,I included htc.h file for my project.But,Now has other Error in building.
ErrorInDelay.PNG
ErrorInDelay.PNG (68.37 KiB) Viewed 11569 times
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Help for Start 1st project with HI-TECH C

Post by SemiconductorCat » Sun May 13, 2012 10:12 am

It's not pic16F877.h it's "16F877.h

But Use htc.h as sevenzero told.
And sounds like Delay_ms() is a macro, and that macro needs you to define your oscillator
frequency.

Code: Select all

#define FCY     40000000UL
correct value may depend on your crystal , I have configured it for 4MHz.

Since htc.h or pic.h are general include files you need to say your crystal frequency
in order to generate that macro.Otherwise it will be a undef.



EDIT: Ops you're using lite edition right. I think you need to do a helder file injection in
this case. Dig this http://www.edaboard.com/thread210298-2.html , sounds like you
need to write your own.

And sevenzero, are you on complete version of Hi-TEch c , can upload the delay.h ?
Last edited by SemiconductorCat on Sun May 13, 2012 10:29 am, edited 1 time in total.
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: Help for Start 1st project with HI-TECH C

Post by Nandika » Sun May 13, 2012 10:23 am

SemiconductorCat wrote:And sounds like Delay_ms() is a macro, and that macro needs you to define your oscillator
frequency.
How am I define my oscillator frequency?
I included your code like this.But,Not change...

Code: Select all

#include "pic.h"
#define FCY     40000000UL

void main(){
	TRISB=0;
	PORTB=0;
	
	do{
		PORTB=~PORTB;
		Delay_ms(500);
	}while(1);
		
}

however,How am i use this Library function in my code?
is library function equal to macro?
User avatar
SevenZero
Major
Major
Posts: 263
Joined: Sun Nov 01, 2009 8:37 pm

Re: Help for Start 1st project with HI-TECH C

Post by SevenZero » Sun May 13, 2012 10:31 am

I asked you to go though Neo's How to start with Microcontrollers tutorial. Everything you need is there.

You need to make those delay files and include the delay.h.

Within delay.h, notice #define PIC_CLK 4000000 //4Mhz. That's it!
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Help for Start 1st project with HI-TECH C

Post by SemiconductorCat » Sun May 13, 2012 10:33 am

Try define FCY thing above the include.

To answer your question about macros , you need to turn a C++ book up and read a chapter about
Preprocessor. Functions or inlines are better than macros. But still we can't live without preprocessor.
It's not possible to live without preprocessor.

But I think here the real problem is the lack of delay.h in your lite edition. I think sevenzero could post
his one. So you could do this injection.



EDIT: Neo have that already, Yes add that delay.c and delay.h to your project as neo told.
So sounds like we all using lite edition right !
User avatar
SevenZero
Major
Major
Posts: 263
Joined: Sun Nov 01, 2009 8:37 pm

Re: Help for Start 1st project with HI-TECH C

Post by SevenZero » Sun May 13, 2012 11:30 am

Try define FCY thing above the include.
Nothing like this for HI-TECH C. Semi.. is messed up with another compiler.
macros
That's nothing complicated.
#define ADD(A, B, R) R = A + B;

So if you call ADD(5,3,ret), precompiler will replace that line with ret = 5 + 3; before compilation. That's simple as that.
But I think here the real problem is the lack of delay.h in your lite edition. I think sevenzero could post his one. So you could do this injection.
There isn't any delay thing built-in to HI_TECH C. You need to write something by your own or else found someone else's.
EDIT: Neo have that already, Yes add that delay.c and delay.h to your project as neo told.
So sounds like we all using lite edition right !
No. It's not because of Lite Edition thing. You will find a delay under samples in Standard Edition but it is completely different to what Neo has added. So it is that you need to write what you need as you need with HI-TECH C. Nothing built-in including the processor definition file.
Post Reply

Return to “Embedded Systems”