'**************************************************************** '* Name : random_generator.pdp * '* Author : Rob Seward * '* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 11/20/2005 * '* Version : 1.0 * '* Notes : http://robseward.com * '* : * '**************************************************************** define OSC 20 On Interrupt Goto myint ' Define interrupt handler (PBP Gimme) ' This lets the PIC know where to go ' if an interrupt takes place INTCON = %11100000 ' Enable Peripheral interrupts (Hardware Serial included) ' AND Timer Interrupts PIE1 = %01000001 'Enable Comparator and timer1 interrupts T1CON = %00001001 'timer1 enable 'Cmon has to be in mode 010 for software reference, and the interal reference is set 'by the voltage reference module VRCON = %10001000 'Voltage Reference module register - 1000 'CMCON = %00000100 'Comparator register (hardware reference voltage) CMCON = %00000010 'Comparator register (software reference voltage) 'turn on hardware serial transmit DEFINE HSER_TXSTA 20h ' Set baud rate DEFINE HSER_BAUD 19200 TRISB = %00101000 TRISA = 255 'input statusLED var portb.4 modeSwitch var portb.5 xorSwitch var portb.3 prevMode var bit prevXor var bit counter var word shift var byte outByte var byte inBit var bit flip var bit counter = 0 high statusled main: goto main disable myint: if PIR1.6 = 1 then 'if interupt is comparator interrupt CMCON.6 = 0 PIR1.6 = 0 counter = counter + 1 endif if PIR1.0 = 1 then 'if interrupt is caused by timer1 PIR1.0 = 0 TMR1H = $F5 'set timer interval TMR1L = $00 if modeSwitch = 0 then 'random byte mode inBit = counter // 2 'output 1's and 0's if xorSwitch = 1 then inBit = inBit ^ flip flip = ~flip endif outbyte = outByte | (inBit << shift) shift = shift + 1 if shift = 8 then shift = 0 hserout [outbyte] outByte = 0 endif endif if modeSwitch = 1 then 'asci out inBit = counter // 2 'output 1's and 0's if xorSwitch = 1 then inBit = inBit ^ flip flip = ~flip endif HSerout [DEC inBit] endif counter = 0 endif resume enable