I wrote this, but it is very slow.
The pic is 16F1824, and RA2 is connected to the base of BC547, RC3 to opamp and the output of the opamp to the collector of BC547 and emmiter to speaker.
@ __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
@ __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
DEFINE OSC 4
OSCCON = %01101000 '4mhz oscillator
DEFINE CCP3_REG PORTA 'Channel-1 port
DEFINE CCP3_BIT 2 'Channel-1 bit
TRISA = 0
TRISC = 0 ' OUTPUT
ANSELA = 0
ANSELC = 0
OPTION_REG.7=0 ' Weak pullup enabled
OPTION_REG.6=0 ' Interrupt Edg Select bit
OPTION_REG.5=0 ' TMR0CS Timer0 Clock Source select
OPTION_REG.4=0 ' TMR0CS Timer0 Source edge select
OPTION_REG.3=0 ' Prescaller assignemnet (0-> timer0)
OPTION_REG.2=1 ' Prescaller rate
OPTION_REG.1=1 ' Prescaller rate
OPTION_REG.0=1 ' Prescaller rate
'Prescaler 1:256, INTERRUPT every 65,536ms
x var BYTE
ON INTERRUPT GOTO ISR
INTCON = %10100000 ' enable TMR0 and GLOBAL
X = 0
GOTO START
START
sound portc.3, [255, 65535]
goto START
ISR:
disable
X=X+5
IF X>255 THEN
X=0
ENDIF
hpwm 3,x,20000
INTCON.2=0
resume
enable
end
Where is my mistake ?
Bookmarks