Hi, I have a problem with the return from a subrutine. It works fine but It takes aprox. 20sec. I don't if it's a software or hardware problem.
I have all unused input pins tied to groun and the ones I'm using have a pull up resistor.
Here is the code
define osc 4
TRISA = %00010000
TRISB = %10001111
intcon = 0
clear
num var byte
x var word
pulsos var byte
cuenta var byte
velocidad var word
circunferencia var byte
demora var byte
t1 var portb.4
t2 var portb.5
t3 var portb.6
timer con 9
data @0, 1
goto start
on interrupt goto tiempo
start:
OPTION_REG = %10000111
INTCON = %10100000
read 0, circunferencia
goto main
main:
if portb.3 = 0 then gosub setup
if intcon.1 = 1 then
pulsos = pulsos + 1
intcon.1 = 0 ; pongo a 0 el flag de la interrupcion en Rb0
endif
if cuenta = 4 then
cuenta = 0
velocidad = pulsos * circunferencia * 100 ; *100 para dividir por .25seg que esta multi * 100 para pasarlo a 250
velocidad = velocidad / 25 ; dividio .25seg por 100
velocidad = velocidad * 36 ; 3600seg / 1000metros = 3.6 const para convertir a k/h * 10 para poder trabajarlo
velocidad = velocidad / 400 ; velocidad /10 por multiplicar 3.6 *10 y /4 ya que tengo .25 segundos (1/4seg) velo/10/40 = velo/40
x = velocidad
pulsos = 0
endif
gosub display
goto main
display:
num = x dig 0 ; unidad de X y lo manda a num
porta = num
high t1
pause 1
pause 1
pause 1
low t1
num = x dig 1 ; decena de X y lo manda a num
porta = num
high t2
pause 1
pause 1
pause 1
low t2
num = x dig 2 ; centena de X y lo manda a num
porta = num
high t3
pause 1
pause 1
pause 1
low t3
return
setup: ; entra en la configuracion de la circunferencia
disable
if portb.2 = 0 then
return ; HERE IS THE PROBLEM IT TAKES 20 SECONDS TO RETURN
enable
endif
x = circunferencia
for demora = 1 to 20
gosub display
next
if portb.3 = 0 then
circunferencia = circunferencia + 1
if circunferencia = 216 then circunferencia = 0
endif
goto setup
disable
tiempo:
cuenta = cuenta + 1
TMR0 = timer
INTCON.2 = 0
resume
enable
Bookmarks