Autor Tema: Guardar datos en programa en medio de ejecucion Pic 16f84A  (Leído 3176 veces)

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

Desconectado Vangeluz

  • PIC12
  • **
  • Mensajes: 74
    • Vangeluzweb
Guardar datos en programa en medio de ejecucion Pic 16f84A
« en: 28 de Junio de 2012, 02:13:27 »
Hola, que tal, quisiera que me den algun ejemplo, de como agregar datos en medio de ejecucion.

por ejemplo:

Manejar 2 digitos 7 segmentos en cuenta regresiva de 99 a 0, y por medio de 1 pulsador, entrar en un menu 5 memorias programables, en

las cuales pueda poner 5 tiempos definidos para comenzar la cuenta regresiva, ( siempre en modo de ejecucion ) por ejemplo 10, 20, 30, 40,

50.

Osea, al correr el programa, las 5 memorias estan a 0, y en modo de ejecucion ir agregando los valores, ( por supuesto con sus respectivos

pulsadores necesarios ).

Partiendo de algo simple con un contador 7 segmentos seria el siguiente ejemplo de contador ascendente con 1 pulsador.

Código: ASM
  1. list p=16F84A
  2. #include P16F84A.inc
  3. __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
  4.  
  5. ;**** Definicion de variables ****
  6.  
  7. Contador   equ      0x0C   ; Registro para almacenar conteo
  8. Contador1   equ      0x0D   ; Registro utilizado en demora.-
  9. Contador2   equ      0x0E   ; Registro utilizado en demora.-
  10. Pulsador   equ      7   ; Definimos Pulsador como el bit 7, en este caso sera para PORTB
  11.  
  12. ;**** Inicio  del Micro ****
  13.  
  14. Reset      org      0x00      ; Aqui comienza el micro.-  
  15.          goto   Inicio      ; Salto a inicio de mi programa.-          
  16.  
  17. ;**** Tabla de conversion BCD a 7 Segmentos ****
  18.  
  19. ; Se coloca al inicio para asegurar ubicacion en Pagina.-  
  20.       org   0x05      ; Origen del codigo de tabla.-
  21. BCD7SEG:            ; retlw b'gfedcba'  para display catodo comun  
  22.       addwf   PCL,1      ; Se incrementa el contador del programa.-  
  23.       retlw   b'0111111'   ; 0      
  24.       retlw   b'0000110'   ; 1      
  25.       retlw   b'1011011'   ; 2      
  26.       retlw   b'1001111'   ; 3      
  27.       retlw   b'1100110'   ; 4      
  28.       retlw   b'1101101'   ; 5      
  29.       retlw   b'1111101'   ; 6      
  30.       retlw   b'0000111'   ; 7      
  31.       retlw   b'1111111'   ; 8      
  32.       retlw   b'1101111'   ; 9      
  33.       clrf   Contador      ; Si llega 10, se resetea contador  
  34.       retlw   b'0111111'   ; 0
  35.  
  36.  
  37. Inicio         bsf   STATUS,RP0    ; Pasamos de Banco 0 a Banco 1.-  
  38.          movlw   b'10000000'   ; RB7 como entrada y los demas como salida.-  
  39.          movwf   TRISB  
  40.          bcf   STATUS,RP0   ; Paso del Banco 1 al Banco 0  
  41.          movlw   b'0111111'   ; Comienza en cero.-  
  42.          movwf   PORTB  
  43.          clrf   Contador
  44.  
  45. ;**** Testeo de Pulsador ****
  46.  
  47. Testeo         btfss   PORTB,Pulsador   ; Testeamos si esta a 1 logico.-  
  48.          goto   Testeo      ; No, seguimos testeando.-  
  49.          call   Demora_20ms   ; Eliminamos Efecto rebote  
  50.          btfss   PORTB,Pulsador   ; Testeamos nuevamente.-  
  51.          goto   Testeo      ; Falsa Alarma, seguimos testeando.-  
  52.          incf   Contador,1   ; Se ha pulsado, incrementamos contador.-  
  53.          movfw   Contador      ; pasamos contador a W  
  54.          call   BCD7SEG      ; Llamamos tabla.-  
  55.          movwf   PORTB      ; Cargamos valor recibido por Tabla en PORTB  
  56.          btfsc   PORTB,Pulsador   ; Esperamos a que se suelte el pulsador -**-  
  57.          goto   $-1      ; No, PCL - 1, --> btfss   PORTA,Pulsador.-  
  58.          call   Demora_20ms   ; Eliminamos efecto rebote.-  
  59.          btfsc   PORTB,Pulsador   ; Testeamos nuevamente.-  
  60.          goto   $-4      ; No, Falsa alarma, volvemos a testear a que se suelte (**).-  
  61.          goto   Testeo      ; Si, Testeamos nuevamente.-        
  62.  
  63. ;**** Demora ****
  64.  
  65. Demora_20ms      movlw   0xFF      ;    
  66.          movwf   Contador1   ; Iniciamos contador1.-
  67. Repeticion1      movlw   0x19      ;    
  68.          movwf   Contador2   ; Iniciamos contador2
  69. Repeticion2      decfsz   Contador2,1   ; Decrementa Contador2 y si es 0 sale.-        
  70.          goto   Repeticion2   ; Si no es 0 repetimos ciclo.-  
  71.          decfsz   Contador1,1   ; Decrementa Contador1.-  
  72.          goto   Repeticion1   ; Si no es cero repetimos ciclo.-  
  73.          return         ; Regresa de la subrutina.-    
  74.          end

Ese seria un ejemplo simple, ahora ahi me gustaria agregar la forma de poder guardar las 5 memorias en medio de la ejecucion, ( asi sean 2 memorias de 1 digito ) espero haberme hecho entender ...

PD: tambien me gustaria lograr aunque es mas complejo, y no se si alguien lo ha hecho aun.  Escribir en un LCD en medio de la ejecucion .... Gracias a todos !!!


 
Vangeluz

Desconectado tapi8

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1506
Re: Guardar datos en programa en medio de ejecucion Pic 16f84A
« Respuesta #1 en: 28 de Junio de 2012, 12:39:04 »
Si te entiendo bien, quieres que haga la cuenta atras 99 a 0 mostrando 200ms cada numero, por ejemplo, si pulsas un pulsador pase a mostrarlos cada 400ms, pulsando otro 600ms....¿seria esto?

Tambien en vez de 5 pulsadores podrias poner 2 pulsadores, uno aumenta el tiempo y otro y otro lo decrementa, ¿voy bien asi o te entendi mal?

Desconectado Vangeluz

  • PIC12
  • **
  • Mensajes: 74
    • Vangeluzweb
Re: Guardar datos en programa en medio de ejecucion Pic 16f84A
« Respuesta #2 en: 29 de Junio de 2012, 01:27:41 »
Si te entiendo bien, quieres que haga la cuenta atras 99 a 0 mostrando 200ms cada numero, por ejemplo, si pulsas un pulsador pase a mostrarlos cada 400ms, pulsando otro 600ms....¿seria esto?

Tambien en vez de 5 pulsadores podrias poner 2 pulsadores, uno aumenta el tiempo y otro y otro lo decrementa, ¿voy bien asi o te entendi mal?

Gracias Tapi, nuevamente ahi presente !!! , mira lo que buscaria es poder guardar en la memoria sea 2, 3 o 5 memorias ( osea como ejemplo el anterior con 1 digito 7 Seg. ).
Supongamos que ( siempre hablando del programa en ejecucion ), que ya tenga un menu de 2, 3 o 5 memorias en 0, y cuando yo elija la primera por ej. le ponga por ej: 5, entonces con otro pulsador daria un START y iniciaria el contador desde 5 ... no se si me explico ... espero que si, de todas maneras dejo un programita que vi como ejemplo, aunque no entendi como es que guarda esta informacion ....
Dejo un ejemplo conocido de un contador de 4 cifras, que es programable con 15 posibilidades de guardar, setear, editar nuevamente y ejecutarlas desde la cifra escogida de las 15 ....

Código: ASM
  1. ;-------------------------------------------------------------------------
  2. ;                             Darkroom Timer                              
  3. ;               April '99  Stan Ockers (ockers@anl.gov)                  
  4. ;             Modified by Vassilis Papanikolaou, April '05                                        
  5. ;                                                                        
  6. ;       Counts down from 0-99 min and 0-59 sec giving an alarm at 0      
  7. ;     initial counts are held in data EEPROM setable with one button      
  8. ;                                                                        
  9. ;  RBO-RB3 to bases of transistors connect to common cathode of displays.
  10. ;  RA0-RA3 to 1,2,4,8 BCD inputs of CD4511 7 segment latch and driver.    
  11. ;  RB7 to start pushbutton used to start countdown and silence alarm.    
  12. ;  RB6 goes to time set pushbutton use to sucessively set the digits.    
  13. ;  RA4 with pull-up resistor goes to PB to select from 15 starting counts
  14. ;  RB4 goes to Dot Points                                                                                                
  15. ;  RB5 goes to Relay                                                                                 
  16. ;-------------------------------------------------------------------------
  17.  
  18.         PROCESSOR   PIC16F84A                                                                   ; PIC type
  19.     #INCLUDE    "P16f84A.INC"                                                           ; Include file
  20.         __CONFIG        _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF        ; Fuses
  21.         ERRORLEVEL      -302                                                                            ; No bank warnings
  22.  
  23. ;-------------------------------------------------------------------------
  24. ;    Here we define our own personal registers and give them names        
  25. ;-------------------------------------------------------------------------
  26.  
  27. SEC             EQU H'0C'          ; this register holds the value of seconds
  28. SEC10           EQU H'0D'          ; holds value of 10's of seconds
  29. MIN             EQU H'0E'          ; holds value of minutes
  30. MIN10           EQU H'0F'          ; holds value of 10's of minutes
  31. DIGCTR          EQU H'10'          ; 8 bit counter, only 2 lowest bits actually used
  32. DIGIT           EQU H'11'          ; hold digit number to access table
  33. INTCNT          EQU H'12'          ; counts # interrupts to determine when 1 sec up
  34. FUDGE           EQU H'13'          ; allows slight adjustment every 7 interrupts
  35. RUNFLG          EQU H'14'          ; bit 0 only, tells if countdown in progress
  36. W_TEMP          EQU H'15'          ; temporarily holds value of W
  37. STATUS_TEMP EQU H'16'              ; temporarily holds value of STATUS
  38. SECNT           EQU H'17'          ; used in counting 25, 20 msec delays for 1 sec
  39. CNTMSEC         EQU H'18'          ; used in timing of milliseconds
  40. ALARM           EQU H'19'          ; bit 0 only, used as flag for when to alarm
  41. OFFSET          EQU H'1A'          ; hold offset of address in EEPROM
  42. KEEP        EQU H'1B'              ; hold RB4 and RB5 state
  43.  
  44. ;-------------------------------------------------------------------------
  45. ;    Here we give names to some numbers to make their use more clear      
  46. ;-------------------------------------------------------------------------
  47.  
  48.    #DEFINE   START_PB  D'7'
  49.    #DEFINE   SET_PB    D'6'
  50.    #DEFINE   SELECT_PB D'4'
  51.  
  52.    #DEFINE   RB0       D'0'
  53.    #DEFINE   RB1       D'1'
  54.    #DEFINE   RB2       D'2'
  55.    #DEFINE   RB3       D'3'
  56.    #DEFINE   RB4       D'4'
  57.    #DEFINE   RB5       D'5'
  58.  
  59. ;-------------------------------------------------------------------------
  60. ;         We set the start of code to orginate a location zero            
  61. ;-------------------------------------------------------------------------
  62.  
  63.       ORG 0
  64.  
  65.             GoTo MAIN                  ; jump to the main routine
  66.             NOP                        
  67.             NOP                        
  68.             NOP                        
  69.             GoTo INTERRUPT             ; interrupt routine
  70.  
  71. ;-------------------------------------------------------------------------
  72. ;    This table is used to get a bit pattern that will turn on a digit    
  73. ;-------------------------------------------------------------------------
  74.  
  75. BITPAT      ADDWF PCL,f                ; get bit pattern for transistors
  76.             RETLW H'0E'                ; a low, (0), turns the transistor on  
  77.             RETLW H'0D'                  
  78.             RETLW H'0B'                  
  79.             RETLW H'07'                  
  80.  
  81. ;-------------------------------------------------------------------------
  82. ;          Initialization routine sets up ports and timer                
  83. ;-------------------------------------------------------------------------
  84.  
  85. INIT        MOVLW H'C0'                ; PB6 & PB7 inputs all others outputs
  86.             TRIS PORTB                
  87.             MOVLW H'10'                ; Port RA4 input, others outputs
  88.             TRIS PORTA                
  89.             MOVLW H'03'                ; prescaler on TMR0 and 1:16
  90.             OPTION                    
  91.             MOVLW H'A0'                ; GIE & T0IE set T0IF cleared
  92.             MOVWF INTCON              
  93.             MOVLW H'F4'                ; initialize INTCNT
  94.             MOVWF INTCNT              
  95.             MOVLW H'06'                ; initialize FUDGE
  96.             MOVWF FUDGE                
  97.             CLRF OFFSET                ; initialize OFFSET
  98.             Return                    
  99.  
  100. ;-------------------------------------------------------------------------
  101. ;   This is the interrupt routine that is jumped to when TMR0 overflows  
  102. ;-------------------------------------------------------------------------
  103.  
  104. INTERRUPT   MOVWF W_TEMP               ; save W
  105.             SWAPF STATUS,W             ; save status
  106.             MOVWF STATUS_TEMP          ; without changing flags
  107.             ;-------------------------------------------------------------
  108.             MOVF PORTB,W                           ; save PORTB
  109.             ANDLW H'30'                            ; mask out unwanted bits    
  110.                         MOVWF KEEP                                 ; save RB4 and RB5
  111.             ;-------------------------------------------------------------
  112.             INCF DIGCTR,f              ; next digit #
  113.             MOVF DIGCTR,W              ; get it into W
  114.             ANDLW H'03'                ; mask off 2 lowest bits
  115.             MOVWF DIGIT                ; save it for later
  116.             ADDLW H'0C'                ; point at register to display
  117.             MOVWF FSR                  ; use as pointer
  118.             MOVF INDF,W                ; get value of reg pointed to into W
  119.             MOVWF PORTA                ; output to CD4511
  120.             MOVF DIGIT,W               ; recall digit #
  121.             Call BITPAT                ; get bit pattern
  122.                         ;-------------------------------------------------------------
  123.             IORWF KEEP,W                   ; restore RB4 and RB5
  124.                         MOVWF PORTB                ; select transistor
  125.                         ;-------------------------------------------------------------
  126.             DECFSZ INTCNT,f            ; finished 1 sec ?
  127.             GoTo RESTORE               ; not yet, return and enable inter.
  128.             Call EVERYSEC              ; go to every second routine
  129.             MOVLW H'F4'                ; reset INTCNT to normal value
  130.             MOVWF INTCNT              
  131.             DECFSZ FUDGE,f             ; time for fudge?
  132.             GoTo RESTORE               ; not yet, continue on
  133.             MOVLW H'06'                ; reset FUDGE to 6
  134.             MOVWF FUDGE                
  135.             INCF INTCNT,f              ; INTCNT to 245
  136. RESTORE     SWAPF STATUS_TEMP,W        ; get original status back
  137.             MOVWF STATUS               ; into status register
  138.             SWAPF STATUS_TEMP,f        ; old no flags trick again
  139.             SWAPF STATUS_TEMP,W        ; to restore W
  140.             BCF INTCON,T0IF            ; clear the TMR0 interrupt flag
  141.             RETFIE                     ; finished
  142.  
  143. ;-------------------------------------------------------------------------
  144. ;       This routine is called by the interrupt routine every second      
  145. ;-------------------------------------------------------------------------
  146.  
  147. EVERYSEC    BTFSS RUNFLG,0             ; return if runflg not set
  148.             Return  
  149.                         ;-------------------------------------------------------------            
  150.             MOVLW  1 << 4                  
  151.                         XORWF  PORTB, f                    ; Toggle DPs
  152.                         ;-------------------------------------------------------------            
  153.             DECF SEC,f                 ; decrement seconds digit
  154.             INCFSZ SEC,W               ; test for underflow
  155.             GoTo CKZERO                
  156.             MOVLW H'09'                ; reset sec to 9
  157.             MOVWF SEC                  
  158.             DECF SEC10,f               ; decrement SEC10
  159.             INCFSZ SEC10,W             ; check underflow
  160.             GoTo CKZERO                
  161.             MOVLW H'05'                  
  162.             MOVWF SEC10                
  163.             DECF MIN,f                
  164.             INCFSZ MIN,W              
  165.             GoTo CKZERO                
  166.             MOVLW H'09'              
  167.             MOVWF MIN                  
  168.             DECF MIN10,f              
  169. CKZERO      MOVF SEC,f                 ; test SEC for zero
  170.             BTFSS STATUS,Z            
  171.             Return                    
  172.             MOVF SEC10,f               ; check SEC10 for zero
  173.             BTFSS STATUS,Z            
  174.             Return                    
  175.             MOVF MIN,f                 ; check MIN for zero
  176.             BTFSS STATUS,Z            
  177.             Return                    
  178.             MOVF MIN10,f               ; check MIN10 for zero
  179.             BTFSS STATUS,Z            
  180.             Return                    
  181.             CLRF RUNFLG                ; stop the countdown
  182.             BSF ALARM, 0               ; set the alarm flag
  183.             Return                    
  184.  
  185. ;-------------------------------------------------------------------------
  186. ;          This is a routine to read a byte from the data EEPROM          
  187. ;-------------------------------------------------------------------------
  188.  
  189. READEE      MOVWF EEADR                ; set up eeprom address from W
  190.             BSF STATUS,RP0             ; change to page 1
  191.             BSF EECON1,RD              ; set the read bit
  192.             BCF STATUS,RP0             ; back to page 0
  193.             MOVF EEDATA,W              ; return value in W
  194.             Return                    
  195.  
  196. ;-------------------------------------------------------------------------
  197. ;         This routine fills the display registers from data EEPROM      
  198. ;-------------------------------------------------------------------------
  199.  
  200. GETEE       MOVLW H'01'                ; EEprom location 1 +
  201.             ADDWF OFFSET,W             ; offset from start
  202.             Call READEE                ; into W
  203.             MOVWF SEC                  ; into SEC register
  204.             MOVLW H'02'                ; location 2 +
  205.             ADDWF OFFSET,W             ; offset from start
  206.             Call READEE                ; into W
  207.             MOVWF SEC10                ; into SEC10 register
  208.             MOVLW H'03'                ; location 3 +
  209.             ADDWF OFFSET,W             ; offset from start
  210.             Call READEE                ; into W
  211.             MOVWF MIN                  ; into MIN register
  212.             MOVLW H'04'                ; location 4 +
  213.             ADDWF OFFSET,W             ; offset from start
  214.             Call READEE                ; into W
  215.             MOVWF MIN10                ; into MIN10 register
  216.             Return                    
  217.  
  218. ;-------------------------------------------------------------------------
  219. ;              This routine writes a byte to data EEPROM                  
  220. ;-------------------------------------------------------------------------
  221.  
  222. WRITEEE     BSF STATUS,RP0             ; set up EEADR and EEDATA first
  223.             CLRF EECON1                
  224.             BSF EECON1,WREN            ; enable write
  225.             MOVLW H'55'                ; magic sequence
  226.             MOVWF EECON2              
  227.             MOVLW H'AA'                  
  228.             MOVWF EECON2              
  229.             BSF EECON1,WR              
  230. EELOOP      BTFSC EECON1,WR            ; wait for WR to go low
  231.             GoTo EELOOP                ; not yet
  232.             BSF EECON1,WREN            
  233.             BCF EECON1,EEIF            ; clear the interrupt flag
  234.             BCF STATUS,RP0             ; return to page 0
  235.             Return                    
  236.  
  237. ;-------------------------------------------------------------------------
  238. ;         This routine puts display registers into data EEPROM            
  239. ;-------------------------------------------------------------------------
  240.  
  241. PUTEE       MOVF SEC,W                 ; put digit registers into EEprom
  242.             MOVWF EEDATA              
  243.             MOVLW H'01'                ; EEPROM location 1 +  
  244.             ADDWF OFFSET,W             ; offset from start
  245.             MOVWF EEADR                
  246.             Call WRITEEE              
  247.             MOVF SEC10,W              
  248.             MOVWF EEDATA              
  249.             MOVLW H'02'                ; EEPROM location 2 +  
  250.             ADDWF OFFSET,W             ; offset from start
  251.             MOVWF EEADR                
  252.             Call WRITEEE              
  253.             MOVF MIN,W                
  254.             MOVWF EEDATA              
  255.             MOVLW H'03'                ; EEPROM location 3 +  
  256.             ADDWF OFFSET,W             ; offset from start
  257.             MOVWF EEADR                
  258.             Call WRITEEE              
  259.             MOVF MIN10,W              
  260.             MOVWF EEDATA              
  261.             MOVLW H'04'                ; EEPROM location 4 +  
  262.             ADDWF OFFSET,W             ; offset from start
  263.             MOVWF EEADR                
  264.             Call WRITEEE              
  265.             Return                    
  266.  
  267. ;-------------------------------------------------------------------------
  268. ;         This is the main routine, the program starts here              
  269. ;-------------------------------------------------------------------------
  270.  
  271. MAIN        Call INIT                  ; set up ports etc.
  272.  
  273. ;-------------------------------------------------------------------------
  274. ;           We will return to this point when alarm is shut off.          
  275. ;-------------------------------------------------------------------------
  276.  
  277. EE2D        Call GETEE                 ; put eeprom in display regs.
  278.             BCF RUNFLG, 0              ; clear run flag so no countdown
  279.             BCF ALARM, 0               ; clear alarm flag
  280.                         ;-------------------------------------------------------------
  281.             BCF PORTB,RB5              ; turn RELAY OFF    
  282.             BSF PORTB,RB4              ; turn DPs ON
  283.                         ;-------------------------------------------------------------
  284.             Call WAITSTARTUP           ; wait till no switches pressed
  285.             Call WAITSETUP
  286.             Call WAITSELECT
  287.  
  288. ;-------------------------------------------------------------------------
  289. ;      This loop checks for either pushbutton and acts  accordingly      
  290. ;-------------------------------------------------------------------------
  291.  
  292. KEYCHKLOOP  BTFSS PORTB,START_PB       ; check for start pressed
  293.             GoTo STARTCNT              ; yes, start count
  294.             BTFSS PORTB,SET_PB         ; check for set pressed
  295.             GoTo SETDISP               ; yes, set display
  296.             BTFSS PORTA,SELECT_PB      ; check select pushbutton pressed
  297.             GoTo SETSELECT             ; yes, select starting count
  298.             GoTo KEYCHKLOOP            ; loop to catch key press
  299.  
  300. ;-------------------------------------------------------------------------
  301. ;    If start key has been pressed then start countdown process,          
  302. ;    I initially released this code with only the setting of the          
  303. ;    run flag included.  If you think about it you must also reset        
  304. ;    TMR0 to zero.  TMR0 is free running and could have any value        
  305. ;    0-255 when the button in pressed. Also INTCNT has to be              
  306. ;    initialized because the previous count could have been cancelled.    
  307. ;-------------------------------------------------------------------------
  308.  
  309. STARTCNT    Call WAITSTARTUP           ; wait for release of start key
  310.             MOVLW D'244'               ; reset INTCNT
  311.             MOVWF INTCNT
  312.             CLRF TMR0                  ; and clear timer 0
  313.                         ;-------------------------------------------------------------
  314.             BSF PORTB,RB5              ; turn RELAY ON  
  315.                         ;-------------------------------------------------------------
  316.             BSF RUNFLG, 0              ; start the countdown
  317.  
  318. ;-------------------------------------------------------------------------
  319. ;        Once started just loop looking for cancel or reaching 0000      
  320. ;-------------------------------------------------------------------------
  321.  
  322. MAINLOOP    BTFSS PORTB,START_PB       ; countdown in progress, check start
  323.             GoTo EE2D                  ; start over again if pressed
  324.             BTFSC ALARM, 0             ; reached 0000 yet?      
  325.             GoTo RELAYOFF              ; yes, turn RELAY OFF
  326.             GoTo MAINLOOP              ; no start switch, continue looping
  327.  
  328. ;-------------------------------------------------------------------------
  329. ;    This code sounds the alarm and waits on start to be pressed          
  330. ;-------------------------------------------------------------------------
  331.  
  332. RELAYOFF
  333. FINALWAIT   ;-------------------------------------------------------------
  334.                     BCF PORTB,RB5              ; turn RELAY OFF
  335.             BSF PORTB,RB4              ; turn DPs ON
  336.                         ;-------------------------------------------------------------
  337.             BTFSC PORTB,START_PB       ; start button pressed
  338.             GoTo  FINALWAIT            ; not yet
  339.             Call DLY20                 ; debounce just to make sure
  340.             BTFSC PORTB,START_PB       ; second look
  341.             GoTo FINALWAIT             ; nah, keep waiting
  342.             Call WAITSTARTUP           ; now wait for the switch up
  343.             GoTo EE2D                  ; start all over again
  344.  
  345. ;-------------------------------------------------------------------------
  346. ;                    Wait for release of start button                    
  347. ;-------------------------------------------------------------------------
  348.  
  349. WAITSTARTUP BTFSS PORTB,START_PB       ; wait for release
  350.             GoTo WAITSTARTUP           ; not released yet
  351.             Call DLY20                 ; debounce release
  352.             BTFSS PORTB,START_PB       ; 2nd check, make sure released
  353.             GoTo WAITSTARTUP           ; keep checking
  354.             Return
  355.  
  356. ;-------------------------------------------------------------------------
  357. ;                    Wait for release of set button                      
  358. ;-------------------------------------------------------------------------
  359.  
  360. WAITSETUP   BTFSS PORTB,SET_PB         ; wait for release
  361.             GoTo WAITSETUP             ; not yet
  362.             Call DLY20                 ; debounce release
  363.             BTFSS PORTB,SET_PB         ; 2nd check, make sure released
  364.             GoTo WAITSETUP             ; keep checking
  365.             Return
  366.  
  367. ;-------------------------------------------------------------------------
  368. ;                    Wait for release of select button                    
  369. ;-------------------------------------------------------------------------
  370.  
  371. WAITSELECT  BTFSS PORTA,SELECT_PB      ; wait for release
  372.             GoTo WAITSELECT            ; not yet
  373.             Call DLY20                 ; debounce release
  374.             BTFSS PORTA,SELECT_PB      ; 2nd check, make sure released
  375.             GoTo WAITSELECT            ; keep checking
  376.             Return
  377.  
  378. ;-------------------------------------------------------------------------
  379. ;       Routine to follow sets the countdown time digit by digit          
  380. ;-------------------------------------------------------------------------
  381.  
  382. SETDISP     Call WAITSETUP             ; wait for set key to be released
  383.             MOVLW H'0A'                ; put A's in digits, (no display)
  384.             MOVWF MIN10                ; 10's of minutes
  385.             MOVWF MIN                  ; minutes
  386.             MOVWF SEC10                ; 10's of seconds
  387.             MOVWF SEC                  ; seconds
  388. STARTMIN10  CLRF  MIN10                ; 0 now in MIN10
  389. MOREMIN10   MOVLW H'19'                ; 25 delays of 20 msec
  390.             MOVWF SECNT                ; into counting register
  391. WAIT1       Call DLY20                
  392.             BTFSS PORTB,SET_PB         ; set key pressed?
  393.             GoTo MINSET                ; yes MIN10 now set
  394.             DECFSZ  SECNT,f            ; finished 1 sec delay?
  395.             GoTo WAIT1                 ; continue wait
  396.             INCF MIN10,f               ; every second increment 10's MIN
  397.             MOVLW H'0A'                ; reached 10?
  398.             SUBWF MIN10,W              
  399.             BTFSC STATUS,Z             ; Z set if reached 10
  400.             GoTo STARTMIN10            ; start again with 0
  401.             GoTo MOREMIN10             ; set up another 1 sec delay
  402. MINSET      Call WAITSETUP             ; wait for release of set key
  403. STARTMIN    CLRF MIN                   ; 0 into MIN
  404. MOREMIN     MOVLW H'19'                ; 25 delays of 20 msec
  405.             MOVWF SECNT                ; into counting register
  406. WAIT2       Call DLY20                
  407.             BTFSS PORTB,SET_PB         ; set pressed?
  408.             GoTo SETSEC10              ; yes, finished with MIN
  409.             DECFSZ SECNT,f             ; finished 1 sec delay?
  410.             GoTo WAIT2                 ; continue wait
  411.             INCF MIN,f                 ; every second increment MIN
  412.             MOVLW H'0A'                ; reached 10?
  413.             SUBWF MIN,W              
  414.             BTFSC STATUS,Z             ; Z set if reached 10
  415.             GoTo STARTMIN              ; put zero in if Z set
  416.             GoTo MOREMIN               ; set up another 1 sec delay
  417. SETSEC10    Call WAITSETUP             ; wait release
  418. STARTSEC10  CLRF SEC10                 ; 0 into SEC10
  419. MORESEC10   MOVLW H'19'                ; 25 delays of 20 msec
  420.             MOVWF SECNT                ; into counting register
  421. WAIT3       Call DLY20                
  422.             BTFSS PORTB,SET_PB         ; set pressed?
  423.             GoTo  SETSEC               ; yes quit incrementing
  424.             DECFSZ SECNT,f             ; finished 1 sec delay?
  425.             GoTo WAIT3                 ; continue wait
  426.             INCF SEC10,f               ; every second increment 10's SEC
  427.             MOVLW H'06'                ; reached 6?
  428.             SUBWF SEC10,W              
  429.             BTFSC STATUS,Z             ; Z set if reached 6
  430.             GoTo STARTSEC10            ; put zero in if Z set
  431.             GoTo MORESEC10             ; set up another 1 sec delay
  432. SETSEC      Call WAITSETUP             ; wait for release
  433. STARTSEC    CLRF SEC                   ; 0 into SEC
  434. MORESEC     MOVLW H'19'                ; 25 delays of 20 msec
  435.             MOVWF SECNT                ; into counting register
  436. WAIT4       Call DLY20                
  437.             BTFSS PORTB,SET_PB         ; set button pressed?
  438.             GoTo  FINSET               ; yes finished setting digits
  439.             DECFSZ SECNT,f             ; finished 1 sec delay?
  440.             GoTo WAIT4                 ; continue wait
  441.             INCF SEC,f                 ; every second increment SEC
  442.             MOVLW H'0A'                ; reached 10?
  443.             SUBWF SEC,W              
  444.             BTFSC STATUS,Z             ; Z set if reached 10
  445.             GoTo STARTSEC              ; put zero in if Z set
  446.             GoTo MORESEC               ; set up another 1 sec delay
  447. FINSET      BCF INTCON, GIE            ; disable interrupts
  448.             Call PUTEE                 ; put new digits into EEPROM
  449.             BSF INTCON, GIE            ; re-enable interrupts
  450.             Call WAITSETUP             ; make sure set switch up
  451.             GoTo KEYCHKLOOP            ; start checking buttons again
  452.  
  453. ;-------------------------------------------------------------------------
  454. ;        Selects starting count by changing EEPROM location 0            
  455. ;-------------------------------------------------------------------------
  456.  
  457. SETSELECT   MOVLW D'4'                 ; offset up 4
  458.             ADDWF OFFSET,F             ; next offset position
  459.             MOVLW D'60'                ; reached 16th yet?
  460.             SUBWF OFFSET,W             ; will give zero if yes
  461.             BTFSC STATUS,Z             ; skip if not 64
  462.             CLRF  OFFSET               ; reset position to zero
  463.             MOVLW 0                    ; EEPROM location
  464.             MOVWF EEADR                ; set up address
  465.             MOVF OFFSET,W              ; offset # into W
  466.             MOVWF EEDATA               ; set up data
  467.             BCF INTCON,GIE             ;  clear GIE, disable interrupts
  468.             Call WRITEEE               ; save # in location 0
  469.             BSF INTCON,GIE             ; re-enable interrupts
  470.             Call GETEE                 ; get new start count into display
  471.             Call WAITSELECT            ; make sure select switch is up
  472.             GoTo KEYCHKLOOP            ; start checking buttons again
  473.  
  474. ;-------------------------------------------------------------------------
  475. ;  The following are various delay routines based on instruction length.    
  476. ;  The instruction length is assumed to be 1 microsecond (4Mhz crystal).  
  477. ;-------------------------------------------------------------------------
  478.  
  479. DLY20       MOVLW 20                   ; delay for 20 milliseconds
  480.  
  481. ; N millisecond delay routine
  482.  
  483. NMSEC       MOVWF CNTMSEC              ; delay for N (in W) milliseconds
  484. MSECLOOP    MOVLW D'248'               ; load takes 1 microsec
  485.             Call MICRO4                ; by itself CALL takes ...
  486.                                        ; 2 + 247 X 4 + 3 + 2 = 995
  487.             NOP                        ; 1 more microsec
  488.             DECFSZ CNTMSEC,f           ; 1 when skip not taken, else 2
  489.             GoTo MSECLOOP              ; 2 here: total 1000 per msecloop
  490.             Return                     ; final time through takes 999 to here
  491.                                        ; overhead in and out ignored
  492.  
  493. ; 1 millisecond delay routine
  494.  
  495. ONEMSEC     MOVLW D'249'               ; 1 microsec for load W
  496.                                        ; loops below take 248 X 4 + 3 = 995
  497. MICRO4      ADDLW H'FF'                ; subtract 1 from 'W'
  498.             BTFSS STATUS,Z             ; skip when you reach zero
  499.             GoTo MICRO4                ; loops takes 4 microsec, 3 for last
  500.             Return                     ; takes 2 microsec
  501.                                        ; call + load  W + loops + return =
  502.                                        ; 2 + 1 + 995 + 2 = 1000 microsec
  503.  
  504. ;-------------------------------------------------------------------------
  505. ;    Here we set up the initial values of the digits in data EEPROM      
  506. ;-------------------------------------------------------------------------
  507.            
  508.                   ORG H'2100'
  509.  
  510.           DE 0, 0, 3, 0, 0      ; 1st starting #
  511.           DE    0, 0, 1, 0      ; 2nd starting #
  512.           DE    0, 0, 2, 0      ; 3rd starting #
  513.           DE    0, 0, 3, 0      ; 4th starting #
  514.           DE    0, 0, 4, 0      ; 5th starting #
  515.           DE    0, 0, 5, 0      ; 6th starting #
  516.           DE    0, 0, 6, 0      ; 7th starting #
  517.           DE    0, 0, 7, 0      ; 8th starting #
  518.           DE    0, 0, 8, 0      ; 9th starting #
  519.           DE    0, 0, 9, 0      ; 10th starting #
  520.           DE    0, 0, 0, 1      ; 11th starting #
  521.           DE    0, 0, 0, 2      ; 12th starting #
  522.           DE    0, 0, 0, 3      ; 13th starting #
  523.           DE    0, 0, 0, 4      ; 14th starting #
  524.           DE    0, 0, 0, 5      ; 15th starting #
  525.  
  526.           END

Creo que por el final donde dice ORG H'2100' por ahi esta la onda porque hay 15 lineas y el programa guarda 15 memorias, pero no logro comprender como programar algo parecido aunque sea co n un digito o con leds o como sea ... gracias !!!
Vangeluz

Desconectado tapi8

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1506
Re: Guardar datos en programa en medio de ejecucion Pic 16f84A
« Respuesta #3 en: 29 de Junio de 2012, 07:12:33 »
Pues siento ser tan torpe pero no acabo de entender lo que quieres. Mira este hilo de un pasamensajes que hicieron aqui hace algun tiempo, donde ademas Brunof explica como guardar los reg. para enviar al letrero luminoso, a ver si es esto mas o menos lo que quieres:

http://www.todopic.com.ar/foros/index.php?topic=25723.0

Desconectado Vangeluz

  • PIC12
  • **
  • Mensajes: 74
    • Vangeluzweb
Re: Guardar datos en programa en medio de ejecucion Pic 16f84A
« Respuesta #4 en: 21 de Julio de 2012, 15:26:15 »
Pues siento ser tan torpe pero no acabo de entender lo que quieres. Mira este hilo de un pasamensajes que hicieron aqui hace algun tiempo, donde ademas Brunof explica como guardar los reg. para enviar al letrero luminoso, a ver si es esto mas o menos lo que quieres:

http://www.todopic.com.ar/foros/index.php?topic=25723.0

Gracias por el apunte, esta interesante.
He visto que usan la opcion de guardar datos en la EEPROM usando algo de ORG 2100h agregando datos.Por ej Org 2100F 0x00, 0x00, 0x00, 0x00
Por ejemplo algo como el famoso programa CERRADURA ELECTRONICA. hay una version que es con la clave fija guardada y otra que es configurable desde un pulsador:

Ej: clave de 4 digitos guardados como ( predeterminado ) 0, 0, 0, 0   mediante pulsadores ya con el proyecto corriendo se puede cambiar por ej a 1,2,3,4 .....
Gracias nuevamente !!!

Vangeluz


 

anything