title "White Noise Generator"
;
; SOFT Bretelle Bruit blanc (ULTRA RAPIDE CANARI - )
; Original Tom Wiltshire for Elecric Druid, March 2008
; adapté et modifié par Hubert LEON - ACTRIS pour cible 12F508
;
; Hardware Notes:
; PIC12F508 running at 4 MHz using internal clock
list p=12f508 ; list directive to define processor
#include <p12f508.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _MCLRE_OFF & _WDT_OFF & _IntRC_OSC
;------------------------------
; Variables
;------------------------------
CBLOCK 0x0010
; LFSR 1, a 31-bit register
LFSR1_1
LFSR1_2
LFSR1_3
LFSR1_4
; LFSR 2, a 23-bit register
LFSR2_1
LFSR2_2
LFSR2_3
; Temporary storage
TEMP
ENDC
;-------------------------------------
; DEFINE STATEMENTS
;-------------------------------------
; Useful bit definitions for clarity
#define ZEROBIT STATUS,Z ; Zero Flag
#define CARRY STATUS,C ; Carry Flag
#define BORROW STATUS,C ; Borrow is the same as Carry
;----------------------------------------------------------------------
; Begin Executable Code Segment
;----------------------------------------------------------------------
org 0x000 ; processor reset vector
movlw b'00101111' ; GP4 Output, all others unused inputs
TRIS GPIO
clrf GPIO
; Set up initial values of the registers
movlw 0x45
movwf LFSR1_1
movlw 0x57
movwf LFSR1_2
movlw 0x9F
movwf LFSR1_3
movlw 0xF2
movwf LFSR1_4
movlw 0xD7
movwf LFSR2_1
movlw 0xC8
movwf LFSR2_2
movlw 0x79
movwf LFSR2_3
MainLoop:
;----------------------------------------------------
swapf LFSR1_4, W ; Get bit 28
movwf TEMP
rlf LFSR1_4, W ; Get bit 31
xorwf TEMP, F
; Shift the XORd bit into carry
rlf TEMP, F
; Shift the register
rlf LFSR1_1, F
rlf LFSR1_2, F
rlf LFSR1_3, F
rlf LFSR1_4, F
; Output the noise bit
movf LFSR1_1, W
movwf GPIO
;----------------------------------------------------
rrf LFSR2_3, W ; Get bit 19
movwf TEMP
rrf TEMP, F
swapf LFSR2_3, W ; Get bit 21
xorwf TEMP, F
; Shift the XORd bit into carry
rrf TEMP, F
; Shift the register
rlf LFSR2_1, F
rlf LFSR2_2, F
rlf LFSR2_3, F
; Output the noise bit
movf LFSR2_1, W
movwf GPIO
goto MainLoop
end