title ID generator module for 3100 project ; status: added seperate commands for volume adjustment and added ; access and drop tones. Ensured o/p pin is low at end of each tone. ; Saved status during interrupts. Untested 23-6-2001 ; Changed method of turning tones on/off from control bit to directly ; enabling or disabling GIE. 06-07-2001 ; Changed messages, changed access & drop routines, ensured RB1 is low ; at the end of messages. Tested & working 21-2-200 ; Selection inputs on RA0:3, volume select with data 0F(low) ; Trigger by lowering RA4 for at least two instruction cycles. ; RB0 : tristate for high volume, driven low for low volume ; RB1 : output, toggle to produce signal ; RB2 : output, high when signal on, low when signal off ; RB3 : output high while message in progress otherwise low ; RB4,5,6,7 : not used ;Note: 16C84 or 16F84 can be used. #include "P16F84.INC" #define bank_0 bcf STATUS,5 ;switch to bank 0 #define bank_1 bsf STATUS,5 ;switch to bank 1 __CONFIG H'3FFD' ;XT, watchdog, start timer. msg equ H'10' ;message data byte msg_ptr equ H'11' ;address of message data byte bitcount equ H'12' ;number of times msg has been shifted tone_ctrl equ H'13' ;tone on/off bits pitch equ H'14' ;holds frequency for current messages speed1 equ H'15' ;delay to set wpm. speed2 equ H'16' w_temp equ H'17' ;store for W during interrupts status_temp equ H'18' ;store for status reg during interrupts ;------------------------------------------------ ; constants msg_pitch equ H'C6' ;adjust to set message frequency hi_beep equ H'A0' ;high beep frequency lo_beep equ H'80' ;low beep frequency wpm equ H'40' ;adjust to set morse speed ;************************************************************************* org 0 ;reset address in 16F84 reset goto init interrupt org 0x004 ;interrupt vector location movwf w_temp ;save off current W register contents movf STATUS,w ;move status register into W register movwf status_temp ;save off contents of STATUS register bcf INTCON,2 ;clear TMR0 interrupt flag movlw H'02' xorwf PORTB,1 ;toggle the tone output pin end_interrupt movf pitch,w ;pre-load TMR0 to set exact tone movwf TMR0 movf status_temp,w ;retrieve copy of STATUS register movwf STATUS ;restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ;restore pre-isr W register contents retfie ;return from interrupt ;========================================================== init bank_1 movlw H'13' ;RB0, 1 & 4 are inputs, rest are o/p movwf TRISB ;(change bit 0 to o/p to drop volume) movlw H'1F' ;set port A pins to input mode movwf TRISA movlw B'10000010' ;no pull-ups,f/4 to TMR0,prescale by 8 movwf OPTION_REG bank_0 clrf tone_ctrl ;start with everything disabled clrf msg clrf msg_ptr clrf bitcount clrf STATUS clrf PORTA clrf PORTB clrf TMR0 clrw movlw msg_pitch ;default to normal pitch movwf pitch movlw B'00100000' ;TMR0 rollover int enabled (not global) movwf INTCON bank_1 ;set to high volume bsf TRISB,0 ;make RB0 an input, not loading the audio bank_0 ; wait for start signal then intercept data D, E and F which are commands. ; remaining data is a message ID. idle bcf PORTB,3 ;make sure not 'in-progress' wait clrwdt ;prevent WDT reset btfsc PORTA,4 ;monitor for start signal goto wait movf PORTA,w ;only keep message bits andlw H'0F' ;discard all but data bits bsf PORTB,3 ;in-progress indicator addwf PCL,f ;jump ahead "w" places goto lookup ;0 = message goto lookup ;1 = message goto lookup ;2 = message goto lookup ;3 = message goto lookup ;4 = message goto lookup ;5 = message goto lookup ;6 = message goto lookup ;7 = message goto lookup ;8 = message goto lookup ;9 = message goto lookup ;A = message goto lookup ;B = message goto lookup ;C = message goto drop_beep ;D = make drop beep goto access_beep ;E = make access beep ;F = select low volume mode for next message only lowvol bank_1 ;gain access to tris B bcf TRISB,0 ;make RB0 an output to sink some signal bank_0 goto idle ;going to init would reset volume! ; the data is still in W lookup call index ;find start of message in table movwf msg_ptr ;target its first byte call msg_loop ;send the message goto init index addwf PCL,f ;jump ahead W places retlw msg_0 - msgtable - 1 ;0 retlw msg_1 - msgtable - 1 ;1 retlw msg_2 - msgtable - 1 ;2 retlw msg_3 - msgtable - 1 ;3 retlw msg_4 - msgtable - 1 ;4 retlw msg_5 - msgtable - 1 ;5 retlw msg_6 - msgtable - 1 ;6 retlw msg_7 - msgtable - 1 ;7 retlw msg_8 - msgtable - 1 ;8 retlw msg_9 - msgtable - 1 ;9 retlw msg_a - msgtable - 1 ;A retlw msg_b - msgtable - 1 ;B retlw msg_c - msgtable - 1 ;C goto init ;D should already be processed (drop) goto init ;E should already be processed (access) goto init ;F should already be processed (lo vol) ; generate low-high tone to announce access is granted access_beep bank_1 bcf TRISB,1 ;enable tone output pin bank_0 movlw lo_beep movwf pitch ;tone 1 call beep call beep movlw hi_beep movwf pitch ;tone 2 call beep bcf PORTB,1 ;ensure tone pin is low goto init ;done ;generate high-low tone to announce access has been lost drop_beep bank_1 bcf TRISB,1 ;enable tone output pin bank_0 movlw hi_beep movwf pitch ;tone 1 call beep call beep movlw lo_beep movwf pitch ;tone 2 call beep bcf PORTB,1 ;ensure tone pin is low goto init ;done beep bsf PORTB,2 ;envelope signal on bsf INTCON,7 ;tone on call delay bcf INTCON,7 ;tone off bcf PORTB,2 ;envelope signal off call delay return ; the Morse tone generating routines msg_loop bank_1 bcf TRISB,1 ;enable tone output pin bank_0 bsf PCLATH,0 ;table is in page 1 call msgtable ;read byte from message table bcf PCLATH,0 ;back to page 0 movwf msg sublw H'FF' ;set Z flag if terminator found btfsc STATUS,Z ;skip next not the terminator return ;finished sending message movlw H'09' ;initialise shift counter movwf bitcount bit_loop decfsz bitcount,f ;count shifts down to zero goto send_bit ;send bit if more to process incf msg_ptr,f ;otherwise try next message byte movf msg_ptr,w goto msg_loop send_bit bcf STATUS,C ;don't shift 0 into LSB rlf msg,f btfss STATUS,C ;see if MSB in "msg" was set goto no_tone bsf INTCON,7 ;enable interrupts to make tone bsf PORTB,2 ;set envelope bits slow_down call delay goto bit_loop ;send next bit no_tone bcf INTCON,7 ;disable interrupts to stop tone bcf PORTB,2 ;clear the envelope bits bcf PORTB,1 ;always stop with tone o/p = 0 goto slow_down delay ;slow down to set morse speed clrf speed1 movlw wpm movwf speed2 delay_loop decfsz speed1,f goto delay_loop clrwdt decfsz speed2,f goto delay_loop return ;************************************************************************* ; message information is in page 1 org H'100' msgtable addwf PCL,f msg_0 retlw 000 retlw 0EE ;GB3ZZ retlw 08E retlw 0A8 retlw 0AB retlw 0B8 retlw 0EE retlw 0A3 retlw 0BA retlw 080 retlw 0FF msg_1 retlw 000 retlw 0EE ;GB3ZZ North Bristol IO81RM retlw 08E retlw 0A8 retlw 0AB retlw 0B8 retlw 0EE retlw 0A3 retlw 0BA retlw 080 retlw 000 retlw 0E8 ; retlw 0EE retlw 0E2 retlw 0E8 retlw 0E2 retlw 0A8 retlw 03A retlw 0A2 retlw 0E8 retlw 0A2 retlw 0A3 retlw 08E retlw 0EE retlw 02E retlw 0A0 retlw 028 retlw 0EE retlw 0E3 retlw 0BB retlw 0A8 retlw 0BB retlw 0BB retlw 08B retlw 0A3 retlw 0B8 retlw 0FF msg_2 retlw 000 retlw 0EE ;GB3XG retlw 08E retlw 0A8 retlw 0AB retlw 0B8 retlw 0EA retlw 0E3 retlw 0BA retlw 0FF msg_3 retlw 0EE ;GB3XG Dundry Hill IO81QJ retlw 08E retlw 0A8 retlw 0AB retlw 0B8 retlw 0EA retlw 0E3 retlw 0BA retlw 000 retlw 0EE ; retlw 08A retlw 0E3 retlw 0A3 retlw 0A8 retlw 0BA retlw 03A retlw 0EE retlw 00A retlw 0A2 retlw 08B retlw 0A8 retlw 0BA retlw 080 retlw 0A3 ; retlw 0BB retlw 08E retlw 0EE retlw 0A2 retlw 0EE retlw 0EE retlw 03B retlw 0AE retlw 02E retlw 0EE retlw 0FF msg_4 retlw 0EB ;K retlw 080 retlw 000 retlw 0FF msg_5 retlw 0BB ;1 retlw 0BB retlw 080 retlw 0FF msg_6 retlw 0AE ;2 retlw 0EE retlw 0FF msg_7 retlw 0AB ;3 retlw 0B8 retlw 0FF msg_8 retlw 0AA ;4 retlw 0E0 retlw 0FF msg_9 retlw 0AA ;5 retlw 080 retlw 0FF msg_a retlw 0BB ;P retlw 0A0 retlw 000 retlw 0FF msg_b retlw 0A8 ;S retlw 000 retlw 0FF msg_c retlw 0E2 ;TEST retlw 02A retlw 038 retlw 0FF END