littletransistor
New Member
Hey there,
I managed to create an Interrupt handler and some stuff to let the speaker ring a note while the main routine is to blink an LED, but it seems that the speaker took over and the LED didn't blink.
I could have missed something inside - what must I need to do to make it to trigger the speaker and do the LED altogether?
note: PIC 18F1320, 4MHz OSC
I managed to create an Interrupt handler and some stuff to let the speaker ring a note while the main routine is to blink an LED, but it seems that the speaker took over and the LED didn't blink.
I could have missed something inside - what must I need to do to make it to trigger the speaker and do the LED altogether?
Code:
#include <p18F1320.inc>
CONFIG WDT=OFF; disable watchdog timer
CONFIG MCLRE = OFF; MCLEAR Pin off
CONFIG DEBUG = OFF; Enable Debug Mode
CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
CONFIG OSC = INTIO2;Internal oscillator, port function on RA6
CONFIG PWRT = ON
org 0x00
goto Init
cblock 0x20
Delay1
Delay2
count1
count2
note1
noteCount
endc
cblock 0x60
W_Save
STATUS_Save
endc
org 0x08
ISR:
movwf W_Save
movf STATUS,w
movwf STATUS_Save
playNote:
btfsc INTCON,TMR0IF
movlw d'250'
movwf TMR0L
clrf W
movlw d'86'
incf noteCount
cpfseq noteCount
goto ExitISR
btg LATA,1
clrf noteCount
goto ExitISR
ExitISR:
movf STATUS_Save,w
movwf STATUS
swapf W_Save,f
swapf W_Save,w
retfie
Init:
movlw b'01100000'
movwf OSCCON
clrf T0CON
movlw b'11000111'
movwf T0CON
movlw 0x00
movwf TRISB
clrf LATB
movlw b'00000001'
movwf TRISA
clrf LATA
movlw b'11100000'
movwf INTCON
main:
btg LATB,2
call Delay
goto main
Delay:
DelayLoop:
DECFSZ count1,f ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
GOTO DelayLoop
DECFSZ count2,f
GOTO DelayLoop
return
end
note: PIC 18F1320, 4MHz OSC