;*******************************************************************
;  Nixie Thermostat - Hardware Test (Nixie display tubes only)
;    Professor M. Csele, 2006
;*******************************************************************
;  HARDWARE:
;  Target is an 18F252  XTAL=4MHz, XT, ICD-2 debugger
;
;  PORT B:
;   RB0 to RB3 - Nixie #1 (LSD)
;  PORT C:
;   RC0 to RC3 - Nixie #2
;   RC4 to RC7 - Nixie #3 (MSD)
;*********************************************************************
        LIST    p=18F252       ;PIC18F252 is the target processor
        INCLUDE "P18F252.INC"  ;Include file with register defines

	;Programming Configuration Information
	__CONFIG    _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H				;XT (4MHz XTAL)
	__CONFIG    _CONFIG2L, _BOR_ON_2L & _BORV_27_2L & _PWRT_ON_2L	;Power-Up timer ON
																	;Brown-out at 2.7V
	__CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H		;WDT OFF for debug
	__CONFIG    _CONFIG3H, _CCP2MX_OFF_3H					;CCP Module Off
	__CONFIG    _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_ON_4L	;DEBUG On
	
	;UnProtect entire device program space for debugging
	__CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L 
	__CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
	__CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L 
	__CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H

	;Programming Configuration ENDS

;*************************************************************************
; Register Defines: All used registers are in the range 0x00-0x7F allowing
;                   access via the ACCESS BANK feature of the 18F processor
;*************************************************************************
;Assorted miscellaneous general-purpose registers
DlyRegA     equ     10  ;Temp register for time delay
DlyRegB     equ     11  ;Temp register for time delay
DlyRegC     equ     12  ;Temp register for timedelay

LoopCtr		equ		13  ;Counter for main loop timing
DisplayTemp	equ		14	;Temp register for display

;********************************************************************
; Main Program Begins
;*********************************************************************
	nop						;Required for ICD Debugging
	nop
		
	clrf	BSR,A	      	;Ensure BSR register points to first block

;Setup Ports for Nixie display test
	clrf    PORTB,A       ;Make All Outputs LOW
	movlw   b'11110000'   ;Port B outputs driving nixie
	movwf   TRISB,A

	clrf    PORTC,A       ;Make All Outputs LOW
    movlw   b'00000000'   ;Port C all outputs driving two nixies
    movwf   TRISC,A

	clrf	PORTB			;Display "00.0" to start
	clrf	PORTC  

	clrf	LoopCtr			;Counter for MainLoop

MainLoop
	call	LongDelay		;Hold display for a second

	incf 	LoopCtr,f		;Increment the loop counter

	movf	LoopCtr,w
	andlw	b'00001111'		;Extract just the lower four bits (0x00 - 0x0F)
	movwf	DisplayTemp		;Save for the next digit
	movwf	PORTB			;Display digit on the LSB Nixie

	swapf	DisplayTemp,w	;Copy counter to the upper four bits
	iorwf	DisplayTemp,w	;Make upper four & lower four the same
	movwf	PORTC			;Display digits on the upper two Nixies

	goto	MainLoop


;########## LONG DELAY ##########
;A long delay used for loop timing
LongDelay
		movlw   H'8'
		movwf   DlyRegA
ldelayc	movlw   H'FF'
		movwf   DlyRegB
ldelayb movlw   H'FF'
		movwf   DlyRegC
ldelaya decfsz  DlyRegC,f     ;Inner Loop
		goto    ldelaya
		decfsz  DlyRegB,f     ;Middle Loop
		goto    ldelayb
		decfsz  DlyRegA,f     ;Outer Loop
		goto    ldelayc
		return


       END



