		title	200noise
;
;
;	PIC10F200で作るホワイトノイズ
;
		list      p=10f200
		#include <p10f200.inc>

		__CONFIG	_CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC 

		__idlocs	0x0100
;
;0x10	ver1.0	08/08/22	最初の版
;
		radix	dec

;
OPTION_VAL	equ	b'11000000'
		;	b7:	Wake-up Pin Chng	0: enable 1:disable
		;	b6:	Pullup		0: enable 1:disable
		;	b5:	T0CS		0: int	 1:out
		;	b4:	T0Se		0: up	1: down
		;	b3:	PSA		0: tm0	1: WDT
		;	b2-b0:	Prescale
TRIS_VAL		equ	b'1000'
			; GP0-GP2が出力に設定可
			; GP3は INPUT/MCLR
			;b3:	GP3
			;b2:	GP2
			;b1:	GP1
			;b0:	GP0

NOISE		equ	0	; GP0
;

;=========
; RAMS
;========
;
; 0x10-0x1f


		cblock	0x10
;
		gpio_back
;
		shiftH
		shiftM
		shiftL
		tapreg
		endc

;
TAP_A		EQU	7	;for H
TAP_B		EQU	6	;for H
TAP_C		EQU	6	;for M
TAP_D		EQU	0	;for L

		ORG	0x0
boot:
;
;;		andlw	0xfe		; b0: 0: 
		movwf	OSCCAL

;

		movlw	OPTION_VAL
		option
		movlw	TRIS_VAL
		TRIS	GPIO

		clrf	gpio_back
		movf	gpio_back,W
		movwf	GPIO

		movlw	H'AA'
		movwf	shiftH
		movwf	shiftL
		movlw	H'0F'
		movwf	shiftM
;
loop:
		clrf	tapreg
;
		btfsc	shiftH,TAP_A
		incf	tapreg,f
		btfsc	shiftH,TAP_B
		incf	tapreg,f
		btfsc	shiftL,TAP_C
		incf	tapreg,f
		btfsc	shiftL,TAP_D
		incf	tapreg,f
	; output
		bsf	gpio_back,NOISE	; NOISE output
		btfss	shiftL,0		; outbit
		bcf	gpio_back,NOISE
		movf	gpio_back,w
		movwf	GPIO
	;
		bcf	STATUS,C	; Shift
		btfsc	tapreg,0
		bsf	STATUS,C
		rrf	shiftH,f
		rrf	shiftM,f
		rrf	shiftL,f
;
		goto	loop

		end

