• AVR Freaks

Hot!pc issues in 1 page long codes

Author
Alex887
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/03/26 09:04:07
  • Location: 0
  • Status: offline
2020/04/06 10:30:21 (permalink)
0

pc issues in 1 page long codes

hi friends
 
so... as i said in the title, i have a 800 instrucctions code in assembler. it works ok for the most part. but in some areas , with heavy goto/call or nesting, happens to have pc problems.  specifically in some look up tables. moving the table position in the code changes the bug problem.i had the same problem in the past and here  i was told to put the lut at the begining. it worked out well with all mi codes since. and althougth i´ve read about the subjet i guesed that i would have not to care about pclaht under the 2k word programs. i think im wrong. what i am missing?
#1

16 Replies Related Threads

    mlp
    boots too small
    • Total Posts : 912
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/06 12:43:58 (permalink)
    +1 (1)
    Alex887
    what i am missing?

    Line 42.

    Mark (this opinion available for hire)
    #2
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/06 13:02:45 (permalink)
    0

     LIST P=16f887 ;
     
     #INCLUDE "P16F887.INC" ;
     __CONFIG _CONFIG1, _FOSC_INTRC_NOCLKOUT & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF
    ; CONFIG2
    ; __config 0xFFFF
     __CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF
     
     #DEFINE COUNTERA 0x20
     #DEFINE COUNTERB 0x21
     #DEFINE COUNTERC 0x22
     
     #DEFINE B1 0X23
     #DEFINE B2 0X24
     #DEFINE B3 0X25
     #DEFINE B4 0X26
     #DEFINE B5 0X27
     #DEFINE B6 0X28
     #DEFINE D11 0X29
     #DEFINE D12 0X2A
     #DEFINE D13 0X2B
     #DEFINE D21 0X2C
     #DEFINE D22 0X2D
     #DEFINE D23 0X2E
     #DEFINE D31 0X2F
     #DEFINE D32 0X30
     #DEFINE D33 0X31
     #DEFINE D41 0X32
     
     #DEFINE D42 0X33
     #DEFINE D43 0X34
     #DEFINE D51 0X35
     #DEFINE D52 0X36
     #DEFINE D53 0X37
     #DEFINE D61 0X38
     #DEFINE D62 0X39
     #DEFINE D63 0X3A
     
     
     #DEFINE L19 0X3B
     #DEFINE L27 0X3C
     #DEFINE L11 0X3D
     #DEFINE L12 0X3E
     #DEFINE L14 0X3F
     #DEFINE L15 0X40
     
     #DEFINE L21 0X41
     #DEFINE L13 0X42
     #DEFINE L16 0X43
     #DEFINE L31 0X44
     #DEFINE L32 0X45
     #DEFINE L33 0X46
     
     
     #DEFINE ESTADO 0X70
     #DEFINE COUNTERD 0X71
     #DEFINE ACTUAL 0X72
     #DEFINE ACUM1 0X73
     #DEFINE ACUM2 0X74
     #DEFINE ACUM3 0X75
     
     #DEFINE INSP 0X76
     #DEFINE INSPT 0X77
     #DEFINE DEADT 0X79
     #DEFINE EXP 0X7A
     #DEFINE EXPT 0X7B
     #DEFINE DEADT2 0X7C
     #DEFINE TOTAL 0X7D
     #DEFINE INSPTA 0X7E
     #DEFINE EXPTA
     
     #DEFINE C1 0X7F
     #DEFINE C2 0X80
     #DEFINE C3 0X81
     #DEFINE C4 0X82
     #DEFINE C5 0X83
     #DEFINE C6 0X84
     #DEFINE L29 0X85
     
     
     
     ORG 0x00
     GOTO SETUP
     ORG 0x05
    SETUP BSF STATUS,RP0 ;BANCO 1
         MOVLW B'11111111'
         MOVWF TRISA ;PUERTO A ENTRADAS
         CLRF TRISB ;PUERTO B SALIDAS
         CLRF TRISC ;PUERTO C SALIDAS
         MOVLW B'00000000'
         MOVWF TRISE ;PUERTO E SALIDAS
         MOVLW B'00000100'
         MOVWF TRISD ;PUERTO D 0-6 ENTRADAS 7 SALIDA
         BSF STATUS,RP1 ;BANCO 3
         CLRF ANSEL ;PUERTOS ANALOGICOS COMO DIGITAL
         CLRF ANSELH ;PUERTOS ANALOGICOS COMO DIGITAL
         ;BSF OSCCON,IRCF0
         
         BCF STATUS,RP1
         BCF STATUS,RP0 ;BANCO 0
         
         CLRF PORTA
         CLRF PORTB
         CLRF PORTD
         CLRF PORTE
         CLRF ESTADO
         
         CLRWDT
         
         
         CLRWDT
         ;===================================================================
         ;CARGA DE VALORRES DE EEPRON EN REGISTROS L
         MOVLW D'1'
         CALL LEER
         MOVWF B1
         MOVLW D'2'
         CALL LEER
         MOVWF B2
         MOVLW D'3'
         CALL LEER
         MOVWF B3
         MOVLW D'4'
         CALL LEER
         MOVWF B4
         MOVLW D'5'
         CALL LEER
         MOVWF B5
         MOVLW D'6'
         CALL LEER
         MOVWF B6
         
         
         MOVF B1,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D11
         MOVF ACUM2,W
         MOVWF D12
         
         MOVF B2,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D21
         MOVF ACUM2,W
         MOVWF D22
         
         MOVF B3,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D31
         MOVF ACUM2,W
         MOVWF D32
         
         MOVF B4,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D41
         MOVF ACUM2,W
         MOVWF D42
        
         MOVF B5,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D51
         MOVF ACUM2,W
         MOVWF D52
         
         MOVF B6,W
         CALL TRAS
         MOVF ACUM1,W
         MOVWF D61
         MOVF ACUM2,W
         MOVWF D62
         
         CLRWDT
         

         
         CLRWDT
         
         GOTO INI
         
         
    TRAS
         MOVWF ACUM3
         CLRF ACUM1
         CLRF ACUM2
    SRUT MOVF ACUM3,1
         BTFSC STATUS,Z
         RETURN
         DECF ACUM3
         INCF ACUM1
         MOVLW D'10'
         SUBWF ACUM1,W
         BTFSS STATUS,Z
         GOTO SRUT
         CLRF ACUM1
         INCF ACUM2
         GOTO SRUT
         
         
         
         
         
         
        
         
        
         
    LEER
        BANKSEL EEADR
         
         MOVWF EEADR
      banksel EECON1 ;
      bsf EECON1,RD ; EE Read
      banksel EEDAT ;
      movf EEDAT,W ;
      banksel 0x00
         RETURN
         
         

         
         
         
         
         
         
         
    INI
    ;DISPLAY SETUP ==============================================
         
         CALL DELAY_30MS
         
         MOVLW B'00000000'
         MOVWF PORTD
         MOVLW B'00111111' ;configuracion de interfase,y tipo de digito
         MOVWF PORTB
         NOP
         NOP
         NOP
         NOP
         BTFSC PORTD,2
         GOTO $-1
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         CLRWDT
         
         MOVLW B'00000000'
         MOVWF PORTD
         MOVLW B'00001111' ;display encendido, cursor encendido,posicion de cursor encendido
         MOVWF PORTB
         NOP
         NOP
         NOP
         NOP
         BTFSC PORTD,2
         GOTO $-1
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         CLRWDT
         
         MOVLW B'00000000'
         MOVWF PORTD
         MOVLW B'00000001' ;CLEAR DISPLAY
         MOVWF PORTB
         NOP
         NOP
         NOP
         NOP
         BTFSC PORTD,2
         GOTO $-1
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         CLRWDT
         
         CALL DELAY_30MS
         
         CLRWDT
         
         MOVLW B'00000000'
         MOVWF PORTD
         MOVLW B'00000110' ;DESPLAZAMIENTO DERECHO
         MOVWF PORTB
         NOP
         NOP
         NOP
         NOP
         BTFSC PORTD,2
         GOTO $-1
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS

     
         
         
         
    ;================================================
    ;MENSAJE INICIAL
         

         
    ;==============================================


    ;===========================================
    ;MENSAJE STAND BY
    STAND CLRWDT
         
         MOVLW B'00000000'
         MOVWF PORTD
         BTFSC PORTD,2
         GOTO $-1
        
         MOVLW B'10000000'
         MOVWF PORTB
         NOP
         NOP
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         MOVLW 'V'
         MOVWF L21
         CALL ESCRI
         MOVLW 'O'
         MOVWF L21
         CALL ESCRI
         MOVLW 'L'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         
         MOVLW B'00000001'
         MOVWF PCLATH
         MOVF D62,W
         
         
         CALL TABLA
         
         MOVWF L21
         CALL ESCRI
         MOVF D61,W
         
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVLW '%'
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         MOVLW 'I'
         MOVWF L21
         CALL ESCRI
         MOVLW 'N'
         MOVWF L21
         CALL ESCRI
         MOVLW 'S'
         MOVWF L21
         CALL ESCRI
         MOVLW 'P'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D12,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D11,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         
    ;========================
         MOVLW B'00000000'
         MOVWF PORTD
         BTFSC PORTD,2
         GOTO $-1
        
         MOVLW B'11000000'
         MOVWF PORTB
         NOP
         NOP
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         MOVLW 'R'
         MOVWF L21
         CALL ESCRI
         MOVLW '/'
         MOVWF L21
         CALL ESCRI
         MOVLW 'M'
         MOVWF L21
         CALL ESCRI
         MOVLW 'I'
         MOVWF L21
         CALL ESCRI
         MOVLW 'N'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D52,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D51,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         
         MOVLW 'E'
         MOVWF L21
         CALL ESCRI
         MOVLW 'X'
         MOVWF L21
         CALL ESCRI
         MOVLW 'P'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D32,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D31,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         

         GOTO STAND_BY

    ;==============================================================================================
    ;==============================================================================================
    ;LOOP STAND BY

         
         
         
    STAND_BY
         
         BTFSC PORTA,0
         GOTO STAND
         BTFSC PORTA,1
         GOTO STAND
         BTFSC PORTA,2
         GOTO STAND
         BTFSC PORTA,3
         GOTO STAND
         
    STAND1 CLRWDT
         BTFSC PORTA,0 ;INSPIRACION MENOS
         GOTO DECB1
         BTFSC PORTA,1 ;INSPIRACION MAS
         GOTO INCB1
         BTFSC PORTA,2 ;VOLUMEN MENOS
         GOTO DECB6
         BTFSC PORTA,3 ;VOLUMEN MAS
         GOTO INCB6
         BTFSC PORTA,4 ;MARCHA
         GOTO RUND
         GOTO STAND1
         
    INCB1 MOVLW D'99'
        
         SUBWF B1,W
         BTFSC STATUS,Z
         GOTO STAND
         INCF B1,1
         MOVLW D'9'
         SUBWF D11,W
         BTFSC STATUS,Z
         GOTO $+3
         INCF D11,1
         GOTO STAND
         CLRF D11
         INCF D12,1
         GOTO STAND

    DECB1 MOVLW D'5'
         SUBWF B1,0
         BTFSC STATUS,Z
         GOTO STAND
         DECF B1,1
         MOVF D11,W
         BTFSC STATUS,Z
         GOTO $+3
         DECF D11,1
         GOTO STAND
         MOVLW D'9'
         MOVWF D11
         DECF D12
         GOTO STAND
         
         
    INCB6 MOVLW D'99'
         SUBWF B6,W
         BTFSC STATUS,Z
         GOTO STAND
         INCF B6,1
         MOVLW D'9'
         SUBWF D61,W
         BTFSC STATUS,Z
         GOTO $+3
         INCF D61,1
         GOTO STAND
         CLRF D61
         INCF D62,1
         GOTO STAND
         
         
    DECB6 MOVLW D'5'
         SUBWF B6,0
         BTFSC STATUS,Z
         GOTO STAND
         DECF B6,1
         MOVF D61,W
         BTFSC STATUS,Z
         GOTO $+3
         DECF D61,1
         GOTO STAND
         MOVLW D'9'
         MOVWF D61
         DECF D62
         GOTO STAND
         
         
         
         
         
         
         
         
         
         ;================================================
         ;CONVERSON VALORES

         
         
         
       
         
         
    ;==============================================================================================
    ;==============================================================================================
         
        
         
         
         
         
           ;===========================================================================

               ;=================================
        ;ESCRITURA EN MEMORIA EEPROM DE VALORES DE ETAPA
    EEPROM MOVF L13,W
         BANKSEL EEADR
         MOVWF EEDAT
         MOVLW D'1'
         MOVWF EEADR
         BANKSEL 0X00
         CALL ESCRIBE
         
         MOVF L16,W
         BANKSEL EEADR
         MOVWF EEDAT
         MOVLW D'2'
         MOVWF EEADR
         BANKSEL 0X00
         CALL ESCRIBE
         

    ESCRIBE
         banksel EEADR
      
       ;Data memory value to write

      banksel EECON1
      bsf EECON1,WREN ;Enable writes

      bcf INTCON,GIE ;Disable INTs
      btfsc INTCON,GIE ;SEE AN576
      goto $-2 ;
      movlw 55h ;
      movwf EECON2 ;
      movlw 0AAh ;
      movwf EECON2 ; Write 55h
      bsf EECON1,WR ;
      bsf INTCON,GIE ; Enable INTs

      btfsc EECON1,WR ; Wait for write to complete
      goto $-1 ;
      
      bcf EECON1,WREN ; Disable writes
      banksel 0X00 ; Bank 0
         RETURN
         
         
         
         
         
         ;===============================

    ;===================================================================================================
    TABLA ADDWF PCL,1
         RETLW B'00110000'
         RETLW B'00110001'
         RETLW B'00110010'
         RETLW B'00110011'
         RETLW B'00110100'
         RETLW B'00110101'
         RETLW B'00110110'
         RETLW B'00110111'
         RETLW B'00111000'
         RETLW B'00111001'
         RETURN
         

    ESCRI CLRWDT
         MOVLW B'00001000'
         MOVWF PORTD
         MOVF L21,W
         MOVWF PORTB
         NOP
         NOP
         BTFSC PORTD,2
         GOTO $-1
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         RETURN
    ;===================================================================================================

         
         
         
    RUND MOVLW D'23'
         MOVWF B3
    RUN CLRWDT
         
         MOVLW B'00000000'
         MOVWF PORTD
         BTFSC PORTD,2
         GOTO $-1
        
         MOVLW B'10000000'
         MOVWF PORTB
         NOP
         NOP
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         MOVLW 'V'
         MOVWF L21
         CALL ESCRI
         MOVLW 'O'
         MOVWF L21
         CALL ESCRI
         MOVLW 'L'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D62,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D61,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVLW '%'
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         MOVLW 'I'
         MOVWF L21
         CALL ESCRI
         MOVLW 'N'
         MOVWF L21
         CALL ESCRI
         MOVLW 'S'
         MOVWF L21
         CALL ESCRI
         MOVLW 'P'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D12,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D11,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         
    ;========================
         MOVLW B'00000000'
         MOVWF PORTD
         BTFSC PORTD,2
         GOTO $-1
        
         MOVLW B'11000000'
         MOVWF PORTB
         NOP
         NOP
         BSF PORTD,1
         CALL DELAY_300NS
         BCF PORTD,1
         CALL DELAY_300NS
         
         MOVLW 'R'
         MOVWF L21
         CALL ESCRI
         MOVLW '/'
         MOVWF L21
         CALL ESCRI
         MOVLW 'M'
         MOVWF L21
         CALL ESCRI
         MOVLW 'I'
         MOVWF L21
         CALL ESCRI
         MOVLW 'N'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D52,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D51,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVLW ' '
         MOVWF L21
         CALL ESCRI
         
         MOVLW 'E'
         MOVWF L21
         CALL ESCRI
         MOVLW 'X'
         MOVWF L21
         CALL ESCRI
         MOVLW 'P'
         MOVWF L21
         CALL ESCRI
         MOVLW ':'
         MOVWF L21
         CALL ESCRI
         MOVF D32,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         MOVF D31,W
         CALL TABLA
         MOVWF L21
         CALL ESCRI
         BCF ESTADO,3

     

    ;==============================================================================================
    ;==============================================================================================
    ;LOOP STAND BY
    STAND_BYR
         
         BTFSC ESTADO,2
         GOTO FILTRO_OFF
         GOTO STAND1R
         
    FILTRO_OFF BTFSC PORTA,0
         GOTO MOT
         BTFSC PORTA,1
         GOTO MOT
         BTFSC PORTA,2
         GOTO MOT
         BTFSC PORTA,3
         GOTO MOT
         BCF ESTADO,2
         
    STAND1R CLRWDT
         BTFSC PORTA,0 ;INSPIRACION MENOS
         GOTO DECB1R
         BTFSC PORTA,1 ;INSPIRACION MAS
         GOTO INCB1R
         BTFSC PORTA,2 ;VOLUMEN MENOS
         GOTO DECB6R
         BTFSC PORTA,3 ;VOLUMEN MAS
         GOTO INCB6R
         GOTO MOT

         
    INCB1R MOVLW D'99'
         SUBWF B1,W
         BTFSC STATUS,Z
         GOTO MOT
         INCF B1,1
         MOVLW D'9'
         SUBWF D11,W
         BTFSC STATUS,Z
         GOTO R11
         INCF D11,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
    R11 CLRF D11
         INCF D12,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT

    DECB1R MOVLW D'5'
         SUBWF B1,0
         BTFSC STATUS,Z
         GOTO MOT
         DECF B1,1
         MOVF D11,W
         BTFSC STATUS,Z
         GOTO R12
         DECF D11,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
    R12 MOVLW D'9'
         MOVWF D11
         DECF D12,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
         
         
    INCB6R MOVLW D'99'
         SUBWF B6,W
         BTFSC STATUS,Z
         GOTO MOT
         INCF B6,1
         MOVLW D'9'
         SUBWF D61,W
         BTFSC STATUS,Z
         GOTO R13
         INCF D61,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
    R13 CLRF D61
         INCF D62,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
          
    DECB6R MOVLW D'5'
         SUBWF B6,0
         BTFSC STATUS,Z
         GOTO MOT
         DECF B6,1
         MOVF D61,W
         BTFSC STATUS,Z
         GOTO R14
         DECF D61,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT
    R14 MOVLW D'9'
         MOVWF D61
         DECF D62,1
         BSF ESTADO,2
         BSF ESTADO,3
         GOTO MOT

         
         
         

    MOT CLRWDT
         BTFSC ESTADO,0 ;CONTROL DE CARGA DATOS
         GOTO SENT
         MOVF B1,W
         MOVWF C1 ;INSP
         MOVF B6,W
         MOVWF C4 ;VOL
         MOVF B2,W
         MOVWF C2
         MOVF B3,W
         MOVWF C3
         BSF PORTD,4
         BSF ESTADO,0
      ;BANDERA DE CARGA
        
         
         
         
    SENT CLRWDT
         BTFSC ESTADO,1 ;CONTROL DE DIRECCION
         GOTO CCKW ;A RUTINA CCKW

    CKW
              
         BCF PORTE,0
         MOVF C4,0 ;RUTINA CKW
         BTFSC STATUS,Z
         GOTO LOL
         
         DECFSZ C1,1
         GOTO MOT
         BTFSS PORTE,1
         GOTO LOC
         BCF PORTE,1
         DECF C4,1
         MOVF B1,0
         MOVWF C1
         GOTO MOT
    LOC BSF PORTE,1
         DECF C4,1
         MOVF B1,0
         MOVWF C1
         GOTO MOT
         
    LOL DECFSZ C3,1
         GOTO NEXT1
         BCF ESTADO,0
         BSF ESTADO,1
         BTFSC ESTADO,3
         GOTO MOT
         GOTO MOT
    NEXT1 MOVF B6,0
         MOVWF C4
         GOTO MOT
         
      
         
         
         

    CCKW
         
         BCF PORTD,4
         BSF PORTE,0
         MOVF C4,0 ;RUTINA CKW
         BTFSC STATUS,Z
         GOTO LOL1
         
         DECFSZ C1,1
         GOTO MOT
         BTFSS PORTE,1
         GOTO LOC1
         BCF PORTE,1
         DECF C4,1
         MOVF B1,0
         MOVWF C1
         GOTO MOT
    LOC1 BSF PORTE,1
         DECF C4,1
         MOVF B1,0
         MOVWF C1
         GOTO MOT
         
    LOL1 DECFSZ C3,1
         GOTO NEXT2
         BCF ESTADO,0
         BCF ESTADO,1
         BTFSC ESTADO,3
         GOTO MOT
         GOTO MOT
    NEXT2 MOVF B4,0
         MOVWF C4
         GOTO MOT
         
         ;DELAY INSP
    INSPDE CLRWDT
      MOVF INSPT,W
      MOVWF INSPTA
          movlw D'13'
      movwf COUNTERB
      movlw D'255'
      movwf COUNTERA
    looOP CLRWDT
      decfsz COUNTERA,1
      goto loop2
      decfsz COUNTERB,1
      goto looOP
      DECFSZ INSPTA
      GOTO $-10
      RETURN
      
      
        
    ;PIC Time Delay = 0,03000000 s with Osc = 4000000 HZ
    DELAY_30MS MOVLW D'1'
      MOVWF COUNTERC
      MOVLW D'50'
      MOVWF COUNTERB
      MOVLW D'255'
      MOVWF COUNTERA
      DECFSZ COUNTERA,1
      GOTO $-1
      DECFSZ COUNTERB,1
      GOTO $-5
      DECFSZ COUNTERC,1
          GOTO $-9

      RETURN

    ;PIC Time Delay = 0,0030000 s with Osc = 4000000 Hz
    DELAY_300NS CLRWDT
      movlw D'1'
      movwf COUNTERC
      movlw D'1'
      movwf COUNTERB
      movlw D'12'
      movwf COUNTERA
      decfsz COUNTERA,1
      goto $-1
      decfsz COUNTERB,1
      goto $-5
      decfsz COUNTERC,1
      goto $-9
      return

    ;PIC Time Delay = 60,00000000 s with Osc = 4000000 Hz

    ;PIC Time Delay = 0,01001000 s with Osc = 4000000 Hz
    DELAY10MS CLRWDT
          movlw D'13'
      movwf COUNTERB
      movlw D'255'
      movwf COUNTERA
    loop2 CLRWDT
      decfsz COUNTERA,1
      goto loop2
      decfsz COUNTERB,1
      goto loop2
      RETURN
      
      
      ;PIC Time Delay = 3,00000100 s with Osc = 4000000 Hz
    DELAY60S
      movlw D'6'
      movwf COUNTERC
      movlw D'19'
      movwf COUNTERB
      movlw D'174'
      movwf COUNTERA
    loop1 CLRWDT
      decfsz COUNTERA,1
      goto loop1
      decfsz COUNTERB,1
      goto loop1
      decfsz COUNTERC,1
      goto loop1
      RETURN
      
      END

    #3
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/06 13:14:34 (permalink)
    0
    i´ve modified pclath and managed to make   the code work, kind of geting the idea of pc counter computed goto  function. the code may be modified due to debuging at the time of upload. im more interested in understandig the basic off pc rather than making this particular code work. 
     
    so, using goto/call can only modify the lower 8 bits of pc, therefore for long jumps i may have the wrong (11:9)bits, or rollovers, not necesary being at page boundary. is this rigth?
     
    thanks in advance
     
    #4
    ric
    Super Member
    • Total Posts : 26942
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pc issues in 1 page long codes 2020/04/06 13:18:44 (permalink)
    +2 (2)
    Alex887
    so, using goto/call can only modify the lower 8 bits of pc, therefore for long jumps i may have the wrong (11:9)bits, or rollovers, not necesary being at page boundary. is this rigth?

    Wrong.
    You are describing what happens when you change PCL by writing to that register (only affecting bits 0-7).
    GOTO and CALL write to many more bits of the PC. The datasheet tells you exactly how many.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 08:05:52 (permalink)
    0
    so the problem is not the call/goto instrucction itself, it is in the pcl modification in the lut, being to close to the first 8 bits roll over in the pc...
    #6
    ric
    Super Member
    • Total Posts : 26942
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pc issues in 1 page long codes 2020/04/08 13:08:12 (permalink)
    +1 (1)
    Note, if you upgrade to a PIC16F1xxx or 16F1xxxx chip, the whole problem goes away, as you can directly read tables in program memory via the FSRx/INDFx register pairs.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    1and0
    Access is Denied
    • Total Posts : 10779
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 15:30:50 (permalink)
    +1 (1)
    Alex887
    m more interested in understandig the basic off pc rather than making this particular code work. 

     
    Read the "PCL and PCLATH" section in your PIC16F887 datasheet. It's only half a page. ;)
     
    #8
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 16:02:47 (permalink)
    0
    1and0

     
     
     
     
    Read the "PCL and PCLATH" section in your PIC16F887 datasheet. It's only half a page. ;)
     
     



    ha ha, yes i´ve read it several times in the past including this days and in other sources. but in the rush of work and the debuging nigthmare of goto spaguetti it didnt got trought.
     
    ric

    Note, if you upgrade to a PIC16F1xxx or 16F1xxxx chip, the whole problem goes away, as you can directly read tables in program memory via the FSRx/INDFx register pairs.
     
     




    thanks for the advise. i´m reading about it. but i think i should search for a datasheet for a pic available in my country. and start learning c coding haha. any pic sugestions?
     
    regards.
    #9
    ric
    Super Member
    • Total Posts : 26942
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pc issues in 1 page long codes 2020/04/08 16:11:13 (permalink)
    0
    As you don't reveal what "my country" is, that's a bit hard.
    As I said, look for any 16F1xxx or 16F1xxxx chip that you can get.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 16:27:35 (permalink)
    0
    i´m in Argentina. looking at pic16f1503. kind of expensive but i guess its on high perfomance category
    #11
    Beau Schwabe
    Starting Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2019/09/23 21:16:53
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 18:20:52 (permalink)
    +1 (1)
    Here is a computed CALL routine that might help.  Keep in mind that any writes to the PCLATH have no effect to the program location UNTIL you write to the PCL directly or do a CALL or a GOTO.  Because of that you can use it to your advantage.
     

        UDATA
    Temp_Address    res 2
    Index        res 1
        
     
     ORG 0x00
     

    MainLOOP:
            movlw   d'6'            ; Load Offset Index here
            movwf   Index
            Call    Computed_CALL  
            
        goto    MainLOOP
        
        
    Computed_CALL:    
        
                            movlw    HIGH    TABLA        ; Move HIGH Address into Temp_Address+1
                            movwf    Temp_Address+1
                            movlw    LOW    TABLA        ; Move LOW Address into    Temp_Address
                            movwf    Temp_Address

                            movf    Index    ,W        ; Add Index to Temp_Address
                            addwf    Temp_Address,F
                            btfsc    STATUS,C        ; Check for overflow
                            incf    Temp_Address+1        ; Increment Temp_Address+1 on overflow
        
                            movf    Temp_Address+1,W    ; Start PCL jump ; result is in W    
                            movwf    PCLATH
                            movf    Temp_Address,W
                            movwf    PCL


    ;===================================================================================================
        org        d'510'                ; Chosen to purposefully straddle a boundary ... can be anywhere                    
    TABLA:
         RETLW B'00110000'        ;<-- Index = 0    ; Note: These returns "complete" the return from the 'Computed_CALL'
         RETLW B'00110001'        ;<-- Index = 1
         RETLW B'00110010'        ;<-- Index = 2
         RETLW B'00110011'        ;<-- Index = 3
         RETLW B'00110100'        ;<-- Index = 4
         RETLW B'00110101'        ;<-- Index = 5
         RETLW B'00110110'        ;<-- Index = 6
         RETLW B'00110111'        ;<-- Index = 7
         RETLW B'00111000'        ;<-- Index = 8
         RETLW B'00111001'        ;<-- Index = 9
           
      END

    #12
    1and0
    Access is Denied
    • Total Posts : 10779
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 18:44:39 (permalink)
    0
    Beau Schwabe
    Here is a computed CALL routine that might help.  Keep in mind that any writes to the PCLATH have no effect to the program location UNTIL you write to the PCL directly or do a CALL or a GOTO.  Because of that you can use it to your advantage.
    Computed_CALL:    
                            movlw    HIGH    TABLA        ; Move HIGH Address into Temp_Address+1
                            movwf    Temp_Address+1
                            movlw    LOW    TABLA        ; Move LOW Address into    Temp_Address
                            movwf    Temp_Address

                            movf    Index    ,W        ; Add Index to Temp_Address
                            addwf    Temp_Address,F
                            btfsc    STATUS,C        ; Check for overflow
                            incf    Temp_Address+1        ; Increment Temp_Address+1 on overflow
        
                            movf    Temp_Address+1,W    ; Start PCL jump ; result is in W    
                            movwf    PCLATH
                            movf    Temp_Address,W
                            movwf    PCL


    You can improve the efficiency of that routine by NOT using the "Temp_Address" variable. Also, the "Index" variable is not necessary.
     
    #13
    1and0
    Access is Denied
    • Total Posts : 10779
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/08 18:54:32 (permalink)
    +1 (1)
    Alex887
     LIST P=16f887 ;
     
     #DEFINE C2 0X80
     #DEFINE C3 0X81
     #DEFINE C4 0X82
     #DEFINE C5 0X83
     #DEFINE C6 0X84
     #DEFINE L29 0X85


    These variables overlap SFRs in your PIC device.
     
    #14
    Beau Schwabe
    Starting Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2019/09/23 21:16:53
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/09 00:44:00 (permalink)
    0
    1and0
    You can improve the efficiency of that routine by NOT using the "Temp_Address" variable. Also, the "Index" variable is not necessary.



    Ok, 1and0, you got me thinking.  I'm sure there is an even better way to do this.  I removed the use of ""Temp_Address" and "Index" but I still needed a Temp variable to hold the PCL value until the last moment so I used the FSR register.  Probably not a good programming practice but any loop woth it's weight using the FSR would initialize it first anyway.  I'm open for any suggestions or comments.
     

     
     ORG 0x00
     

    MainLOOP:
            movlw   d'6'            ; Load Offset Index here
            Call    Computed_CALL  
            
        goto    MainLOOP
        
        
    Computed_CALL:    
                            clrf    PCLATH            ; Clear upper PC Latch
                            addlw    LOW    TABLA        ; add preloaded value in W register to TABLA LOW address; store in W
                            btfsc    STATUS,C        ; Check for address boundary overflow
                            incf    PCLATH,F        ; Increment upper PC Latch if there is an overflow  
                            movwf    FSR            ; Use the FSR register as a Temp Register to hold W register value
                            movf    PCLATH,W        ; Move upper PC Latch to W register
                            addlw    HIGH    TABLA        ; Add W register to TABLA HIGH address; store in W
                            movwf    PCLATH            ; Move W register to TABLA HIGH address
                            movf    FSR,W            ; Move the FSR Temp register to W register
                            movwf    PCL            ; Move the W register to PCL ; This move causes an indexed jump

    ;===================================================================================================
        org        d'510'                ; Chosen to purposefully straddle a boundary ... can be anywhere                    
    TABLA:
         RETLW B'00110000'        ;<-- Index = 0    ; Note: These returns "complete" the return from the 'Computed_CALL'
         RETLW B'00110001'        ;<-- Index = 1
         RETLW B'00110010'        ;<-- Index = 2
         RETLW B'00110011'        ;<-- Index = 3
         RETLW B'00110100'        ;<-- Index = 4
         RETLW B'00110101'        ;<-- Index = 5
         RETLW B'00110110'        ;<-- Index = 6
         RETLW B'00110111'        ;<-- Index = 7
         RETLW B'00111000'        ;<-- Index = 8
         RETLW B'00111001'        ;<-- Index = 9
           
      END
     

    post edited by Beau Schwabe - 2020/04/09 00:47:11
    #15
    ric
    Super Member
    • Total Posts : 26942
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pc issues in 1 page long codes 2020/04/09 01:43:51 (permalink)
    +1 (1)
    If you get particularly devious, you can use the PCLATH register itself as the temporary storage.
     
    https://www.microchip.com/forums/FindPost/876718
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    Alex887
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/26 09:04:07
    • Location: 0
    • Status: offline
    Re: pc issues in 1 page long codes 2020/04/09 16:14:29 (permalink)
    0
    Beau Schwabe
    Here is a computed CALL routine that might help.  Keep in mind that any writes to the PCLATH have no effect to the program location UNTIL you write to the PCL directly or do a CALL or a GOTO.  Because of that you can use it to your advantage.
     

     
        UDATA
    Temp_Address    res 2
    Index        res 1
        
     
     ORG 0x00
     

    MainLOOP:
            movlw   d'6'            ; Load Offset Index here
            movwf   Index
            Call    Computed_CALL  
            
        goto    MainLOOP
        
        
    Computed_CALL:    
        
                            movlw    HIGH    TABLA        ; Move HIGH Address into Temp_Address+1
                            movwf    Temp_Address+1
                            movlw    LOW    TABLA        ; Move LOW Address into    Temp_Address
                            movwf    Temp_Address

                            movf    Index    ,W        ; Add Index to Temp_Address
                            addwf    Temp_Address,F
                            btfsc    STATUS,C        ; Check for overflow
                            incf    Temp_Address+1        ; Increment Temp_Address+1 on overflow
        
                            movf    Temp_Address+1,W    ; Start PCL jump ; result is in W    
                            movwf    PCLATH
                            movf    Temp_Address,W
                            movwf    PCL


    ;===================================================================================================
        org        d'510'                ; Chosen to purposefully straddle a boundary ... can be anywhere                    
    TABLA:
         RETLW B'00110000'        ;<-- Index = 0    ; Note: These returns "complete" the return from the 'Computed_CALL'
         RETLW B'00110001'        ;<-- Index = 1
         RETLW B'00110010'        ;<-- Index = 2
         RETLW B'00110011'        ;<-- Index = 3
         RETLW B'00110100'        ;<-- Index = 4
         RETLW B'00110101'        ;<-- Index = 5
         RETLW B'00110110'        ;<-- Index = 6
         RETLW B'00110111'        ;<-- Index = 7
         RETLW B'00111000'        ;<-- Index = 8
         RETLW B'00111001'        ;<-- Index = 9
           
      END
     





     
    its a nice aproach to table management. i´m shure it will be handy in the future
     
    1and0
     
    These variables overlap SFRs in your PIC device.
     




    Yes, i learned it the hard way...
    #17
    Jump to:
    © 2020 APG vNext Commercial Version 4.5