PDA

View Full Version : Data conversions



Gerhardt
- 24th August 2015, 20:39
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



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

Archangel
- 25th August 2015, 01:22
syntax error
{ != [
check your serout line

Gerhardt
- 25th August 2015, 07:41
Wow, that sure makes me feel like a drone, I looked at that a hundred times.
Thanks

Gerhardt
- 26th August 2015, 17:43
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?

HenrikOlsson
- 26th August 2015, 20:01
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.

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


/Henrik.

Gerhardt
- 28th August 2015, 07:39
Yes, that's true, but if you add dec to the serout command it doesn't compile

richard
- 28th August 2015, 13:10
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]