1

For the life of me I can't make a timer for PIC18 or precisely PIC18f87j11. All I want to do is to have a counter that increments every 1 second. I just want to monitor how long PIC18 been running in terms of seconds.

Most of the tutorials out there are for PIC16 and are in assembly. I am trying to do this using C programming. For someone who is beginner I understand better if I see examples, so without examples I can't progress.

please someone show me an example, thank you!

Ammar
  • 1,203
  • 5
  • 27
  • 64

2 Answers2

1

To begin understanding timers you will need to have a look at their documentation. I suggest searching the manufacturers website. There are 5 timer available. If you use Timer0 which is either a 8 bit or 16bit timer. You will need to set the correct configuration for T0CON. Also you will need to have correct interrupt settings (INTCONbits), so a an event can be generated by interrupt service routine once timer expired.

You will most likely need to calculate the prescale value you require for correct timing, in your case 1 second. It does depend on FOsc: Here is a tutorial Here an example of C code using MPLab and another one based on MPLab and hi-tech compiler. It is not for same chip, however it is based on PIC18F family.

It's been a awhile since I have visited PIC18F, so if any correction required, please do so.

shobhonk
  • 621
  • 5
  • 15
0

If you use HIGH-TECH compiler, you can simply use its special function for close, open, read and write timers modules in below directory:

...\HI-TECH Software\PICC-18\9.80\sources\plib\Timers According to your microcontroller name, you can figure out which version of these function is written for your microcontroller. So for first step, open pconfig.h file and search your microcontroller name to see for every module which version is fit to your microcontroller registers. Good Luck

mahtab
  • 79
  • 1
  • 6