Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

How to pass the address as a parameter ?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
xury

Bascom Member



Joined: 28 Jun 2011
Posts: 10

poland.gif
PostPosted: Thu Jun 30, 2011 4:13 pm    Post subject: How to pass the address as a parameter ? Reply with quote

Hi it's my first topic on this forum.
I want to pass the address of data in internal eeprom in subroutine.
Something like:
Code:

$eeprom
Data 0                                                    
Smsc:
Data "00000000000"                                          
Telefon1:
Data "48621321321"                                          
Telefon2:
Data "486231321321"                                        
Segment3:
Data "11000B91"                                          

Declare Sub Build_sms(bylabel Por1  As Bit , Bylabel Tel1 As word ,bylabel)  Pdu1 As word)


And I don't know how to get an address the beginning data from EEPROM
Code:

Using BYLABEL does not work:
DO
(...)
Call Build_sms(portc.1 , telefon1 , Pdu_uzb)
(...)
Loop
End

Sub Build_sms(bylabel Por1  As Bit , Bylabel Tel1 As word ,bylabel pdu1 as word)  
         
 (...)
Readeeprom textvar , Por1                     'port number as parameter also don't work
.....
Readeeprom textvar, Tel1                      'the addres of data in eeprom don't work
....
Readeeprom textvar , Pdu_uzb                'third adress passing to subroutine don't work  
End Sub
 

I tried Adr and ADR2 and both not working with label in eeprom.
There is another solution to get an proper data address from eeprom ?
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Thu Jun 30, 2011 5:18 pm    Post subject: Reply with quote

Hi, and welcome to this friendly forrum.

I don't know exactly what you are trying to do but take a look at the "lookup" statement.

Frank.
Back to top
View user's profile
xury

Bascom Member



Joined: 28 Jun 2011
Posts: 10

poland.gif
PostPosted: Thu Jun 30, 2011 5:34 pm    Post subject: Reply with quote

Hi
Unfortunately Lookup does not work with data stored in eeprom.

I want pass as parameter eeprom ofset to subrutine, or solutnion how to get this ofset to variable.

$eeprom
Code:

label1:
data "first data"
label2: "second data"



I know that Label2 ofset is 12, but I want to know it without counting previous data, so I need the solution how to get label2 addres from eeprom and use it with Readeeprom ?
Back to top
View user's profile
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Thu Jun 30, 2011 6:15 pm    Post subject: Reply with quote

Readeeprom can already accept the label name as part of it's argument so you can jump to Label2 whenever you wish.

READEEPROM VAR, LABELNAME
Back to top
View user's profile Yahoo Messenger
xury

Bascom Member



Joined: 28 Jun 2011
Posts: 10

poland.gif
PostPosted: Thu Jun 30, 2011 6:22 pm    Post subject: Reply with quote

Yes, but how to pass the label as the parameter in the subroutine ?
Look at my first post. I want pass addres to read eeprom through subroutine.
Back to top
View user's profile
rsavas

Bascom Member



Joined: 10 Aug 2010
Posts: 197
Location: Baldwin, Ontario

canada.gif
PostPosted: Thu Jun 30, 2011 8:25 pm    Post subject: How to pass the address as a parameter ? Reply with quote

I get it , you want to pass the address referenced to the EEPROM storage location by means of the subroutine.
So if the MPU has a 32 bit linear addressing range, you would pass a 32 bit address (4 bytes) in the subroutine,
so that you could point to one of the data locations.

'Using the example as shown in the help for "DECLARE SUB":

Code:

Dim B As Byte , W As Word

Declare Sub Somesub(bylabel Mylabel As Word)
Somesub Alabel
End

Sub Somesub(bylabel Mylabel As Word)
  W = Mylabel                 ' this points to the BYTE address of the data
  lds _dptrl,{W }             ' point to
  LDS _dptrh,{W+1}
  Read B : Print B
End Sub

$eeprom
Alabel:
Data 1 , 2 , 3
 


What I do not understand is:
"W = Mylabel ' this points to the BYTE address of the data"

But "Mylabel" is defined as a Word, so should it not be worded as, "The Word address pointing to the data Byte"!!

I have a similar problem, that I could not figure out as well.
How to use a reference to a base point location and increment the reference to point to the new calculated address?
Expanding on the example in the help for "$EEPROM"

Code:

Const eeprom_ref = &H100
Dim B As Byte
Readeeprom B , eeprom_ref
Print B
Readeeprom B , eeprom_ref + 1
Print B
Readeeprom B , eeprom_ref + 2
Print B
Readeeprom B , eeprom_ref + 3
Print B
Readeeprom B , eeprom_ref + 4
Print B
Readeeprom B , eeprom_ref + 5
Print B
Readeeprom B , eeprom_ref + 6
Print B
Readeeprom B , eeprom_ref + 7
Print B
End

$eeprom
eeprom_ref:
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8
$data
End
 


Or as another example,

Code:

Const Eeprom_ref = &H100

Dim B As Byte
B = 0

Do
  WriteEeprom B , eeprom_ref
  Incr B
Loop Until eeprom_ref = &H107

Do
  Readeeprom B , eeprom_ref
  Print B
Loop Until eeprom_ref = &H107

End
 


I have a funny feeling that it is a limitation of the programming language itself. That is why the example shows the assembler coding method as the way to construct pointers, to accomplish this task!!
Would like to know if I am right or wrong!!

Regards
Rick


Last edited by rsavas on Thu Jun 30, 2011 9:26 pm; edited 1 time in total
Back to top
View user's profile
xury

Bascom Member



Joined: 28 Jun 2011
Posts: 10

poland.gif
PostPosted: Thu Jun 30, 2011 9:22 pm    Post subject: Reply with quote

Yes, that's exactly what I want to do

I tested the example you wrote. It works fine with data from flash memory without the assembler code. The variable is a word because they offset the flash cell is a two byte. Currently, unless there is no way to get the offset to the data in eeprom. I hope I'm wrong. When I tried to use to label LOADLABEL eeprom always get the number 180, regardless to which I refer to the label.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sun Jul 03, 2011 1:16 am    Post subject: Reply with quote

I do something similar, just by defining an array at the start of eeprom, and then passing the address as a word.
Code:

Dim eMyData(1) as eram byte

dim wEAddress as word
dim bData as byte

wEAddress = 214 'for example

bData = eMyData(wEAddress) 'returns the data at address 214 relative to wherever eMyData base address is.
 


Note that it does not matter that you dimension only a 1 byte array, Bascom lets you read and write over the full address space, so you can name other variables in eeprom space, and reference them by location relative to eMyData.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5207
Location: Holland

blank.gif
PostPosted: Wed Jul 13, 2011 10:09 am    Post subject: Reply with quote

in the 2070 version it is possible to pass the address of an eeprom label. have a look at the help.
_________________
Mark
Back to top
View user's profile Visit poster's website
cucuruzel

Bascom Member



Joined: 18 Mar 2010
Posts: 53
Location: Cluj-Napoca

romania.gif
PostPosted: Wed Jul 13, 2011 6:35 pm    Post subject: Reply with quote

Is it mandatory to be a label ?

ERAM variables wont do the work ?

dim smsc as eram string *12
dim telefon1 as eram string *12
dim telefon2 as eram string *12
dim segment3 as eram string *9
...

and then just use them as normal variables ...
Back to top
View user's profile Visit poster's website Yahoo Messenger
xury

Bascom Member



Joined: 28 Jun 2011
Posts: 10

poland.gif
PostPosted: Fri Jul 15, 2011 11:18 pm    Post subject: Reply with quote

Thank you Mark for your improvements.
I'm just reading updated help page, and I looking updated description of Loadlabel function.
In addition, I read the updated description of the "Declare Sub" and I see that it can be used with the eeprom. Only a small mistake in the description. I think it should be:
DECLARE SUB TEST [([ByRef / ByVal / BYLABEL] var as type)]
These new capabilities will allow me to significantly reduce the code.

BTW... How to pass single pin as a parameter ? (for ex. Portd.4)

[edited]
I just read something in help page:
"Bits are global and can not be passed with functions or subs."

So passing pins as parameters is not possible ? But all ports should be ? I'm right or wrong ?
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sun Jul 17, 2011 11:26 pm    Post subject: Reply with quote

I would hold a byte variable as a place to store all the bit settings for one port, then you can pass the address of that variable by ref to any routine you need to modify the bits. At some point in your program, you then have one and only one routine which takes the variable and transfers it to the actual hardware port. That way you know exactly when and where the port is updated. You can of course extend this to other ports as well, or even have bit combinations in one variable which map to different ports. The point is that if you do it this way, you totally separate the software manipulations from the hardware, enabling you to debug each section independently.

Of course there are some case, usually involving tight timing or sequencing requirements, where you may not be able to do this, but for general purpose port line sensing and switching, its much more convenient.

The recent thread "Cannot read status of output pin" has some discussion about this type of thing.
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9784

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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