some help with math - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 65 of 65
  1. #41
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    unfortunalty the for /next loop of x_scan can be 2 or 3 so not easy to break into even words -mm darn

  2. #42
    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

  3. #43
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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.

  4. #44
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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

  5. #45
    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

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


    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

  7. #47
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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

  8. #48
    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

  9. #49
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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

  10. #50
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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

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


    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

  12. #52
    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

  13. #53
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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

  14. #54
    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

  15. #55
    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

  16. #56
    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.

  17. #57
    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

  18. #58
    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

  19. #59
    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.

  20. #60
    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

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    hi thanks for the input guys

    to get it to do what i want i used longs ;(
    which i would like to change to 2 x word variables for this one long variable "Event_Dist_Speed "

    i thinking perhaps the nbit math may work but not sure how it may be done with the calculations i have now


    Code:
    ' routine to calc speed based on sec under 18 hours 
    Distance_Calc_Speed0:            
                  
      if Event_Dist_Timebase = 0 then Event_Dist_Speed = Event_Dist_Value                      ' calculate speed with base in secs 
      if Event_Dist_Timebase = 1 then Event_Dist_Speed = Event_Dist_Value*60                   ' calculate speed with base in mins
      Event_Dist_Speed = Event_Dist_Speed*100/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)  
      if Event_Dist_Timebase = 2 then gosub Distance_Speed_Calc2                               ' calculate speed with base in hours - gosub becuase it is called as a seprate display 
     ' HSEROUT [" Event_Dist_Speed = ",dec Event_Dist_Speed, 10,13] ' debug 
                 
     return   
    ' ----------------------------------------------------------------
     ' routine to calc speed based on sec 's 
    ' used when time is >18 hours so that value is < word max size            
    Distance_Calc_Speed1:            
           
    
     return   
    
    ' ------------------------------------------------------------------
    ' show KPH or MPH on every base reading formular 
    ' calculate speed with hours base 
    ' called as 2nd speed display details 
    Distance_Speed_Calc2:
        
        Event_Dist_Speed = Event_Dist_Value*360 
        if Event_Dist_Measure  = 0 then  Event_Dist_Speed = (Event_Dist_Speed*1000/5280)/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)       ' if feet distance base 
        if Event_Dist_Measure  = 1 then  Event_Dist_Speed =  Event_Dist_Speed*100       /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)/100   ' if meters distance base 
        if Event_Dist_Measure  > 1 then  Event_Dist_Speed =  Event_Dist_Speed*1000      /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)       ' if Miles or KM  distance base 
       
      '  HSEROUT [" hour reading Event_Dist_Speed = ",dec Event_Dist_Speed ,10,13] ' debug 
    return                     
    
    '------------------------------------------------------------------
    
    Show_Speed_Value:
       gl_x = 0
       gl_y = 48  
       gl_k = 0 
       for gl_k = 0 to 7
            lookup gl_k,["    x.xx"],Sml_font               ' 8 chrs 
            gosub Get_Sml_font                                    ' Get Font in K9_Fonts_banners.bas    
            gl_x = gl_x+8
       next gl_k      
      
       gl_x = 0                 ' puts 5 digits of speed 00000.xx 
       g_num = Event_Dist_Speed /100  ' get the base value 00000.xx 
       gosub Sml_put_5dig
                 
       
       gl_x = 48                ' put first 2 digits of speed xxxxx.00 
       g_num = Event_Dist_Speed 
       gosub Sml_put_2dig
       
      
       
              
      
     return

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    varable ranges information

    Event_Dist_Speed input = 1 - 4096
    time = combined values of EL1 varables - time range = 1sec - 8 days ' note days varable not used as yet , base time calculations based on secs
    expect that if hours >18 then the secs will be droped and time caclulation base of mins - not tested yet

  23. #63
    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 the Nmath caclualtions

    can a math action be done directly without copy a pbp var to a Pvar first ?

    A var byte

    Tmp32bit_1 var byte[PRECISION]
    Tmp32bit_2 var byte[PRECISION]
    Result var byte[PRECISION]

    eg - direct method
    @ MATH_ADD A, Tmp32bit_2, Result ; A+B =Res


    or do i always need to get the standard PBP var byte into a Pvar before the math calculation

    eg

    @ MOVE?BP A , Tmp32bit_1 ' copy byte PBP to Pvar
    @ MATH_ADD Tmp32bit_1, Tmp32bit_2, Result ; A+B =Res


    cheers

    sheldon

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    DT - ALL math done with these routines are done at the PRECISION level, and all variables used with the MATH functions must be (PRECISION) bytes in length.
    re reading the post make it clear

  25. #65
    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 ended up changing all the posted code that needed the long varable to work out speed to Nbit math

    it took some work time ,but the rewards are there in size of the reduced compile size - in my case i saved 8.5k over using longs

    although i needed only 1 long varable - the speed value - selecting longs added 10.5k to compile size as soon as you tick the box , and that is a very big overhead when flash space is very tight

    Nbit math has it high overheads as well - the include is compiled about 700bytes , but the real overhead is in having to use multi 32bit PRESISON varables( 4 were needed) to do the step by step math operations that can be avoided when using longs , as a result more ram space is used , and it is noticeably slower than using longs when showing the results, even when at 64Mhz.

    Also having to do multi divides , the separate remainder value needs to be reincorporated into any following math which adds extra code and where possible should be avoided until you need the result reading back into PBP

    anyone having to add longs , where only1 or 2 longs may be need should look at Nbit math as a possible alternative , more so when flash space is tight and longs are an expensive overhead in compile space.

    cheers

    Sheldon

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