Autor Tema: Problemas con programa cronometro descendente.  (Leído 2439 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado melectro

  • PIC10
  • *
  • Mensajes: 21
Problemas con programa cronometro descendente.
« en: 03 de Julio de 2008, 14:36:29 »
Hola a todos.Soy relativamente nuevo en el tema PIC , pero llevo un rato con la electronica ,hice algunos programas en PBP pero se me produjo un lio en un punto y no puedo salir. rebotando
Estoy tratando con PBP de hacer un cronometro descendente (fijar un numero determinado y despues de pasAdo ese tiempo emita un "1" en una salida de un 16F84.
Seria asi con dos pulsadores selecciono el numero ej. 3456 (max 9999) ajusto con uno sube y otro baja.Otro pulsador seria el ENTER .Con otra entrada se dispara y comienza la cuenta regresiva.Llegado ese punto una salida del pic cambia a 1.
Presentar todo en un LCD de una linea por 16 digitos.
Tengo que repetir lo mimo cuatro veces , es decir , cuatro opciones de tiempos y los tiempos son modo1 = 9999 Ms (milisegundos)
Modo 2 99.99 Ms Milisegundos.Modo 3 9999 segundos y un ultimo modo en MM y SS minutos y segundos 99 y 99 respectivamente.
Trate de usar un 16F84 pero no me alcanza para tanto codigo , creo que un 16F628A estaria bien , pero ...... no se como implementarlo para los tres primeros modos y de ultima el cuarto no lo pongo.

Mi codigo es:(funciona solo para un modo y creo que se puede optimizar bastante.

'****************************************************************
'*  Name    : Melectro                                     *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 06/07/2006                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :  16F648    .                                           *
'****************************************************************

'MODO 1 EN mS 9999
'MODO 2 EN mS 999.9
'MODO 3 EN SEG 9999
'MODO 4 REPETICION DE N VECES POR XXXX mS.
' 60.000 mS = 1 MINUTO             
' 1.000 uS = 1 SEG.               
'10.000 SEG =                 
               
               
    'DEFINICION DE PINES
    'PORTB.4 = SALIDA  1 MAS SALIDA SONORA BEEP
    'PORTB.5 = DIGITO
    'PORTB.6 = POSICION U, D , C ,UM.  MODO MODO1 , ...  MODO4.
    'PORTB.7 = START o ENTER
    'PORTB.2 = ENTRADA
    'PORTA.0-4 = LCD
    'PORTB.3 = LCD
    'PORTB.4 = SALIDA
    'PORTB.1 = VER DISPARO LED           
               
                define LCD_BITS 4
                define LCD_LINES 2
                U VAR BYTE   ;unidad modo 1
                U2 VAR BYTE  ;unidad modo 2
                U3 VAR BYTE  ;unidad modo 3
                U4 VAR BYTE  ;unidad modo 4
                D VAR BYTE  ;decena 1
                D2 VAR BYTE  ;decena 2
                D3 VAR BYTE  ;decena 3
                D4 VAR BYTE  ;decena 4
                C VAR BYTE  ;centena 1
                C2 VAR BYTE  ;centena 2
                C3 VAR BYTE  ;centena 3
                C4 VAR BYTE  ;centena 4
                UM VAR BYTE ; unidad de mil 1 9999 ms.total 10.000 ms  = 10 seg.
                UM2 VAR BYTE ; unidad de mil 2 9999 ms.total 10.000 ms  = 10 seg.
                UM3 VAR BYTE ; unidad de mil 3 9999 ms.total 10.000 ms  = 10 seg.
                UM4 VAR BYTE ; unidad de mil 4 9999 ms.total 10.000 ms  = 10 seg.
                co VAR  BYTE ;  variable selecciona  numero , unid dec cent um .
                cur VAR BYTE 'VARIABLE SELECCIONA MODO1.
                cur2 VAR BYTE 'VARIABLE SELECCIONA MODO2.
                cur3 VAR BYTE 'VARIABLE SELECCIONA MODO3.
                cur4 VAR BYTE 'VARIABLE SELECCIONA MODO4.
                ST var byte
                mode var byte
                mode2 var byte
                mode3 var byte
                t1 var word
                t2 var byte
                t3 var byte
                t4 var byte
                W0 var word
            U = 0  :  D = 0 : c = 0 : UM = 0
            co = 0 : cur = 0 :cur2 = 0:cur3 = 0 : cur4 = 0
            PAUSE 500
            lcdout $fe,1,"Melectro" , $fe,$c0 ,"Photo 06"
            PAUSE 1500
            Lcdout $fe, 1 , " Modo 1 "
            pause 1000
modo:            if portb.6 = 0 then  ; SELECCIONA MODO
            select case mode
            mode = mode + 1
            if  mode > 3 then mode = 1
           
            case 1: call curs
            case 2: call curs2
            case 3: call curs3
            end select
            endif
            goto modo
           
                             

;        ****************** MODO 1 ***************************
                   
   curs:           cur = cur + 1
                if cur > 4 then cur = 1
                if cur = 1 then call inicio_u
                if cur = 2 then call inicio_d
                if cur = 3 then call inicio_c
                if cur = 4 then call inicio_um           
                goto  curs
                return
               
INICIO_U:
Lcdout $fe,1," Unid",$fe,$c0,#uM,$fe,$c1,#C,$fe,$c2,#D,$fe,$c3,#U," MS"
            pause 250
            if portb.7 = 0 then call start
            if portb.6 = 0 then call curs
            IF PORTB.5 = 0 AND  cur = 1 THEN
                                     
     
            U = U + 1
            IF U > 9 THEN U = 0
            endif           
            GOTO INICIO_U     
            RETURN
           
            INICIO_D:
Lcdout $fe,1,"  Dec",$fe,$c0,#uM,$fe,$c1,#C,$fe,$c2,#D,$fe,$c3,#U," MS"
            pause 250
            if portb.7 = 0 then call start
            if portb.6 = 0 then call curs
            IF PORTB.5 = 0 AND  cur = 2 THEN
                             
            D = D + 1
            IF D > 9 THEN D = 0
            endif           
            GOTO INICIO_D     
            RETURN
           
            INICIO_C:
Lcdout $fe,1,"  cen",$fe,$c0,#uM,$fe,$c1,#C,$fe,$c2,#D,$fe,$c3,#U," MS"
            pause 250
            if portb.7 = 0 then call start
            if portb.6 = 0 then call curs
            IF PORTB.5 = 0 AND  cur = 3 THEN
                   
            C = C + 1
            IF C > 9 THEN C = 0
            endif           
            GOTO INICIO_C     
            RETURN
           
            INICIO_UM:
Lcdout $fe,1,"Umil",$fe,$c0,#uM,$fe,$c1,#C,$fe,$c2,#D,$fe,$c3,#U," MS"
            pause 250
            if portb.7 = 0 then call start
            if portb.6 = 0 then call curs
            IF PORTB.5 = 0 AND  cur = 4 THEN
           
                   
            Um = Um + 1
            IF Um > 9 THEN Um = 0
            endif           
            GOTO INICIO_Um     
            RETURN
           
           
start:       
            lcdout $fe,1," ",#UM,#C,#D,#U ," MS"
            pause 100

            Pulsin portb.2,0,W0               
            If W0 <> 0 Then disparo           
            goto start
                       
                     
disparo:    low portb.4   :lcdout $fe,1," ",#UM,#C,#D,#U ," MS" ,$fe,$C0," INICIO"
            T1 = (UM*1000+c*100+d*10+u)
            pause  T1
            high portb.4
            pause 100
            low portb.4 :low portb.1
            return

            U2 = 0  :  D2 = 0 : c2 = 0 : UM2 = 0
              cur2 = 0:cur3 = 0 : cur4 = 0
            lcdout $fe,1
            PAUSE 500
            lcdout $fe,1,"Melectro" , $fe,$c0 ,"  08"
            PAUSE 1500
            Lcdout $fe, 1 , " Modo 2 "
            pause 1000

           
                   
   curs2:           cur2 = cur2 + 1
                if cur2 > 4 then cur2 = 1

                if cur2 = 1 then call inicio_u2
                if cur2 = 2 then call inicio_d2
                if cur2 = 3 then call inicio_c2
                if cur2 = 4 then call inicio_um2           
                goto  curs2
                return
                   
INICIO_U2:
Lcdout $fe,1,"Decimal",$fe,$c0,#uM2,$fe,$c1,#C2,$fe,$c2,#D2,$fe,$c3,".",#U2," MS"
            pause 250
            if portb.7 = 0 then call start2
            if portb.6 = 0 then call curs2
            IF PORTB.5 = 0 AND  cur2 = 1 THEN
                                     
     
            U2 = U2 + 1
            IF U2 > 9 THEN U2 = 0
            endif           
            GOTO INICIO_U2     
            RETURN
           
            INICIO_D2:
Lcdout $fe,1,"  Uni",$fe,$c0,#uM2,$fe,$c1,#C2,$fe,$c2,#D2,$fe,$c3,".",#U2," MS"
            pause 250
            if portb.7 = 0 then call start2
            if portb.6 = 0 then call curs2
            IF PORTB.5 = 0 AND  cur2 = 2 THEN
                             
            D2 = D2 + 1     
            IF D2 > 9 THEN D2 = 0
            endif           
            GOTO INICIO_D2     
            RETURN
           
            INICIO_C2:
Lcdout $fe,1,"  Dec",$fe,$c0,#uM2,$fe,$c1,#C2,$fe,$c2,#D2,$fe,$c3,".",#U2," MS"
            pause 250
            if portb.7 = 0 then call start2
            if portb.6 = 0 then call curs2
            IF PORTB.5 = 0 AND  cur2 = 3 THEN
                   
            C2 = C2 + 1
            IF C2 > 9 THEN C2 = 0
            endif           
            GOTO INICIO_C2     
            RETURN
           
            INICIO_UM2:
Lcdout $fe,1,"  Cen",$fe,$c0,#uM2,$fe,$c1,#C2,$fe,$c2,#D2,$fe,$c3,".",#U2," MS"
            pause 250
            if portb.7 = 0 then call start2
            if portb.6 = 0 then call curs2
            IF PORTB.5 = 0 AND  cur2 = 4 THEN
           
                   
            Um2 = Um2 + 1
            IF Um2 > 9 THEN Um2 = 0
            endif           
            GOTO INICIO_Um2     
            RETURN
           
           
start2:       
            lcdout $fe,1,#UM2,#C2,#D2,".",#U2 ," MS"
            pause 100

            Pulsin portb.2,0,W0                 
            If W0 <> 0 Then disparo2           
            goto start2
                       
                     
disparo2:   low portb.4   
            lcdout $fe,1,#UM2,#C2,#D2,".",#U2 ," MS" ,$fe,$C0," INICIO"
            T1 = (UM2*1000+c2*100+d2*10+u2)/10
            pause  T1
            high portb.4
            pause 100
            low portb.4 :low portb.1
            return
            end
'********************      MODO 3         ***********************
            lcdout $fe,1
            PAUSE 500
            lcdout $fe,1,"Melectro" , $fe,$c0 ,"  08"
            PAUSE 1500
            Lcdout $fe, 1 , " Modo 3 "
            pause 1000


               
   curs3:           cur3 = cur3 + 1
                if cur3 > 4 then cur3 = 1
                if cur3 = 1 then call inicio_u3
                if cur3 = 2 then call inicio_d3
                if cur3 = 3 then call inicio_c3
                if cur3 = 4 then call inicio_um3           
                goto  curs3
                return
                   
INICIO_U3:
Lcdout $fe,1,"  Uni",$fe,$c0,#uM3,$fe,$c1,#C3,$fe,$c2,#D3,$fe,$c3,#U3," Seg"
            pause 250
            if portb.7 = 0 then call start3
            if portb.6 = 0 then call curs3
            IF PORTB.5 = 0 AND  cur3 = 1 THEN
                                     
     
            U3 = U3 + 1
            IF U3 > 9 THEN U3 = 0
            endif           
            GOTO INICIO_U3     
            RETURN
           
            INICIO_D3:
Lcdout $fe,1,"  Dec",$fe,$c0,#uM3,$fe,$c1,#C3,$fe,$c2,#D3,$fe,$c3,#U3," Seg"
            pause 250
            if portb.7 = 0 then call start3
            if portb.6 = 0 then call curs3
            IF PORTB.5 = 0 AND  cur3 = 2 THEN
                             
            D3 = D3 + 1     
            IF D3 > 9 THEN D3 = 0
            endif           
            GOTO INICIO_D3     
            RETURN
           
            INICIO_C3:
Lcdout $fe,1,"  Cen",$fe,$c0,#uM3,$fe,$c1,#C3,$fe,$c2,#D3,$fe,$c3,#U3," Seg"
            pause 250
            if portb.7 = 0 then call start3
            if portb.6 = 0 then call curs3
            IF PORTB.5 = 0 AND  cur3 = 3 THEN
                   
            C3 = C3 + 1
            IF C3 > 9 THEN C3 = 0
            endif           
            GOTO INICIO_C3     
            RETURN
           
            INICIO_UM3:
Lcdout $fe,1,"Umil",$fe,$c0,#uM3,$fe,$c1,#C3,$fe,$c2,#D3,$fe,$c3,#U3," Seg"
            pause 250
            if portb.7 = 0 then call start3
            if portb.6 = 0 then call curs3
            IF PORTB.5 = 0 AND  cur3 = 4 THEN
           
                   
            Um3 = Um3 + 1
            IF Um3 > 9 THEN Um3 = 0
            endif           
            GOTO INICIO_Um3     
            RETURN
           
           
start3:       
            lcdout $fe,1,#UM3,#C3,#D3,#U3 ," Seg"
            pause 100

            Pulsin portb.2,0,W0                 
            If W0 <> 0 Then disparo3           
            goto start3
                       
                     
disparo3:   low portb.4   
            lcdout $fe,1,#UM3,#C3,#D3,#U3 ," Seg" ,$fe,$C0," INICIO"
            T1 = (UM3*1000+c3*100+d3*10+u3)* 1000
            pause  T1
            high portb.4
            pause 100
            low portb.4 :low portb.1
            return
            end

           
Se me ocurre que como se repite todo 3 veces y solo cambia la salida , se podria implemetar una rutina para llegar al numero t despues seleccionar el tipo de salida .si es 9999 Ms o seg etc , pero no se como implementarlo.


Agradeceria cualquier ayuda u orientacion posible.

Saludos.
Jorge.