BCD to Integer instr. - STEP7

gumis

Member
Join Date
Mar 2009
Location
Bialystok
Posts
30
Hi all,


BCD to Integer instruction in STEP7 reads the contents specified in the input parameter as a three digit number in binary coded decimal format (BCD,+-999) and converts this number to an integer value. I understand that twelve less significant bits represents value and bit no.12 represents sign. Am I right?

My purpose is to convert eight bits ( MSB represents sign bit; bits:6,5,4 represent one BCD digit and 3,2,1,0 represent second BCD digit) to decimal value.

Could you give me some tip how to start up with this problem?

Regards,
gumis
 
Here's the source code for an FC that will do the job:

Code:
FUNCTION FC 3 : INT
TITLE =
VERSION : 0.1

VAR_INPUT
  byData : BYTE ; 
END_VAR
VAR_TEMP
  bNegative : BOOL ; 
  byCopy : BYTE ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     #byData; 
      T     #byCopy; 
      LAR1  P##byCopy; 
      A      [AR1,P#0.7]; 
      =     #bNegative; 
      R      [AR1,P#0.7]; 
      L     B [AR1,P#0.0]; 
      BTI   ; 
      A     #bNegative; 
      JCN   plus; 
      NEGI  ; 
plus: T     #RET_VAL; 
END_FUNCTION
 
Quick and dirty with an intermediary word (MW10):

Code:
      L     0                           // clear intermediary word
      T     MW    10
      L     #byte_BCD                   // load original data
      T     MB    11
      A     M     11.7                  // move sign bit from byte to word address
      =     M     10.7
      R     M     11.7
      L     MW    10                    // convert to integer
      BTI   
      T     #word_integer
 

Similar Topics

Hi, I'm communicating with a generator controller via Modbus, and not sure how best to write the time to it. The generator is expecting the...
Replies
0
Views
1,110
I am receiving 16 I/O pts. into an Integer called LC. I want to convert this to a BCD. What is the easiest way (instruction?) to do this? If...
Replies
2
Views
2,441
Hi all, I am quite new to PLC programming, so pardon my noob-ness. First, I have counters & timers in my program that I use to calculate total...
Replies
2
Views
3,540
hi... i have an issue in s7 300 plc, while we run the machine(in idle there is no fault) , plc cpu goes in SF mode, after restart the power cycle...
Replies
2
Views
117
Hi. I’m doing a PV 1400e to PVP 7 migration and I don’t know how to convert the old 8digit BCD type from PB1400e into something that will work on...
Replies
2
Views
589
Back
Top Bottom