Display 2 WORDs as a 32bit integer


Results 1 to 14 of 14

Threaded View

  1. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Display 2 WORDs as a 32bit integer

    Many years back, I solved the problem like this.

    I have a variable Total defined as 4 bytes

    In the routine that increments the total, I did it like this
    Code:
         
    Total       var byte[4]    ' packed BCD totalizer upto 99999999
    
    asm
    ; assembler code embedded into PBP increments Total till 99999999 and then rolls over
    
              incf  _Total+3
    	  movlw 100
    	  subwf _Total+3,w
    	  btfss status,c
    	  goto  DoneTotal
    	  clrf  _Total+3
    	  ;
    	  incf  _Total+2
    	  movlw 100
    	  subwf _Total+2,w
    	  btfss status,c
    	  goto  DoneTotal
    	  clrf  _Total+2
    	  ;
    	  incf  _Total+1
    	  movlw 100
    	  subwf _Total+1,w
    	  btfss status,c
    	  goto  DoneTotal
    	  clrf  _Total+1
    	  ;
    	  incf  _Total+0
    	  movlw 100
    	  subwf _Total+0,w
    	  btfss status,c
    	  goto  DoneTotal
    	  clrf  _Total+0
    DoneTotal:
    
    endasm
    This allows for a maximum total content of 99,99,99,99 with Total[3] being the lowest byte

    Now, in the display routine, I did something like this to show the lower 6 digits. Mind you, this is only for unsigned values.

    Code:
      		Dat = Total[2] dig 0
      			gosub Code2Segment       ' convert to 7 segment code
      			gosub Dsp_Data                ' display the 7 segment code
                            Dat = Total[2] dig 1
      			gosub Code2Segment
      			gosub Dsp_Data
      
      			Dat = Total[1] dig 0
      			gosub Code2Segment
      			gosub Dsp_Data
                            Dat = Total[1] dig 1
      			gosub Code2Segment
      			gosub Dsp_Data
      
      			Dat = Total[0] dig 0
      			gosub Code2Segment
      			gosub Dsp_Data
                            Dat = Total[0] dig 1
      			gosub Code2Segment
      			gosub Dsp_Data
    I hope this will help you find some solution to your stated problem.

    Cheers
    Last edited by Jerson; - 1st December 2024 at 14:06. Reason: Error in code fixed

Similar Threads

  1. Microchip 32bit floating point to integer conversion
    By timmers in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st February 2011, 16:49
  2. IEEE 754 32bit floating point value.
    By shawn in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th December 2010, 12:32
  3. Signed 32bit to ASCII?
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th May 2010, 22:13
  4. Retrieving 32bit Multiply Result
    By Darrel Taylor in forum Code Examples
    Replies: 42
    Last Post: - 28th January 2008, 15:15
  5. Newbee How to get LCD to display 4-6 var words
    By emmett brown in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th August 2006, 01:11

Members who have read this thread : 18

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