Afternoon C,
I am not quite sure what you are asking.
Is it for example: a 8 bit Byte Named Mode, 00100010 .? and you want to make say bit 2 =1, you could use Mode.2=1
Afternoon E and J,
I am able to work it out, but I am trying to find the best way, especially as there are many registers, with various combinations of bits in each byte and variable number of bits in each section.
In J's reply he correctly shows that bit 3 is 0x08, but it it shown as 0x01. I can usually see what the lower bits should be, but 'say' bits 6-5 need one bit changing, how would I do that?
I am able to enter each bit into the calculator as binary and then output a HEX number, is this how it's done? This is a bit long winded though
Hi I,
I think you're misunderstanding what I'm asking. When you looked at each example, how did you find the 3 settings. Are you so practiced that you know them, or did you use some equipment, i,e, a calculator or reference sheet?
I find it difficult, and it it takes me a lot of time, and I hope to find a better way than the way I use, which is convert each section into binary and enter each bit as I go along into a calculator which outputs the HEX, which I enter into the code.
Ive been using hex now for soooo long I know the bit weights of by heart... If you don't care for bit weights... Just try and use hex or binary... Most systems have data sheets with all the settings in... You just need to create the definitions in a file.
PA = b10000000
MaxPower = b01000000
OutputPower = b00000111
Ive been using hex now for soooo long I know the bit weights of by heart... If you don't care for bit weights... Just try and use hex or binary... Most systems have data sheets with all the settings in... You just need to create the definitions in a file.
PA = b10000000
MaxPower = b01000000
OutputPower = b00000111
going back to initial post if you do them separate you command it separate:
MODE = 0x01 ;
Lowfrequencymodeon = 0x01;
if you wrap it together then you need more like as below,
but then you can't call them by the bit names like MODE and Lowfrequencymodeon:
regopmode = (Lowfrequencymodeon<<3) + (MODE);
We work with computers.... Micro's are essentially the same... Binary is the language of the computer..
you have seen the bit weights..... 128, 64, 32, 16, 8, 4, 2 and 1... Each bit carries a decimal "weight" these are pretty well know, Hexadecimal is binary shorthand.... If you can work well with Hex and Bin, your computer programming will be 100% better..
We work with computers.... Micro's are essentially the same... Binary is the language of the computer..
you have seen the bit weights..... 128, 64, 32, 16, 8, 4, 2 and 1... Each bit carries a decimal "weight" these are pretty well know, Hexadecimal is binary shorthand.... If you can work well with Hex and Bin, your computer programming will be 100% better..
going back to initial post if you do them separate you command it separate:
MODE = 0x01 ;
Lowfrequencymodeon = 0x01;
if you wrap it together then you need more like as below,
but then you can't call them by the bit names like MODE and Lowfrequencymodeon:
regopmode = (Lowfrequencymodeon<<3) + (MODE);
Hi Doc,
I am using existing programs from other sources written in languages, I can barely follow, but I see lines written in the way you suggest. They have a list separated by commas, with the list shown in the REG e,g, SX1276SetOpMode(OpMode_ModeLoRa|OpMode_LowFrequencyModeOn|OpMode_ModeSleep), (I know that |=OR)
I'll have to ask if this can be used in the Oshonsoft section.
C.
hi C,
The '|' is not recognised in OSH, in your eg: list replace the '|' with OR
OSH is very limited so it may burp.
e,g, SX1276SetOpMode(OpMode_ModeLoRa OR OpMode_LowFrequencyModeOn OR OpMode_ModeSleep)
hi C,
The '|' is not recognised in OSH, in your eg: list replace the '|' with OR
OSH is very limited so it may burp.
e,g, SX1276SetOpMode(OpMode_ModeLoRa OR OpMode_LowFrequencyModeOn OR OpMode_ModeSleep)
Morning Eric,
I was just about to post in Oshonsoft.
I assume that I use sections like OpMode_ModeSleep....OpMode_ModeTX, then change the list accordingly through the program as I need to change the settings?
Am I correct that he OR will join the different section HEXs as my question?
I'm not keen on 'Burping' but if it looks as though it's working, would you say it will be reliable?
C.
hi C,
Perhaps a simple OR example will make clearer.
You know that a BCD '1' is 00000001 0r 0x01 , we cannot display this using a LCD, which requires ASCII characters.
So to turn this into a ASCII number '1' we OR the 0x01 with 0x30 which makes it 0x31 which is a ASCII '1' character, which we can display.
The 0x01 in BIN is 00000001 and the 0x30 is 00110000 and when they a ORed together give 00110001 .
Do that make sense to you.?
E
Have you tried
Dim regopmode As Byte
regopmode = lrm Or mt
regopmode= regopmode OR res1 :::: you cannot use the 'res', its part of the compiler language, choose say res1
hi C,
Perhaps a simple OR example will make clearer.
You know that a BCD '1' is 00000001 0r 0x01 , we cannot display this using a LCD, which requires ASCII characters.
So to turn this into a ASCII number '1' we OR the 0x01 with 0x30 which makes it 0x31 which is a ASCII '1' character, which we can display.
The 0x01 in BIN is 00000001 and the 0x30 is 00110000 and when they a ORed together give 00110001 .
Do that make sense to you.?
E
Have you tried
Dim regopmode As Byte
regopmode = lrm Or mt
regopmode= regopmode OR res1 :::: you cannot use the 'res', its part of the compiler language, choose say res1
Hi Eric,
You may recall that I've been using OR 80 in my SX1278 programs to switch the WRITE bit on when writing the registers, so I am kind of familiar with ORs
I have just tried your suggestion, which works, and verifies with a calculator however the answer has puzzled me.
regopmode = longrangemode Or modulationtype
regopmode = regopmode Or reserved1
regopmode = regopmode Or lowfrequencymodeon
regopmode = regopmode Or modestdby
If the longrangemode bit is changed to 0x01 the result is the same as if it is 0x00 Result 0x01. So the RegOpMode Register has not been changed.