AT89s52 para medicon ultrasonica

Aca les paso el fuente del programa que hice
Código:
$crystal = 12000000
Declare Sub Pulseint (v As Integer)
Declare Sub Pulseout (v As Integer)

Dim V As Integer
Dim W1 As Single
Dim W2 As Single

P0 = 0
P1 = 0
P2 = 0
P3 = 0
Cls
Do

   Call Pulseout(v)
   Call Pulseint(v)

   Locate 1 , 1
   Lcd "V=" ; V
   W1 = 2 * V
   W2 = W1 / 115
   Locate 2 , 1
   Lcd W2 ; " cm"
Loop
End

Sub Pulseout (v As Integer)
   Config Timer0 = Timer , Gate = Internal , Mode = 1
   On Timer0 Timer_0_int
   Mov tl0,#251
   Mov th0,#255
   Enable Interrupts
   Enable Timer0
   Start Timer0
   P0.2 = 1
   Inicio:
   Goto Inicio
   Timer_0_int:
   P0.2 = 0
End Sub


Sub Pulseint (v As Integer)

      Config Timer0 = Timer , Gate = External , Mode = 1
      On Timer0 Timer_0_int1
      Mov tl0,#0
      Mov th0,#0
      Enable Interrupts
      Enable Timer0
      P0.2 = 0
      Inicio1:
      If P0.2 = 0 Then Goto Pasa
      Goto Inicio1
      Pasa:
      If P0.2 = 1 Then Goto Medir
      Goto Pasa
      Medir:
      Start Timer0
      Salto:
      If P0.2 = 0 Then Goto Enviar
      Goto Salto
      Enviar:
      Stop Timer0
      V = Th0 * 256
      V = V + Tl0
      'Print V ; "us"
      'W1 = 2 * V
      'W2 = W1 / 115
      'Print W2 ; "ms"
      Mov tl0,#0
      Mov th0,#0
      Wait 1
      Goto Salida
      Timer_0_int1:
      Print "error"
      Salida:
End Sub
el problema que tengo es que en Pulseout, después que inicializlo los Th0 y Ti0, cuando entea el el loop de inicio, se pierden los valores de los registros y se queda ahí indefinidamente.
 
Última edición por un moderador:
Atrás
Arriba