problem copying from a book

rob nash

Senior Member
hello again,
i am yet stuck again this time i,ve copied the following program from the book "programming and customizing SE" the programme meant to be for 08m, i dont fully understand it all but i put it through the wizard for an
28x2

when i run the syntax checker it comes back with an error on line 50
" fahreading = fahreading xor
^
Error: Syntax error in this line!"

its something to do with "xor" as i remove that statement the checker fine
but then flags up the next line " $FFFF + 1 " as an error

would someone please shed some light on what am doing wrong?
or is the program not compatiable with the 28X2



Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

symbol owport = c.1
symbol lcd    = b.7

symbol tempreading = b0
symbol csign       = b1
symbol fsign       = b2
symbol fahreading  = w3
symbol fahdecdigit = w4


pause 500
serout lcd,n2400,(254,1)
pause 30

 do
 readtemp owport,tempreading
 gosub displayC
 gosub displayF
 loop

 displayC:
       if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif

       serout lcd,n2400,(254,$80)
       serout lcd,n2400,(csign,"",#tempreading,"C")
       return

  displayF:
         if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif
       fahreading = tempreading * 10
       fahreading = fahreading * 9/5
       if csign ="-" then
       fahreading = fahreading xor
       $FFFF + 1
       endif
       fahreading = fahreading + 320
       if fahreading > 32767 then fsign = "-"
        fahreading = fahreading xor
        $ffff +1
        else
        fsign ="+"
        endif
        fahdecdigit=fahreading // 10
        fahreading = fahreading / 10

        serout lcd,n2400,(254,$C0)
        serout lcd,n2400,(fsign,""#fahreading,".",#fahdecdigit,"F")
        return

cheer rob
 

Haku

Senior Member
It just needed a little tidying up, this passes the syntax check:

Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

symbol owport = c.1
symbol lcd    = b.7

symbol tempreading = b0
symbol csign       = b1
symbol fsign       = b2
symbol fahreading  = w3
symbol fahdecdigit = w4


pause 500
serout lcd,n2400,(254,1)
pause 30

 do
 readtemp owport,tempreading
 gosub displayC
 gosub displayF
 loop

 displayC:
       if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif

       serout lcd,n2400,(254,$80)
       serout lcd,n2400,(csign,"",#tempreading,"C")
       return

  displayF:
         if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif
       fahreading = tempreading * 10
       fahreading = fahreading * 9/5
       if csign ="-" then
       fahreading = fahreading xor $FFFF + 1
       endif
       fahreading = fahreading + 320
       if fahreading > 32767 then
        fsign = "-"
        fahreading = fahreading xor $ffff +1
        else
        fsign ="+"
        endif
        fahdecdigit=fahreading // 10
        fahreading = fahreading / 10

        serout lcd,n2400,(254,$C0)
        serout lcd,n2400,(fsign,#fahreading,".",#fahdecdigit,"F")
        return
The $ffff was supposed to be immediately after the xor, fsign = "-" was supposed to be on the next line and a comma instead of "" in the serout line.
 

hippy

Technical Support
Staff member
fahreading = fahreading xor $FFFF + 1

That's performing a Two's Complement Negation the long-hand way; invert all bits then add one. It can be replaced by the simpler, faster, shorter and smaller code version of -

fahreading = - fahreading
 

rob nash

Senior Member
well still ploding along the fahrenheit reading part appears working ok i have it displayed on the top line.
the celsius not displaying what i am seeing is "01/01/00 00:00"


Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

symbol owport = c.1
symbol lcd    = b.7

symbol tempreading = b0
symbol csign       = b1
symbol fsign       = b2
symbol fahreading  = w3
symbol fahdecdigit = w4


pause 500
serout lcd,n2400,(254,1)
pause 30

 do
 readtemp owport,tempreading
 gosub displayC
 gosub displayF
 loop

 displayC:
       if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif

       serout lcd,n2400,(254,192)
       serout lcd,n2400,(csign,"",#tempreading,"C")
       return

  displayF:
         if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif
       fahreading = tempreading * 10
       fahreading = fahreading * 9/5
       if csign ="-" then
       fahreading = -fahreading
       endif
       fahreading = fahreading + 320
       if fahreading > 32767 then
        fsign = "-"
        fahreading = -fahreading 
        else
        fsign ="+"
        endif
        fahdecdigit=fahreading // 10
        fahreading = fahreading / 10

        serout lcd,n2400,(254,128)
        serout lcd,n2400,(fsign,#fahreading,".",#fahdecdigit,"F")

thx hippy i made the change you mentioned but what or where am i going wrong with the celsius
cheers rob
 

westaust55

Moderator
Rob,

If this is the recent edition of a book you are working though it would be warranted to email the author and let them know of the typo.

Some authors such as David Lincoln and Ron Hackett have the programs available for download from their respective website.
Ron has proven to be proactive with an addenda page on his website and hopefully David will do likewise.
 

hippy

Technical Support
Staff member
@ rob : There's a missing RETURN at the end of the program. It may be the code is running and ending before the display is ready for it. It certainly means the code won't loop as intended.

Otherwise it could be an AXE033 configuration issue. Try with a simple -

Do
serout lcd, n2400, ("X")
Pause 1000
Loop

see if any "X" appear.

Edit:

serout lcd,n2400,(csign,"",#tempreading,"C")

Put something between the "" to see if that helps.
 
Last edited:

rob nash

Senior Member
hi and good morning
i ran this sort program to test the lcd all was fine


Code:
symbol lcd = b.7
symbol topline     = 128
symbol bottomline = 192




pause 500
serout lcd,n2400,(254,1)
pause 30

Do
 serout lcd,n2400,(254,topline) 
  serout lcd,n2400,("X")
  pause 30
  serout lcd,n2400,(254,bottomline) 
  serout lcd,n2400,("Y")

 Pause 1000
 Loop
now i swaped the lcd over to another i have which has the time and date preinstalled which showed the correct time ect. on the bottem line

Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

symbol owport = c.1
symbol lcd    = b.7

symbol tempreading = b0
symbol csign       = b1
symbol fsign       = b2
symbol fahreading  = w3
symbol fahdecdigit = w4
symbol topline     = 128
symbol bottomline = 192

pause 500
serout lcd,n2400,(254,1)
pause 30


      do
 readtemp owport,tempreading
 gosub displayC
 gosub displayF
 loop

 displayC:
       if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif

       serout lcd,n2400,(254,bottomline)
       serout lcd,n2400,(csign,"",#tempreading,"C")
       
       return
       

  displayF:
         if tempreading >127 then
       csign = "-"
       tempreading = tempreading & $7f
       else
       csign ="+"
       endif
       fahreading = tempreading * 10
       fahreading = fahreading * 9/5
       if csign ="-" then
       fahreading = -fahreading
       endif
       fahreading = fahreading + 320
       if fahreading > 32767 then
        fsign = "-"
        fahreading = -fahreading 
        else
        fsign ="+"
        endif
        fahdecdigit=fahreading // 10
        fahreading = fahreading / 10

        serout lcd,n2400,(254,topline)
        serout lcd,n2400,(fsign,#fahreading,".",#fahdecdigit," f ")
        
        return

which has got me stumped as i look over the program it does'nt mention the time and date anywhere, does anyone have a setup to confirm what am seeing i woundering if am missing some code in the "displayC" part of the program
cheers rob
 
Last edited:

rob nash

Senior Member
ITS WORKING,,
hippy i just added some spaces where you mentioned to add and its displaying both C/F.
thanks
although i need to go to the doctors as when i pinch the temp sensor i have have body temp of 32 C, off to stick it in the freezer,
cheers rob
 

westaust55

Moderator
Rob,

if you need to use any more listing from David Lincoln's book, all of the program listing are available as one great long listing here:
http://www.lincsoft.com/code.txt


The line which gave you grief is correct in the website listings:
Code:
	  if csign = "-" then
	    [COLOR="Red"]fahreading = fahreading xor $FFFF + 1[/COLOR]	'Complement for negative Celsius temperatures
	    endif
 

rob nash

Senior Member
westaut55,
thanks for the link i did find it earler this morning, and as much as i like copy and paste i find that i dont learn as much as if i go though it line by line as hippy points out in post #5, i could copy it but i would'nt of understood the line.
thanks agian
rob
 
Top