;************************************************************************** ; FILE: theremin.asm * ; CONTENTS: Junior Theremin * ; COPYRIGHT: MadLab Ltd. 2001-2003 * ; AUTHOR: James Hutchby * ; UPDATED: 10/11/03 * ;************************************************************************** list p=12C508A ; list p=12C509A ifdef __12C508A include "p12c508a.inc" endif ifdef __12C509A include "p12c509a.inc" endif ; __config _IntRC_OSC & _WDT_OFF & _MCLRE_OFF & _CP_OFF __config _IntRC_OSC & _WDT_OFF & _MCLRE_OFF & _CP_ON __idlocs h'CD10' errorlevel -302,-305 ;************************************************************************** ; * ; Specification * ; * ;************************************************************************** ; power-up self-test - all LEDs flash twice ; double beep then self-calibrates ; re-calibrates every 5s or less ; tone frequency = ~500Hz - ~4kHz ; button1 decreases range by an octave ; button2 increases range by an octave ; both buttons toggles slide/discrete mode ; sleeps after 5 minutes of inactivity, either button to wake ;************************************************************************** ; * ; Port assignments * ; * ;************************************************************************** GPIO_IN equ b'011111' ; GPIO IN status GPIO_OUT equ b'011100' ; GPIO OUT status SPEAKER_PORT equ GPIO ; speaker port SPEAKER1 equ 4 ; speaker output1 SPEAKER2 equ 5 ; speaker output2 SPEAKER_MASK equ b'110000' ; speaker mask SPEAKER_ON equ GPIO_OUT&~(1< 0 entry leds i set i-1 endw endm pattern_ b'0000',1 pattern_ b'0001',1 pattern_ b'0010',1 pattern_ b'0100',1 pattern_ b'1000',1 pattern_ b'1001',1 pattern_ b'1010',1 pattern_ b'1100',2 pattern_ b'1101',2 pattern_ b'1110',2 pattern_ b'1111',3 ;************************************************************************** ; * ; Procedures * ; * ;************************************************************************** ;-------------------------------------------------------------------------- ; polls the pushbuttons, returns NZ flag set if either pushbutton pressed ;-------------------------------------------------------------------------- routine poll movff GPIO,work1 movlw GPIO_IN ; input mode tris GPIO bcf LED_PORT,MUX iorwf GPIO ; poll the buttons clrwdt comf GPIO,w movwf work2 movff work1,GPIO ; re-initialise port incf note,w movlw GPIO_OUT skpz andlw ~(1<