; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; RANDOM ; Generates a pseudorandom number. Works best if called from a loop so that ; the value of its workspace variable (consisting of lowB and hiB) is ; constantly stirred. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 hiB Res d'1' ; MSB of 16-bit random number. lowB Res d'1' ; LSB of 16-bit random number. temp Res d'1' ; Temporary counter for delay. temp2 Res d'1' ; Temporary counter for delay. ; Device data and reset vector org 0 start mov !rb,#0 ; Output to show sequ onence LEDs. MOVLW d'13' ; Arbitrary starting values MOVWF lowB MOVLW d'99' ; for the shift register. MOVWF hiB start_loop CALL Random MOVF lowB,w ; Display 8-bit random numbers MOVWF 6h CALL delay ; on LEDs connected to RB. GOTO start_loop ; Endless loop ; Random number generator. Random MOVF hiB,w ; First, ensure that hiB and lowB aren't IORWF lowB,w ; all zeros. If they are, NOT hiB to FFh. BTFSC status,z ; Otherwise, leave hiB and lowB as is. COMF hiB MOVLW 0x80 ; We want to XOR hiB.7, hiB.6, hiB.4 BTFSC hiB,d'6' ; and lowB.3 together in W. Rather than XORWF hiB ; try to line up these bits, we just BTFSC hiB,d'4' ; check to see whether a bit is a 1. If it XORWF hiB ; is, XOR 80h into hiB. If it isn't, BTFSC lowB,d'3' ; do nothing. When we're done, the XORWF hiB ; XOR of the 4 bits will be in hiB.7. RLF hiB,w ; Move hiB.7 into carry. RLF lowB ; Rotate c into lowB.0, lowB.7 into c. RLF hiB ; Rotate c into hiB.0. RETLW 0h ; Delay loop for program demo. Remove when using just Random. delay DECFSZ temp GOTO delay DECFSZ temp2 GOTO delay RETLW 0h end