;Variables
Dim remainder As word
Dim division As word
Dim SysCalcTempX As word
'
'Version 1.0 2015-07-12 (Shown when view Help/About)
'GCGB v0.94 2015-11-23 (When compling)
'
cls
locate 0,0
print "18F45K80 10Dec15.a"
Wait 500 mS
cls
Main:
division = 2499/100
remainder = SysCalcTempx
locate 0,0
print division
locate 1,0
print remainder
wait 100 mS
goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If both of the parameters of the division are constants, the compiler will do the calculation itself and use the result rather than making the microcontroller work out the same thing every time.
So, if there are two constants used, the microcontroller division routine does not get used, and SysCalcTempX does not get set.
If either of the parameters of the division are variables, the compiler will ensure the microprocessor do es the calculation as the result could be different every time.
So, in the this case the microcontroller division routine does get used, and SysCalcTempX is set.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Would my example calculation being be viable to work with the rules? Sorry if i am being a bit thick with this one.
~~~~~
;Chip Settings
chip 18F45K80,8
include <maths.h>
;Defines (Constants)
define LCD_IO 8
define LCD_RW PORTD.6
define LCD_Enable PORTD.7
define LCD_RS PORTD.5
define LCD_DATA_PORT PORTB
;Variables
Dim remainder As word
Dim division As word
Dim SysCalcTempX As word
Dim dividend As word
dim FWDmVrdg as word
dim RFLmVrdg as word
dim VShigh as word
dim VSlow as word
'AD Ref
dir porta.2 in
dir porta.3 in
'Switches LH Side
Dir Portc.0 in
Dir PORTc.1 In
'Control lines LH Side
dir portc.2 out
dir portc.3 out
dir portd.0 out
dir portd.1 out
'Switches RH Side
Dir PORTD.4 In
'Control lines RH Side
Dir portd.2 out
dir portd.3 out
dir portc.4 out
dir portc.5 out
dir porta.0 in
dir porte.1 out
dir porte.0 in
If you want the decimal value see below. The remainder(SysCalcTempX) is the quotient of the division.
~~~~
'Would my example calculation being be viable to work with the rules? Sorry if i am being a bit thick with this one.
;Chip Settings
chip 16f877a,8
include <maths.h>
;Defines (Constants)
define LCD_IO 8
define LCD_RW PORTD.6
define LCD_Enable PORTD.7
define LCD_RS PORTD.5
define LCD_DATA_PORT PORTB
;Variables
Dim remainder As word
Dim division As word
Dim dividend As word
dim FWDmVrdg as word
dim RFLmVrdg as word
dim VShigh as word
dim VSlow as word
'AD Ref
dir porta.2 in
dir porta.3 in
'Switches LH Side
Dir Portc.0 in
Dir PORTc.1 In
'Control lines LH Side
dir portc.2 out
dir portc.3 out
dir portd.0 out
dir portd.1 out
'Switches RH Side
Dir PORTD.4 In
'Control lines RH Side
Dir portd.2 out
dir portd.3 out
dir portc.4 out
dir portc.5 out
dir porta.0 in
dir porte.1 out
dir porte.0 in
'
'Version 1.0 2015-07-12 (Shown when view Help/About)
'GCGB v0.94 2015-11-23 (When compling)
'
cls
locate 0,0
print "18F45K80 14Dec15.a"
Wait 500 mS
cls
Main:
dividend=708
VSlow=158
locate 0,0
print dividend
print " "
print VSlow
div= dividend/VSlow
Remainder = SysCalcTempX
locate 1,0
print " "
print div
locate 2,0
'remainder = word
print Remainder
locate 2, 10
'calculate decimal value by factoring quotient
remainder = (remainder * 100)/VSlow
print Remainder
locate 3,0
print div
print "."
print remainder
wait 100 mS
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All
I am expecting to see the remainder of the calculation SysCalcTempX=99. Sorry if i am missing something
obvious.
Thanks in advance
;Chip Settings
#chip 18F45K80,8
;Defines (Constants)
#define LCDIO 8
#define LCDRW PORTD.6
#define LCDEnable PORTD.7
#define LCDRS PORTD.5
#define LCDDATAPORT PORTB*
;Variables
Dim remainder As word
Dim division As word
Dim SysCalcTempX As word
'
'Version 1.0 2015-07-12 (Shown when view Help/About)
'GCGB v0.94 2015-11-23 (When compling)
'
cls
locate 0,0
print "18F45K80 10Dec15.a"
Wait 500 mS
cls
Main:
division = 2499/100
remainder = SysCalcTempx
locate 0,0
print division
locate 1,0
print remainder
wait 100 mS
goto Main
That is odd. I am not aware of anyone reporting this issue.
This looks like an error. Can you please try this? I have added 'dividend'
Thanks. Now working.
Spoke with Hugh. Here are the rules:
If both of the parameters of the division are constants, the compiler will do the calculation itself and use the result rather than making the microcontroller work out the same thing every time.
So, if there are two constants used, the microcontroller division routine does not get used, and SysCalcTempX does not get set.
If either of the parameters of the division are variables, the compiler will ensure the microprocessor do es the calculation as the result could be different every time.
So, in the this case the microcontroller division routine does get used, and SysCalcTempX is set.
Would my example calculation being be viable to work with the rules? Sorry if i am being a bit thick with this one.
~~~~~
;Chip Settings
chip 18F45K80,8
include <maths.h>
;Defines (Constants)
define LCD_IO 8
define LCD_RW PORTD.6
define LCD_Enable PORTD.7
define LCD_RS PORTD.5
define LCD_DATA_PORT PORTB
;Variables
Dim remainder As word
Dim division As word
Dim SysCalcTempX As word
Dim dividend As word
dim FWDmVrdg as word
dim RFLmVrdg as word
dim VShigh as word
dim VSlow as word
'AD Ref
dir porta.2 in
dir porta.3 in
'Switches LH Side
Dir Portc.0 in
Dir PORTc.1 In
'Control lines LH Side
dir portc.2 out
dir portc.3 out
dir portd.0 out
dir portd.1 out
'Switches RH Side
Dir PORTD.4 In
'Control lines RH Side
Dir portd.2 out
dir portd.3 out
dir portc.4 out
dir portc.5 out
dir porta.0 in
dir porte.1 out
dir porte.0 in
'
'Version 1.0 2015-07-12 (Shown when view Help/About)
'GCGB v0.94 2015-11-23 (When compling)
'
cls
locate 0,0
print "18F45K80 14Dec15.a"
Wait 500 mS
cls
Main:
dividend=708
VSlow=158
locate 0,0
print dividend
print " "
print VSlow
div= dividend/VSlow
Remainder = SysCalcTempX
locate 1,0
print " "
print div
locate 2,0
print Remainder
locate 3,0
print "Should O/P ? = 4 48"
wait 100 mS
goto Main
Last edit: Anobium 2015-12-14
Looks ok. There is no need to define SysCalcTempX. This should be system created.
The output should be 4 48, but the calculated value is 4 76?
:-) Really?
(1584)+48=680 where (1584)+76=708.
Am I being dim? I may be confused.
Sorry i am definatly not understanding the way this works.
708 / 158 = 4.48?
If you want the decimal value see below. The remainder(SysCalcTempX) is the quotient of the division.
~~~~
'Would my example calculation being be viable to work with the rules? Sorry if i am being a bit thick with this one.
;Chip Settings
chip 16f877a,8
include <maths.h>
;Defines (Constants)
define LCD_IO 8
define LCD_RW PORTD.6
define LCD_Enable PORTD.7
define LCD_RS PORTD.5
define LCD_DATA_PORT PORTB
;Variables
Dim remainder As word
Dim division As word
Dim dividend As word
dim FWDmVrdg as word
dim RFLmVrdg as word
dim VShigh as word
dim VSlow as word
'AD Ref
dir porta.2 in
dir porta.3 in
'Switches LH Side
Dir Portc.0 in
Dir PORTc.1 In
'Control lines LH Side
dir portc.2 out
dir portc.3 out
dir portd.0 out
dir portd.1 out
'Switches RH Side
Dir PORTD.4 In
'Control lines RH Side
Dir portd.2 out
dir portd.3 out
dir portc.4 out
dir portc.5 out
dir porta.0 in
dir porte.1 out
dir porte.0 in
'
'Version 1.0 2015-07-12 (Shown when view Help/About)
'GCGB v0.94 2015-11-23 (When compling)
'
cls
locate 0,0
print "18F45K80 14Dec15.a"
Wait 500 mS
cls
Main:
dividend=708
VSlow=158
locate 0,0
print dividend
print " "
print VSlow
div= dividend/VSlow
Remainder = SysCalcTempX
locate 1,0
print " "
print div
locate 2,0
'remainder = word
print Remainder
locate 2, 10
'calculate decimal value by factoring quotient
remainder = (remainder * 100)/VSlow
print Remainder
locate 3,0
print div
print "."
print remainder
wait 100 mS
Thanks for your patient. Now i follow.
Still having problems. Please accept my apogies in advance.
I am using your above unmodified code above.
Division Calculated GCB
1000/900 1.11 1.11
1000/800 1.25 1.25
1000/750 1.33 1.33
1000/700 1.42 1.60
1000/650 1.53 1.14
1000/600 1.66 1.24
863/547 1.57 1.10
My fault. SysCalcTempX must be overflowing.
Please try adding:
~~~~
Dim SysCalcTempX as Word
Excellent, Thanks.