in my current project i am using a word variable to give me 16 individual "flag" bits that can be set or cleared during different input actions ect, but i am having issues in adressing the individual word bits.
how do i assign names for each of the word bits so they can be referenced individually as they need to be changed?.
Dim CONSTAT as Word this is my word variable for the 16 flag bits.
i have tried the following naming but when i set or clear individual bits it does not change
~~~
#define SER_COM CONSTAT.15
#define VAR_DIR CONSTAT.14
#define BTTN_TYPE CONSTAT.13
#define A2P_TOGGLE CONSTAT.12
#define IN_PULSE CONSTAT.11
#define OUT_PULSE CONSTAT.10
#define LATCH CONSTAT.9
#define MOMENTARY CONSTAT.8
#define MOD_OUT CONSTAT.7
#define IN_DIR CONSTAT.6
#define OUT_DIR CONSTAT.5
#define RUNNING_STATE CONSTAT.4
#define IN_BUTTON CONSTAT.3
#define OUT_BUTTON CONSTAT.2
#define A3P CONSTAT.1
#define A2P CONSTAT.0
~~~
i have even tried declaring the names for bits to see if that changes anything,
~~~
dim SER_COM as bit
dim VAR_DIR as bit
dim BTTN_TYPE as bit
dim A2P_TOGGLE as bit
dim IN_PULSE as bit
dim OUT_PULSE as bit
dim LATCH as bit
dim MOMENTARY as bit
dim MOD_OUT as bit
dim IN_DIR as bit
dim OUT_DIR as bit
dim RUNNING_STATE as bit
dim IN_BUTTON as bit
dim OUT_BUTTON as bit
dim A3P as bit
dim A2P as bit
~~~
when i change the first 5 bits one by one and serout the value after setting each individually i dont see any change in the CONSTAT variable value, it always shows the same on the terminal output (31)
can i address/access the words individual bits this way at all? im sure i have seen similar somewhere but now im doubting that.
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#define LEDD2 PORTA.0
#define LEDD3 PORTA.1
#define LEDD4 PORTA.2
#define LEDD5 PORTA.3
Dir LEDD2 OUT
Dir LEDD3 OUT
Dir LEDD4 OUT
Dir LEDD5 OUT
#define Potentiometer PORTA.4
DIR Potentiometer In
#define SWITCH_DOWN 0
#define SWITCH_UP 1
#define SWITCH PORTA.5
Dir SWITCH In
; ----- Variables
' No Variables specified in this example. All byte variables are defined upon use.
thanks evan, i did get correct data on the serout after setting the word variable to " CONSTAT = 0 " just after the vars were declared and prior to going into main code to let it run and check the setting of the bits was changing as needed.
i guess i was expecting the variable to automatically read 0 value after it was declared and until it was changed but a further serout of the CONSTAT variable on its own prior to changing any bits showed that bit 15 was always set even when nothing was changed, strange but for now its working.
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok, just donloaded that one to look over tomorrow as its 3am gone now lol, ill have to chase you up for that s.d indcall function too, tried with select case to see if i could go that way and that just ate far too much program memory up in one go.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
in my current project i am using a word variable to give me 16 individual "flag" bits that can be set or cleared during different input actions ect, but i am having issues in adressing the individual word bits.
how do i assign names for each of the word bits so they can be referenced individually as they need to be changed?.
Dim CONSTAT as Word this is my word variable for the 16 flag bits.
i have tried the following naming but when i set or clear individual bits it does not change
~~~
#define SER_COM CONSTAT.15
#define VAR_DIR CONSTAT.14
#define BTTN_TYPE CONSTAT.13
#define A2P_TOGGLE CONSTAT.12
#define IN_PULSE CONSTAT.11
#define OUT_PULSE CONSTAT.10
#define LATCH CONSTAT.9
#define MOMENTARY CONSTAT.8
#define MOD_OUT CONSTAT.7
#define IN_DIR CONSTAT.6
#define OUT_DIR CONSTAT.5
#define RUNNING_STATE CONSTAT.4
#define IN_BUTTON CONSTAT.3
#define OUT_BUTTON CONSTAT.2
#define A3P CONSTAT.1
#define A2P CONSTAT.0
~~~
i have even tried declaring the names for bits to see if that changes anything,
~~~
dim SER_COM as bit
dim VAR_DIR as bit
dim BTTN_TYPE as bit
dim A2P_TOGGLE as bit
dim IN_PULSE as bit
dim OUT_PULSE as bit
dim LATCH as bit
dim MOMENTARY as bit
dim MOD_OUT as bit
dim IN_DIR as bit
dim OUT_DIR as bit
dim RUNNING_STATE as bit
dim IN_BUTTON as bit
dim OUT_BUTTON as bit
dim A3P as bit
dim A2P as bit
~~~
when i change the first 5 bits one by one and serout the value after setting each individually i dont see any change in the CONSTAT variable value, it always shows the same on the terminal output (31)
can i address/access the words individual bits this way at all? im sure i have seen similar somewhere but now im doubting that.
tony
I cannot reproduce. My code is shown below. Does this work for you?
~~~~
' ----- v.0.95.007
' ----- Configuration
'Chip Settings.
#chip 16f877a
; ----- Define Hardware settings
; ----- Constants
#define USART_BAUD_RATE 19200
#define USART_TX_BLOCKING
; ----- Variables
' No Variables specified in this example. All byte variables are defined upon use.
; ----- Quick Command Reference:
'[todo]
; ----- Main body of program commences here.
'~~~
#define SER_COM CONSTAT.15
#define VAR_DIR CONSTAT.14
#define BTTN_TYPE CONSTAT.13
#define A2P_TOGGLE CONSTAT.12
#define IN_PULSE CONSTAT.11
#define OUT_PULSE CONSTAT.10
#define LATCH CONSTAT.9
#define MOMENTARY CONSTAT.8
#define MOD_OUT CONSTAT.7
#define IN_DIR CONSTAT.6
#define OUT_DIR CONSTAT.5
#define RUNNING_STATE CONSTAT.4
#define IN_BUTTON CONSTAT.3
#define OUT_BUTTON CONSTAT.2
#define A3P CONSTAT.1
#define A2P CONSTAT.0
' dim Constat as Word alias portb, portd
' dir portb Out
' dir portd Out
dim CONSTAT as Word
IN_BUTTON = On
VAR_DIR = On
SER_COM = On
MOD_OUT = On
MOMENTARY = On
HSerPrint ByteToBin(constat_h)
HSerPrint ByteToBin(constat)
do
loop
end
; ----- Support methods. Subroutines and Functions
Last edit: Anobium 2016-08-10
Also see a demonstration. Test this demo - if this needs adapation let me know - but, this is a good demonstration of have in the portfolio. :-)
thanks evan, i did get correct data on the serout after setting the word variable to " CONSTAT = 0 " just after the vars were declared and prior to going into main code to let it run and check the setting of the bits was changing as needed.
i guess i was expecting the variable to automatically read 0 value after it was declared and until it was changed but a further serout of the CONSTAT variable on its own prior to changing any bits showed that bit 15 was always set even when nothing was changed, strange but for now its working.
tony
ok, just donloaded that one to look over tomorrow as its 3am gone now lol, ill have to chase you up for that s.d indcall function too, tried with select case to see if i could go that way and that just ate far too much program memory up in one go.