PDA

View Full Version : Inicializing to Interrupt World



nuno106
- 22nd November 2015, 19:23
Hello Everyone,

I'm trying to inicialize in programming with interrupts.

I've read lots of posts and try to adapt my way.

Here is my sample code (PIC 16F628A):

Test1:
Pause 500 ' Wait for LCD to startup
Lcdout $FE, 1, "Test" ' Clear LCD screen

Sleep:
TrisB = %01000001
OPTION_REG.7=0
OPTION_REG.6=0 'Trig on falling

INTCON.1 = 0
INTCON.4 = 1

@ SLEEP
@ NOP
@ NOP
PAUSE 500

Lcdout $FE, 1, " Wakeup" ' Clear LCD screen
pause 1500
goto Test1


The program display "Test" and wait. After RB0 interrupt occurs, the display will change to "Wakeup" and after 1,5 sec. it display again "Test" and wait once more for RB0 interrupt.

The interrupt RB0 works fine the first time, but after that enters in sleep mode and never get out of sleep.

Could anyone help me out?

Thanks,
Nuno

mark_s
- 23rd November 2015, 14:54
I think you need to read portb after you awake from sleep to clear the mismatch.

At the top


Dummy var Byte


Place this after your sleep command


Dummy = PORTB

nuno106
- 24th November 2015, 09:05
Hello Mark and thanks for your answer, but it doesn't work...

It happens the same thing, enter the first time, and after that, never enter in sleep again.

I include the "On interrupt goto..." . In this case, the first time it works as expected, but after wakeup the first time, enter in loop in subprogram "Wakeup".

If anyone coul help, i'm lost...

Thanks,
Nuno

mark_s
- 24th November 2015, 16:04
Hi

I dug up some old code I did on a pic16f819. Maybe it will help? I did not see Intcon.7 set in your code?

Place this above your variable declaration


OPTION_REG.6 = 0 'INTERUPT PORTB.0 ON 1 = RISING EDGE 0 = falling
INTCON.4 = 1 'ENABLE RBO INTERUPT


Sleep


SLEEPLOOP:
'OPTION_REG.7 = 0 'ENABLE PULLUP RESISTORS PORTB
INTCON.7 = 1 'ENABLE GLOBLE INTERUPTS
@ SLEEP ;ASSEMBLY SLEEP COMMAND - TURNOFF uP CLOCK

INTCON.7 = 0 'ON INTERUPT DISABLE GLOBLE INTERUPTS
INTCON.1 = 0 'RESET INTERUPT FLAG

Art
- 24th November 2015, 18:00
I don’t know how PBP interrupts work, but yes you do have to clear the interrupt flag.


if INTCON.1 = 1 then ' check if portb.0 interrupt occurred
‘ do the thing you wanted portb.0 interrupt to make happen
INTCON.1 = 0 ' clear portb.0 interrupt flag
endif

This is in a case where the interrupt could have been triggered by more than one event.

nuno106
- 25th November 2015, 11:33
Thanks everyone.

The major problem, was a pull down button RB0, that was not working correctly.

Thanks,
Nuno