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