; Main steering of the wireless lasershow
; receiver part
	list p=16f877
	title "main.asm"
	#include <P16f877.INC>
;;;;;;;;;;;;;;;;;;;equates      ;;;;;;;;;;;;;;;;;
Bank0RAM	equ	H'20'	;lowest Bank0 adress
Bank1RAM	equ	H'A0'	;lowest Bank1 adress
Bank2RAM	equ	H'120'	;lowest Bank2 adress
Bank3RAM	equ	H'1A0'	;lowest Bank3 adress
_baud		equ	H'40'	; 19200 at 20 MHz
;;;;;;;;;;;;;;;;;;;PORTS    ;;;;;;;;;;;;;;;;;;;;;
;PORTA
;PCFG<3:0>  = 0100   ?  3 analog channels AN1,AN2,AN4, internal Vref
	;RA0	Analog RF-strength, 1V = no signal, 0V = Maximum signal
	;RA1	Voltage sense from LV1, (LV1)/2, max ~3V
	;RA2	BSY from RF receiver
	;RA3 	Voltage sense from LV2, (LV2)/3, max ~5V
	;RA4	RDY from RF receiver
	;RA5	Enable to SPI-chain
;PORTB
	;RB0	RC signal from IR receiver
	;RB1	display 1 for LED mux
	;RB2 	display 2 for LED mux
	;RB3
	;RB4 	display 3 for LED mux
	;RB5 	display 4 for LED mux
	;RB6	(program clock)
	;RB7	(program data)
;PORTC
	;RC0	
	;RC1	PWM for controlling low-voltage converter
	;RC2	LED-chain data pin
	;RC3	SPI clk
	;RC4	SPI dataout
	;RC5
	;RC6	RS232 TX
	;RC7	RS232	RX
;PORTD LED-segment
	;RD0	LED-segment A
	;RD1 	LED-segment B
	;RD2 	LED-segment C
	;RD3	LED-segment D
	;RD4 	LED-segment E
	;RD5 	LED-segment F
	;RD6 	LED-segment G
	;RD7 	LED-segment dp
;PORTD keypad
	;RD0	keyboard strobe0
	;RD1 	keyboard strobe1
	;RD2 	keyboard strobe2
	;RD3	keyboard strobe3
	;RD4 	keyboard sense0
	;RD5 	keyboard sense1
	;RD6 	keyboard sense2
	;RD7 	keyboard sense3
;PORTE
	;RE0	Relay1, active high
	;RE1	Relay2, active high
	;RE2	LV1 switch, active high
;;;;;;;;;;;;;;;;;;;variables;;;;;;;;;;;;;;;;;;;;;
	cblock	Bank0RAM	
	W_TEMP0				;temporary storage of w
	S_TEMP				;temporary storage of STATUS
	SLAVE_ADDRESS			; slave address as read from dip switches
	CUR_ADDRESS			; slave being addressed
	CUR_DATA			; current data received
	endc
	cblock Bank1RAM
	W_TEMP1				;temporary storage reserved for w
	endc
	cblock Bank2RAM
	W_TEMP2				;temporary storage reserved for w
	endc
	cblock Bank3RAM
	W_TEMP3				;temporary storage reserved for w
	endc
;; Macro definitions
BANK0	macro
	bcf			STATUS, RP0		;select bank0
	bcf			STATUS, RP1
	endm
BANK1	macro
	bsf			STATUS, RP0		;select bank1
	bcf			STATUS, RP1
	endm
BANK2	macro
	bcf			STATUS, RP0		;select bank2
	bsf			STATUS, RP1
	endm
BANK3	macro
	bsf			STATUS, RP0		;select bank3
	bsf			STATUS, RP1
	endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	org			00h
	goto		Mainline
Mainline
	call		Init
	goto		Mainline
;
Init
	BANK1
	movlw		_baud
	movwf		SPBRG

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	end
