Static non-continuous sound out of speaker in PIC16F877A

Status
Not open for further replies.

Thread Starter

DonutChan

Joined Mar 3, 2019
33
Piano program worked fine in PIC16F84A, although it's almost functional in PIC16F877A, (thanks to some people's help on this site), the speaker keeps buffering, and cuts off every now and then If i press the button for a longer time. Again, program was in assembly.
I honestly have no clue where there could be something wrong..
 

Thread Starter

DonutChan

Joined Mar 3, 2019
33
Nor do we, since you haven't posted here either a schematic or your code :rolleyes:.
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

CLRF TRISD
CLRF TRISC

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
CALL LED1
K7:
BTFSC PORTB,7 ;KEY ON?
GOTO KEY ; no, loop to top

CALL DEL10M
BTFSC PORTB,7
GOTO K7

CALL DO ; play DO




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL LED1
CLRF PORTC
CLRF PORTD
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


GOTO KEY ; go to top

;************************************************
; LED ANIMATIONS
;**************************************************

LED1
bsf PORTC,0
movlw 0x03
movwf PORTC
call DEL10M
movlw 0xFF
movwf PORTD
movwf PORTC
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;***********************************************
; 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

[/CODE]
 

Attachments

Ian Rogers

Joined Dec 12, 2012
1,136
Okay now we see.... You are using Proteus....Have you any idea how much processing is required to produce sounds vis the sound card... Your speaker is warbling because Proteus will be stuck at 100% and not running in realtime..

You'll need to ditch any resistor that isn't doing anything.. ie Xtal and caps ( not needed ) get rid of the 10k between Q11 and LSI replace the resistor on Q11 base for a smaller value.. 470R Replace Q11 for the 2n2222a model ( works better for some reason )

Change LSI to run at 5V not 12... Just tie MCLR to 5v.... Simulation animation can also be turned off..
 

Thread Starter

DonutChan

Joined Mar 3, 2019
33
Okay now we see.... You are using Proteus....Have you any idea how much processing is required to produce sounds vis the sound card... Your speaker is warbling because Proteus will be stuck at 100% and not running in realtime..

You'll need to ditch any resistor that isn't doing anything.. ie Xtal and caps ( not needed ) get rid of the 10k between Q11 and LSI replace the resistor on Q11 base for a smaller value.. 470R Replace Q11 for the 2n2222a model ( works better for some reason )

Change LSI to run at 5V not 12... Just tie MCLR to 5v.... Simulation animation can also be turned off..
done what you said, but the issue persists.. :/ thank you anyways.. all it did was make the sound louder
 
Status
Not open for further replies.
Top