Data conversions


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2015
    Posts
    4

    Default Data conversions

    Wanted to do a temp probe using the 1822 but then got into a situation. The sample code provided to me does an Lcdout command with a dec(temperature) to display. According to the manual this is a decimal conversion from ascii. Then I wanted to be able to store data. Up to here I was ok. Write to eeprom. But I decided to use a serout command instead of LCDout which totally barfed when I tried to compile. I have tried to convert the data into something more friendly like a standard string but am unable to come up with any solution. Yes, I can just use the lcdout command but now it's turned into a challenge/learning experience. Any one have an idea of how to start to convert this into a standard string or how to get this to use the serout command? Even if it's not practical to program into the chip I'm interested from a learning perspective now.

    Thanks much
    Code:
    SerPin VAR PortA.0 ' Serial output pin
    temperature     VAR     WORD            ' Temperature storage
    count_remain    VAR     BYTE            ' Count remaining
    count_per_c     VAR     BYTE            ' Count per degree C
    
    DQ      VAR     PORTC.0                 ' One-wire data pin
    
    ' 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
    
    AA var byte
    BB var byte
    CC var byte
    DD var byte
    
    
            ADCON1 = %00000111              ' Set PORTA and PORTE to digital
            Low PORTE.2                     ' LCD R/W line low (W)
    
    
    mainloop:
            OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
    
            pause 2000
    
            OWOUT DQ, 1, [$CC, $BE]         ' Read the temperature
            OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    
            ' Calculate temperature in degrees C to 2 decimal places
            ' (not valid for negative temperature)
            temperature = temperature */ 1600
            LCDOUT $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
    
            ' Calculate temperature in degrees F to 2 decimal places 
            ' (not valid for negative temperature)
            temperature = (temperature */ 461) + 3200
            LCDOUT $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
            
    serout serpin,N9600,{(temperature/100)] 'won't even compile               
    
    GoTo mainloop                   ' Do it forever
    Last edited by Archangel; - 25th August 2015 at 01:13.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    syntax error
    { != [
    check your serout line
    Last edited by Archangel; - 25th August 2015 at 01:27.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Aug 2015
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    Wow, that sure makes me feel like a drone, I looked at that a hundred times.
    Thanks

  4. #4
    Join Date
    Aug 2015
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    Ok, so that makes it compile but all I get is garbage out. The data is not compatible to that command so I still need to convert the data.
    Anyone have any ideas?

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    Well, provided you've got baudrate, voltage levels and polarity all correct it looks like what's missing is the DEC modifier in serout command. Without the dEC modifier you're sending the data "as is" and not as ASCII text that you can read on a terminal.
    Code:
    serout serpin,N9600,[DEC (temperature/100)]
    /Henrik.

  6. #6
    Join Date
    Aug 2015
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    Yes, that's true, but if you add dec to the serout command it doesn't compile

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


    Did you find this post helpful? Yes | No

    Default Re: Data conversions

    serout2 serpin,N9600,[DEC (temperature/100)] if possible

    or

    serout serpin,N9600,[#(temperature/100)]

    or

    might need to be
    temp=temperature/100

    serout serpin,N9600,[#temp]

Similar Threads

  1. linear data memory & large data arrays
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th June 2011, 23:21
  2. storing data and dumping data?
    By earltyso in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th November 2007, 15:57
  3. Help with Data of fiberoptic
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th June 2007, 14:23
  4. Data
    By gzorzi in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th July 2004, 14:21
  5. ADC Conversions
    By Corey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th October 2003, 04:32

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