Listing for the Frequency Generating subroutine *Define variables and some setup registers for the frequency generating program before calling the program, *Store the frequency generation constant in the variable frec initialize the output of PORTA so that *all outputs except PORTA 4 are high (and thus the filters are off. The output filters to be turned on *are then pulled low. Then the fgen program can be called. *This example will generate 9500Hz from a 3.58MHz Ceramic Oscillator which will last ~250mS. *The frec variable is calculated by the number of loops it takes to wait for a half cycle of the period of the *(half on, half off) required output frequency ( Time=1/(FoutHz * 2halfnodes/cycle), the number of loops is how *long the micro has to wait to achieve this time) and then the timer will allow for the half cycles *to repeat until the timer signals that ~250mS have passed. The program then returns to the *previous routine. This timer allows for frequency-independent tone output time. $base 10T ;decimal default tscr equ $08 ;timer interrupt register output equ $00 ;output port definition (PA0-7) org $00C0 ;RAM origin temp1 rmb 1 ;temporary variable frec rmb 1 ;frequency variable ... lda #$FF sta output ;sets the output porta high so all filters are off ... lda #11 ;constant for 12kHz, can be changed to have different frequencies sta frec ;store in variable frec ... jsr fgen ;call frequency generation subroutine ... *Frequency generating subroutine. Optimize the number of instructions to output the proper frequencies. fgen sta temp1 ;store accumulator in a temp variable lda #04 ;number of interrupts for 250mS (5*65mS) timer bset 2,tscr ;clear real time interrupt flag innr3 bset 4,output ;turn on oscillator output ldx frec ;number for one half cycle innr1 decx ;count down for half cycle bne innr1 ;if not finished, keep counting bclr 4,output ;turn off oscillator output ldx frec ;number for other half of cycle innr2 decx ;count down for half cycle bne innr2 ;if not finished, keep counting brclr 6,tscr,innr3 ;if 65mS not passed (see timer/counter section of docs) do another cycle deca ;subtract from the five 65mS for 250mS total bne timer ;have 250mS gone by? If not go back and repeat all lda temp1 ;restore accumulator rts ;