; beacon.asm ; ; The IR output carrier frequency is 40 khz. ; The IR received carrier is 33 khz. ; ; ; ; ;-------------------------------------------------------------------------------- ; ; Written for 12C508 PIC microcontroller ; Version 1.0 ; by Dale A. Heatherington Jan. 8 2000 ; ;--------------------------------------------------------------------- ; ; PIC12C508 pin assignments ; ; 1 +5v ; 2 Not used ; 3 Visible indicator LED ; 4 IR receiver input (Low = pulse received) ; 5 LED 3 drive (low true) ; 6 LED 2 drive ; 7 LED 1 drive ; 8 GND ;----------------------------------------------------------------------- ;Copyright 2000 by Dale A Heatherington ;;---------------------------------------------------------------------- ;;This program is free software; you can redistribute it and/or modify ;;it under the terms of the GNU General Public License as published by ;;the Free Software Foundation; either version 2 of the License, or ;;(at your option) any later version. ;; ;;This program is distributed in the hope that it will be useful, ;;but WITHOUT ANY WARRANTY; without even the implied warranty of ;;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;GNU General Public License for more details. ;;You should have received a copy of the GNU General Public License ;;along with this program; if not, write to the Free Software ;;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA ;;------------------------------------------------------------------------ RADIX dec processor 12c508 __CONFIG h'0FEA' ;Internal 4 RC mhz osc include "p12c508.inc" ;------------------------------------------------------------ ;GPIO input bits IR1 equ 3 ;IR sensor input (low true, pin 4) ;GPIO output bits LED_1 equ 0 LED_2 equ 1 ;IR LED driver outputs (low true) LED_3 equ 2 RED_LED equ 4 ;Red indicator LED out (low true) gp_save equ 07h gp_last equ 08h count equ 09h tdelay equ 0ah ;--------------------------------------------------------- ;Wait N * 5uS delay macro N local _loop movlw N movwf count _loop nop nop decfsz count goto _loop endm ;;One cycle of 40 KHZ (less 3uS for overhead in other code) ;This takes 22uS to execute. A complete cycle is 25 uS long. cycle_leds MACRO bcf GPIO,LED_1 bcf GPIO,LED_2 bcf GPIO,LED_3 nop nop nop nop nop nop nop nop nop bsf GPIO,LED_1 bsf GPIO,LED_2 bsf GPIO,LED_3 nop nop nop nop nop nop nop endm ;code starts here... ORG 0 main_code movwf OSCCAL ;Internal 4 mhz osc calibration value clrf STATUS movlw 0ffh movwf GPIO movlw 08h ;Bit 3 is the IR sensor input tris GPIO ; movlw 0C0h option wait_trigger comf GPIO,W ; w = ~GPIO movwf gp_save ; gp_save = w andlw 08h ;Keep only IR receiver bit btfsc STATUS,Z goto IR_false ;It's zero, could be a trailing edge. movwf gp_last ;save current value in gp_last goto wait_trigger IR_false movlw 08h andwf gp_last,w btfss STATUS,Z ;See if it was false last time too goto trailing_edge ;If not then we have a trailing edge movf gp_save,w ;..else save the current condition movwf gp_last ;..in gp_last goto wait_trigger ;and go back to wait trailing_edge clrf gp_last ; clear gp_last ; ; ; Now we are at the trailing edge of the received pulse ; movlw 30 ;about 3500 uS movwf tdelay ; delay1 delay 20 ;100us delay element btfss GPIO,IR1 ;Test if another pulse is present goto wait_trigger ;abort if we see a pulse during the delay period decfsz tdelay goto delay1 ;loop up to 35 times for 3500 uS bcf GPIO,RED_LED ;Flash the red indicator LED movlw 20 movwf count pulse cycle_leds ;Make a 500uS beacon reply pulse (40 khz) decfsz count goto pulse delay 83 ;wait 250uS bsf GPIO,RED_LED ;Indicator LED off goto wait_trigger end