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.

16f628 interrupts. how to find out what triggered it.

Status
Not open for further replies.

2camjohn

Member
I am using several interrupt routines in my code for a PIC16f628. They all work fine independantly.

If there are several things that cause interrupts (rbo pin, timer etc) how do i work out what triggered the interrupt?

Is there a register or something that I can test the value of to work this out?

Can someone explain how to do this on a 628.

Cheers
 
2camjohn said:
I am using several interrupt routines in my code for a PIC16f628. They all work fine independantly.

If there are several things that cause interrupts (rbo pin, timer etc) how do i work out what triggered the interrupt?

Is there a register or something that I can test the value of to work this out?

Can someone explain how to do this on a 628.

Cheers

Check the datasheet and application notes, it's all explained - but basically there is a register with flags which tell you what caused the interrupt.
 
Thanks Nigel,

I have read the datasheet several times but I am finding it hard to adapt it to the aplication I am making with the language I am using(basic).

If someone said to me "bit 5 of the cheese register is high when its a timer interrupt, it is low if it is a pin interrupt" i can handle that.
I just find that when I look through the datasheet its all in Double Dutch or something!

I'll have another look through the data sheet and post back here when I think I know what im doing.
 
This is the sort of thing you do:

Code:
                btfsc   PIR1,TMR2IF     ; If Timer 2 caused the interrupt, handle it.
                call    Timer2

This is a section of code out of an interrupt routine, it checks to see if timer2 has caused the interrupt, calling the processing routine if it did, if not it simply carries on. The rest of the interrupt routine obviously saves and restores the various registers.
 
Sorry to keep being a pain Nigel, but my assembly isnt great.


I know btfsc means Bit test, skip if clear.

I assume the first value is the register to test.

What does the other do? Is it the name of the bit in the register?
Have you assigned this to a number for ease of use? or is the bit actually called TMR2IF ? What number bit is this in the register?

I am checking if the bit is clear, so do I just check which register is clear to work out which code to execute?



In my language I just use

Code:
if PIR1.TMR2IF = 0 then

This tests if the TMR2IF'th bit of the PIR1 register is clear? Is that right?

Thanks again
John
 
2camjohn said:
Sorry to keep being a pain Nigel, but my assembly isnt great.


I know btfsc means Bit test, skip if clear.

I assume the first value is the register to test.

What does the other do? Is it the name of the bit in the register?
Have you assigned this to a number for ease of use? or is the bit actually called TMR2IF ? What number bit is this in the register?

All the names are in the include file for the specific PIC, that's what the include file is for. You can check the include file to find what bit it is, or consult the datasheet - you really should consult the datasheet, all the answers are in there.

I am checking if the bit is clear, so do I just check which register is clear to work out which code to execute?



In my language I just use

Code:
if PIR1.TMR2IF = 0 then

This tests if the TMR2IF'th bit of the PIR1 register is clear? Is that right?

I can't comment on your specific language, particularly inside interrupt routines, but that's the right sort of idea.

But again - READ THE DATASHEET - everything is explained there, also learn a reasonable amount of assembler - you can't use a high level language effectively without understanding assembler!.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top