;***************************************************************
;led_disp_tst
;Tests led display on Derbot Hand Controller by writing
;word "HELP" to 4-digit display.
;TJW 17.6.05							         Tested 22.6.05
;***************************************************************
;Configuration Word: RC oscillator, WDT off, power-up timer on, 
;			   brown-out off, LVP off, all code protect on.
 
;								
;   Port A      			Port B      		Port C
;   ------      			------          	------
;0	lcd bus 2/led seg c		-/led cc digit 4	Display RS/led cc digit 2
;1	lcd bus 3/led seg d		keypad col 3		Display E /led cc digit 1
;2	lcd bus 4/led seg e		keypad col 2		Interrupt op
;3	lcd bus 5/led seg f		keypad col 1		SCL
;4	lcd bus 6/led seg g		keypad row 4		SDA
;5	lcd bus 7/led seg dp	keypad row 3		Display RW /led cc digit 3
;6	    -					keypad row 2 		lcd bus 0/led seg a
;7	    -					keypad row 1   		lcd bus 1/led seg b

	list 	p=16F873A
	#include p16f873A.inc

;Specify RAM
delcntr1 equ	20	;used in delay5
;Specify some port bits
;Port C
dig1_cc	equ	1	;digit common cathode drives
dig2_cc	equ 0
dig3_cc	equ	5
;Port B
dig4_cc equ 0
;
	org 00
;Initialise
	bcf	status,rp1
	bsf	status,rp0 		;select memory bank 1
	movlw	B'00000000'	;set all port bits op
	movwf	trisa		
	movwf	trisb		
	movwf	trisc		
	bcf	status,rp0 		;select bank 0
; 
;set digit1	
loop bcf portb,dig4_cc
	movlw B'00011101'	;turn on segments for H
	movwf porta
	bcf	portc,6
	bsf	portc,7
	bsf	portc,dig1_cc  ;enable digit once segments set
	call delay5
;digit2
	bcf	portc,dig1_cc
	movlw B'00011110'	;turn on segments for E
	movwf porta
	bsf	portc,6
	bcf	portc,7
	bsf	portc,dig2_cc	;enable digit
	call delay5
;digit3
	bcf	portc,dig2_cc
	movlw B'00001110'	;turn on segments for E
	movwf porta
	bcf	portc,6
	bcf	portc,7
	bsf	portc,dig3_cc   ;enable digit
	call delay5
;digit4
	bcf	portc,dig3_cc
	movlw B'00011100'	;turn on segments for E
	movwf porta
	bsf	portc,6
	bsf	portc,7
	bsf	portb,dig4_cc	;enable digit
	call delay5
	goto loop
;**********************************************
;SUBROUTINES
;**********************************************
;introduces delay of 5ms approx
delay5  movlw 	D'250'	;250 cycles called 
        movwf  	delcntr1
del1    nop				;5 inst cycles in this loop, ie 20us
 		nop
        decfsz 	delcntr1,1
        goto 	del1
        return
	end
