some help with math


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 65

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default some help with math

    Hi guys i need to make this table of value in code
    Code:
    count		byte code	end value 
    1	-1	0	         0
    2		1              	42
    3		2	        84
    4		3	       126
    5		4	       168
    6		5	       210
    7	-7	0	       0
    8		1             42
    9		2	      84
    10		3	     126
    11		4	     168
    12		5	     210
    13	-13	0	     0
    14		1	     42
    15		2	     84
    16		3	    126
    17		4	    168
    18		5	    210
    19	-19	0	    0
    20		1	   42
    21		2	   84
    22		3	   126
    23		4	   168
    24		5	   210
    25	-25	0	   0
    26		1	  42
    27		2	   84
    28		3	  126
    29		4	  168
    30		5	  210
    code attempt
    Code:
     Data_Length = 42                                  ' 38chrs + 4 byte setting  - required varable for spi flash routine 
            SDC_Page = 129 + (Menu_Subtxt-1)/6                ' page start point + 1 page per each 6 subtxt placed
            IF Menu_subtxt-1 //6 = 0 THEN 
                 SDC_Byte = 0    
            ELSE   
                 SDC_Byte = (Menu_Subtxt-1)+6 *6 + (Menu_Subtxt-1)-6 *6 /6 * Data_Length         ' byte start point per data length
                 
            ENDIF

  2. #2
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    count in the table is Menu_subtxt varable
    end code in the table is the value of SDC_Byte
    byte code in table the intrum caculation prior to mulitply data length

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Try
    Code:
    EndValue = ((Count - 1) // 6) * 42
    Is that what you want?

    /Henrik.

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    interesting results

    i now format the data as word value which now stores the data in the correct byte by byte sequance form ,

    however readcode reads the address data back incorectly for a given address when reading as byte value

    i assume its cos readcode is word based command ???

    is there a way to read the data back for each address byte only ?

    as can be seen on address 5172, 5173 byte values are incorrect for the given address

    Code:
    LG_Font_Base:
              ' Note gl_x char space need be 12 , not normal 24 when using chr else too big a gap space _
              ' Code for "-"  Asci 45    90 real values _
    @ dw      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00      
    @ dw      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3FFC,0x003F,0xFC00,0x3FFC     
    @ dw      0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00  
    @ dw      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
    part of flash dump of font stored

    Code:
    5170- 0000 3ffc 003f fc00 3ffc 003f fc00 3ffc 
    5180- 0000 0000 0000 0000 0000 0000 0000 0000 
    5190- 0000 0000 0000 0000 0000 0000 0000 0000 
    51a0- 0000 
    
    terminal debug dump - for each address read by readcode 
    5170- 0  ,  5171- 0,
    5172- FC,  5173- 3F,
    5174- 3F,  5175- 0,
    5176- 0 ,   5177- FC,
    5178- FC,  5179- 3F,
    517A- 3F,  517B- 0,
    517C- 0 ,  517D- FC,
    517E- FC, 517F- 3F,
    5180- 0  , 5181- 0

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    I will see if I can explain it

    pic18 pgm mem is stored as words , so if the bytes are not an even number the last byte is padded with 00


    if we store this @ db "say",34,"hello",34,0

    then its stored like this lst file extract

    00014A 6173 2279 6568 db "say",34,"hello",34,0 ; note order looks reversed but its really lowbyte first
    6C6C 226F 0000

    when readcode reads it back

    its lowbyte, highbyte

    so the string is returned in order as say"hello",0
    Last edited by richard; - 16th September 2015 at 06:40.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    when stored as words
    @ dw 0x0000,0x0000,0x53d7,0x53d7,0x53d7,0x53d7,0x53d7,0 x53d7,0x53d7,0x53d7,0x53d7,0x0000,0x0000,0x0000,0x 0000,0x0000


    lst file looks like this


    003CF6 0000 0000
    53D7 06827
    0000,0x0000
    53D7 53D7 53D7
    53D7 53D7 53D7
    53D7 53D7 0000
    0000 0000 0000
    0000
    note the order is now not reversed

  7. #7
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    OMG - gee i been playing with hours and i have variations of this same code but it did not work , THANKYOU hendrick , sometime you cant see the wood for the trees

  8. #8
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    end code
    - it is used to put 42 bytes into flash per page of 256 bytes of data

    Code:
    Data_Length = 42                                  ' 38chrs + 4 byte setting  - required varable for spi flash routine 
            SDC_Page = 129 + (Menu_Subtxt-1)/6                ' page start point + 1 page per each 6 subtxt placed
            IF Menu_subtxt-1 //6 = 0 THEN 
               SDC_Byte = 0                                   ' set byte to 0 when  Menu_subtxt = 7, 13, 19etc 
            ELSE   
               SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length  ' byte start point per data length
            ENDIF
            
            HSEROUT ["write SDC_Page = ",dec SDC_Page ,", SDC_Byte = ",dec SDC_Byte,13,10 ] 
            gosub Flash_Font_Common_write                     ' use flash font common write to save subtxt data                 
    
    return

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    I don't think you need the IF/ELSE/ENDIF block in there. SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length should work fine even when Menu_Subtxt - 1 equals 0.

    /Henrik.

  10. #10
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    ok what i dont follow is
    if readcode can read a byte back based on a word address ,

    and the data is written to flash as a word , and therefore are stored in the way i want to read them byte by byte based on address i should be able to get each byte of the word

    what i am finding is that the byte returned is not correct for the address given

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    work just fine for me

    Code:
     
     pause 2000
     
     Serout2 PORTb.7,84,["ready",13,10] 
     addr var word
     inbuff  var byte[30]
     buff var byte[30]       $4f0
     lb var byte
     hb var byte
     lc var byte
     Clear
     
     
     goto StartLoop ' Required
     String1:
     @ data "may \"Hello\"\0"
     String2:
     @ db "say",34,"hello",34,0
     
     String3:
     @ dw      0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00  
     '------------Flash2Ram Macro - Location insensitive -------------------------
     ASM
    Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
       movlw   UPPER msg
       movwf   TBLPTRU
       movlw   HIGH msg
       movwf   TBLPTRH
       movlw   LOW msg
       movwf   TBLPTRL
       movlw   low buffer  
       movwf   FSR2L
       movlw   High buffer
       movwf   FSR2H
       L?CALL  _bfill
       endm
     ENDASM  
       
     ASM   
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1
        endm
      
       
       
       
       
       
     ENDASM
           
    
     
     
     
     
     
    StartLoop: ' This loop repeats continuously just as a test.
    @ Flash2Ram  _buff,_String1' Get a String from flash memory
     Serout2 PORTb.7,84, ["buff ",str buff ,13,10] '  and print it
    @ Flash2Ram  _inbuff,_String2' Get a String from flash memory
     Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
     pause 500
    @ GetAddress _String3 ,_addr  
    for lc=0 to 3 
    readcode addr ,lb
    addr=addr+1 
    readcode addr ,hb
    addr=addr+1 
     Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10] 
    next  
     
     
     
     
     
     
     goto StartLoop ' Repeat
    end 
     
     
     
     
    
     
    bfill: 
    ASM
    Next_Char
       tblrd   *+
       movf   TABLAT,w
       movwf  POSTINC2
       btfss STATUS,Z 
       goto   Next_Char
       return   
    ENDASM

    output



    buff may "Hello"
    inbuff say"hello"
    hb 00 lb 3F
    hb FC lb 00
    hb 3F lb FC
    hb 00 lb 00
    buff may "Hello"
    inbuff say"hello"
    hb 00 lb 3F
    hb FC lb 00
    hb 3F lb FC
    hb 00 lb 00
    buff may "Hello"
    inbuff say"hello"
    hb 00 lb 3F

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    to read as words


    Code:
     
     
     pause 2000
     
     Serout2 PORTb.7,84,["ready",13,10] 
     addr var word
     inbuff  var byte[30]
     buff var byte[30]       $4f0
     lb var byte
     hb var byte
     lc var byte
     lp var word
     Clear
    
     
    
    
    
     goto StartLoop ' Required
    
     String1:
     @ data "may \"Hello\"\0"
    
     String2:
     @ db "say",34,"hello",34,0
     
     String3:
     @ dw      0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00  
    
     '------------Flash2Ram Macro - Location insensitive -------------------------
     ASM
    Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
       movlw   UPPER msg
       movwf   TBLPTRU
       movlw   HIGH msg
       movwf   TBLPTRH
       movlw   LOW msg
       movwf   TBLPTRL
       movlw   low buffer		
       movwf   FSR2L
       movlw   High buffer
       movwf   FSR2H
       L?CALL  _bfill
       endm
     ENDASM  
       
     ASM   
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1
        endm
      
       
       
       
       
       
     ENDASM
    
           
    
    
     
     
     
     
     
    
    StartLoop: ' This loop repeats continuously just as a test.
    @ Flash2Ram  _buff,_String1' Get a String from flash memory
     Serout2 PORTb.7,84, ["buff ",str buff ,13,10] '  and print it
    @ Flash2Ram  _inbuff,_String2' Get a String from flash memory
     Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
     pause 500
    @ GetAddress _String3 ,_addr  
    for lc=0 to 3 
    readcode addr ,lb
    addr=addr+1 
    readcode addr ,hb
    addr=addr+1 
    Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10]
    next  
    
      
    @ GetAddress _String3 ,_addr   
     for lc=0 to 3 
    readcode addr ,lp
    addr=addr+2 
    
    
     Serout2 PORTb.7,84, ["lp ",hex4 lp,13,10] 
    
    next  
     
     
     
     
     goto StartLoop ' Repeat
    end 
     
     
    
     
    
    
    
    
     
    bfill: 
    ASM
    Next_Char
       tblrd   *+
       movf   TABLAT,w
       movwf  POSTINC2
       btfss STATUS,Z 
       goto   Next_Char
       return   
    ENDASM

    output

    lp 3FFC
    lp 0000
    buff may "Hello"
    inbuff say"hello"
    hb 00 lb 3F
    hb FC lb 00
    hb 3F lb FC
    hb 00 lb 00
    lp 003F
    lp FC00
    lp 3FFC
    lp 0000
    buff may "Hello"
    inbuff say"hello"
    hb 00 lb 3F
    h

  13. #13
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    yes your correct hendrick have removed the if/else statements

  14. #14
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    i think what threw me in my thinking hendrick was that the math command of "//" remainder (modulus) in that i have only ever used it to test for the remainder value of 0 or 1 being true /false in a if statement , not to use the remainder value directly

  15. #15
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    yes i thought about doing it that way where i get a word then use high, lowbyte , and thats ok when the for/next loop is for x = 1 to 2 , 4,6 etc so it uses the 2 bytes of the word per loop

    but my for/next loop 1-3 depending on the font so not even word use of 2 bytes is possible

    and if you just get 1 byte using readcode addresss , byte ,

    it will appears to get low byte for an even address , high byte for odd address - regardless of the data stored at that specific address

    eg my listing i put in post - address in flash at 5172,73 = 3FFC

    USING READCODE at address $5172 = $FC -not $3F as stored in flash


    5170- 0000 3ffc 003f fc00 3ffc 003f fc00 3ffc
    5180- 0000 0000 0000 0000 0000 0000 0000 0000
    5190- 0000 0000 0000 0000 0000 0000 0000 0000
    51a0- 0000

    terminal debug dump - for each address read by readcode
    5170- 0 , 5171- 0,
    5172- FC, 5173- 3F,
    5174- 3F, 5175- 0,
    5176- 0 , 5177- FC,
    5178- FC, 5179- 3F,
    517A- 3F, 517B- 0,
    517C- 0 , 517D- FC,
    517E- FC, 517F- 3F,
    5180- 0 , 5181- 0





    if you put this your example of string 3 in
    so if say address return is adress 1234 say 0000


    Code:
    @ GetAddress _String3 ,_addr  
    for lc=0 to 3 
    readcode addr ,lb
    addr=addr+1 
    readcode addr ,hb
    addr=addr+1 
    Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10]
    next

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    sorry but I can't make any sense of what you saying

    can I suggest you make a small program that demonstrates the problem

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    what about this
    Code:
     
     
     pause 2000
     
     Serout2 PORTb.7,84,["ready",13,10] 
     addr var word
     inbuff  var byte[30]
     buff var byte[30]       $4f0
     lb var byte
     hb var byte
     lc var byte
     lp var word
     Clear
    
     
    
    
    
     goto StartLoop ' Required
    
     String1:
     @ data "may \"Hello\"\0"
    
     String2:
     @ db "say",34,"hello",34,0
     
     
    
     '------------Flash2Ram Macro - Location insensitive -------------------------
     ASM
    Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
       movlw   UPPER msg
       movwf   TBLPTRU
       movlw   HIGH msg
       movwf   TBLPTRH
       movlw   LOW msg
       movwf   TBLPTRL
       movlw   low buffer		
       movwf   FSR2L
       movlw   High buffer
       movwf   FSR2H
       L?CALL  _bfill
       endm
     ENDASM  
       
     ASM   
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1
        endm
      
       
       
       
       
       
     ENDASM
    
           
    
    
     
     
     
     
     
    
    StartLoop: ' This loop repeats continuously just as a test.
    @ Flash2Ram  _buff,_String1' Get a String from flash memory
     Serout2 PORTb.7,84, [13,10,"buff ",str buff ,13,10] '  and print it
    @ Flash2Ram  _inbuff,_String2' Get a String from flash memory
     Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
     pause 500
    ;@ GetAddress _String3 ,_addr  
    ' 
    addr =$5170 
     
    for lc=0 to 3
    Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]  
    readcode addr ,lb
    
    addr=addr+1
    ;Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]
    readcode addr ,hb 
    Serout2 PORTb.7,84, [" hb ",hex2 hb ]
    
    Serout2 PORTb.7,84, [" lb ",hex2 lb ]
    addr=addr+1
    next
     
    
      
    
      
    ;@ GetAddress _String3 ,_addr 
    addr =$5170 
    for lc=0 to 3  
    Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]   
    readcode addr ,lp
    addr=addr+2 
    Serout2 PORTb.7,84, [" lp ",hex4 lp]
    next
      
    
    addr =$5177   
    readcode addr ,lb 
    Serout2 PORTb.7,84, [13,10,"odd address ",hex4  addr ] 
    Serout2 PORTb.7,84, [" b ",hex2 lb ] 
    addr =$5176   
    readcode addr ,lb 
    Serout2 PORTb.7,84, [13,10,"even address ",hex4  addr ] 
    Serout2 PORTb.7,84, [" b ",hex2 lb ] 
    
     
     goto StartLoop ' Repeat
    end 
     
     
    
     
    
    
    
    
     
    bfill: 
    ASM
    Next_Char
       tblrd   *+
       movf   TABLAT,w
       movwf  POSTINC2
       btfss STATUS,Z 
       goto   Next_Char
       return   
    ENDASM  
    
    
    
    String3:
    asm
     org 0x5170
      dw      0x003F,0xFC00,0x3FFC,0x5566,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00  
    ENDASM

    output
    buff may "Hello"
    inbuff say"hello"

    address 5170 hb 00 lb 3F
    address 5172 hb FC lb 00
    address 5174 hb 3F lb FC
    address 5176 hb 55 lb 66
    address 5170 lp 003F
    address 5172 lp FC00
    address 5174 lp 3FFC
    address 5176 lp 5566
    odd address 5177 b 55
    even address 5176 b 66

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    eg my listing i put in post - address in flash at 5172,73 = 3FFC

    USING READCODE at address $5172 = $FC -not $3F as stored in flash
    @5172 = $FC = LOW BYTE
    @5173 = $3F = HIGH BYTE

    $3FFC $FC = LOW BYTE $3F = HIGH BYTE

    where is the PROBLEM , IT's all consistent

    org 0x5170
    dw 0x003F,0xFC00,0x3FFC

  19. #19
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    and the maths eqivalant of this

    lookup gl_i,[24,32,40,24,32,40,24,32,40,24,32,40],gl_y ' menu row lines 8,24,32,40 for gl_y

    gl_y = 24+ (gl_i//3 *8) ????

  20. #20
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    Have you tried it, doesn't it work?
    Looks alright to me at first glance.

    /Henrik.

  21. #21
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    no not tried it just looked wrong

  22. #22
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    it appears to work , i have about 10 of these lookups , looking to save space

  23. #23
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Better?
    Code:
    gl_y = 24+((gl_i//3)*8)
    Don’t know if you get screwed over for gl_i less than 3 though.
    I’d expect PBP gives you zero modulus for a value less than 1.
    Last edited by Art; - 8th September 2015 at 19:57.

  24. #24
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    i must not be showing it well , the data seq of the font is the only thing that matters - not how it stored , only how it is read back in sequance i need ,

    it has been split over a lot of posts so ill try re show it in one post
    data was orginally poke /peek
    this uses 2x the space than the data alone in flash

    depeding on the font , data is read back as 3 or 2 bytes for each x scan line accross so cant be out of sequance

    Code:
    pokecode   $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_    
               $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$3F,$FC,$00,$3F,$FC,$00,$3F,$FC,_   
               $00,$3F,$FC,$00,$3F,$FC,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
               $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
    tryed changeing to @ db command using the font data bytes ,
    @ db 0x00 , 0x3F, 0x10, 0xFF..............

    this stores in flash as address - 3F00 , FF10 is NOT stored at same sequance address as font DB command as it is entered

    readcode gives address = $3f , address + 1 = $00 - no good cos the data is not in the font seq required


    tryied

    @ dw 0x003F , 0x10FF

    this stores in flash as address = 003F , 10FF - excellent follows the same data seq as the font bytes and is correct in flash so reading sequantial address should get each byte in sequance

    readcode address 0 , byte = $3F - wrong - it recovers address +1 or low byte
    readcode address +1 , byte = $00 - wrong - it recovers address -1 or high byte


    hope i am showing this better for the issue at hand

    to confirm if the problem is solved by swapping low/ high byte of the font data resolve - it does , but this is alot of work as well

  25. #25
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    tryed changeing to @ db command using the font data bytes ,
    @ db 0x00 , 0x3F, 0x10, 0xFF..............

    this stores in flash as address - 3F00 , FF10 is NOT stored at same sequance address as font DB command as it is entered
    wrong


    it is stored exactly in that order low byte first then high byte , you are feeding in the data high byte first

    readcode will retrieve it in the same order low byte then high byte





    @ dw 0x003F , 0x10FF

    readcode address 0 , byte = $3F - wrong - it recovers address +1 or low byte
    readcode address +1 , byte = $00 - wrong - it recovers address -1 or high byte
    wrong


    @ dw places the data the same way low byte then high byte


    readcode will retrieve it in the same order low byte then high byte
    Code:
     
     pause 2000
     
     Serout2 PORTb.7,84,["ready",13,10] 
     addr var word
     inbuff  var byte[30]
     buff var byte[30]       $4f0
     lb var byte
     hb var byte
     lc var byte
     lp var word
     Clear
    
     
    
    
    
     goto StartLoop ' Required
    
    
     String2:
     @ db 0x3f,0,0,0xfc,0xfc,0x3f,0x66,0x55,0,0
     
     
    asm
     org 0x5170
      dw      0x003F,0xFC00,0x3FFC,0x5566,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000;,0x00  
     org 0x0200  
    ENDASM 
    
    asm 
       
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1
        endm
      
       
       
       
       
       
     ENDASM
    StartLoop:
    Serout2 PORTb.7,84, [13,10,"db data " ]        
    @ GetAddress _String2 ,_addr  
    for lc=0 to 3
    Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]  
    readcode addr ,lb
    
    addr=addr+1
    Serout2 PORTb.7,84, [" lb ",hex2 lb," address ",hex4  addr ]
    readcode addr ,hb 
    Serout2 PORTb.7,84, [" hb ",hex2 hb ]
    
    
    addr=addr+1
    next
     
     
     
     
     
    Serout2 PORTb.7,84, [13,10,"dw data as byte " ] 
    
    addr =$5170 
     
    for lc=0 to 3
    Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]  
    readcode addr ,lb
    
    addr=addr+1
    Serout2 PORTb.7,84, [" lb ",hex2 lb," address ",hex4  addr ]
    readcode addr ,hb 
    Serout2 PORTb.7,84, [" hb ",hex2 hb ]
    
    
    addr=addr+1
    next
     
    
    Serout2 PORTb.7,84, [13,10,"dw data as word " ]  
    
      
    ;@ GetAddress _String3 ,_addr 
    addr =$5170 
    for lc=0 to 3  
    Serout2 PORTb.7,84, [13,10,"address ",hex4  addr ]   
    readcode addr ,lp
    addr=addr+2 
    Serout2 PORTb.7,84, [" lp ",hex4 lp]
    next
      
    
    addr =$5177   
    readcode addr ,lb 
    Serout2 PORTb.7,84, [13,10,"odd address ",hex4  addr ] 
    Serout2 PORTb.7,84, [" high ",hex2 lb ] 
    addr =$5176   
    readcode addr ,lb 
    Serout2 PORTb.7,84, [13,10,"even address ",hex4  addr ] 
    Serout2 PORTb.7,84, [" low ",hex2 lb ] 
    
     
     goto StartLoop ' Repeat
    end
    output
    db data
    address 0184 lb 3F address 0185 hb 00
    address 0186 lb 00 address 0187 hb FC
    address 0188 lb FC address 0189 hb 3F
    address 018A lb 66 address 018B hb 55
    dw data as byte
    address 5170 lb 3F address 5171 hb 00
    address 5172 lb 00 address 5173 hb FC
    address 5174 lb FC address 5175 hb 3F
    address 5176 lb 66 address 5177 hb 55
    dw data as word
    address 5170 lp 003F
    address 5172 lp FC00
    address 5174 lp 3FFC
    address 5176 lp 5566
    odd address 5177 high 55
    even address 5176 low 66

  26. #26
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    gives 0 when less then 3

  27. #27
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    If you have to check for <3 as well you might be approaching the code size of the lookup table.
    Are all the lookup tables repeating like this? It’s the sort of problem I like,
    certianly a mind F* though.

  28. #28
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    as a test i reversed high to low byte in the font structure

    unfortunately it worked , and this is supported by the data dumps as shown in previous posts , so to make the font common routine work i would have to reverse all the data stucture for each font chr - which if i dont have abetter option will need to be done

    Code:
    
            ' Code for "0"  Asci 48    90 real values _   
    @ dw      0x0000,0x0000,0x00FF,0xFF03,0x0FC0,0xF0FF,0xFF1F,0x1FF8,0xF8FF,0xC33F,0x3FFC,0xFC81;,0x3F   
    @ dw      0x813F,0x7FFC,0xFE00,0x007F,0x7FFE,0xFE00,0x007F,0x7FFE,0xFE00,0x007F,0x7FFE,0xFE00,0x007F   ;swaped low high bytes arround 
    @ dw      0x7FFE,0xFE00,0x007F,0x7FFE,0xFE00,0x813F,0x3FFC,0xFC81,0xC33F,0x1FFC,0xF8FF,0xFF1F;,0xF8  
    @ dw      0x0FF8,0xF0FF,0xFF03,0x00C0,0x00FF,0x0000,0x0000,0x0000

  29. #29
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    If you can write to that area your program could swap the data and write it back,
    then set a flag somewhere in a spare EEPROM bit to flag not to do it again.
    That’s if you can’t write something to spit it out a serial terminal in the format you want it.
    If the pic can read that and also has a serial terminal, you should be able to get it to format the lines as code you have above.

  30. #30
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    sorry richard the result i am seeing does not support what your are saying and the results show on the GLCD and debug terminal show the seqaunce for @ db option and @ dw to be incorrect when using readcode i have at the moment , a it gets 1 byte at a time

    remember the whole goel is to

    a. not change the font original data sequence of values
    b. store only the font data values , and not add any other values to flash to get the data back - unlike pokecode does




    try it for your self

    this is font chr "0" , where the font is 24 bits wide for (X) and 30 lines (Y)high
    LG font values for Common_font routine then are
    Y_scan = 29 ' 30 - Y scan lines - 1 - Cos "for " starts at 1
    X_scan = 3 ' 3 - X scan x 8 bits ( 24 bits)
    Font_lookup = 1 ' Use LG_Font_lookup
    gosub Font_Common ' not using flash chip


    with poke/peek it works ok with this code
    terminal should show the same data format and exact seq as the pokecode data

    Code:
     
            ' Code for "0"  Asci 48    90 real values _   
    pokecode $00,$00,$00,$00,$FF,$00,$03,$FF,$C0,$0F,$FF,$F0,$1F,$FF,$F8,$1F,$FF,$F8,$3F,$C3,$FC,$3F,$81,$FC,$3F,_
             $81,$FC,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,_
             $FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$3F,$81,$FC,$3F,$81,$FC,$3F,$C3,$FC,$1F,$FF,$F8,$1F,$FF,$F8,_
             $0F,$FF,$F0,$03,$FF,$C0,$00,$FF,$00,$00,$00,$00,$00,$00,$00
    code to place the code on glcd and terminal - terminal should show the address and data in the same sequance as the data input here
    Code:
    '=================== FONT COMMON ROUTINE - pokecode use ========================== 
    ' Assumes gl_x, gl_y,X_scan,Y_scan,Font_lookup   
    ' ALL FONTS MUST BE gl_x = 8 , 16 , 24 etc 
    ' Inv_font = 0 = normal 1= inverse   
    
    Font_Common: 
       x_save = gl_x                ' save the gl_x start point value 
       y_save = gl_y                ' save the gl_y start point value
       gl_yb  = y_save + Y_scan     ' number of y scans for the char from y starting point(0) 
       gl_xb  = 0 
       Address = 0 
       if Font_lookup = 1  then 
    @ GetAddress _LG_Font_Base, _Font_Base_Address                 ; gets base start address of LG_font into  Font_Base_Address varable 
          Font_Index = (LG_font - 45)* (90*2)                       ' remove the ascii chr value 45 offset  0 * font chr length x 2 cos of RETLW INSTRUCTION for each byte read  in index 
           HSEROUT [13,10,"lg Font_Base_Address = ",hex Font_Base_Address," font index = ",dec Font_Index, 13,10]     'debug 
      endif
            
       if Font_lookup = 2  then                                    ' remove the offset of the first symbol $2D / 45  so start at 0 
    @ GetAddress _Med_Font_Base, _Font_Base_Address
            Font_Index = (Med_font - 45)* (40*2)                   ' remove the ascii chr value 45 offset * font chr length in index
       endif                                        
       Address = Font_Base_Address + Font_Index                    'gets you to the start of the glyph
     
       for gl_y = y_save to gl_yb      ' y scan lines, start to finish values
           gl_x = x_save               ' clear x position to start point (keep it an 8bit multiple)
           gosub gl_gaddr              ' Set address
           
          for gl_xb = 1 to X_scan        ' gl_x byte x  X scan bytes on each line
              peekcode Address,gl_byte   ' read the indexed byte in
              HSEROUT [hex Address,"- ",hex gl_byte, ","]  
             glcd_msb = gl_byte         
              glcd_cmd = DATA_WR_INC     ' write and increment
              gosub send_1               ' send to glcd
              Address = Address+2        ' inc address here +2 cos each byte includes intruction code  , as data start at 0  
          next gl_xb                     ' next byte of font
       next gl_y                       ' next scan line of font
       gl_y = y_save                   ' Restore the Y location    
       gl_x = x_save                   ' Restore the X location
     return

    to use @ db data format the poke code data is changed to this format

    Code:
             ' Code for "0"  Asci 48    90 real values _   
    @ db     0x00,0x00,0x00,0x00,0xFF,0x00,0x03,0xFF,0xC0,0x0F,0xFF,0xF0,0x1F,0xFF,0xF8,0x1F,0xFF,0xF8,0x3F,0xC3,0xFC,0x3F,0x81,0xFC,0x3F
    @ db     0x81,0xFC,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00
    @ db     0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x3F,0x81,0xFC,0x3F,0x81,0xFC,0x3F,0xC3,0xFC,0x1F,0xFF,0xF8,0x1F,0xFF,0xF8
    @ db     0x0F,0xFF,0xF0,0x03,0xFF,0xC0,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    routine to get this data out and into the corect sequance - BUT THIS DOES NOT WORK AS THE DATA IS OUT OF SEQUANCE cos of readcode of low high reading
    Code:
     Font_Common: 
       x_save = gl_x                ' save the gl_x start point value 
       y_save = gl_y                ' save the gl_y start point value
       gl_yb  = y_save + Y_scan     ' number of y scans for the char from y starting point(0) 
       gl_xb  = 0 
       Address = 0 
       if Font_lookup = 1  then 
    @ GetAddress _LG_Font_Base, _Font_Base_Address                 ; gets base start address of LG_font into  Font_Base_Address varable 
           Font_Index = (LG_font - 45)* 90                          ' remove the ascii chr value 45 offset  0 * font chr length                                                            
         HSEROUT [13,10,"lg Font_Base_Address = ",hex Font_Base_Address," font index = ",dec Font_Index, 13,10]     'debug
       endif
            
       if Font_lookup = 2  then                                    ' remove the offset of the first symbol $2D / 45  so start at 0 
    @ GetAddress _Med_Font_Base, _Font_Base_Address
            Font_Index = (Med_font - 45)*40                        ' remove the ascii chr value 45 offset * font chr length in index
       endif                                        
       Address = Font_Base_Address + Font_Index                    'gets you to the start of the glyph
     
       for gl_y = y_save to gl_yb      ' y scan lines, start to finish values
           gl_x = x_save               ' clear x position to start point (keep it an 8bit multiple)
           gosub gl_gaddr              ' Set address
          for gl_xb = 1 to X_scan       ' gl_xb byte x  X scan bytes can be 2 or 3 on each line
             readcode Address,gl_byte
             HSEROUT [hex Address,"- ",hex gl_byte, ","] 
              glcd_msb = gl_byte         ' put in 1st byte - stored as         
              glcd_cmd = DATA_WR_INC     ' write and increment
              gosub send_1               ' send to glcd
              Address = Address + 1      ' inc address + 1  
          next gl_xb                     ' next byte of font
            
       next gl_y                       ' next scan line of font
       gl_y = y_save                   ' Restore the Y location    
       gl_x = x_save                   ' Restore the X location
     return
    same data joined to make word values ,

    these are stored in flash correct seq in flash as the font data shown here

    recovery routine is same as above - and has the same issue readcode gets the data not in correct seq required


    Code:
    
            ' Code for "0"  Asci 48    90 real values _   
    @ dw     0x0000,0x0000,0xFF00,0x03FF,0xC00F,0xFFF0,0x1FFF,0xF81F,0xFFF8,0x3FC3,0xFC3F,0x81FC        ;,0x3F
    @ dw     0x3F81,0xFC7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x7F00
    @ dw     0xFE7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x3F81,0xFC3F,0x81FC,0x3FC3,0xFC1F,0xFFF8,0x1FFF        ;,0xF8
    @ dw     0xF80F,0xFFF0,0x03FF,0xC000,0xFF00,0x0000,0x0000,0x0000

  31. #31
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    well i been going though my code and i had about 35 lookup tables in various values and size , most have been changed now to math calculation , most were of simular in how they need to place font, chrs , on a glcd within menus
    the goal is to reduce code size as lookups really do chew up space

    this along with change any IF /then to a math caclulation where possible
    removing any multi if /then when used to compare to for/next loop compare

    moving bit varables into the same byte to use bit matching on them
    remove any "and " in if/then and just doing 2 if/then statements - this often saved about 50 bytes each
    moving any lookup "txt into spi flash so it not on the main cpu flash

    all these saved so far a total of 33k from a code that started at 127k
    still trying more space as i really would like to get to 90k code before i add the next section

    found pokecode has a limit of 256 bytes before for adata string ,

    and this i cant find a better way to do to reduce its compile size
    Code:
       if val < 6 AND Menu_Select = 211 then 
                lookup val,[1,2,4,8,16,32],val      '  reasign  val to 
                gosub Show_current_sel_2            ' place "*    *" on the selected channel in menu using bit pattern sleection 
             endif 
             
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                lookup val-6,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2 
             endif
             if val =>12 and Menu_Select = 2113 then
                lookup val-12,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2
            endif



    i am also ll stuck with a lot of if then statements when input range checks are done when a key is pressed such as
    and i cant see away to reduce them
    Code:
     Input_Timevalue_Check:
      ' input checks for time inputs from menu1111  
        if Event1_OT_Day >7 then 
           Event1_OT_Day     = 0
           Event1_OT_hour    = 0
           Event1_OT_Min     = 0
           Event1_OT_sec     = 0
           Event1_OT_100th   = 0
           ENDIF
        
        if Countdwn_Day > 7 then
           Countdwn_Day      = 0   ' day settings 
           Countdwn_Hour     = 0
           Countdwn_Min      = 0
           Countdwn_Sec      = 0
           Countdwn_100th    = 0
           ENDIF
           
        if Event_Penalty_Day >7 then 
           Event_Penalty_Day   = 0
           Event_Penalty_Hour  = 0 
           Event_Penalty_Min   = 0
           Event_Penalty_Sec   = 0
           Event_Penalty_100th = 0
           ENDIF 
           
        if Event2_OT_Day >7  then 
           Event2_OT_Day     = 0
           Event2_OT_hour    = 0
           Event2_OT_Min     = 0
           Event2_OT_sec     = 0
           Event2_OT_100th   = 0
           ENDIF
           
        if Preset_EL0_Day >7 then 
           Preset_EL0_Day    = 0
           Preset_EL0_Hour   = 0
           Preset_EL0_Min    = 0
           Preset_EL0_Sec    = 0
           Preset_EL0_100th  = 0
           ENDIF
                                                                                            
        if Event1_OT_Hour >23      then Event1_OT_Hour     = 23
        if Countdwn_Hour  >23      then Countdwn_Hour      = 23
        if Event_Penalty_Hour > 23 then Event_Penalty_Hour = 23
        if Event2_OT_Hour > 23     then Event2_OT_Hour     = 23
        if Preset_EL0_Hour > 23    then Preset_EL0_Hour    = 23
        if Event1_OT_Hour <1       then Event1_OT_Hour     = 0 
        if Countdwn_Hour  <1       then Countdwn_Hour      = 0 
        if Event_Penalty_Hour <1   then Event_Penalty_Hour = 0 
        if Event2_OT_Hour  <1      then Event2_OT_Hour     = 0 
        if Preset_EL0_Hour <1      then Preset_EL0_Hour    = 0 
                                                                                                
        if Event1_OT_Min >59       then Event1_OT_Min     = 59 
        if Countdwn_Min > 59       then Countdwn_Min      = 59
        if Event_Penalty_Min > 59  then Event_Penalty_Min = 59
        if Event2_OT_Min >59       then Event2_OT_Min     = 59
        if Preset_EL0_Min >59      then Preset_EL0_Min    = 59
        if Event1_OT_Min <1        then Event1_OT_Min     = 0 
        if Countdwn_Min <1         then Countdwn_Min      = 0
        if Event_Penalty_Min <1    then Event_Penalty_Min = 0
        if Event2_OT_Min <1        then Event2_OT_Min     = 0
        if Preset_EL0_Min <1       then Preset_EL0_Min    = 0
       
        if Event1_OT_Sec >59       then Event1_OT_Sec     = 59
        if Countdwn_Sec >59        then Countdwn_Sec      = 59
        if Event_Penalty_Sec >59   then Event_Penalty_Sec = 59
        if Event2_OT_Sec > 59      then Event2_OT_Sec     = 59 
        if Preset_EL0_Sec > 59     then Preset_EL0_Sec    = 59
        if Event1_OT_Sec <1        then Event1_OT_Sec     = 0
        if Countdwn_Sec <1         then Countdwn_Sec      = 0
        if Event_Penalty_Sec <1    then Event_Penalty_Sec = 0
        if Event2_OT_Sec <1        then Event2_OT_Sec     = 0
        if Preset_EL0_Sec <1       then Preset_EL0_Sec    = 0
       
        if Event1_OT_100th > 99    then Event1_OT_100th     = 99        
        if Countdwn_100th > 99     then Countdwn_100th      = 99
        if Event_Penalty_100th >99 then Event_Penalty_100th = 99
        if Event2_OT_100th > 99    then Event2_OT_100th     = 99
        if Preset_EL0_100th > 99   then Preset_EL0_100th    = 99
        if Event1_OT_100th <1      then Event1_OT_100th     = 0      
        if Countdwn_100th <1       then Countdwn_100th      = 0
        if Event_Penalty_100th <1  then Event_Penalty_100th = 0
        if Event2_OT_100th <1      then Event2_OT_100th     = 0
        if Preset_EL0_100th <1     then Preset_EL0_100th    = 0
    
     return

  32. #32
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    I expect you realise that pokecode uses twice the memory to store a byte compared to @ db , @ data ...........

  33. #33
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    thats what i ended up doing art and swapped the lot arround , although pain in butt readcode is the best option for the fonts that are not loaded in the spi flash , fortunately there are only 30 font chrs like this

  34. #34
    Join Date
    May 2013
    Location
    australia
    Posts
    2,390


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    if Event1_OT_Hour >23 then Event1_OT_Hour = 23
    if Event1_OT_Hour <1 then Event1_OT_Hour = 0
    can be replaced by if Event1_OT_Hour is a byte

    Event1_OT_Hour=Event1_OT_Hour min 23
    saves heaps of typing if nothing else

  35. #35
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    has anyone a way to use 2 word value varables to accumulate an math value with out using longs or floating point

  36. #36
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    Depends on your particular needs, here's one way to be used when the value to be added fits within a WORD:
    Code:
    HW VAR WORD
    LW VAR WORD
    Temp VAR WORD
    AddValue VAR WORD
    
    Temp = LW    ' Copy low word
    
    LW = LW + AddValue
    
    IF LW < Temp THEN   ' Low word wrapped around
      HW = HW + 1
    ENDIF
    If the value to be added is always one then:
    Code:
    HW VAR WORD
    LW VAR WORD
    
    LW = LW + 1
    IF LW = 0 THEN    'Low word wrapped around.
       HW = HW + 1
    ENDIF
    /Henrik.

  37. #37
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Why you don't try N-Bit_MATH?
    http://www.picbasic.co.uk/forum/show...2694#post82694
    I use this code to store result as string in array
    Code:
    'Convert 64Bit to string
        @  MOVE?CP  10, _Tmp64bit   ; copy a CONSTANT to a Pvar
        FOR i=19 TO 0 STEP -1
            @  MATH_DIV  _Int64Bit, _Tmp64bit, _Res64bit    ; Res = A / B;  Remainder in REG_Z
            ValueStr[i]=REG_Z+48
            @  MOVE?PP  _Res64bit, _Int64Bit                ; copy a Pvar to a Pvar
        NEXT i

  38. #38
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    I expect you realise that pokecode uses twice the memory to store a byte compared to @ db , @ data ...........
    umm no i did not i am very new to using pokecode and peekcode , i am just trying it out now , and using darrel getaddress built into the INTs18.inc to get the the address in mem or where its put the label

  39. #39
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    looking at a hex dump noticed that pokecode stores a byte as a word value in the flash , this is real waist of space , can i store the data as a word and then get it back as a byte or if needed a word if so how , this must have been done a lot before

  40. #40
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hey Longpole001, you asked this:

    and this i cant find a better way to do to reduce its compile size

    if val < 6 AND Menu_Select = 211 then
    lookup val,[1,2,4,8,16,32],val ' reasign val to
    gosub Show_current_sel_2 ' place "* *" on the selected channel in menu using bit pattern sleection
    endif

    Why not use the PBP command "DCD for the lookup table problem like this:

    Value = DCD Value

    When you come into the statement value will be a number between 0 and something less than 31, DCD will give it a value based on the bit position which is what you are doing with the lookup command. a value of 0 = 1, a value of 1 = 2, a value of 2 = 4 and so on. At lease that's how I would do it...
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. Help with A/D math!
    By dbodenheimer in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th March 2011, 00:51
  2. Math help please...
    By Ioannis in forum General
    Replies: 2
    Last Post: - 20th June 2008, 10:18
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  4. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 14:45
  5. math help
    By houa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th January 2006, 16:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts