Hi J,You don't need a separate variable chip_sel.
Chip select can be done outside of the functions.
Also the values of the arguments can be written directly to the function.
For example:
wr_adr = 0x60 'WRITE 0xE0 %01100000 RESET ADDR [Is this needed?]
wr_byte = 0xb6 '%10110110 resets BMP280 = 0x00
chip_sel = altmtr_cs
Call periph_wr(wr_adr, wr_byte)
rd_adr = 0xd0 'address of ID =0x58 =88
rd_Byte = 0 'Dummy BYTE
data = periph_rd(rd_adr)
--->
altmtr_cs=0
Call periph_wr(0x60,0xb6)
Waitms 50
data = periph_rd(0xe0)
altmtr_cs=1
Hserout "READ RST 0 ", #data, Cr
etc....
I got #75 square function to work with a global variable.hi S,
I agree this is way that Oshonsoft deals with the Return value, but I prefer the alternative method of returning the variable through an pre-assigned Global argument.
E
Hi E,hi,
I am just dealing with basic code.
Usually a Function Returns a data value to the calling routine and a Proc does not Return any data.
In OSH it appears to be the wrong way around!
A Func does not return but a Proc does, yet the coding is shown as
Code line:
Function writeit(arg1 As Byte, arg2 As Byte, arg3 As Byte) As Word which indicates a WORD is returned.
Code line:
Proc proctest(arg1 As Byte, arg2 As Byte) ' no reference is given for the returned value!
Run this simple demo program to show this problem, I am not surprised you are having difficulty in getting the code right.
E
Hi E,hi, Ref post 85,
Are you sure that All Digital is the only change you have to that program.?
It does not work for me, the Functions return a '0'
Post a screen shot.
E
The line before Hserout has "b = square(9)". Since "square" is a variable (when defined as Function), it is initialized as zero. And, since the function does not replace or set that value of "square" variable, it remains at zero. Global variables always work, that is not debatable. It is understanding that when a function is declared, it is defined as a variable and is allocated storage space. Unless one writes to that variable, it will remain as zero.I got #75 square function to work with a global variable.
Old PIC IDE v.7.85 and using watch variables.
Could the Hserout #b be the problem?
Hi E,hi C,
Which PC did you use to make it work.?
If there is a All Digital bug we should let Vlad know.
E
Hi S and D,When you use a global variable, it is equivalent to using two identical global variables. Wasteful. The variable you define and the variable defined by the function definition. It is no easier to use a separately defined global variable than using the global variable defined by the function name. Try using a global definition then replacing the variable name with he function name (& remove the global variable definition). It should still work.
Hi E,hi C,
Which PC did you use to make it work.?
If there is a All Digital bug we should let Vlad know.
E
Sorry for the confusion. I’m not referring to either example. I’m responding to.general comments that have said that a global variable is easier and always works. I disagree and my reply explains why.Hi S and D,
Are you replying about 'E's example or mine?
I can see that you both have been programming for a while, so your answers can be a little 'over my head', but almost understandable, thanks.
EDIT: I think with one or the other of FUNC/PROC a Global VARIABLE 'say' [test] can be also set inside the FUNC/PROC? and used in a different way, as it's a different VARIABLE. Not sure?)
C
Hi D,Sorry for the confusion. I’m not referring to either example. I’m responding to.general comments that have said that a global variable is easier and always works. I disagree and my reply explains why.
Hi E,hi, Ref post 85,
Are you sure that All Digital is the only change you have to that program.?
It does not work for me, the Functions return a '0'
Post a screen shot.
E