Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

pass an eeprom variable to sub/function

 
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 Unsupported versions
View previous topic :: View next topic  
Author Message
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Wed May 24, 2017 5:25 pm    Post subject: pass an eeprom variable to sub/function Reply with quote

Hi

i want to pass a variable and its related eeprom variable to sub and by pressing a key save current value of variable to related eeprom variable,how is it possible?

for example

Code:

dim param as byte
dim e_param as eram byte

dim m as byte
dim e_m as byte

dim s as byte
dim e_s as eram byte

sub save_to_ee(param as byte,e_param as byte,key_condition)

if key_condition=1 then
   e_param=param
endif

end sub

-
-
-
key_condition=pinb.0
call save_to_ee(m,e_m,key_condition)

key_condition=pinb.0
call save_to_ee(s,e_s,key_condition)

end
 


(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Wed May 24, 2017 5:28 pm    Post subject: Reply with quote

some note:

-compiler dont accept eeprom variables as input argument
-compiler accept eeprom variable as byval

so it make a copy of value of variable and we can not save value to eeprom in sub/functions.

thanks
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 677

poland.gif
PostPosted: Wed May 24, 2017 6:22 pm    Post subject: Reply with quote

I use tables for that. You should only decide which address will represent which value.



Code:
Config Submode = New

'general purposes
Dim N As Byte , Helpb As Byte , Helpw As Word

'variables
Dim My_bytes(20) As Byte , My_ee_bytes(20) As Eram Byte


Sub Read_whole_memory()

 For N = 1 To 20
  My_bytes(n) = My_ee_bytes(n)
 Next

End Sub

Sub Save_to_ee(byval Address As Byte)

 My_bytes(address) = Helpb
 My_ee_bytes(address) = Helpb

End Sub


Call Save_to_ee(1)                      'for example


You can even add aliases that will be related to variable function. For example:
Code:
Voltage Alias 1
Current Alias 2

Call Save_to_ee(current)
Back to top
View user's profile Visit poster's website
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Wed May 24, 2017 7:22 pm    Post subject: Reply with quote

thanks a lot EDC
i remember that we have some instructions in assembly for find address,why the compiler does not find address by these instruction automatically and write to related address?!
is some limitions on stack or frame or some things else?
Back to top
View user's profile
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 Unsupported versions 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