PIC16F84A to PIC16F877 migration failure.

Discussion in 'General Electronics Chat' started by DonutChan, Mar 16, 2019.

  1. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    I had my piano program successfully work on PIC16F84A, but when i took the same program with the same wiring to another PIC(Pic16F877) on Proteus, the sound keeps cutting off in an annoying way. I don't know why. Same problem happened after i took it to PIC16F877A. I used assembly code,, some buttons and a speaker, along with their resistors etc.. please help? i tried to look for some hints but nothing seemed to tick.
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    Post your code?
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    18,805
    5,854
    The code you posted has a problem!
    Max.:rolleyes:
     
    JohnInTX likes this.
  4. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    (i used a program i found on the web, but got a grasp of how it works.)

    Code (Microchip Assembler):
    1.  
    2.   list        p=16f877A
    3.  
    4.     #include    <p16f877A.inc>
    5.  
    6.    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
    7.  
    8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    9.  
    10.     CBLOCK    H'0C'  
    11.  
    12.  
    13.  
    14.     CNT
    15.  
    16.     CNT10
    17.  
    18.     CNTM
    19.  
    20.     ENDC
    21.  
    22. ;*****************************************
    23.  
    24. ;
    25.  
    26. ;*****************************************
    27.  
    28.  
    29.  
    30.  
    31.  
    32.     CLRF    PORTB
    33.  
    34.     BSF    STATUS,RP0
    35.  
    36.     CLRF    TRISA
    37.  
    38.     BCF    OPTION_REG,7
    39.  
    40.     MOVLW    H'FF'
    41.  
    42.     MOVWF    TRISB
    43.  
    44.     BCF    STATUS,RP0
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52. ;*******************************************
    53.  
    54. ;    KEY
    55.  
    56. ;*******************************************
    57.  
    58. KEY
    59.  
    60.     BTFSC    PORTB,0        ;KEY ON?
    61.  
    62.     GOTO    K1        ;KEY OFF
    63.  
    64.     CALL    DEL10M        ;
    65.  
    66.     BTFSC    PORTB,0  
    67.  
    68.     GOTO    KEY         ;KEY OFF
    69.  
    70.     CALL    DO_        ;?h
    71.  
    72. K1    BTFSC    PORTB,1        ;KEY ON?
    73.  
    74.     GOTO    K2        ;KEY OFF
    75.  
    76.     CALL    DEL10M
    77.  
    78.     BTFSC    PORTB,1  
    79.  
    80.     GOTO    K1
    81.  
    82.     CALL    RE      
    83.  
    84. K2    BTFSC    PORTB,2        ;KEY ON?
    85.  
    86.     GOTO    K3        ;KEY OFF
    87.  
    88.     CALL    DEL10M
    89.  
    90.     BTFSC    PORTB,2
    91.  
    92.     GOTO    K2
    93.  
    94.     CALL    MI      
    95.  
    96. K3    BTFSC    PORTB,3        ;KEY ON?
    97.  
    98.     GOTO    K4        ;KEY OFF
    99.  
    100.     CALL    DEL10M
    101.  
    102.     BTFSC    PORTB,3
    103.  
    104.     GOTO    K3
    105.  
    106.     CALL    FA  
    107.  
    108. K4    BTFSC    PORTB,4        ;KEY ON?
    109.  
    110.     GOTO    K5        ;KEY OFF
    111.  
    112.     CALL    DEL10M
    113.  
    114.     BTFSC    PORTB,4
    115.  
    116.     GOTO    K4
    117.  
    118.     CALL    SO        ;?\
    119.  
    120.  
    121.  
    122. K5    BTFSC    PORTB,5        ;KEY ON?
    123.  
    124.     GOTO    K6        ;KEY OFF
    125.  
    126.     CALL    DEL10M
    127.  
    128.     BTFSC    PORTB,5
    129.  
    130.     GOTO    K5
    131.  
    132.     CALL    RA  
    133.  
    134. K6    BTFSC    PORTB,6        ;KEY ON?
    135.  
    136.     GOTO    K7        ;KEY OFF
    137.  
    138.     CALL    DEL10M
    139.  
    140.     BTFSC    PORTB,6
    141.  
    142.     GOTO    K6
    143.  
    144.     CALL    SI  
    145.  
    146. K7    BTFSC    PORTB,7        ;KEY ON?
    147.  
    148.     GOTO    KEY         ;KEY OFF
    149.  
    150.     CALL    DEL10M
    151.  
    152.     BTFSC    PORTB,7
    153.  
    154.     GOTO    K7
    155.  
    156.     CALL    DO  
    157.  
    158.  
    159.  
    160.     GOTO    KEY
    161.  
    162. ;***********************************************
    163.  
    164. ;    10MSEC
    165.  
    166. ;  
    167.  
    168. ;***********************************************
    169.  
    170.  
    171.  
    172.  
    173.  
    174. DEL10M     MOVLW    10
    175.  
    176.     MOVWF    CNT10
    177.  
    178. DLY10    MOVLW    142
    179.  
    180.     MOVWF    CNTM
    181.  
    182. DLYU     GOTO    $+1
    183.  
    184.     GOTO    $+1
    185.  
    186.     DECFSZ    CNTM,1
    187.  
    188.     GOTO    DLYU
    189.  
    190.     DECFSZ    CNT10,1
    191.  
    192.     GOTO    DLY10
    193.  
    194.     RETURN
    195.  
    196.  
    197.  
    198.  
    199.  
    200.  
    201.  
    202.  
    203.  
    204. ;**********************************************  
    205.  
    206.  
    207.  
    208. DO_    BSF    PORTA,0
    209.  
    210.     MOVLW    67
    211.  
    212.     MOVWF    CNT
    213.  
    214.     CALL    DLY
    215.  
    216.     GOTO    $+1
    217.  
    218.     GOTO    $+1
    219.  
    220.     NOP
    221.  
    222.     BCF    PORTA,0
    223.  
    224.     MOVLW    67
    225.  
    226.     MOVWF    CNT
    227.  
    228.     CALL    DLY
    229.  
    230.     GOTO    $+1
    231.  
    232.     BTFSS    PORTB,0
    233.  
    234.     GOTO    DO_
    235.  
    236.     RETURN
    237.  
    238.  
    239.  
    240. RE    BSF    PORTA,0
    241.  
    242.     MOVLW    60
    243.  
    244.     MOVWF    CNT
    245.  
    246.     CALL    DLY
    247.  
    248.     GOTO    $+1
    249.  
    250.     BCF    PORTA,0
    251.  
    252.     MOVLW    59
    253.  
    254.     MOVWF    CNT
    255.  
    256.     CALL    DLY
    257.  
    258.     GOTO    $+1
    259.  
    260.     GOTO    $+1
    261.  
    262.     GOTO    $+1
    263.  
    264.     BTFSS    PORTB,1
    265.  
    266.     GOTO    RE
    267.  
    268.     RETURN
    269.  
    270.  
    271.  
    272. MI    BSF    PORTA,0
    273.  
    274.     MOVLW    53
    275.  
    276.     MOVWF    CNT
    277.  
    278.     CALL    DLY
    279.  
    280.     GOTO    $+1  
    281.  
    282.     GOTO    $+1
    283.  
    284.     GOTO    $+1
    285.  
    286.     NOP
    287.  
    288.     BCF    PORTA,0
    289.  
    290.     MOVLW    53
    291.  
    292.     MOVWF    CNT
    293.  
    294.     CALL    DLY
    295.  
    296.     GOTO    $+1
    297.  
    298.     BTFSS    PORTB,2
    299.  
    300.     GOTO    MI
    301.  
    302.     RETURN
    303.  
    304.  
    305.  
    306. FA    BSF    PORTA,0
    307.  
    308.     MOVLW    50
    309.  
    310.     MOVWF    CNT
    311.  
    312.     CALL    DLY
    313.  
    314.     GOTO    $+1  
    315.  
    316.     GOTO    $+1
    317.  
    318.     BCF    PORTA,0
    319.  
    320.     MOVLW    50
    321.  
    322.     MOVWF    CNT
    323.  
    324.     CALL    DLY
    325.  
    326.     NOP
    327.  
    328.     BTFSS    PORTB,3
    329.  
    330.     GOTO    FA
    331.  
    332.     RETURN
    333.  
    334.  
    335.  
    336. SO    BSF    PORTA,0
    337.  
    338.     MOVLW    45
    339.  
    340.     MOVWF    CNT
    341.  
    342.     CALL    DLY
    343.  
    344.     NOP
    345.  
    346.     BCF    PORTA,0
    347.  
    348.     MOVLW    44
    349.  
    350.     MOVWF    CNT
    351.  
    352.     CALL    DLY
    353.  
    354.     GOTO    $+1
    355.  
    356.     GOTO    $+1
    357.  
    358.     BTFSS    PORTB,4
    359.  
    360.     GOTO    SO
    361.  
    362.     RETURN
    363.  
    364.  
    365.  
    366. RA    BSF    PORTA,0
    367.  
    368.     MOVLW    40
    369.  
    370.     MOVWF    CNT
    371.  
    372.     CALL    DLY
    373.  
    374.     BCF    PORTA,0
    375.  
    376.     MOVLW    39
    377.  
    378.     MOVWF    CNT
    379.  
    380.     CALL    DLY
    381.  
    382.     GOTO    $+1
    383.  
    384.     NOP
    385.  
    386.     BTFSS    PORTB,5
    387.  
    388.     GOTO    RA
    389.  
    390.     RETURN
    391.  
    392.  
    393.  
    394. SI    BSF    PORTA,0
    395.  
    396.     MOVLW    35
    397.  
    398.     MOVWF    CNT
    399.  
    400.     CALL    DLY
    401.  
    402.     GOTO    $+1
    403.  
    404.     GOTO    $+1
    405.  
    406.     BCF    PORTA,0
    407.  
    408.     MOVLW    35
    409.  
    410.     MOVWF    CNT
    411.  
    412.     CALL    DLY
    413.  
    414.     BTFSS    PORTB,6
    415.  
    416.     GOTO    SI
    417.  
    418.     RETURN
    419.  
    420.  
    421.  
    422. DO    BSF    PORTA,0
    423.  
    424.     MOVLW    33
    425.  
    426.     MOVWF    CNT
    427.  
    428.     CALL    DLY
    429.  
    430.     GOTO    $+1
    431.  
    432.     NOP
    433.  
    434.     BCF    PORTA,0
    435.  
    436.     MOVLW    33
    437.  
    438.     MOVWF    CNT
    439.  
    440.     CALL    DLY
    441.  
    442.     NOP
    443.  
    444.     BTFSS    PORTB,7
    445.  
    446.     GOTO    DO
    447.  
    448.     RETURN
    449.  
    450.  
    451.  
    452.  
    453.  
    454.  
    455.  
    456.  
    457.  
    458.  
    459.  
    460.  
    461.  
    462. ;*************************************************
    463.  
    464. ;  
    465. ;************************************************
    466.  
    467.  
    468.  
    469.  
    470.  
    471. DLY    GOTO    $+1
    472.  
    473.     GOTO    $+1
    474.  
    475.     DECFSZ    CNT,1
    476.  
    477.     GOTO    DLY
    478.  
    479.     RETURN
    480.  
    481.  
    482.  
    483.  
    484.  
    485.  
    486.  
    487. ;*************************************************
    488.  
    489. ;    END
    490.  
    491. ;*************************************************
    492.  
    493.     END
     
    Last edited by a moderator: Mar 16, 2019
  5. jpanhalt

    Expert

    Jan 18, 2008
    7,632
    1,855
    The 16F84A has 2 banks of memory. The 16F877(A) has 4 banks. That is probably where your problem is. There is no way to solve it without your code.

    Please use code tags like this: [code=MPASM] <insert code>[/code] and single space if possible.
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    CBLOCK H'0C' is wrong. RAM starts at 20h in the '877
     
  7. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    thank you for pointing that out! although i just fixed it, the problem still persists.. but i appreciate that ^^
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    Any warnings from the assembler?
    Also, turn LVP OFF in the CONFIG to be able to use RB3 as an IO input.
     
    Last edited: Mar 16, 2019
  9. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    i'm relatively aware of that, i just think that there's some kind of register that is on by default, messing with the consistency of the sound? it just keeps buffering ;;;
     
  10. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    only one, which i'm not sure i understand.
    "Argument out of range. Least significant bits used." at the line starting by DLY10
     
  11. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    If you are using an ISCP programmer, RB6 and RB7 will be used by that.
    Do you have a PICkit or similar debugger? In that case, RB6 and RB7 are not usable for general IO while debugging.
     
    Last edited: Mar 16, 2019
  12. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    also done ^^; still no significant improvement though,,
     
  13. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    I don't currently have a programmer with me, i'm just testing it over on Proteus. it doesn't seem to work
     
  14. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    Change
    DLY10 MOVLW 142
    to
    DLY10 MOVLW .142

    The default radix for the assembler is hex and 142h won't fit into one byte. You should visit the other constants as well or add
    radix = dec
    at the beginning of the code.

    Based on that value, I'm assuming that the original code used decimal as the default radix. Hard to tell with internet code.

    If NOT, then you'll have to sort out what the original programmer meant by that line.
     
  15. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    okay, i did what you said, and it definitely improved things, only a little buffering left
     
  16. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    No more warnings from the assembler?
     
  17. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    hmm, 3 messages, all the same: "Register in operand not in bank 0. Ensure that bank bits are correct" lines 35,37,41.
    I've had these on working programs, didn't really disrupt its process?
     
  18. atferrari

    AAC Fanatic!

    Jan 6, 2004
    3,350
    1,305
    Not sure but isn't any document by Microchip detailing the steps to migrate from the 84A to the 877?
     
  19. DonutChan

    Thread Starter Member

    Mar 3, 2019
    33
    1
    not exactly.. didn't find these two specific PICs.. maybe i just didn't come across it during my search.
     
  20. JohnInTX

    Moderator

    Jun 26, 2012
    3,766
    1,976
    I cleaned it up for you. No warnings left and added some comments to help you debug it.
    I also added
    movlw 06h ; make ALL port pins digital
    movwf ADCON1

    to make RA0 a digital pin.
    Good luck!

    Code (Microchip Assembler):
    1.  
    2.   list  p=16f877A
    3.   radix dec  ; numbers in code imply decimal but check!
    4.  
    5.   ERRORLEVEL -302  ; suppress cross bank warnings
    6.  
    7.   #include  <p16f877A.inc>
    8.   __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
    9. ;***************** RAM  *******************************
    10.  
    11.   CBLOCK  H'20'
    12.   CNT
    13.   CNT10
    14.   CNTM
    15.   ENDC
    16.  
    17.   ;***************** START  **************************
    18.  
    19.   ORG 0
    20.   CLRF  PORTB
    21.  
    22.   BSF  STATUS,RP0
    23.  
    24.   CLRF  TRISA
    25.   BCF  OPTION_REG,7
    26.   MOVLW  H'FF'
    27.   MOVWF  TRISB
    28.  
    29.   movlw  06h  ; make ALL port pins digital!!!
    30.   movwf  ADCON1
    31.  
    32.   BCF  STATUS,RP0
    33.  
    34. ;*******************************************
    35. ;  KEY
    36. ;*******************************************
    37. KEY:
    38. K0:
    39.   BTFSC  PORTB,0  ; KEY ON?
    40.   GOTO  K1  ; no, check next key
    41.   CALL  DEL10M  ; else, its pressed, debounce time..
    42.   BTFSC  PORTB,0  ; then check again
    43.   GOTO  K0  ; KEY OFF, back to top
    44.   CALL  DO_  ; else, key still down Play DO
    45.  
    46. K1:
    47.   BTFSC  PORTB,1  ;KEY ON?
    48.   GOTO  K2  ;no, check next key
    49.  
    50.   CALL  DEL10M  ; debounce delay
    51.   BTFSC  PORTB,1  ; check key again
    52.   GOTO  K1  ; OFF - go back to top of loop
    53.  
    54.   CALL  RE  ; else, play RE then fall through looking for next key
    55.  
    56. K2:
    57.   BTFSC  PORTB,2  ;KEY ON?
    58.   GOTO  K3  ;no
    59.  
    60.   CALL  DEL10M
    61.   BTFSC  PORTB,2
    62.   GOTO  K2
    63.  
    64.   CALL  MI  ; play ME
    65.  
    66. K3:
    67.   BTFSC  PORTB,3  ;KEY ON?
    68.   GOTO  K4  ;no
    69.  
    70.   CALL  DEL10M
    71.   BTFSC  PORTB,3
    72.   GOTO  K3
    73.  
    74.   CALL  FA  ; play FA
    75.  
    76. K4:
    77.   BTFSC  PORTB,4  ;KEY ON?
    78.   GOTO  K5
    79.  
    80.   CALL  DEL10M
    81.   BTFSC  PORTB,4
    82.   GOTO  K4
    83.  
    84.   CALL  SO  ; play SO
    85.  
    86. K5:
    87.   BTFSC  PORTB,5  ;KEY ON?
    88.   GOTO  K6
    89.  
    90.   CALL  DEL10M
    91.   BTFSC  PORTB,5
    92.   GOTO  K5
    93.  
    94.   CALL  RA  ; play RA
    95.  
    96. K6:
    97.   BTFSC  PORTB,6  ;KEY ON?
    98.   GOTO  K7
    99.  
    100.   CALL  DEL10M
    101.   BTFSC  PORTB,6
    102.   GOTO  K6
    103.  
    104.   CALL  SI  ; play SI
    105.  
    106. K7:
    107.   BTFSC  PORTB,7  ;KEY ON?
    108.   GOTO  KEY  ; no, loop to top
    109.  
    110.   CALL  DEL10M
    111.   BTFSC  PORTB,7
    112.   GOTO  K7
    113.  
    114.   CALL  DO  ; play DO
    115.  
    116.   GOTO  KEY  ; go to top
    117.  
    118. ;***********************************************
    119. ;  10MSEC DELAY
    120. ;***********************************************
    121. DEL10M:
    122.   MOVLW  10
    123.   MOVWF  CNT10
    124.  
    125. DLY10:
    126.   MOVLW  142
    127.   MOVWF  CNTM
    128.  
    129. DLYU:
    130.   GOTO  $+1
    131.   GOTO  $+1
    132.   DECFSZ  CNTM,1
    133.   GOTO  DLYU
    134.  
    135.   DECFSZ  CNT10,F
    136.   GOTO  DLY10
    137.  
    138.   RETURN
    139.  
    140. ;**********************************************
    141. ; Play notes
    142. DO_:
    143.   BSF  PORTA,0  ; high 1/2 cycle of note
    144.   MOVLW  67  ; delay
    145.   MOVWF  CNT
    146.   CALL  DLY
    147.   GOTO  $+1
    148.   GOTO  $+1
    149.   NOP
    150.  
    151.   BCF  PORTA,0  ; low 1/2 cycle of note
    152.   MOVLW  67  ; delay
    153.   MOVWF  CNT
    154.   CALL  DLY
    155.   GOTO  $+1
    156.  
    157.   BTFSS  PORTB,0 ; check key down each full cycle
    158.   GOTO  DO_  ; play another cycle
    159.   RETURN
    160.  
    161. RE:
    162.   BSF  PORTA,0
    163.   MOVLW  60
    164.   MOVWF  CNT
    165.   CALL  DLY
    166.   GOTO  $+1
    167.  
    168.   BCF  PORTA,0
    169.   MOVLW  59
    170.   MOVWF  CNT
    171.   CALL  DLY
    172.   GOTO  $+1
    173.   GOTO  $+1
    174.   GOTO  $+1
    175.  
    176.   BTFSS  PORTB,1
    177.   GOTO  RE
    178.   RETURN
    179.  
    180. MI:
    181.   BSF  PORTA,0
    182.   MOVLW  53
    183.   MOVWF  CNT
    184.   CALL  DLY
    185.   GOTO  $+1
    186.   GOTO  $+1
    187.   GOTO  $+1
    188.   NOP
    189.  
    190.   BCF  PORTA,0
    191.   MOVLW  53
    192.   MOVWF  CNT
    193.   CALL  DLY
    194.   GOTO  $+1
    195.  
    196.   BTFSS  PORTB,2
    197.   GOTO  MI
    198.   RETURN
    199.  
    200. FA:
    201.   BSF  PORTA,0
    202.   MOVLW  50
    203.   MOVWF  CNT
    204.   CALL  DLY
    205.   GOTO  $+1
    206.   GOTO  $+1
    207.  
    208.   BCF  PORTA,0
    209.   MOVLW  50
    210.   MOVWF  CNT
    211.   CALL  DLY
    212.   NOP
    213.  
    214.   BTFSS  PORTB,3
    215.   GOTO  FA
    216.   RETURN
    217.  
    218. SO:
    219.   BSF  PORTA,0
    220.   MOVLW  45
    221.   MOVWF  CNT
    222.   CALL  DLY
    223.   NOP
    224.  
    225.   BCF  PORTA,0
    226.   MOVLW  44
    227.   MOVWF  CNT
    228.   CALL  DLY
    229.   GOTO  $+1
    230.   GOTO  $+1
    231.  
    232.   BTFSS  PORTB,4
    233.   GOTO  SO
    234.   RETURN
    235.  
    236. RA:
    237.   BSF  PORTA,0
    238.   MOVLW  40
    239.   MOVWF  CNT
    240.   CALL  DLY
    241.  
    242.   BCF  PORTA,0
    243.   MOVLW  39
    244.   MOVWF  CNT
    245.   CALL  DLY
    246.   GOTO  $+1
    247.   NOP
    248.  
    249.   BTFSS  PORTB,5
    250.   GOTO  RA
    251.   RETURN
    252.  
    253. SI:
    254.   BSF  PORTA,0
    255.   MOVLW  35
    256.   MOVWF  CNT
    257.   CALL  DLY
    258.   GOTO  $+1
    259.   GOTO  $+1
    260.  
    261.   BCF  PORTA,0
    262.   MOVLW  35
    263.   MOVWF  CNT
    264.   CALL  DLY
    265.  
    266.   BTFSS  PORTB,6
    267.   GOTO  SI
    268.   RETURN
    269.  
    270. DO:
    271.   BSF  PORTA,0
    272.   MOVLW  33
    273.   MOVWF  CNT
    274.   CALL  DLY
    275.   GOTO  $+1
    276.   NOP
    277.  
    278.   BCF  PORTA,0
    279.   MOVLW  33
    280.   MOVWF  CNT
    281.   CALL  DLY
    282.   NOP
    283.  
    284.   BTFSS  PORTB,7
    285.   GOTO  DO
    286.   RETURN
    287.  
    288. ;************************************************
    289. ; Note delay
    290.  
    291. DLY:
    292.   GOTO  $+1
    293.   GOTO  $+1
    294.   DECFSZ  CNT,F
    295.   GOTO  DLY
    296.  
    297.   RETURN
    298.  
    299. ;*************************************************
    300.   END
    301.  
     
    Last edited: Mar 16, 2019
Loading...