View previous topic :: View next topic |
Author |
Message |
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Wed Mar 03, 2021 12:10 am Post subject: var=PINx dynamic |
|
|
To read a port one writes a statement like
MYByte = PINA
or
MYByte = PinC.3
Is it possible to have the C and the 3 be variables?
like MYByte = Readpin Port_Number . bitnumber
Where Port_Number and bitnumber are Varibles?
(BASCOM-AVR version : 2.0.8.3 ) |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 03, 2021 1:48 am Post subject: |
|
|
For what chip because any may be addressed differently....Mega Xmega? Offset? |
|
Back to top |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Wed Mar 03, 2021 4:00 am Post subject: |
|
|
Code: | Mybyte Alias Pina
Mybit Alias 3
Config Mybyte.mybit = Input
Set Mybyte.mybit
Dim Bitnumber As Byte
Bitnumber = 1
' Config Mybyte.bitnumber = Input 'This will result in an error.
Set Mybyte.bitnumber
Bitnumber = 2
Set Mybyte.bitnumber
|
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 03, 2021 4:05 am Post subject: |
|
|
I dont investigate it but it is obvious that you cant set PINx.... you can only set PORTx or DDRx |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 03, 2021 5:12 am Post subject: |
|
|
I make mistake here |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Wed Mar 03, 2021 10:05 am Post subject: |
|
|
only the BIT part can be used with a variable.
The port part is not variable but you could make a function for that.
In the Xmega it would be simple, while in the normal AVR all the ports have different address. _________________ Mark |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Wed Mar 03, 2021 11:24 am Post subject: |
|
|
Hi,
I can't imagine what you need it for. Perhaps I can only think of creating a library. It works for output values and I used it but not in Bascom. I assume Bascom assigns translation registers based on the processor's def file. If you would like to do so you can assign the registry address of your variable to the beginning of the program and then work with it. But there is an unpleasant complication in losing the direct address option and turning it into an indirect one. So the advantage of In,Out,SBI,CBI will be lost to you.
RS |
|
Back to top |
|
|
|