 ;Example program for using the the REVA board's LEDs, buttons and switches
; with the RAISONANCE assembler.

;Displays, on the LEDs, the value of the buttons and switches

;Note that you must put the jumpers for the LEDs, buttons and switches.

;This also shows how you must protect the ICC pins in order to debug.


$include(st7263B.inc)

;-------------------------------------------------------------------------------
;   Constants
;-------------------------------------------------------------------------------
	NULL			EQU 	0

;-------------------------------------------------------------------------------
;   Segments
;-------------------------------------------------------------------------------

	RSG?DATA			 	segment		DATA INPAGE0
	RSG?CODE			 	segment		CODE
	
	
;-------------------------------------------------------------------------------
;   Data
;-------------------------------------------------------------------------------

rseg RSG?DATA
_readval:
	ds	1

;-------------------------------------------------------------------------------
;   Code
;-------------------------------------------------------------------------------

rseg RSG?CODE
_reset:

	;reset stack pointer
  	RSP
  	;mask interrupts
  	SIM
  	
   ;initialize the ports config (input mode by default)
	LD A, #0h
	LD PADDR, A
	LD PBDDR, A
	LD PDDDR, A	
	
;main function. that's where the debug session goes at the beginning.
_main:
  	
  	;configure port D as output
	LD A, #0FFh
	LD PDDDR, A

_main_loop:
  
	;read the switches
	LD A, PADR
	SWAP A
	OR A, #0F0h; SW1 to SW4 are now in A3..A0
	LD _readval, A ; we store SW1 to SW4 states
	
	; read the buttons from PB4 and PB5
	LD A, PBDR
	OR A, #0CFh
	AND A, _readval
	
	;display value on the LEDs
	LD PDDR, A

	JP	_main_loop

;----------------------------------------------------------------
; VECTORS table

cseg at 0FFFEh

   dw    _reset         ;RESET
			
END 










