;	gpasm -a inhx8m trans2.asm
;	Testprogram for seriel overførsel til RPi
;	DB Henrik Kressner


processor	10F322
include		p10f322.inc

 		__CONFIG _WDTE_OFF & _FOSC_INTOSC

cblock 0x40
	a,b,c,d,e,f,h
	Result
	i
	RegNr
endc
;	org	0x61
;var:	dt      "Hallo verden",'\0'

x	org	0x60
y	org	0x61

	org	H'00'  ; Reset vector
	goto	setup

	org	0x05
setup	movlw   B'01010000'
        movwf   OSCCON		; Clk Frq = 4 Mhz
	clrf	ANSELA		; Port 0, 1 og 2 digital I/O
	movlw	B'00000110'
	movwf	TRISA		; Port 0 er output, 1 og 2 er input
	clrf	PORTA

	movlw	0x60
	movwf	RegNr
	movlw	'H'
	movwf	x
	movlw	'a'
	movwf	y

start:	movfw	0x60
	movlw	0x60
	movwf	FSR
	
	movwf	Result		;  movwf   0x60, hvis result er på addr 0x60
	movlw 	0x9		; Vi skal overføre 8 bit og stoppe
	movwf	i
	call	Tx

	movlw	'a'
        movwf   Result          ; = movwf Result
        movlw   0x9             ; Vi skal overføre 8 bit og stoppe
        movwf   i
        call    Tx

	goto	start

Tx	decfsz	i,1             ; Har vi talt til 8 ?
	goto	cont
	return
cont	btfsc	PORTA, RA1      ; Vent på RPi
        goto	$-1
	btfss	PORTA, RA1	; RPi vil have en bit
	goto    $-1
	rlf     Result,1
	btfsc	STATUS,C	; Tjek carry
	goto	on
	goto	off

on      bsf     PORTA,RA0       ; Port 0 ON
        goto    Tx

off     bcf     PORTA,RA0       ; Port 0 OFF
        goto    Tx


	end
