; LOOKUP index (in w), table
; Finds the table entry corresponding to index (in w) and 
; returns it in w. This demonstration uses a table to map the 
; numbers 0 through F hex to patterns on a seven-segment LED
; display. It assumes that the display is connected with segment
; a to rb.0, b to rb.1... and g to rb.6 through current-limiting 
; resistors of 220 ohms minimum. When the program runs, it counts
; upward 0, 1, 2, 3...through F, then begins the count again at 0. 

; Device data and reset vector
	device	pic16c55,xt_osc,wdt_off,protect_off
	reset	start

	org     8
count	ds	1	; Counter variable for demo.
temp	ds	1	; Variables for delays
temp2	ds	1	; used in demo subroutines. 

	org	0

Lookup	jmp	pc+w		; Jump to entry spec'd by w.
	retw	63,6,91,79	; 0, 1, 2, 3
	retw	102,109,125	; 4, 5, 6
	retw	7,127,103	; 7, 8, 9
	retw	119,124,57	; A, B, C
	retw	94,121,113	; D, E, F

start	mov	!rb, #0		; All outputs for LEDs
	clr	rb		; All LEDs off to begin.
	clr	count		; Start count at 0. 
:loop	mov	w,count		; Put number to look up into w.
	AND	w,#00001111b	; Strip off high bits. 
	call	Lookup		; Call the table. 
	mov	rb,w		; Write pattern in w to LEDs. 
:wait	djnz	temp,:wait	; Short delay. 
	djnz	temp2,:wait
	inc	count		; count = count + 1
	jmp	:loop		; Do it again.

