PIC16F877A Timer2 interrupt

Thread Starter

dragu_stelian

Joined Mar 18, 2017
6
Hello !
I really need help.
I am new to PIC. So i have been using pic16F877A microcontroller.
I have the next code and i get the next error:
Can't open include file "16F877A.h": No such file or directory
I don't find the 16F877A.h header file.
I am using Mplab IDE and HI-TECH compliler.
On C drive ("C:\Program Files (x86)\HI-TECH Software\PICC\9.83\include") into include folder i found
as16f877a.h header file.
Please help me!
Thank you!

C:
#include <16F877A.h>
#use delay(crystal=4000000)

byte i;
#INT_TIMER2
void timer2_isr(void)
{
   clear_interrupt(INT_TIMER2);
   i++;
   if(i > 9)
   {
   i = 0;
   output_toggle(PIN_B0);
   }
}
void main()
{
   setup_timer_2 (T2_DIV_BY_16, 0xF0, 13 );  // Timer2 prescaler 16,
                                             // Preload value 0xF0, postoscaler 13
   clear_interrupt(INT_TIMER2);              // Clear Timer2 interrupt flag bit
   enable_interrupts(INT_TIMER2);            // Enable Timer2 interrupt
   enable_interrupts(GLOBAL);
   output_low(PIN_B0);

   while(TRUE) ; // Endless loop
}
Moderators note: used code tags
 
Last edited by a moderator:

Thread Starter

dragu_stelian

Joined Mar 18, 2017
6
16F877a.inc is included with the MPLAB IDE on installation.
Did you search the Microchip directory?
Max.
Now I have searched into the Microchip directory but I did not found the file 16F877a.inc.
But I found a file 16f877a.cgen.inc into Microchip\xc8\v1.41\include.
Can you be more specific please, where in the Microchip directory, and what do I have to do to not use that file.
Thank you for your help!
 

MaxHeadRoom

Joined Jul 18, 2013
28,686
When you install MPLB all INC files are loaded into C:\program files\microchip\MPASM suite\
I don't use C so I am not sure how you would use it in C?
Max.
 

spinnaker

Joined Oct 29, 2009
7,830
Search for a file something like p16cxxx.h

If memory serves that is the include file that you use for HTC and then the compiler figures it out for you.

For example I have some old source I am pretty sure is HTC and I have

#include <p18cxxx.h> in my code.
 

JohnInTX

Joined Jun 26, 2012
4,787
You are programming in C so you want a .h file, not a .inc. .h files are written for the C compiler syntax.
In your project, make sure that the paths are set up to find the include directory for the compiler.
You might try expressing the filename exactly, case included. I have seen versions of PICC-18 where it makes a difference. I don't know about yours but it is an easy one to try.
Open the as16f877a.h file and see if it looks like C instead of assembler. If it does, use that.
If you find the file, you can put it in your source directory and specify it using quotes to avoid path issues.
Good luck.

Edit while typing: I agree with spinnaker, if you are starting out, why not use current stuff? MPLABX and XC8 is free. You'll get better support since many of us have moved on from HiTech to XC.

As far as the code is concerned, I don't see any IO port initialization nor a setting for PR2. CONFIG fuses also must be set correctly if you are running this on an actual chip instead of MPSIM.
 
Last edited:

Thread Starter

dragu_stelian

Joined Mar 18, 2017
6
You are programming in C so you want a .h file, not a .inc. .h files are written for the C compiler syntax.
In your project, make sure that the paths are set up to find the include directory for the compiler.
You might try expressing the filename exactly, case included. I have seen versions of PICC-18 where it makes a difference. I don't know about yours but it is an easy one to try.
Open the as16f877a.h file and see if it looks like C instead of assembler. If it does, use that.
If you find the file, you can put it in your source directory and specify it using quotes to avoid path issues.
Good luck.

Edit while typing: I agree with spinnaker, if you are starting out, why not use current stuff? MPLABX and XC8 is free. You'll get better support since many of us have moved on from HiTech to XC.

As far as the code is concerned, I don't see any IO port initialization nor a setting for PR2. CONFIG fuses also must be set correctly if you are running this on an actual chip instead of MPSIM.



Thank you for your time JohnInTX.
I tried all you said about the as16f877a.h file, does not work, but I have installed the CCS C Compiler and works fine.
I will try the project using MPLABX and XC8.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
I will try the project using MPLABX and XC8.
That would be a good use of your time. Lots of us here use XC8 (and MikroC to a lesser extent). For getting started, I would recommend XC8.

When you create your .C source, you don't need to worry about the processor includes. All you have to include is the file xc.h - the compiler will figure out what you need from there. Nice.
C:
#include <xc.h>  // done!
 
Last edited:
Top