Help with code

HAZELEB

Member
Hi can anyone see why this code will not run it’s an experiment from David Lincolns
Book programming and customizing the picaxe Microcontroller any help will be appreciated
'picaxe-18x quad temperaturelogger
'options picaxe-18x 4 mhz 16x gosubs

symbol lcdlatch = 2
symbol lcddata = 1
symbol lcdinst = 0

symbol setcursor = 8
symbol lcdon = 4
symbol cursoron = 2
symbol blink = 1
symbol cleardisplay = 1
symbol lcdline1 = $80
symbol lcdline2 = $c0

symbol outbyte = b0
symbol nblcount = b1
symbol rs = b2
symbol counter = b3
symbol reading = b3
symbol tempsign = b4
symbol temp100 = b5
symbol temp10 = b6
symbol temp1 = b7
symbol temp0 = b8
symbol temp00 = b9
symbol wwork = w5
symbol wworkhi = b11
symbol wworklo = b10
symbol temperature = w6
symbol positivesign = "+"
symbol negativesign = "-"
symbol decimalchar = "."
symbol separatorchar = ","


rs = lcdinst
for counter = 0 to 5
lookup counter, ($33, $32, $28, $0c, cleardisplay, $06), outbyte
gosub lcdout
next counter

loop:

debug w0
reading = $31
readtemp12 2, temperature
gosub prosesstemp

reading = $32
readtemp12 1, temperature
gosub prosesstemp

reading = $33
readtemp12 0, temperature
gosub prosesstemp
pause 500
reading = $34
readtemp12 7, temperature
gosub prosesstemp
pause 500
goto loop


prosesstemp:
tempsign = positivesign
w0 = temperature
if bit11 = 0 then postemp
tempsign = negativesign
temperature = 4096 - temperature

postemp:
wwork = temperature & $000f
wwork = wwork * 625
wwork = wwork + 55 / 100

temp00 = wworklo // 10 + $30
if temp00 <> $30 then ptt0
temp00 = " "

ptt0:
temp0 = wworklo / 10 + $30
wwork = temperature / 16
temp1 = wwork // 10 + $30
wwork = wwork / 10
temp10 = wwork // 10 + $30
temp100 = wwork / 10 + $30
if temp10 <> $30 or temp100 <> $30 then ptt10
temp10 = " "

ptt10:
if temp100 <> $30 then ptt100
temp100 = " "

PTT100:
IF READING = "4" THEN DISPLAY4
IF READING = "3" THEN DISPLAY3
IF READING = "2" THEN DISPLAY2

OUTBYTE = lcdline1
goto movecursor

display2:
outbyte = lcdline1 + 9
goto movecursor

display3:
outbyte = lcdline2
goto movecursor

display4:
outbyte = lcdline2 + 9

movecursor:
rs = lcdinst
gosub lcdout

sertxd (reading)
b0 = separatorchar
if b0 = 0 then dtnosep
sertxd (separatorchar)

dtnosep:
rs = lcddata
outbyte = tempsign
gosub lcdout
sertxd (tempsign)

outbyte = temp100
gosub lcdout
sertxd ( temp100)

outbyte = temp10
gosub lcdout
sertxd (temp10)

outbyte = temp1
gosub lcdout
sertxd (temp1)

outbyte = decimalchar
gosub lcdout
sertxd (decimalchar)

outbyte = temp0
gosub lcdout
sertxd (temp0)

outbyte = temp00
gosub lcdout
sertxd (temp00)

b0 = separatorchar
if b0 = 0 then dtnosep1
sertxd (separatorchar)


dtnosep1:
return


lcdout:
for nblcount = 1 to 2
if bit4 = 0 then nob4
pins = outbyte & $E0 | 8 | 4 | rs
goto latchout

nob4:
pins = outbyte & $E0 | 4 | rs

latchout:
low lcdlatch
pause 500
outbyte = outbyte * 16
next nblcount
return




















 

MartinM57

Moderator
You need to be more precise I'm afraid!

It doesn't run at all?
It runs and doesn't display anything on the LCD?
It loops and I see w0 on the debug window but it's not the right value?
Something else?

We're happy to help, but you have to help us too!
 

manuka

Senior Member
There may be a code error- suggest you contact the author directly about this. Otherwise gain some ideas from the similar Rev.Ed 4 ch. 18X data logger <A href='http://www.rev-ed.co.uk/docs/axe110.pdf' Target=_Blank>External Web Link</a>
 

HAZELEB

Member
Hi to MartinM57
Thanks for your reply, I&#8217;m working through David Lincolns book trying to learn picaxe code, the previous projects have all worked however this one is more complex so I cannot be of more help. Thanks again for your input I will try Stan&#8217;s suggestion and contact the author.


To Stan.
I will also checkout that 18X data logger thanks for that Stan.

Regards.
Hazeleb
 

MartinM57

Moderator
I don't think you need to rush back to the author just yet!

Instead of typing/loading the whole program in and finding that it doesn't run, work out, yourself, what the different parts of the program are trying to do and how they do it.

Then just test parts of the program one at a time using the DEBUG statement and maybe SERTXD and try to find the problem yourself.

When you're really stuck, come back here with a clear description of what you don't understand and I'm sure someone will be here to help.

You'll get a lot of satisfaction when you find and solve the problem (the code isn't that complicated to be honest) - and you'll learn a whole load about the PICAXE and programming in general whilst doing it.

Good luck!


Edited by - MartinM57 on 12/19/2005 8:13:07 PM
 
Top