PIC16F84A to PIC16F877 migration failure.

Thread Starter

DonutChan

Joined Mar 3, 2019
33
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.
 

Thread Starter

DonutChan

Joined Mar 3, 2019
33
Post your code?
(i used a program i found on the web, but got a grasp of how it works.)

Code:
  list        p=16f877A

    #include    <p16f877A.inc>

   __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    CBLOCK    H'0C'  



    CNT

    CNT10

    CNTM

    ENDC

;*****************************************

;

;*****************************************





    CLRF    PORTB

    BSF    STATUS,RP0

    CLRF    TRISA

    BCF    OPTION_REG,7

    MOVLW    H'FF'

    MOVWF    TRISB

    BCF    STATUS,RP0







;*******************************************

;    KEY

;*******************************************

KEY

    BTFSC    PORTB,0        ;KEY ON?

    GOTO    K1        ;KEY OFF

    CALL    DEL10M        ;

    BTFSC    PORTB,0  

    GOTO    KEY         ;KEY OFF

    CALL    DO_        ;?h

K1    BTFSC    PORTB,1        ;KEY ON?

    GOTO    K2        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,1  

    GOTO    K1

    CALL    RE      

K2    BTFSC    PORTB,2        ;KEY ON?

    GOTO    K3        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,2

    GOTO    K2

    CALL    MI      

K3    BTFSC    PORTB,3        ;KEY ON?

    GOTO    K4        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,3

    GOTO    K3

    CALL    FA  

K4    BTFSC    PORTB,4        ;KEY ON?

    GOTO    K5        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,4

    GOTO    K4

    CALL    SO        ;?\



K5    BTFSC    PORTB,5        ;KEY ON?

    GOTO    K6        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,5

    GOTO    K5

    CALL    RA  

K6    BTFSC    PORTB,6        ;KEY ON?

    GOTO    K7        ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,6

    GOTO    K6

    CALL    SI  

K7    BTFSC    PORTB,7        ;KEY ON?

    GOTO    KEY         ;KEY OFF

    CALL    DEL10M

    BTFSC    PORTB,7

    GOTO    K7

    CALL    DO  



    GOTO    KEY

;***********************************************

;    10MSEC

;  

;***********************************************





DEL10M     MOVLW    10

    MOVWF    CNT10

DLY10    MOVLW    142

    MOVWF    CNTM

DLYU     GOTO    $+1

    GOTO    $+1

    DECFSZ    CNTM,1

    GOTO    DLYU

    DECFSZ    CNT10,1

    GOTO    DLY10

    RETURN









;**********************************************  



DO_    BSF    PORTA,0

    MOVLW    67

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    GOTO    $+1

    NOP

    BCF    PORTA,0

    MOVLW    67

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    BTFSS    PORTB,0

    GOTO    DO_

    RETURN



RE    BSF    PORTA,0

    MOVLW    60

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    BCF    PORTA,0

    MOVLW    59

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    GOTO    $+1

    GOTO    $+1

    BTFSS    PORTB,1

    GOTO    RE

    RETURN



MI    BSF    PORTA,0

    MOVLW    53

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1  

    GOTO    $+1

    GOTO    $+1

    NOP

    BCF    PORTA,0

    MOVLW    53

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    BTFSS    PORTB,2

    GOTO    MI

    RETURN



FA    BSF    PORTA,0

    MOVLW    50

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1  

    GOTO    $+1

    BCF    PORTA,0

    MOVLW    50

    MOVWF    CNT

    CALL    DLY

    NOP

    BTFSS    PORTB,3

    GOTO    FA

    RETURN



SO    BSF    PORTA,0

    MOVLW    45

    MOVWF    CNT

    CALL    DLY

    NOP

    BCF    PORTA,0

    MOVLW    44

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    GOTO    $+1

    BTFSS    PORTB,4

    GOTO    SO

    RETURN



RA    BSF    PORTA,0

    MOVLW    40

    MOVWF    CNT

    CALL    DLY

    BCF    PORTA,0

    MOVLW    39

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    NOP

    BTFSS    PORTB,5

    GOTO    RA

    RETURN



SI    BSF    PORTA,0

    MOVLW    35

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    GOTO    $+1

    BCF    PORTA,0

    MOVLW    35

    MOVWF    CNT

    CALL    DLY

    BTFSS    PORTB,6

    GOTO    SI

    RETURN



DO    BSF    PORTA,0

    MOVLW    33

    MOVWF    CNT

    CALL    DLY

    GOTO    $+1

    NOP

    BCF    PORTA,0

    MOVLW    33

    MOVWF    CNT

    CALL    DLY

    NOP

    BTFSS    PORTB,7

    GOTO    DO

    RETURN













;*************************************************

;  
;************************************************



  

DLY    GOTO    $+1

    GOTO    $+1

    DECFSZ    CNT,1

    GOTO    DLY

    RETURN







;*************************************************

;    END

;*************************************************

    END
 
Last edited by a moderator:

jpanhalt

Joined Jan 18, 2008
11,087
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.
 

JohnInTX

Joined Jun 26, 2012
4,787
Any warnings from the assembler?
Also, turn LVP OFF in the CONFIG to be able to use RB3 as an IO input.
 
Last edited:

Thread Starter

DonutChan

Joined Mar 3, 2019
33
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.
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 ;;;
 

JohnInTX

Joined Jun 26, 2012
4,787
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:

Thread Starter

DonutChan

Joined Mar 3, 2019
33
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.
I don't currently have a programmer with me, i'm just testing it over on Proteus. it doesn't seem to work
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
 

Thread Starter

DonutChan

Joined Mar 3, 2019
33
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.

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.
okay, i did what you said, and it definitely improved things, only a little buffering left
 

JohnInTX

Joined Jun 26, 2012
4,787
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:
  list  p=16f877A
  radix dec  ; numbers in code imply decimal but check!

  ERRORLEVEL -302  ; suppress cross bank warnings

  #include  <p16f877A.inc>
  __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;***************** RAM  *******************************

  CBLOCK  H'20'
  CNT
  CNT10
  CNTM
  ENDC

  ;***************** START  **************************

  ORG 0
  CLRF  PORTB

  BSF  STATUS,RP0

  CLRF  TRISA
  BCF  OPTION_REG,7
  MOVLW  H'FF'
  MOVWF  TRISB

  movlw  06h  ; make ALL port pins digital!!!
  movwf  ADCON1

  BCF  STATUS,RP0

;*******************************************
;  KEY
;*******************************************
KEY:
K0:
  BTFSC  PORTB,0  ; KEY ON?
  GOTO  K1  ; no, check next key
  CALL  DEL10M  ; else, its pressed, debounce time..
  BTFSC  PORTB,0  ; then check again
  GOTO  K0  ; KEY OFF, back to top
  CALL  DO_  ; else, key still down Play DO

K1:
  BTFSC  PORTB,1  ;KEY ON?
  GOTO  K2  ;no, check next key

  CALL  DEL10M  ; debounce delay
  BTFSC  PORTB,1  ; check key again
  GOTO  K1  ; OFF - go back to top of loop

  CALL  RE  ; else, play RE then fall through looking for next key

K2:
  BTFSC  PORTB,2  ;KEY ON?
  GOTO  K3  ;no

  CALL  DEL10M
  BTFSC  PORTB,2
  GOTO  K2

  CALL  MI  ; play ME

K3:
  BTFSC  PORTB,3  ;KEY ON?
  GOTO  K4  ;no

  CALL  DEL10M
  BTFSC  PORTB,3
  GOTO  K3

  CALL  FA  ; play FA

K4:
  BTFSC  PORTB,4  ;KEY ON?
  GOTO  K5

  CALL  DEL10M
  BTFSC  PORTB,4
  GOTO  K4

  CALL  SO  ; play SO

K5:
  BTFSC  PORTB,5  ;KEY ON?
  GOTO  K6

  CALL  DEL10M
  BTFSC  PORTB,5
  GOTO  K5

  CALL  RA  ; play RA

K6:
  BTFSC  PORTB,6  ;KEY ON?
  GOTO  K7

  CALL  DEL10M
  BTFSC  PORTB,6
  GOTO  K6

  CALL  SI  ; play SI

K7:
  BTFSC  PORTB,7  ;KEY ON?
  GOTO  KEY  ; no, loop to top

  CALL  DEL10M
  BTFSC  PORTB,7
  GOTO  K7

  CALL  DO  ; play DO

  GOTO  KEY  ; go to top

;***********************************************
;  10MSEC DELAY
;***********************************************
DEL10M:
  MOVLW  10
  MOVWF  CNT10

DLY10:
  MOVLW  142
  MOVWF  CNTM

DLYU:
  GOTO  $+1
  GOTO  $+1
  DECFSZ  CNTM,1
  GOTO  DLYU

  DECFSZ  CNT10,F
  GOTO  DLY10

  RETURN

;**********************************************
; Play notes
DO_:
  BSF  PORTA,0  ; high 1/2 cycle of note
  MOVLW  67  ; delay
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1
  NOP

  BCF  PORTA,0  ; low 1/2 cycle of note
  MOVLW  67  ; delay
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1

  BTFSS  PORTB,0 ; check key down each full cycle
  GOTO  DO_  ; play another cycle
  RETURN

RE:
  BSF  PORTA,0
  MOVLW  60
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1

  BCF  PORTA,0
  MOVLW  59
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1
  GOTO  $+1

  BTFSS  PORTB,1
  GOTO  RE
  RETURN

MI:
  BSF  PORTA,0
  MOVLW  53
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1
  GOTO  $+1
  NOP

  BCF  PORTA,0
  MOVLW  53
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1

  BTFSS  PORTB,2
  GOTO  MI
  RETURN

FA:
  BSF  PORTA,0
  MOVLW  50
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1

  BCF  PORTA,0
  MOVLW  50
  MOVWF  CNT
  CALL  DLY
  NOP

  BTFSS  PORTB,3
  GOTO  FA
  RETURN

SO:
  BSF  PORTA,0
  MOVLW  45
  MOVWF  CNT
  CALL  DLY
  NOP

  BCF  PORTA,0
  MOVLW  44
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1

  BTFSS  PORTB,4
  GOTO  SO
  RETURN

RA:
  BSF  PORTA,0
  MOVLW  40
  MOVWF  CNT
  CALL  DLY

  BCF  PORTA,0
  MOVLW  39
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  NOP

  BTFSS  PORTB,5
  GOTO  RA
  RETURN

SI:
  BSF  PORTA,0
  MOVLW  35
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  GOTO  $+1

  BCF  PORTA,0
  MOVLW  35
  MOVWF  CNT
  CALL  DLY

  BTFSS  PORTB,6
  GOTO  SI
  RETURN

DO:
  BSF  PORTA,0
  MOVLW  33
  MOVWF  CNT
  CALL  DLY
  GOTO  $+1
  NOP

  BCF  PORTA,0
  MOVLW  33
  MOVWF  CNT
  CALL  DLY
  NOP

  BTFSS  PORTB,7
  GOTO  DO
  RETURN

;************************************************
; Note delay

DLY:
  GOTO  $+1
  GOTO  $+1
  DECFSZ  CNT,F
  GOTO  DLY

  RETURN

;*************************************************
  END
 
Last edited:
Top