Is this site valid?

Status
Not open for further replies.

AGCB

Member
Am I lacking understanding or is this (romux.com sound generation) a bunch of bull? I'll keep on trying to figure it out if someone says it's good but it seems to be riddled with errors and possibly bogus altogether.

The sound generation part looks interesting but It's not working for me.

Thanks.
 
By 'not working for me' do you mean it won't compile? It looks like the code listing has been generated using OCR (after scanning, for example), and some letters are wrong & spaces have been inserted where they shouldn't have been.

After fixing the typos, the following will compile (doesn't mean it will work though)
Code:
    PROCESSOR  16f84A
    #include "P16F84A.inc"

__CONFIG _CP_OFF  &  _WDT_OFF  &  _PWRTE_ON   &  _XT_OSC

	Cblock    0x0C                             ;RAM strating address
PRESCbeep
Beep_TEMP1                                 ;Belongs  to macro  "BEEP"
Beep_TEMP2
Beep_TEMP3
HIcnt                                           ;Auxiliary variable  for macro pausems
LOcnt
LOOPcnt
	endc

#define BEEPport PORTA,3                   ;Port and pin beeper  is  located at
#define BEEPtris TRISA,3

	ORG        0x00                                ;Reset vector
	goto     Main
	ORG        0x04                                ; Interrupt vector
	goto     Main                                ;no  intertupt routine

BEEP     MACRO    FREQ, DURATION
        MOVLW   FREQ
        MOVWF   BEEP_TEMP1
        MOVLW   DURATION
        CALL  BEEPSUB 
        ENDM


BEEPINIT MACRO
        BCF    BEEPPORT 
        BSF STATUS, RP0
        BCF BEEPTRIS 
        BCF    STATUS,RP0
        ENDM


BEEPSUB MOVWF BEEP_TEMP2;SET THE  SOUND DURATION 
        CLRF  TMR0              ;INITIALIZE  THE   COUNTER
        BCF     BEEPPORT 
        BSF     STATUS,RP0
        BCF     BEEPPORT 
        MOVLW  PRESCBEEP    ;SET PRESCALER  FOR THRO 
        MOVWF   OPTION_REG ; OPTION <-  U 
        BCF STATUS,RP0
 
BEEPA       
        BCF INTCON,T0IF;CLEAR THRO  OVERFLORA  FLAG 
BEEPB       
        BSF   BEEPPORT
        CALL B_WAIT          ;DURATION OF  LOGICAL   "1"
        BCF   BEEPPORT
        CALL B_WAIT          ;DURATION OF  LOGICAL   "0"
        BTFSS   INTCON,T0IF;CHECK THRO  OVERFLORA  FLAG, 
        GOTO    BEEPB            ;SKIP  IF  SET
        DECFSZ BEEP_TEMP2,1 ;IS BEEP_TEHP2  =  0   ? 
        GOTO     BEEPA            ;IF NOT,   JUMP BACK  TO BEEP
        RETURN

B_WAIT 
        MOVFW BEEP_TEMP1 
        MOVWF   BEEP_TEMP3
B_WAITA  
        DECFSZ    BEEP_TEMP3,1 
        GOTO     B_WAITA
        RETURN

Main                                                          ;Beginning of  the program
        banksel TRISA
        movlw   b'00010111'             ;       initializing port A
        movwf   TRISA                   ;"          ;TRISA <-  0x17
        banksel  PORTB
Loop
        BEEPinit                                     ;Initialising Beeper
;~~~~~~~ these have been commented to allow the program to compile ~~~~~
;        button PORTA,   0,0,   Playl   ;Button 1
;        button PORTA,   1,0,   Play2   ;Button 2
;        goto      Loop 
Playl
        BEEP  0xFF,    0x02
        BEEP  0x90,    0x05
        BEEP  0xC0,    0x03
        BEEP  0xFF,   0x03                       ;First tune
        goto  Loop 
Play2
        BEEP  0xbb,   0x02
        BEEP  0x87,    0x05
        BEEP  0xa2,   0x03
        BEEP  0x98,   0x03                       ;Second tune
        goto  Loop
	End                                               ;End of program
 
Last edited:
With a little modification I got it to work but the range of frequency and duration is too limited. I hope to find or write one with more latitude.

Thanks for your time and input!
Aaron
 
Hi Aaron.

Try this:
Code:
#include "p16f84a.inc"

	radix dec

	Cblock    0x0C                             ;RAM strating address
frequency
frequencyH
loops
loopsH
acc
accH
	endc

ADD16   MACRO   DST,SRC 
        MOVF    (SRC),W         ; Get low byte
        ADDWF   (DST),F         ; Add to destination
        MOVF    (SRC)+1,W       ; Get high byte
        BTFSC   STATUS,C        ; Check for carry
        INCF    (SRC)+1,W       ; Add one for carry
        ADDWF   (DST)+1,F       ; Add high byte into DST
        ENDM

MOV16LF	MACRO	DST,SRC
	movlw	(SRC)&255
	movwf	(DST)
	movlw	(SRC)>>8
	movwf	(DST)+1
	ENDM

TONE	MACRO	FREQ,MILLISECONDS
	LOCAL	loopCount,correctedFreq
correctedFreq 	set (FREQ)*1000/1017
loopCount		set (MILLISECONDS)*1000/15*(correctedFreq)/65536
	if (loopCount&255) == 0				; correct for the 16 bit looping construct
loopCount		set loopCount+0x0101
	else
loopCount		set loopCount+0x0100
	endif
	
	MOV16LF	frequency,correctedFreq
	MOV16LF	loops,loopCount
	call	ToneFunc
	ENDM

	org 0
main:
	movlw	0
	TRIS    PORTB
	TONE	1000,1500
	TONE	1500,500

	goto	main

; 15 cycles / loop
waiting:
	goto	$+1
	nop
ToneFuncDelay:
	goto	$+1
ToneFunc:
	bcf	PORTB,0				; 1
	ADD16	acc,frequency	; 7	
	btfss	STATUS,C		; 8
	goto	waiting			

	bsf	PORTB,0				

	decfsz	loops,f			
	goto	ToneFuncDelay	

	decfsz	loops+1,f
	goto	ToneFunc
	
	bcf	PORTB,0	
	return
	end
good luck
 
Last edited:
DOUGY83
What kind of pic is that code Written for? There are insrtuctions and terms (DST SRT) that I don't understand.
 
Aaron, I've corrected the code above so that the duration calculation is now correct.

Re DST, SRC - DST is the destination register address & SRC is the source register address. The instructions you don't understand are probably the macros e.g. ADD16, MOV16LF - which are for adding 2x 16 bit numbers together and for assigning a 16-bit literal to a 16-bit variable, respectively.

code is for pic16f84a - just like your original code.

in the main code, use the TONE macro to make the tone. The first parameter is the frequency in Hz, the second is the duration in milliseconds. Freq range is from 1 to 65k, duration from some lower limit (something like a cycle or two at 'Freq') to whatever 65000 cycles at 'Freq' is. e.g. max duration is around a second at 65k, around 2 seconds at 32k, around 8 seconds at 8kHz, etc...
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…