Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

How to alias a variable

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
BlackSky

Bascom Member



Joined: 01 Jan 2008
Posts: 9
Location: South Korea

south_korea.gif
PostPosted: Mon Jul 05, 2021 10:41 am    Post subject: How to alias a variable Reply with quote

Dim Led_port As Byte

Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Config Porta.3 = Output
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portb.3 = Output

Led_port.0 Alias Porta.0
Led_port.1 Alias Porta.1
Led_port.2 Alias Porta.2
Led_port.3 Alias Porta.3
Led_port.4 Alias Portb.0
Led_port.5 Alias Portb.1
Led_port.6 Alias Portb.2
Led_port.7 Alias Portb.3

Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Porta.3 = 0
Portb.0 = 0
Portb.1 = 0
Portb.2 = 0
Portb.3 = 0

If defined like this, if &HF0 is set to Led_Port, the LED connected to PortB.0~3 is turned on, and if &H0F is set, the LED connected to PortA.0~3 is not turned on?

I just tested and the value is entered in the variable correctly, but the output does not go out to the port defined as ALias.

Please help from someone you know.

Thank you.

(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.8.3 )

_________________
I Like Freedom....
And....
I Like Programming too...
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Mon Jul 05, 2021 12:46 pm    Post subject: Reply with quote

Better try like this.

Code:
Dim Led_port As Byte                                        '0-3 PORTA 4-7 PORTB
Dim Helpb As Byte

Ddra = Ddra Or &B0000_1111                                  'A0-A3 Outputs
Ddrb = Ddrb Or &B0000_1111                                  'B0-B3 Outputs

'---
Helpb = Led_port And &B0000_1111
Porta = Porta Or Helpb                                      'set
Helpb = Led_port Or &B1111_0000
Porta = Porta And Helpb
Shift Led_port , Right , 4
Portb = Portb Or Led_port
Helpb = Led_port Or &B1111_0000
Portb = Portb And Helpb
'--- 75cycles  0.005ms

End


Why not newest Bascom?
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1980

blank.gif
PostPosted: Mon Jul 05, 2021 3:01 pm    Post subject: Re: How to alias a variable Reply with quote

BlackSky wrote:
If defined like this, if &HF0 is set to Led_Port, the LED connected to PortB.0~3 is turned on, and if &H0F is set, the LED connected to PortA.0~3 is not turned on?

Your code does not work and the simulator tells it. If you write something to the variable Led_port then nothing happens to the ports.
Thus your claim is wrong.

Long version:
As well the aliased var ('oldvar' in help) can reference a bit, the new name ('newvar') can not point to, respectively can not be named like an existing var.

An ALIAS is only a different name for the same variable or register-bit, the compiler knows which var to access.
It means also: you can NOT automatically link the variable with the port, as linking a variable with two ports requires additional code, which is not ALIAS's purpose.

Short version:
It won't work this way.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1980

blank.gif
PostPosted: Mon Jul 05, 2021 4:29 pm    Post subject: Reply with quote

EDC wrote:
Better try like this.
Code:
Porta = Porta Or Helpb

Better not.

Code:
Given:
Led_Port = &B1000_0100
PortA = &B0100_0010

Code:
Exec:
Helpb = Led_port And &B0000_1111
'-> HelpB: &B0000_0100
Porta = Porta Or Helpb
'-> PortA: &B0100_0110   <- undesired intermediate state
Helpb = Led_port Or &B1111_0000
'-> HelpB: &B1111_0100
Porta = Porta And Helpb
'-> Porta: &B0100_0100

Even lasting only a few cycles, your code creates intermediate states on hardware, which can be avoided by using another temporary var and not misusing the Port as helper var.
Back to top
View user's profile
BlackSky

Bascom Member



Joined: 01 Jan 2008
Posts: 9
Location: South Korea

south_korea.gif
PostPosted: Mon Jul 05, 2021 10:39 pm    Post subject: Re: How to alias a variable Reply with quote

Thanks for your reply.

I didn't ask why the code I made didn't work, but if there is a possible way.

_________________
I Like Freedom....
And....
I Like Programming too...
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1980

blank.gif
PostPosted: Mon Jul 05, 2021 11:57 pm    Post subject: Re: How to alias a variable Reply with quote

BlackSky wrote:
I didn't ask why the code I made didn't work

That was for free, you're welcome.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum