PDA

View Full Version : How to make a word as decimal in if then else statement



jeroeni
- 24th January 2011, 08:53
Hello there!

I'm pretty new here and pretty new with PICBasic, but I can tell you, I love it to work with it. Maybe my english is not so good but I'm doing my best!

Some problems I see in my programming but i can't fix them...

I need to know how to use a WORD in a DECimal If then Else statement. I've seen that "if DEC name = ...." wil absolutely not work. "If @name = ..." doens't work eather.

Can anyboody tell me how i can solve this problem so i can go futher?

Thanks a lot.

Cheers.

Acetronics2
- 24th January 2011, 10:25
Hi,

Your question is not so clear ...

so : could you post the line ( or snippet ) you try to write and which doesn't work or compile ???

I think you try to test CHARACTERS in a string ... but can you confirm ?

Alain

jeroeni
- 24th January 2011, 11:00
Thanks for replying...

Well. Thiis will work but reply's on LCD as a ASCII code:



Print at 2, 1, Temp ; Read temp from a dS1820


and this will works to convert the ASCII code to a normal celcius:



Print at 2, 1, DEC Temp ; Read temp from a dS1820


Now i want to do an if then else statement on the Temp var. If I only take this code:



IF Temp = ... THEN


the Temp var will only reads the ASCII code, but I want the source to read the celcius in the if statement, and not the ASCII code...

I hope this makes it clearer.

Acetronics2
- 24th January 2011, 11:20
Are you sure you posted on the right forum ???

I'm not ... :D

Alain

jeroeni
- 24th January 2011, 11:25
I am not sure... As I said... my english is not really good :P But if somebody can move it for me.. please :)

mackrackit
- 24th January 2011, 11:35
I am not sure... As I said... my english is not really good :P But if somebody can move it for me.. please :)

Are you using Pic Basic (PRO) ?

jeroeni
- 24th January 2011, 12:01
Yeah, I'm using the pro version.

Acetronics2
- 24th January 2011, 12:13
Your lines look to be an uncontrolled mix of Basic and C languages ...

So, it will be rather difficult to help you ...

BTW "Jeroen" ... that reminds me something... ;)
what's your mother language ???

I'd bet Dutch ...

Alain

jeroeni
- 24th January 2011, 15:18
You're correct. I'm from Holland, a dutch guy...

jeroeni
- 24th January 2011, 15:27
I will explain what I am trying to do... maybe it helps... in bad english, lol

I've got 2 components, a DS1820 and a simple LED, both on other ports.
When the DS1820 gets on 21,2celcius for example, the LED must blink, on 21,2+ the LED stays on, on 21,2- the LED turns off. The code I've got to control the DS1820 is:



Above clear:
SYMBOL Convert = $44
SYMBOL RdScratchPad = $BE
SYMBOL SkipROM = $CC
SYMBOL Graad = 223
SYMBOL DS1820 = PORTA.1
SYMBOL verwarming = PORTA.6

DIM Temp AS WORD
DIM Remain AS BYTE
DIM Slope AS BYTE
DIM BD1 AS BYTE

--------

OWRITE DS1820, 1, [SkipROM, Convert]
OWRITE DS1820, 1, [SkipROM, RdScratchPad]
OREAD DS1820, 2, [Temp.LOWBYTE, Temp.HIGHBYTE, BD1, BD1, BD1, BD1, Remain, Slope] ',CRC]

Temp = (((Temp >> 1) * 100) - 25) + (((Slope - Remain) * 100) / Slope)

PRINT AT 1, 1, DEC Temp / 100, ".", DEC1 Temp / 10, Graad, "C "


by the way, verwarming is dutch... but doens't mather... it's just a symbol :)

But how can i control the LED with the code above? I used a IF then ELSE statement on Temp but Temp shows only symbols (not with DEC in front of it at the PRINT line, so not on LCD with that code)


When i use this, just for example what Temp do without DEC, I get the most funnyest symbols and icons on LCD :D


PRINT AT 1, 1, Temp


Anyhow... I need to put it in a If then Else statement... to control the led

Acetronics2
- 24th January 2011, 15:45
I will explain what I am trying to do... maybe it helps... in bad english, lol

I've got 2 components, a DS1820 and a simple LED, both on other ports.
When the DS1820 gets on 21,2celcius for example, the LED must blink, on 21,2+ the LED stays on, on 21,2- the LED turns off. The code I've got to control the DS1820 is:



Above clear:
SYMBOL Convert = $44
SYMBOL RdScratchPad = $BE
SYMBOL SkipROM = $CC
SYMBOL Graad = 223
SYMBOL DS1820 = PORTA.1
SYMBOL verwarming = PORTA.6

DIM Temp AS WORD
DIM Remain AS BYTE
DIM Slope AS BYTE
DIM BD1 AS BYTE

--------

OWRITE DS1820, 1, [SkipROM, Convert]
OWRITE DS1820, 1, [SkipROM, RdScratchPad]
OREAD DS1820, 2, [Temp.LOWBYTE, Temp.HIGHBYTE, BD1, BD1, BD1, BD1, Remain, Slope] ',CRC]

Temp = (((Temp >> 1) * 100) - 25) + (((Slope - Remain) * 100) / Slope)

PRINT AT 1, 1, DEC Temp / 100, ".", DEC1 Temp / 10, Graad, "C "


by the way, verwarming is dutch... but doens't mather... it's just a symbol :)

But how can i control the LED with the code above? I used a IF then ELSE statement on Temp but Temp shows only symbols (not with DEC in front of it at the PRINT line, so not on LCD with that code)

Try to use PBP commands for the words I've put in RED ...

Will work much better ... ;) ... IF YOU USE PICBASIC PRO, WHICH IS NOT THE CASE ...

Alain

mister_e
- 24th January 2011, 16:55
calm down Alain ;)

jeroeni seems you're using another variant of PICBasic compiler, to me it looks like Proton Picbasic whose forum is located at the following link

http://www.protonbasic.co.uk/forum.php?

HTH

Acetronics2
- 24th January 2011, 17:05
Hi, Steve

Sorry ... I couldn't recognise this one ... which is running fine.



' One-wire temperature for PROTON Board and DS1820
Include "PROTON_4.INC"

Dim Temperature As Word ' Temperature storage
Dim Count_remain As Byte ' Count remaining
Dim Count_per_c As Byte ' Count per degree C
Dim Dum As Byte ' Dummy variable to pad OWIN
Symbol DQ = PORTC.0 ' One-wire data pin
DelayMS 500 ' Wait for PICmicro to stabilise
Cls
Mainloop:
OWrite DQ, 1, [$CC, $44] ' Start temperature conversion
While ORead DQ, 4 = 0 : Wend ' Check for still busy converting
OWrite DQ, 1, [$CC, $BE] ' Read the Temperature
ORead DQ, 0, [Temperature.LowByte, Temperature.HighByte, Dum,Dum,Dum,Dum, Count_remain, Count_per_c]
' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
Temperature = (((Temperature >> 1) * 100) - 25) + (((Count_per_c - Count_remain) * 100) / Count_per_c)
Print $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
Print $FE, $C0, Dec (Temperature / 100), ".", Dec2 Temperature, " F"
DelayMS 1000 ' Display once a second
GoTo Mainloop ' Do it forever




mackrackit

Are you using Pic Basic (PRO) ?




jeroeni

Yeah, I'm using the pro version


Ok, Ok ... :D

mister_e
- 24th January 2011, 17:08
5103 . . . . . . . . . .

jeroeni
- 24th January 2011, 17:16
Sorry, i guess i misunderstoot... PicBasic = program language and proton ide is the compiler, or is my mind freaking out with me now ? :P

HenrikOlsson
- 24th January 2011, 19:11
Hi,
No, your mind is not freaking out but this is not the forum for Proton.

It's often confusing as there are several BASIC-compilers for PIC available from different vendors, many of them with the phrasing or names like PICBasic.

It doesn't get easier by the fact the THIS forum (which is for the PICBASIC compiler from MELABS) are hosted by Crownhill which are the developers of the Proton compiler.....

For Proton specific questions you might have better luck at the Proton forum (http://www.protonbasic.co.uk/).

With that said, and without knowing Proton the DEC modifier (at least in PBP) is used to convert the value contained in a variable to ASCII text in order to print to a display or serial terminal etc. If you do something like Temp = 100 the variable called Temp will contain the value 100. Now you can do stuff like

If Temp > 125 then Goto CoolDown
If Temp < 75 then Goto HeatUp
But if you want to display the value of Temp on a display or terminal simply saying LCDOUT Temp (PRINT Temp in your case) will display the letter 'd' because 100 is the ASCII code for 'd'

In order to display 100 the compiler needs to convert the value 100 into the text '1' '0' '0' and THAT is what the DEC modifier does.

/Henrik.

jeroeni
- 25th January 2011, 14:33
Okay thanks a lot. I will figure it out.

Have a great day!

Cheers