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.

PIC18 C Code for Dragonfly

Status
Not open for further replies.

ThiSel

New Member
Hi Guys,

Has anyone written code with interrupt vectors for PIC18 series with C18?

I am trying to make a timer overflow in Bill's Dragonfly kit.

The code I have is this:

OpenTimer0(
TIMER_INT_ON &
T0_8BIT &
T0_SOURCE_EXT &
T0_PS_1_16);

#pragma interrupt TimerOverflow
void TimerOverflow()
{
...

Not sure how to enable GIE and the Timer interrupt. It's not documented in the Microchip C18 manual (maybe I'm not looking properly)

So far, I'm running on the debugger and the function never gets fired!

Thanks guys!
 
You have to set the INTCON bits GIE and T0IE, can't recall of the top of my head but you may also have to set PIE.
Don't forget to clear the T0IF flag before you exit the interrupt routine. GIE will be set automatically with a RETFIE instruction, not sure how C handles it.
 
Also, TIMER0 is configured as a counter: T0_SOURCE_EXT choose an external clock as trigger. If you're using TMR0 as a timer, use T0_SOURCE_INT instead.

TMR0 interrupts are enabled by TIMER_INT_ON (the GIE bit must be set, as suggested).

Personally I don't use that function to configure timers, but it's described in the C18 C Compiler Libraries guide, not in the manual of the compiler.
 
Yep, I'm using a 18F2525.

I Have used Hi-Tech C before and I know how to set it from code there. But for Microchip C18, cant seem to be able to locate it.

Most of the reference out there is on Hi-tech C.
 
Setting up the interrupt vector using C18 is not very intuitive. There is an example in the accompanying documentation but it's easy to miss.

Mike (Pommie) was kind enough to provide an example in the following thread (a little further down on the first page of the thread).

Junebug Servo C18 code.

Kind regards, Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top