8 digit number from Hserin

sodeaf

Senior Member
Hey Guys, I'm stuck, and my brain is very confused.
I am using Hserin via rs232 to receive an 8 digit (meter) number from a machine.
I use the command
PTr=2
Bcdtoassci w1,w2 and so on for all 8 digits
Then
W1=w1-$30 to get Actual number, I have managed to place the higher 4 numbers in one word variable and the lower 4 in another. As well display them on LCD.

What I am trying to do is poll that machine after each play, retrieve the number and display the difference on the LCD.
I would need to calculate using the full 8 digit number, for the score could change by a significant amount each time.
Then if the difference is higher then let's say 2000 they would receive a free game play. It's an old arcade game I am trying to modernize.

As well I am tying to minimize the amount of variables being used

Thanks Steve
 

westaust55

Moderator
What is the raw format of the number on the machine you are reading from
Your post suggest you are "massaging" the 8 digit number into two words for sending, is that the case.

Keep in mind that hserin can only accept byte values (not word).

There is a past thread by Jeremy Leach on 32-bit math if you care to search for that.
 

nick12ab

Senior Member
What calculation? The difference that's mentioned afterwards?

What LCD?

Minimize the variables used by what?

This sounds more like a blog entry stating your progress (with top-secret code) rather than a request for help.
 

sodeaf

Senior Member
Hey there,
No not Top Secret, I do apologize for the vague description, for I wrote that with my cell last night, and I was away from the PC with the code..

hserin [100,main], 0,8 'Receive 8 bytes into sp
ptr=2 'Start of last 4 digits
bcdtoascii @ptr,w20,w21
ptr=3
bcdtoascii @ptr,b44,b45
ptr=4 'Start of last 4 digits
bcdtoascii @ptr,w24,w25
ptr=5
bcdtoascii @ptr,b52,b53

w20 = w20-$30*1000
w21 = w21-$30
b44 = b44-$30*10
b45 = b45-$30'End of first 4 Digit of 8 Digit Meter w20-w21-b44-b43
w24 = w24-$30*1000
w25 = w25-$30*100
b52 = b52-$30*10
b53 = b53-$30
w19 = w20+w21+b44+b45 'Higher 4 DIGITS
w18 = w24+w25+b52+b53 'Lower 4 Digits
w17 = w18-w27

serout B.2,N2400_16,(254,196,#w19,#w18)
serout b.2,n2400_16,(254,128,"Current Score Win",#w17)
w27 = w18

The Machine sends 4-Byte BCD Meter.. The First 2 bytes are the machine id and command..

I managed to display the 8 digit value on a 2x20 VFD display without an issue. as well I can mange the simple calculation of determining the winning score using just the lower 4 numbers.. but I cant seem to figure out how to calculate the entire 8 digit number.
so if the start 8 digit # is 00251234 and after game is 00354321 I would like to display Current Score #00103087
As well I will be installing an arcade ticket Dispenser. So I will need to take the number 00103087 and divide by 5000 = 2.6 so the player would receive 3 Tickets. This is all in theory regarding tickets and amount to "win" a ticket, for when I get it working I will then decided the actual amount. Any help would be greatly appreciated..

As well if anyone has any other suggestions on what I have written as far as code, Is it the right way? Are there alternatives? I read a bit about Jeremy's 32-Bit Calculator.. that is cool and all, but a lot more then what I need.. (I think) These picaxe chips are amazing and I love playing around on these little projects, there has to be an easier way to do what I need..


Happy New Year

Steve
 

AllyCat

Senior Member
Hi Steve,

Well, I believe hippy has posted a BCD (byte) subtraction routine, and I have posted some 32-bit division, subtraction, addition and binary to decimal conversion routines, both in the "code snippets" section. There's no need to convert to ASCII characters because that can be done with the # operator in the serial transmission.

However, IMHO it's far better to Keep It Simple by splitting the BCD bytes into separate digits. It may use a little more memory (24 bytes if you want to store the result of the subtraction as well as the input data) but very few "variables". The key is to use byte pointers to avoid long explicit lists of variables (I've put the buffers at RAM location 60 upwards). Here's some sample code which seems to simulate what you may want. Not fully commented to give you some work still to do. ;)

Code:
#picaxe 20x2
put 5,1		; 1	; TEST DATA
put 6,16		; $10000000

; SPLIT THE BCD DIGITS  
ptr = 2
bptr = 60
for b1 = 0 to 7
     @bptrinc = @ptr / 16
     @bptrinc = @ptrinc // 16
next b1

;  SUBTRACT
bptr = 75			; Pointers to LAST digit in buffers
b2 = 67
b4 = 83
for b1 = 0 to 7
    peek b2,b3
    b5 = @bptrdec - b3
    dec b2
    if b5 > 15 then		; Negative result
	b5 = b5 + 10
	dec @bptr		; Borrow from next digit
    endif
    poke b4,b5
    dec b4
next b1	

; DISPLAY 
bptr = 76			; Start of print buffer
serout b.2,n2400_16,(254,128,"Optional Text ")
for b1 = 0 to 7
    serout b.2,n2400_16,(#@bptrinc)
next b1
Cheers, Alan.
 
Top