some help with math


Closed Thread
Results 1 to 40 of 65

Hybrid View

  1. #1
    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

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    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

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


    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

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 : 0

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