Re-sent as original bounced ? /Tony -----Ursprungligt meddelande----- Fr=E5n: K=FCbek Tony = Skickat: den 14 april 2001 12:03 Till: Pic Mailing list (E-post) =C4mne: Re: ]PIC[: Navigating in big tables Hi, an example based on Scott's code but for the 18X series (i.e table read functions ): #define STRING_HOWDY 0 #define STRING_PICLIST 1 #define STRING_HELLO 2 #define STRING_NONSENSE 3 #define STRING_LAST 4 ; use like ; MOVLW STRING_HELLO ; CALL GET_STRING ; content in String... ; ;+++++ ; GET_STRING - Enter with string number in w, reads string from memory until null detected ; ( due to an request from James Newton ) = ; For the 18Cxx series using the table read functions = ; Replica of an multistring example by Scott Dattalo, but converted= to use table functions instead. ; Handles upto 256 separate strings ( or data or text etc ) ; This version uses the following ram: ; StringTmp one byte ; String x amount of bytes, where to put the string, could be replaced by an byte output ; routine ; By Tony K=FCbek, 2001-01-25 ; email: tony.kubek@flintab.com ; = GET_STRING ; we enter with string number in w MOVWF StringTmp ; save menu string index temporarily = MOVLW HIGH(STRING_PTR_TABLE) ; get pointer high byte to string pointer table ; MOVWF TBLPTRH,A ; setup high adress MOVF StringTmp,W ; get offset back = ADDWF StringTmp,W ; multiply with two to get string pointer offset = ; test for overflow when doubling string pointer offset SKPNC = INCF TBLPTRH,F,A ; inc high byte adress = ADDLW LOW(STRING_PTR_TABLE) ; add offset to pointer to the string low byte ; MOVWF StringTmp ; save it SKPNC ; check if low byte generated overflow INCF TBLPTRH,F,A ; then add one to high byte = ; clear upper adress ( we dont have that amount of program mem ) CLRF TBLPTRU,A MOVFF StringTmp,TBLPTRL ; finally set low adress ; read the two bytes TBLRD*+ ; read low adress of menu and increment pointer MOVFF TABLAT,StringTmp ; save it temporarily TBLRD*+ ; read high adress of string and increment pointer MOVFF TABLAT,TBLPTRH; set high adress for char loop MOVFF StringTmp,TBLPTRL ; and set low adress = ; setup fsr0 to point to menutext variable were we will put the bytes ; could ofcource be omitted if putputting one byte at a time in loop below MOVLW HIGH(String) MOVWF FSR0H MOVLW LOW(String) MOVWF FSR0L GET_STRING_CHAR_LOOP ; loop through the string ( until null detected ) TBLRD*+ ; read next byte and increment pointer MOVF TABLAT,W,A ; get byte into w ANDLW 0xFF SKPNZ ; if byte is zero we have reached the end of string GOTO GET_STRING_NULL ; now get consecutive bytes ; save the byte in the string MOVWF POSTINC0 ; save byte and increment fsr0 pointer GOTO GET_STRING_CHAR_LOOP GET_STRING_NULL ; end string with null MOVWF INDF0 = ; now we can read other data located directly after the string or just return... RETURN = ;+++++ ; STRING_PTR_TABLE - the pointer table to the strings, two bytes for each string ; = STRING_PTR_TABLE = DW STRING0 DW STRING1 DW STRING2 DW STRING4 ; etc..upto 255 = ;+++++ ; STRING_TABLE - all the strings... ; Note if strings have fixed length then the pointer table above is= not necessary ; then offset can be calculated instead STRING_TABLE STRING0: DB "HOWDY",0x00 STRING1: DB "PICLIST",0x00 STRING2: DB "HELLO WORLD",0x00 STRING3: DB "ALMOST THE LAST ONE",0x00 STRING3: DB "I'M THE LAST ONE",0x00 = = Tony K=FCbek, Flintab AB = =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2= =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2= =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2 E-mail: tony.kubek@flintab.com =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2= =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2=B2= =B2=B2=B2=B2=B2=B2=B2=B2=B2=B2 -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads