Computed goto 2 using program rom indexed rom using

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0 L_BYTE equ 0x06 H_BYTE equ 0x07 LFSR 0, 0X40 movlw 0x04 movwf COUNT clrf H_BYTE clrf L_BYTE Loop: movf POSTINC0, W; Loop: addwf L_BYTE, F; bnc Next bnc incf H_BYTE, F; incf Next: decfsz COUNT, F Next: decfsz bra Loop bra 54 Lookup Table Implementation Lookup • There are two methods for reading a There table: table: 1. Computed goto 2. Using program ROM (Indexed-ROM Using addressing mode) addressing 55 Lookup Table Using Computed Goto Lookup • Prelab: Write a subroutine to output a digit pattern Prelab: in the 7-segment LED when given the number. Use a lookup table using Computed Goto. lookup 56 Lookup Table Using Computed Goto Lookup • Add an offset to PCL to access the Add appropriate item in the table appropriate • retlw will load the desired item to WREG e.g., SVN_SEG: movf PAT_NUM, W movf e.g., addwf addwf addwf addwf retlw retlw retlw retlw retlw retlw retlw retlw WREG, W PCL, F B‘xxxxxxxx' B‘xxxxxxxx' B‘xxxxxxxx' B‘xxxxxxxx' 57 Indexed-ROM addressing mode Indexed-ROM • We can use program ROM to store fixed We data. data. • Use the db (define byte) directive to Use db define fixed data in program ROM. define • Example: org 0x500 org array db 0x00, 0x01, 0x02, 0x03 • ROM: [000500] = 0x00, [000501] = 0x01 ROM: 0x01 [000502] = 0x02, [000503] = 0x0358 0x03 Reading Data Using TBLPTR and TABLAT Reading • To access data in a location in ROM, we To need a register specifying which location we want to access TBLPTR • TBLPTR must have 21 bits to address TBLPTR the whole range of ROM. the • TBLPTR is divided into three 8-bit parts: TBLPTR TBLPTRL (low), TBLPTRH (high), TBLPTRU (upper). • We need a register to store the data We fetched by a table read operation 59 TABLAT TABLAT Table Read Operations Table • tblrd* – After read, TBLPTR stays the same • tblrd*+ – Reads then increments TBLPTR Reads increments • tblrd*– Reads then decrements TBLPTR Reads decrements • tblrd+* – Increments TBLPTR then reads 60 Steps for Table Read from ROM Steps 1. Write an array to program ROM by Write using the db directive. db 2. Specify the table pointer (TBLPTR) Specify from which data is read. from 3. Perform a tblrd instruction. Perform tblrd 4. The data read is stored in the table The latch (TABLAT). latch 61 Tutorial 7 Q1 Tutorial • Assume that the program memory Assume space starting from 0x000500 store your student ID number. Each digit of your student ID number is stored in a byte. Write a program to copy the content from the program memory to the data memory starting from 0x040. 62 63 64...
View Full Document

This document was uploaded on 11/07/2013.

Ask a homework question - tutors are online