;; ;; flasher.asm, a PIC 16F84/12C509 based multi-frequency 24-bit ;; psuedo-random security LED flasher. ;; Copyright (C) 1999 James Cameron (quozl@us.netrek.org) ;; ;; 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; proto equ 1 ; we are prototyping on 16F84 ; change to zero for final burn on 12C509 if proto == 1 processor 16f84 list f=inhx8m include "p16f84.inc" __CONFIG _CP_OFF & _WDT_ON & _HS_OSC else processor 12c509 list f=inhx8m include "p12c509a.inc" __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IntRC_OSC endif ; general purpose register allocation ; first common free address as per ; p12 of 12c509 spec ; p13 of 16f84 spec beat equ 0x0c ; frequency beat mask ranl equ 0x0d ; 24-bit random number ranm equ 0x0e ranh equ 0x0f if proto == 1 ; which port to use port equ PORTB else port equ GPIO endif m_input equ b'00000000' ; input mask, which bits are input org 0x00 ; reset vector if proto != 1 ; for 12C509 movwf OSCCAL ; store oscillator calibration endif goto main dt "ax7 1998-07-17 quozl@us.netrek.org flasher" reinitialise: ; set up ports if proto == 1 ; are we on 16f84? clrf TMR0 bsf STATUS,RP0 ; select register bank 1 clrwdt movlw b'11111100' ; assign 1:16 prescaler to WDT movwf OPTION_REG bsf STATUS,RP0 movlw m_input movwf TRISB bcf STATUS,RP0 else ; otherwise 12c509 clrwdt clrf TMR0 movlw b'11011100' ; assign 1:16 prescaler to WDT option ; ... and disabled TOCS movlw m_input tris GPIO endif retlw 0 initialise: ; clear the random number seed movlw 0xa5 movwf ranh movwf ranm movwf ranl retlw 0 alive: ; update the LED drivers incf beat,f ; increment the beat movf beat,w ; merge with low bits of random number andwf ranl,w movwf port ; sent the result to the port drivers retlw 0 random: ; find next random number movf ranl,w ; check total value zero iorwf ranh,w btfsc STATUS,Z comf ranh,f ; invert some bits if so movlw 0x80 btfsc ranh,6 xorwf ranh,f btfsc ranh,4 xorwf ranh,f btfsc ranl,3 xorwf ranh,f bcf STATUS,C ; clear the carry flag btfsc ranh,7 ; if the high bit is set ... bsf STATUS,C ; ... set also the carry flag rlf ranl,f rlf ranm,f rlf ranh,f retlw 0 main: btfsc STATUS,NOT_TO ; if this is a reset or power-up ... call initialise ; ... clear random number seed call reinitialise ; set port drivers and WDT prescaler main_1: call alive ; update LED outputs call random ; find next random number sleep ; sleep for next WDT wakeup goto main_1 ;; ;; known problem on 12c509 during wake-up, the output lines are ;; momentarily not driven, which causes a flickering. ;; end