itoa or wordtostring function?


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2013
    Posts
    16

    Default itoa or wordtostring function?

    Does Picbasic Pro have a function to convert a unsigned 16bit variable into an ascii text number? If so, what is it?

    Thanks.

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Could you give a couple of examples of what you mean?

    ie. show the unsigned 16 bit value and what the result should look like?
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Offhand, a WORD has 16 bits unsigned and can be displayed on an LCD using DEC format.

    More on this in PBP manual under LCDOUT command if this is what you want.

    Robert

  4. #4
    Join Date
    Jan 2013
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Quote Originally Posted by Demon View Post
    Offhand, a WORD has 16 bits unsigned and can be displayed on an LCD using DEC format.

    More on this in PBP manual under LCDOUT command if this is what you want.

    Robert
    Thanks for the reply. I read that part of the manual and tried using the DEC modifier, but couldn't figure out the correct syntax. I hope someone can post a sample.

  5. #5
    Join Date
    Jan 2013
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Quote Originally Posted by Heckler View Post
    Could you give a couple of examples of what you mean?

    ie. show the unsigned 16 bit value and what the result should look like?
    Thanks for the reply. Here's the way I am doing it now, but it seems there should be a simpler way.

    Code:
    ' Program Code:
    PAUSE 1000 'Pauses 1 second to allow LCD to setup.
    start:
    ADCIN 0, left_pot 'Reads analog voltage on AN0, converts it to 10-bit digital
        'value, and stores it as left_pot.
    lpot = (left_pot*4) 'Multiplies left_pot times 4 to get voltage.
    lthousands = (lpot//10000)/1000 'Extracts thousands digit from 4 digit voltage.
    lhundreds = (lpot//1000)/100 'Extracts hundreds digit from 4 digit voltage.
    ltens = (lpot//100)/10 'Extracts tens digit from 4 digit voltage.
    lunits = (lpot//10) 'Extracts units digit from 4 digit voltage.
    ADCIN 1, right_pot 'Reads analog voltage on AN1, converts it to 10-bit digital
        'value and stores it as right_pot.
    rpot = (right_pot*4) 'Multiplies right_pot times 4 to get voltage.
    rthousands = (rpot//10000)/1000 'Extracts thousands digit from 4 digit voltage.
    rhundreds = (rpot//1000)/100 'Extracts hundreds digit from 4 digit voltage.
    rtens = (rpot//100)/10 'Extracts tens digit from 4 digit voltage.
    runits = (rpot//10) 'Extracts units digit from 4 digit voltage.
    LCDOUT $FE,1,"Left Pot  = ", DEC left_pot 'Clears LCD screen, displays
        '"Left Pot = " and the decimal value of left_pot.
    lcdout $FE,$C0,"Voltage   = ", #lthousands, ".", #lhundreds, #ltens, #lunits
        'Sends left pot voltage to LCD.
    LCDOUT $FE,$94,"Right Pot = ", DEC right_pot 'Sets LCD to beginning of
        'second line and displays "Right Pot = " and the decimal value of
        'right_pot.
    lcdout $FE,$D4,"Voltage   = ", #rthousands, ".", #rhundreds, #rtens, #runits
        'Sends right pot voltage to LCD.
    Here's a picture of the LCD with the above displayed.

    Name:  PIC16F88 TL431A ADC LCD Demo (lo res).jpg
Views: 1092
Size:  101.7 KB
    Last edited by tracecom; - 5th January 2014 at 04:58.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    I just found this in Lab X1 folder:

    Code:
    ' PicBasic Pro program to display result of
    ' 10-bit A/D conversion on LCD
    '
    ' Connect analog input to channel-0 (RA0)
    
    ' Define LOADER_USED to allow use of the boot loader.
    ' This will not affect normal program operation.
    Define	LOADER_USED	1
    
    ' Define LCD registers and bits
    Define	LCD_DREG	PORTD
    Define	LCD_DBIT	4
    Define	LCD_RSREG	PORTE
    Define	LCD_RSBIT	0
    Define	LCD_EREG	PORTE
    Define	LCD_EBIT	1
    
    ' Define ADCIN parameters
    Define	ADC_BITS	10	' Set number of bits in result
    Define	ADC_CLOCK	3	' Set clock source (3=rc)
    Define	ADC_SAMPLEUS	50	' Set sampling time in uS
    
    adval	var	word		' Create adval to store result
    
    
    	TRISA = %11111111	' Set PORTA to all input
    	ADCON1 = %10000010	' Set PORTA analog and right justify result
    	Low PORTE.2		' LCD R/W line low (W)
    
    	Pause 500		' Wait .5 second
    
    loop:	ADCIN 0, adval		' Read channel 0 to adval
    
    	Lcdout $fe, 1		' Clear LCD
    	Lcdout "Value: ", DEC adval	' Display the decimal value  
    
    	Pause 100		' Wait .1 second
    
    	Goto loop		' Do it forever
    	End
    Maybe there's something in there that will help you (in case you don't have Lab X1 samples). I saw nothing at first glance.

    Robert

  7. #7
    Join Date
    Jan 2013
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    @Demon

    Thanks. That is the information I needed. I haven't yet figured out how to insert a decimal point in it, but maybe that will be possible.

  8. #8
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Since the software only works with whole numbers, there is no concept of a decimal point. You have to manage placing it where you feel it is supposed to be on your own. (sort of like a slide rule before calculators LOL)

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


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Hi,
    The typical way of doing this is to have your number scaled 10 or 100 or 1000 times (or whatever) so that a value in myVAR of 12345 corresponds to 123.45 (for example). Then, to put that on the LCD, you can do something like
    Code:
    LCDOUT $FE, 1, "My value= ", DEC myVAR/100, ".", DEC2 myVAR//100   ' Clear screen and print result with two decimal places.
    The myVAR/100 will divide the value by 100 and print the result, which in this case will be 123.
    The myVAR//100 will again divide the value by 100 but then it'll take the remainder of that division, in this case 45, and print that.
    The DEC2 specifies that the number should always be printed with two digits.

    /Henrik.

  10. #10
    Join Date
    Jan 2013
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    The typical way of doing this is to have your number scaled 10 or 100 or 1000 times (or whatever) so that a value in myVAR of 12345 corresponds to 123.45 (for example). Then, to put that on the LCD, you can do something like
    Code:
    LCDOUT $FE, 1, "My value= ", DEC myVAR/100, ".", DEC2 myVAR//100   ' Clear screen and print result with two decimal places.
    The myVAR/100 will divide the value by 100 and print the result, which in this case will be 123.
    The myVAR//100 will again divide the value by 100 but then it'll take the remainder of that division, in this case 45, and print that.
    The DEC2 specifies that the number should always be printed with two digits.

    /Henrik.
    Here's my code; it works. Thanks.

    ETA: I am using a 4.096V reference.

    Code:
    ' Aliases and Modifiers:
    
    ' Program Code:
    PAUSE 1000 'Pauses 1 second to allow LCD to setup.
    start:
    ADCIN 0, left_pot 'Reads analog voltage on AN0, converts it to 10-bit digital
        'value, and stores it as left_pot.
    lpot = (left_pot*4) 'Multiplies left_pot times 4 to get 1000x voltage.
    
    ADCIN 1, right_pot 'Reads analog voltage on AN1, converts it to 10-bit digital
        'value and stores it as right_pot.
    rpot = (right_pot*4) 'Multiplies right_pot times 4 to get 1000x voltage.
    
    LCDOUT $FE,1,"Left Pot  = ", DEC left_pot 'Clears LCD screen, displays
        '"Left Pot = " and the decimal ADC of left_pot.
    LCDOUT $FE,$C0, "Voltage = ", DEC lpot/1000, ".", DEC3 lpot//1000
        'Displays result to 3 decimal places.
    
    LCDOUT $FE,$94,"Right Pot = ", DEC right_pot 'Sets LCD to beginning of
        'second line and displays "Right Pot = " and the decimal ADC of
        'right_pot.
    LCDOUT $FE,$D4, "Voltage = ", DEC rpot/1000, ".", DEC3 rpot//1000
        'Displays result to 3 decimal places.
    Last edited by tracecom; - 5th January 2014 at 20:49.

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: itoa or wordtostring function?

    Trace Communications, I knew I saw that somewhere before.

    I like your power supply PCB above; good idea to have it clip onto a breadboard, tidy and solid. My solution was "el cheapo", just a 5VDC wall adapter with a small electrolyte cap at the end. One day I'm going to either short-circuit the flimsy leads or snap them off.

    You do know you can advertise your PCBs in the advert subforum right?

    Robert
    Last edited by Demon; - 4th October 2016 at 16:37.

Similar Threads

  1. ARCSIN function
    By mjphillips1981 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 20:19
  2. Need help with write function
    By Christopher4187 in forum General
    Replies: 10
    Last Post: - 12th July 2006, 04:12
  3. COUNT Function
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th June 2006, 06:26
  4. How does serin function?
    By a_critchlow in forum Serial
    Replies: 3
    Last Post: - 7th February 2006, 08:10
  5. ATAN2(,) function
    By vk2tds in forum PBP Wish List
    Replies: 0
    Last Post: - 25th November 2005, 02:52

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