PDA

View Full Version : problem with asm interrupt



servo260
- 20th December 2004, 00:22
Hi,

I'm trying to use asm interrupts in pbp but I have the following problem:

the interrupt works fine, but the main program works at "half" if that makes sense, it only run a part of the main program while doing the interrupt.

here is the simple code i'm using to test it:

define osc 20


clear

pulsos var word

x var word

num var byte

wsave var byte $20 system
ssave var byte bank0 system
psave var byte bank0 system



TRISA = %11111111 ; configura el puerto A como salida

TRISB = %10000000 ; configura los puertos B0-6 como salida



goto start ; salta al programa principal antes que la interrupcion



define INTHAND display ; indica cual es la interrupcion







start:

option_reg = %00000111

intcon = %10100000


main:

x = 123

pause 500

x = 321

pause 500

goto main


asm
display movwf wsave ; display rutine
swapf STATUS, W
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave
endasm

num = x dig 0

portb = num

high portb.4

pauseus 50

low portb.4

num = x dig 1

portb = num

high portb.5

pauseus 50

low portb.5

num = x dig 2

portb = num

high portb.6

pauseus 50

low portb.6

asm
bcf INTCON, 1

movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W

retfie
endasm


the problem is I only get to see the 123.



If someone knows how to solve this please help me.

Thanks.

servo260
- 20th December 2004, 02:31
I have change the bcf INTCON.1 to INCON.2 but it is still not working.

Bruce
- 20th December 2004, 05:11
At 20MHz with a TMR0 prescaler of 1:256 you only have 13mS before TOIF will be set again, and generate the next interrupt.

You're using 500mS delays in main with a 13mS TMR0 interrupt time. Try a delay time shorter than your interrupt time, or save & restore the registers used to hold the delay value, or insert your long delay within the body of the interrupt routine.

You can delay inside the interrupt routine as long as you like before the RETFIE, but I would reload TMR0 with 0 before resetting TOIF.

servo260
- 20th December 2004, 08:16
Thanks, though, it is still not eorking.
How do I save & restore the registers used to hold the delay value? ; what do I have to save in order to continue whatever thing the program was doing?

I'm new with pics and pbp.

Ingvar
- 20th December 2004, 10:04
You're using Basic statements in your Assembler interrupt. That's a big nono unless you save and restore PBPs workingregisters. Looking at the compiled code it seems that R0 through 3 is used. Try adding ......

r0save = R0
r1save = R1
r2save = R2
r3save = R3

...... directly after your first ASM block, and ........

R0 = r0save
R1 = r1save
R2 = r2save
R3 = r3save

.... right before your second ASM block.

You should also declare your new variables at the top of your program .......

r0save VAR WORD bank0
r1save VAR WORD bank0
r2save VAR WORD bank0
r3save VAR WORD bank0

/Ingvar

servo260
- 20th December 2004, 17:02
Thanks, everithing is working fine.