please dont rip this site


Lookup

finds a table entry corresponding to an index number.

A classic application for Lookup is to convert the numbers 0 through 9 (or 0 through F in hexadecimal) into patterns for seven-segment displays. Throughout this book, you will see other applications, such as the table Pinz that some routines use to change a number in the range of 0 through 7 into a byte with a 1 in the corresponding position for use as a bit mask.

Lookup tables are an inherent PIC capability made possible by the retw instruction, which stands for "return with literal value in w." A table consists of a way to select from a list of retws. The instruction jmp pc+w takes care of this. Since the program counter always points to the next instruction, a 0 in w selects the first retw from the list; a 1 the second; a 2 the third, and so on.

The Parallax assembler allows great flexibility in formatting data for tables. You can type one retw n per line, or use the shorthand retw n1,n2,n3...For tables of text, you can type retw 'Text data in retw table'. The assembler will turn this into a series of retws with the ASCII codes for each character of the text. For an example of such a table, see the program listing for Lookdown.

A couple of cautions about using tables. First, your program must ensure that the number in w never exceeds the maximum entry in the table. If it does, program execution will jump completely over the table. Second, tables must be in the first 256 words of a 512-word program-memory page because of the way the PIC's computed-jump mechanism works.

Demonstrating Lookup.

To see Lookup in operation, either run the program with the PSIM simulator, or connect the circuit below to an erasable PIC or PIC emulator, such as the Parallax downloader. Assemble and run LOOKUP.SRC. When you apply power to the PIC, the display will count upward in hexadecimal from 0 to F.

James Newton says: To drive multiple displays, just connect the first displays cathode to ra.0 and the second displays cathode to ra.1 Use the same code you would to drive one display, but call it twice, once with ra.0 low and ra.1 high and again with ra.0 high and ra.1 low. Continue to do this as quickly as possible. See also Driving 8 or 9 7 segment displays with 8 or 9 io pins (and no extra circuitry)


;
; ***************************************************************************
; ***  Bubble Software Parallax to PIC Source Converter. Copyright 1999.  ***
; ***  http://www.bubblesoftonline.com                 email: sales@picnpoke.com  ***
; ***************************************************************************
;
; 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
	P = pic16c55
	#include <16c55.inc>   ; processor assembler definitions
	_CONFIG _xt_osc & _wdt_off & _protect_off
 reset start

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

 org 0

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

start        MOVLW d'0'                 ; All outputs for LEDs
             TRIS 6h
             CLRF 6h                    ; All LEDs off to begin.
             CLRF count                 ; Start count at 0. 
start_loop   MOVF count,w               ; Put number to look up into w.
             ANDLW b'00001111'          ; Strip off high bits. 
             CALL Lookup                ; Call the table. 
             MOVWF 6h                   ; Write pattern in w to LEDs. 
start_wait   DECFSZ temp                ; Short delay. 
             GOTO start_wait
             DECFSZ temp2               
             GOTO start_wait
             INCF count                 ; count = count + 1
             GOTO start_loop            ; Do it again.

             
             
             end


; 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. 

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

; Device data and reset vector
	device	pic16c55,xt_osc,wdt_off,protect_off
	reset	start
	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.

See also:


file: /Techref/microchip/seepicsrc/psbpix/lookup.htm, 7KB, , updated: 2011/3/9 03:34, local time: 2024/11/17 19:19,
TOP NEW HELP FIND: 
3.136.236.126:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/techref/microchip/seepicsrc/psbpix/lookup.htm"> Using lookup tables to convert numbers to seven segment LED display patterns</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .