• AVR Freaks

Hot!pic18f4520 crashes unexpectedly

Author
nesmio
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2011/08/23 02:05:26
  • Location: Rome - Italy
  • Status: offline
2020/07/10 02:36:16 (permalink)
0

pic18f4520 crashes unexpectedly

Hi everyone,
 
I have this problem: while browsing the various menus (using D0pin , D1pin and D2pin) the pic18f could freeze. It doesn't always happen, but randomly.
If I don't use the keyboard keys, everything works.
when the pic18f freezes I can only switch it off and on again.
 
my pic18f4520 uses:
- a 20x4 display with I2c interface;
- 2 channels of the ADC module;
- does not use interrupts;
- 4Mhz oscillator cristal.
 
pic18f's pinout:
;A0 in analogic Water Temp thermo fireplace
;A1 in analogic Water Pression thermo fireplace 
;A2 out dgt signal UP DGT potentiometer (thermo fireplace air intake)
;A3 out dgt thermo fireplace allarm
;A4 out dgt diplay illumination
;A5 in dgt motorized valve status (cooling down)
;
;B0 in dgt thermo fireplace smoke temperature 
;B1 in dgt motorized valve status (hot water production)
;B2 in dgt motorized valves status (natural gas boiler connection valve)
;B3 in dgt motorized valves status (thermo fireplace connection valve )
;B4 in dgt not used
;B5 in dgt flooding sensor
;B6 in dgt not used
;B7 in dgt not used
;
;C0 out dgt display power
;C1 in dgt domestic hot water flow switch
;C2 in dgt thermo fireplace door switch
;C3 in dgt bus I2C SCK 
;C4 in dgt bus I2C SDA
;C5 out dgt not used
;C6 out dgt not used
;C7 out dgt not used
;
;D0 in dgt button "-" 
;D1 in dgt button "OK"
;D2 in dgt button "+"
;D3 out dgt signal DW DGT potentiometer (thermo fireplace air intake)
;D4 out dgt not used 
;D5 out dgt relay scambio metano legna (legna mandata)
;D6 out dgt relay inibizione caldaia metano/ACS da PST
;D7 out dgt relay scambio metano/legna (2 metano in parallelo - legna ritorno)
;
;E0 out dgt relay e/v raffreddamento T/C
;E1 out dgt relay circolatore T/C + aria rimbotto TC
;E2 out dgt relay e/v ACS

pic18f's bits configuration:

#define BAUD D'100'
#define FOSC D'4000'
#include p18f4520.inc ;Include standard header file for the selected device.
 
;- CONFIGURATION REGISTER 1H - 
CONFIG IESO=OFF 
CONFIG OSC=XT 
;- CONFIGURATION REGISTER 2L 
CONFIG BOREN=OFF, BORV=3 
;- CONFIGURATION REGISTER 2H 
CONFIG WDT=OFF, WDTPS=128 
;- CONFIGURATION REGISTER 3H 
CONFIG CCP2MX=PORTC 
;- CONFIGURATION REGISTER 4L 
CONFIG STVREN=OFF, LVP=OFF, DEBUG=OFF 
;- CONFIGURATION REGISTER 5L 
CONFIG CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF 
;- CONFIGURATION REGISTER 5H 
CONFIG CPD=OFF, CPB=OFF 
;- CONFIGURATION REGISTER 6L 
CONFIG WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF 
;- CONFIGURATION REGISTER 6H 
CONFIG WRTD=OFF, WRTB=OFF, WRTC=OFF 
;- CONFIGURATION REGISTER 7L 
CONFIG EBTR3=OFF, EBTR2=OFF, EBTR1=OFF, EBTR0=OFF 
;- CONFIGURATION REGISTER 7H 
CONFIG EBTRB=OFF

pic18f ports configuration:
 
ORG 0x0000
movlw 0x80 ; 80 --> W (disabilita le resistenze di pull-up della porta B)
movff WREG,INTCON2 ; W --> INTCON2
movlw 0x00 ; 00 --> W (tutti gli interrupts sono disabilitati)
movff WREG,INTCON ; W --> INTCON 
movff WREG,INTCON3 ; W --> INTCON3 
movff WREG,RCON ; W --> RCON 
movlw 0x00 ; 00 --> W 
movff WREG,RCSTA ; W --> RCSTA (RC6 and RC7 as I/O pins) ----- usart disabilitata -----
; MSSP module
banksel SSPCON1
movlw 0x28
movff WREG,SSPCON1 ; MSSP attivo - master mode - c3 e c4 come bus I2C
banksel SSPSTAT
movlw 0x80
movff WREG,SSPSTAT ; bus I2C @ 100 KHz 
banksel SSPADD
movlw (FOSC / (4*BAUD)) -1 ; imposta sspadd per i baud desiderati
movff WREG,SSPADD

; configurazione PORTA 
movlw 0x01 ; 01 --> W 
movff WREG,ADCON0 ; W --> ADCON0 (ADC=0n)
movlw 0x0D ; 0D --> W 
movff WREG,ADCON1 ; W --> ADCON1 I/O=A2,A3,A5,E0,E1,E2,B2,B3,B1,B4,B0 Analogico=A0
movlw 0xBE ; BE --> W 
movff WREG,ADCON2 ; W --> ADCON2 impostazioni ADC module
clrf T0CON ; RA4 come i/o pin --- timer0 disabilittao ---- 
clrf LVDCON ; RA5 come I/O pin
movlw 0x23 ; A2:A4 output dgt - A0 e A1 input analogici A5 input dgt 
movwf TRISA 
clrf PORTA ; azzeramento porta A 
; configurazione PORTB 
movlw 0xFF ; FF --> W 
movwf TRISB ; RB0:RB5 in - B6:B7 out
; configurazione PORTC
movlw 0x1E
movwf TRISC ; C0:C7 come bits di output tranne C1-->C4
clrf PORTC
; configurazione PORTD 
movlw 0x07
movwf TRISD ; D0:D2 in - D3:D7 out
clrf PORTD
; configurazione PORTE
clrf TRISE ; E0:E2 come bits di output
clrf PORTE ; azzero la porta E
movlb 0x01
call azzera_variabili_stb
...
can you help me?
 
Thank you
 
Simon
#1

17 Replies Related Threads

    atferrari
    Super Member
    • Total Posts : 1448
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/10 04:11:20 (permalink)
    +1 (1)
    Help yourself by posting your code between the code tags available when composing the text.

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #2
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 05:33:55 (permalink)
    -1 (1)
    hi atferrari,
     
     

    I send you part of my code.
     
    This is the subprogram where execution hangs (one of many):
     
    ;----------------------------------------------------------------------
    avvia_test:
    clrf CNT_CONV
    bcf FLAG_SYS_2,5
    bcf FLAG_SYS_2,6
    bsf FLAG_SYS_3,6     ; esegue gestione_tercam in modalità simulazione
    bcf PORTA,4
    call ritardo1000      ; 1 second delay
    call ritardo250        ; 0,25 second delay
    call ritardo250
    call pulisci_display      ; clear the display
    call ritardo250
    call scrivi_testtc
    call scrivi_opz_test
    bsf PORTA,4
    clrf CNT_FOR_TEST
    call decodifica_tasti_display        ; shows info on display based on the value of CNT_FOR_TEST
    call ritardo250
    loop_test:
       call ritardo62_test         ; 62millisecond delay
       incf CNT_CONV
       movlw 0x16
       cpfsgt CNT_CONV
       goto next_tastomenotest
           clrf CNT_CONV
           call converti              ; converts analog inputs in numeric value
    next_tastomenotest:
       btfsc PORTD,0 ;             "-" botton 
       goto next0_test
           decf CNT_FOR_TEST
           movlw 0xFF
           cpfseq CNT_FOR_TEST
           goto next_tastomeno
              clrf CNT_FOR_TEST
              call lampi
    next_tastomeno:
           movlw 0x0A
           cpfslt CNT_FOR_TEST
           goto next0_test
           bcf PORTA,4
           call ritardo250
           call ritardo250
           call ritardo250
           call ritardo1000
           bsf PORTA,4
           call decodifica_tasti_display
           call ritardo250

    next0_test:
     
       btfsc PORTD,2                ; + botton
       goto next1_test
          incf CNT_FOR_TEST 
          movlw 0x0F
          cpfsgt CNT_FOR_TEST
          goto next_tastopiu
            movff WREG,CNT_FOR_TEST
            call lampi
    next_tastopiu:
          movlw 0x0A
          cpfslt CNT_FOR_TEST
          goto next1_test
          bcf PORTA,4
          call ritardo250
          call ritardo250
          call ritardo250
          call ritardo1000
          bsf PORTA,4
          call decodifica_tasti_display
          call ritardo250
    next1_test:
     
      movlw 0x09
      cpfsgt CNT_FOR_TEST
     goto next11_test
         call decodifica_tasti_display    ; if CNT_FOR_TEST grater 09 continuously shows the info on the display       
                                                           ;(automatic refresh)
         call ritardo250
         call ritardo250
         call ritardo250
         call ritardo1000
    next11_test:
     
       btfsc PORTD,1     ; change/ok button
       goto next2_test
       movlw 0x09
       cpfsgt CNT_FOR_TEST
       goto non_e_opz_09
           call lampi
           goto next2_test
    non_e_opz_09:
       call decodifica_tasti_azioni       ; does things according to the value of CNT_FOR_TEST
       bcf PORTA,4
       call ritardo250
       call ritardo250
       call ritardo250
       call ritardo1000
       bsf PORTA,4
       call decodifica_tasti_display       ; show info based on things done

       call ritardo250
       call scrivi_opz_test               ;shows the meaning of the keys (fourth line of the display)

       call ritardo250
    next2_test:
     
    btfss FLAG_SYS_2,5
    goto loop_test
     
     
    call pulisci_display
    call scrivi_attendere
    call ritardo1000
    call ritardo1000
    call ritardo1000

    btfss PORTD,5
    goto exit_test_0
    bcf PORTD,5
    call ritardo1000
    call ritardo1000
    exit_test_0:
    btfss PORTD,6
    goto exit_test_1
    bcf PORTD,6
    call ritardo1000
    call ritardo1000
    exit_test_1:
    btfsc PORTD,1
    goto exit_test_2
    bcf PORTD,7
    call ritardo1000
    call ritardo1000
    exit_test_2:
    btfss PORTE,0
    goto exit_test_3
    bcf PORTE,0
    call ritardo1000
    call ritardo1000
    exit_test_3:
    btfss PORTE,1
    goto exit_test_4
    bcf FLAG_SYS_3,0
    clrf CNT_CIRC_HH
    clrf CNT_CIRC_PROD
    bsf FLAG_SYS_3,4
    bcf PORTE,1
    call ritardo1000
    call ritardo1000
    exit_test_4:
    btfss PORTE,2
    goto exit_test_5
    bcf PORTE,2
    call ritardo1000
    call ritardo1000
    exit_test_5:
    btfss PORTA,3
    goto exit_test_6
    bcf PORTA,3
    call ritardo1000
    call ritardo1000
    exit_test_6:

    bsf FLAG_SYS,1 ; inibisce il controllo delle ee/vv per permettere
    ; il corretto posizionamento
    bcf FLAG_SYS_3,6
    movlw 0x05 ; illuminazione display a tempo
    movff WREG,CNTLED
    bsf PORTA,4
    bsf FLAG_SYS_2,0 ; si inizia con il led acceso
    return
    ;----------------------------------------------------------------------
     

    I posted comments to help you understand the code
     
    tnks
     
    #3
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/10 05:43:47 (permalink)
    +1 (1)
    I guess you did not understand the request for "code tags"
    Place
    [CODE]
    before your block of code, and
    [/CODE]
    after it, except use lower-case "code" and "/code" where  I used upper case so you could see them.
    If I use lower case, it looks like this:

    before your block of code, and


    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!
    #4
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 06:14:18 (permalink)
    0 (2)
    i'm sorry ... but I still don't understand what I have to dosad: sadpink: pink
    #5
    atferrari
    Super Member
    • Total Posts : 1448
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/10 06:32:11 (permalink)
    +1 (1)
    Use the Full Version window to compose your post. Explore the tools up on the bar.
    One is what you use to tag text as code.

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3984
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 06:57:40 (permalink)
    -1 (3)
    It's code that only you can understand.
     
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #7
    NorthGuy
    Super Member
    • Total Posts : 6228
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 07:37:00 (permalink)
    +1 (1)
    This is a bug in your code. Since you wrote the code, you have better chance to find it than anyone else.
    #8
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 08:19:18 (permalink)
    0
    @atferrari, my code sent as you suggested...
     
    tnks
     
     
     
     
     
     

    ;----------------------------------------------------------------------
    avvia_test:
    clrf CNT_CONV
    bcf FLAG_SYS_2,5
    bcf FLAG_SYS_2,6
    bsf FLAG_SYS_3,6 ; esegue gestione_tercam in modalità simulazione
    bcf PORTA,4
    call ritardo1000 ; 1 second delay
    call ritardo250 ; 0,25 second delay
    call ritardo250
    call pulisci_display ; clear the display
    call ritardo250
    call scrivi_testtc
    call scrivi_opz_test
    bsf PORTA,4
    clrf CNT_FOR_TEST
    call decodifica_tasti_display ; shows info on display based on the value of CNT_FOR_TEST
    call ritardo250
    loop_test:
       call ritardo62_test ; 62millisecond delay
       incf CNT_CONV
       movlw 0x16
       cpfsgt CNT_CONV
       goto next_tastomenotest
           clrf CNT_CONV
           call converti ; converts analog inputs in numeric value
    next_tastomenotest:
       btfsc PORTD,0 ; "-" botton
       goto next0_test
           decf CNT_FOR_TEST
           movlw 0xFF
           cpfseq CNT_FOR_TEST
           goto next_tastomeno
              clrf CNT_FOR_TEST
              call lampi
    next_tastomeno:
           movlw 0x0A
           cpfslt CNT_FOR_TEST
           goto next0_test
           bcf PORTA,4
           call ritardo250
           call ritardo250
           call ritardo250
           call ritardo1000
           bsf PORTA,4
           call decodifica_tasti_display
           call ritardo250

    next0_test:
     
       btfsc PORTD,2 ; + botton
       goto next1_test
          incf CNT_FOR_TEST
          movlw 0x0F
          cpfsgt CNT_FOR_TEST
          goto next_tastopiu
            movff WREG,CNT_FOR_TEST
            call lampi
    next_tastopiu:
          movlw 0x0A
          cpfslt CNT_FOR_TEST
          goto next1_test
          bcf PORTA,4
          call ritardo250
          call ritardo250
          call ritardo250
          call ritardo1000
          bsf PORTA,4
          call decodifica_tasti_display
          call ritardo250
    next1_test:
     
      movlw 0x09
      cpfsgt CNT_FOR_TEST
     goto next11_test
         call decodifica_tasti_display ; if CNT_FOR_TEST grater 09 continuously shows the info on the display
                                                           ;(automatic refresh)
         call ritardo250
         call ritardo250
         call ritardo250
         call ritardo1000
    next11_test:
     
       btfsc PORTD,1 ; change/ok button
       goto next2_test
       movlw 0x09
       cpfsgt CNT_FOR_TEST
       goto non_e_opz_09
           call lampi
           goto next2_test
    non_e_opz_09:
       call decodifica_tasti_azioni ; does things according to the value of CNT_FOR_TEST
       bcf PORTA,4
       call ritardo250
       call ritardo250
       call ritardo250
       call ritardo1000
       bsf PORTA,4
       call decodifica_tasti_display ; show info based on things done

       call ritardo250
       call scrivi_opz_test ;shows the meaning of the keys (fourth line of the display)

       call ritardo250
    next2_test:
     
    btfss FLAG_SYS_2,5
    goto loop_test
     
     
    call pulisci_display
    call scrivi_attendere
    call ritardo1000
    call ritardo1000
    call ritardo1000

    btfss PORTD,5
    goto exit_test_0
    bcf PORTD,5
    call ritardo1000
    call ritardo1000
    exit_test_0:
    btfss PORTD,6
    goto exit_test_1
    bcf PORTD,6
    call ritardo1000
    call ritardo1000
    exit_test_1:
    btfsc PORTD,1
    goto exit_test_2
    bcf PORTD,7
    call ritardo1000
    call ritardo1000
    exit_test_2:
    btfss PORTE,0
    goto exit_test_3
    bcf PORTE,0
    call ritardo1000
    call ritardo1000
    exit_test_3:
    btfss PORTE,1
    goto exit_test_4
    bcf FLAG_SYS_3,0
    clrf CNT_CIRC_HH
    clrf CNT_CIRC_PROD
    bsf FLAG_SYS_3,4
    bcf PORTE,1
    call ritardo1000
    call ritardo1000
    exit_test_4:
    btfss PORTE,2
    goto exit_test_5
    bcf PORTE,2
    call ritardo1000
    call ritardo1000
    exit_test_5:
    btfss PORTA,3
    goto exit_test_6
    bcf PORTA,3
    call ritardo1000
    call ritardo1000
    exit_test_6:

    bsf FLAG_SYS,1 ; inibisce il controllo delle ee/vv per permettere
    ; il corretto posizionamento
    bcf FLAG_SYS_3,6
    movlw 0x05 ; illuminazione display a tempo
    movff WREG,CNTLED
    bsf PORTA,4
    bsf FLAG_SYS_2,0 ; si inizia con il led acceso
    return
    ;----------------------------------------------------------------------

    #9
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/10 08:34:57 (permalink)
    0
    @atferrari:  this is the code that configures the pic
    regards
     

    ;----------------------------------------------------------------------
    ;A0 in analogic Water Temp thermo fireplace
    ;A1 in analogic Water Pression thermo fireplace
    ;A2 out dgt signal UP DGT potentiometer (presa aria)
    ;A3 out dgt allarm thermo fireplace
    ;A4 out dgt diplay illumination
    ;A5 in dgt motorized valve status (cooling down)
    ;
    ;B0 in dgt smoke temperature [=1]
    ;B1 in dgt motorized valve status (hot water production) [=1: acs viene prodotta da TC]
    ;B2 in dgt motorized valves status (natural gas boiler) [=1: TC disattivo]
    ;B3 in dgt motorized valves status (thermo fireplace) [=1: TC attivo]
    ;B4 in not used
    ;B5 in dgt flooding [=0]
    ;B6 in not used
    ;B7 in not used
    ;
    ;C0 out dgt display power (1:alimentazione display)
    ;C1 in dgt domestic hot water flow switch 0= flusso acs 1= no flusso acs
    ;C2 in dgt thermo fireplace door switch [=1: l'anta è sollevata (aperta)]
    ;C3 in dgt bus I2C SCK
    ;C4 in dgt bus I2C SDA
    ;C5 out not used
    ;C6 out not used
    ;C7 out not used
    ;
    ;D0 in dgt button "-" tastiera #1 - errori (-)
    ;D1 in dgt button "OK" tastiera #2 - configurazione (OK)
    ;D2 in dgt button "+" tastiera #3 - manutenzione (+)
    ;D3 out dgt segnale DW potenziometro DGT (presa aria)
    ;D4 out not used
    ;D5 out dgt relay scambio metano legna (legna mandata)
    ;D6 out dgt relay inibizione caldaia metano/ACS da PST
    ;D7 out dgt relay scambio metano/legna (2 metano in parallelo - legna ritorno)
    ;
    ;E0 out dgt relay e/v raffreddamento T/C
    ;E1 out dgt relay circolatore T/C + aria rimbotto TC
    ;E2 out dgt relay e/v ACS
    ;---------------------------------------------------------------------

    #define BAUD D'100'
    #define FOSC D'4000'

    #include p18f4520.inc ;Include standard header file
                                 ;for the selected device.

    ;- CONFIGURATION REGISTER 1H -
    CONFIG IESO=OFF
    CONFIG OSC=XT
    ;- CONFIGURATION REGISTER 2L
    CONFIG BOREN=OFF, BORV=3
    ;- CONFIGURATION REGISTER 2H
    CONFIG WDT=OFF, WDTPS=128
    ;- CONFIGURATION REGISTER 3H
    CONFIG CCP2MX=PORTC
    ;- CONFIGURATION REGISTER 4L
    CONFIG STVREN=OFF, LVP=OFF, DEBUG=OFF
    ;- CONFIGURATION REGISTER 5L
    CONFIG CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF
    ;- CONFIGURATION REGISTER 5H
    CONFIG CPD=OFF, CPB=OFF
    ;- CONFIGURATION REGISTER 6L
    CONFIG WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF
    ;- CONFIGURATION REGISTER 6H
    CONFIG WRTD=OFF, WRTB=OFF, WRTC=OFF
    ;- CONFIGURATION REGISTER 7L
    CONFIG EBTR3=OFF, EBTR2=OFF, EBTR1=OFF, EBTR0=OFF
    ;- CONFIGURATION REGISTER 7H
    CONFIG EBTRB=OFF
      
    PROCESSOR 18f4520
    RADIX HEX

    ; dichiarazioni costanti
    ;constant xxx=0x00
      

    ; dichiarazione variabili
    CNT0 EQU 0x100 ; contatore ciclo di ritardo
    CNT1 EQU 0x101 ; contatore ciclo di ritardo
    CNT_EEVV EQU 0x102 ; contatore ciclo di ritardo
    CNT_TURBO EQU 0x103
    TIMERABOCCO_HEX EQU 0x104 ; variabile di appoggio per lettura portB
    TIMEPROTCIRC_HEX EQU 0x105 ; variabile di appoggio per lettura PORTD
    APPO_INT EQU 0x106
    DISPL EQU 0x107
    CNT_CIRC_HH EQU 0x108
    CNT_STEP_PA EQU 0x109
    CNT_CONV EQU 0x10A ; contatore per eseguire le conversioni
    DECINE_TEMP EQU 0x10B
    UNITA_TEMP EQU 0x10C
    APPO_AIR EQU 0x10D
    FLAG_SYS_1 EQU 0x10E
    FLAG_SYS EQU 0x10F
    T_IST EQU 0x110 ; temperatura istantanea
    T_START EQU 0x111 ; temp quando rilevata fiamma
    FLAG_ERR EQU 0x112
    LEDS EQU 0x113
    CNT_MIN EQU 0x114
    CNT_RABOCCO EQU 0x115
    CNT_CIR_RUN EQU 0x116
    CNT_ORE EQU 0x117
    CNT_GG EQU 0x118
    VAL_CNT_AIOF EQU 0x119
    CNT_AIOF EQU 0x11A
    RIPETI_CNT_AIOF EQU 0x11B
    APPO_TOFF EQU 0x11C
    T_AIR EQU 0x11D ; temp in cui gestire la presa aria
    APPO_BCK EQU 0x11E
    BCK_FFLLGG EQU 0x11F
    FLAG_SYS_2 EQU 0x120
    BAR_IST EQU 0x121
    ; variabili configurative - inizio -
    FLAG_CONF_0 EQU 0x122
    FLAG_CONF_1 EQU 0x123
    TPRODMAX EQU 0x124 ;il picco massimo raggiunto x sessione
    T_LOAD_WOOD EQU 0x125 ;47C°
    TACS_ON EQU 0x126 ;50C°
    TACS_OFF EQU 0x127 ;45C°
    BAR_L EQU 0x128 ;0,8Bar
    TMAX_ON EQU 0x129 ;90C°
    TMAX_OFF EQU 0x12A ;87C°
    AIR_OFFSET EQU 0x12B ;offset presa aria
    TIME_AIOF EQU 0x12C ;durata offset presa aria
    MOLT_TIAIOF EQU 0x12D ;moltiplica il tempo TIME_AIOF
    TIME_TURBO EQU 0x12E ;durata riapertura pa (turbo)
    OFFSET_TURBO EQU 0x12F ;offset presa aria per turbo
    TIMEOUT_ACS EQU 0x130 ; minuti superati i quali sono ammesse
    TIME_OFF_CIRC EQU 0x131 ; ritardo in ore spengimento post spengimento TC
    TIME_PROT_CIRC EQU 0x132 ; durata in minuti ciclo protezione circolatore
    TIME_RABOCCO EQU 0x133 ; durata rabocco acqua TC
    ; variabili configurative - fine - ; variazioni sulla produzione ACS da TC
     
    DECIMAL_PRESS EQU 0x134
    CNT_FOR_TEST EQU 0x135
    CNT_TEST_L EQU 0x136
    CNT_TEST_H EQU 0x137
    CNT_FOR_CONF EQU 0x138
    CNT_FOR_VAL EQU 0x139
    APPO_VAL EQU 0x13A
    MAXYT EQU 0x13B
    T0 EQU 0x13C
    T1 EQU 0x13D
    CNT_PORTA EQU 0x13E
    FLAG_ERR_1 EQU 0x13F
    INDEX EQU 0x140
    CNTLED EQU 0x141
    CNT_PA EQU 0x142
    APPO_OFFSET EQU 0x143
    APPO_TIME EQU 0x144
    CNT_SEC EQU 0x145
    T_D EQU 0x146
    T_U EQU 0x147
    NEW_POS_PA EQU 0x148
    APPO_MODE EQU 0x149
    BCK_MOLT EQU 0x14A
    CNT_BELL EQU 0x14B
    BCK_OFFS EQU 0x14C
    BCK_TIME EQU 0x14D
    CNT_FLUS EQU 0x14E
    UNITA_PRESS EQU 0x14F
    TIMEOUTACS_HEX EQU 0x150
    CNT_ACS EQU 0x151
    CNT_CIRC_PROD EQU 0x152
    FLAG_SYS_3 EQU 0x153
    CNT_TRAND EQU 0x154
    CNT_WOOD EQU 0x155
    BCK_FLAGERR EQU 0x156
    TIMEOFFCIRC_HEX EQU 0x157
    BCK_FLAGERR1 EQU 0x158


    ; inizio programma principale
    ORG 0x0000
    movlw 0x80 ; 80 --> W (disabilita le resistenze di pull-up della porta B)
    movff WREG,INTCON2 ; W --> INTCON2
    movlw 0x00 ; 00 --> W (tutti gli interrupts sono disabilitati)
    movff WREG,INTCON ; W --> INTCON
    movff WREG,INTCON3 ; W --> INTCON3
    movff WREG,RCON ; W --> RCON
    movlw 0x00 ; 00 --> W
    movff WREG,RCSTA ; W --> RCSTA (RC6 and RC7 as I/O pins) ----- usart disabilitata -----

    ; MSSP module
    banksel SSPCON1
    movlw 0x28
    movff WREG,SSPCON1 ; MSSP attivo - master mode - c3 e c4 come bus I2C
    banksel SSPSTAT
    movlw 0x80
    movff WREG,SSPSTAT ; bus I2C @ 100 KHz
    banksel SSPADD
    movlw (FOSC / (4*BAUD)) -1 ; imposta sspadd per i baud desiderati
    movff WREG,SSPADD


    ; configurazione PORTA
    movlw 0x01 ; 01 --> W
    movff WREG,ADCON0 ; W --> ADCON0 (ADC=0n)

    movlw 0x0D ; 0D --> W
    movff WREG,ADCON1 ; W --> ADCON1 I/O=A2,A3,A5,E0,E1,E2,B2,B3,B1,B4,B0 Analogico=A0

    movlw 0xBE ; BE --> W
    movff WREG,ADCON2 ; W --> ADCON2 impostazioni ADC module

    clrf T0CON ; RA4 come i/o pin --- timer0 disabilittao ----
    clrf LVDCON ; RA5 come I/O pin
    movlw 0x23 ; A2:A4 output dgt - A0 e A1 input analogici A5 input dgt
    movwf TRISA
    clrf PORTA ; azzeramento porta A
    ; configurazione PORTB
    movlw 0xFF ; FF --> W
    movwf TRISB ; RB0:RB5 in - B6:B7 out
    ; configurazione PORTC
    movlw 0x1E
    movwf TRISC ; C0:C7 come bits di output tranne C1-->C4
    clrf PORTC
    ; configurazione PORTD
    movlw 0x07
    movwf TRISD ; D0:D2 in - D3:D7 out
    clrf PORTD
    ; configurazione PORTE
    clrf TRISE ; E0:E2 come bits di output
    clrf PORTE ; azzero la porta E
    ; inizializzazione variabili
    movlb 0x01
    call azzera_variabili_stb
    ...

    #10
    atferrari
    Super Member
    • Total Posts : 1448
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/10 10:09:55 (permalink)
    +2 (2)
    Something I learnt quite soon is, when creating fresh code, is to add functional parts and test them progressively.Exactly thinking of quella tastiera, I would peel off everything but the keypad routine and verify how it works. That never failed to me. I see you are disabling the pullup resistors. I like them. How many keys are you using?

    Word of caution 1: make sure that your keys are properly debounced. I use 35 ms and, until now, no problems.

    Word of caution 2: when pressing a key you have two options: expecting an action to happen once, (no matter how long you keep the key pressed down) or otherwise,  an action repeating again and again until you release the key.

    Word of caution 3: if your application requires only single keys pressed down at a certain moment, the code servicing each key should cater for that to eliminate the risk of having two or more pressed down even for an instant.

    Buena suerte
    post edited by atferrari - 2020/07/16 03:00:28

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #11
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/14 06:06:04 (permalink)
    0
    hi atferrari, 
     
    I know the rules you suggested to me and i'm using (only) 3 keys... my code, when i used a 20x4 display in 4 bit mode,  worked well, now a little less sad: sad
     
    For technical reasons I had to use the display with i2c interface (I need to have a longer wiring length between pic18f and display).

    i used I2C to pilot an rtcc successfully, but is the first time i use I2c to pilot an display with serial interface: 
    it seems I have full control of the display, but on the most beautiful it freezes mad: mad
     
    I am currently testing my code (stress test) and have come to the conclusion that the hang is introduced from the I2c part: I suspect I'm wrong in the configuration / use of the i2c.
     
    The drama is that everything is ok for me and I don't know where to start. it would take a pair of external eyes...
     
    Regards
     
    #12
    atferrari
    Super Member
    • Total Posts : 1448
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/14 06:29:14 (permalink)
    0
    Sorry nesmio,
    Mi experience using I2C has been always in short distances with no problems. Not sure what else to suggest.

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #13
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/14 06:35:16 (permalink)
    +2 (2)
    How long is the cable?
    How many ground wires?
    What value pull up resistors?
    Which end of the cable are the pull up resistors?

    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!
    #14
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/14 07:14:11 (permalink)
    0

    - the cable is about 10 feet long  (the cable is a piece of cat 6 network cable);
    - one groud wire;
    - pull up resistors are 2,2 Kohm 1/2 watt;
    - resistors are close to pic18f.
     
    tnks
     
     
     
    #15
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic18f4520 crashes unexpectedly 2020/07/14 13:19:56 (permalink)
    +2 (2)
    - the cable is about 10 feet long  (the cable is a piece of cat 6 network cable);
    That is much longer than I2C is intended for.
    It is possible, but you must be very careful.
    - one groud wire;
    Ouch. Not enough!
    Use one twisted pair in the cable for SCL and ground, and a second twisted pair for SDA and ground.
    Do NOT run SDA and SCL up the same twisted pair!
     
    - pull up resistors are 2,2 Kohm 1/2 watt;
    - resistors are close to pic18f.
    The resistors would be better at the far end, or even better doubled in value (4.7k) and at both ends.
     

    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
    davea
    Super Member
    • Total Posts : 278
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/14 17:53:08 (permalink)
    0
    The resistors would be better at the far end, or even better doubled in value (4.7k) and at both ends.

    best way..
    and power on 1 pair
    post edited by davea - 2020/07/14 17:58:12
    #17
    nesmio
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2011/08/23 02:05:26
    • Location: Rome - Italy
    • Status: offline
    Re: pic18f4520 crashes unexpectedly 2020/07/15 00:03:16 (permalink)
    0

    thanks, I will treasure the suggestions you have given me.
    ...

    then I will tell you how it will end.
     
    regards
    #18
    Jump to:
    © 2020 APG vNext Commercial Version 4.5