Changing declared variables names on the fly
Hello,
This is probably a dumb question but is there a way using PBP to have a variable with-in a declared variable name? Its a little hard to explain exactly what I mean but it would be sort of like this:
You want to print a variable name to your Lcd so you print:
LCDOUT $FE,1,"On_Timer_Hour",DEC M," "
the On_Timer_Hour would be your declared variable and the variable with-in it would be the M variable. Setting the M variable before the print to the Lcd (or in your code) would change the variable name displayed to the Lcd. So the variable On_Timer_Hour could be On_Timer_Hour1, On_Timer_Hour2, On_Timer_Hour3 ect. ect.. It would be great if I could implement that concept in my code. Wishful thinking?
Why I'm asking is: I'm writing a timer program where the user can programme 10 different On and Off times that repeats every 24 hours using Darrels ELASPED.PBP. I have in excess of 100 variables that all have a numerical value at the end of the variable name. If it is possible to use a variable with-in a declared variable name then it would save a lot of code space.
In each of the 10 timer sections (I'd like to have more if I can gain more code space) I have intermediate dummy variables that all have to be set then re-set to implement my code. It would be great if I could just change one M variable that would change them all. There's a lot I don't understand about programming, like array variables with a variable index or other concepts that could make writing code more efficient. What is the concept of a variable index? Would that have anything to with what I'm trying to accomplish here?
Is it possible or just wishful thinking.
Thanks
jessey
How do I READ & WRITE to the EEPROM 1, [1,2,3......]
Hello Sayzer,
Thanks for answering my question. Forgive my ignorance but I'm not familiar with your code example or how to implement it. I am familiar with how to read & write to the eeprom, for a byte variable I use
EEPROMData0 VAR BYTE
U VAR EEPROMData0
READ 0, EEPROMData0
to write I use:
EEPROMData0 = U
Write 0, EEPROMData0
then for a word variable I use
EEPROMData1 VAR WORD
V VAR EEPROMData1
Read 1, EEPROMData1.byte0
Read 2, EEPROMData1.byte1
to write I use:
Write 1, EEPROMData1.byte0
Write 2, EEPROMData1.byte1
In your example code I don't know how I would write to locations 1 to 10 and 101 to 110 of the eeprom address location 1? Could you please explain the concept as I'm not sure how to do that. I can sorta understand your Index loop but I don't see any relationship between the Index variable and the EEPROM 1, [1,2,3......] statement? I've seen the EEPROM 1, [1,2,3......] statements in some of the code examples in the archives but I just don't understand the concept.
Could you educate me about how this works?
Thanks
jessey
How do I write to the eeprom locations?
Hi Sayzer,
Thanks for your explanation about the For-Next loop, I think I can grasp the concept of the Index For-Next loop now but what I don't understand is how do I write the values to the different eeprom locations. I added some push buttons to your code to try and increase and decrease the OnTime & OffTime variables and the Hour variable in an attempt to flash an Led but can't get it to work. Could you please help me to understand how to write to the different eeprom locations?
Thanks
jessey
Code:
'Pic18f452-20/P
Increase_OnTime_Push_Button VAR PORTD.2 '(pin 21) 2nd
Decrease_OnTime_Push_Button var PORTB.0 '(pin 33) 3rd
Increase_OffTime_Push_Button var PORTB.1 '(pin 34) 4th
Decrease_OffTime_Push_Button var PORTB.2 '(pin 20) 5th
Change_On_Off_Time_Push_Button VAR PORTD.1 '(pin 35) 6th
Led VAR PORTA.1 '(pin 3)
Buzzer VAR PORTC.2 '(pin 17)
OnTime var byte
OffTime var byte
Index var byte
Hour var byte
HOUR = 0
Is_Pressed con 0
Is_Not_Pressed con 1
EEPROM 1,[1,2,3,4,5,6,7,8,9,10,101,102,103,104,105,106,107,108,109,110]
GOTO MainLoop
Change_On_Off_Time:
PWM Buzzer,250,1
WHILE Change_On_Off_Time_Push_Button = Is_Pressed : PAUSE 100 : WEND
Loop:
IF Increase_OnTime_Push_Button = Is_Pressed THEN
OnTime = OnTime + 1 : PWM Buzzer,250,1
WRITE 1, OnTime
ENDIF
IF Decrease_OnTime_Push_Button = Is_Pressed THEN
OnTime = OnTime - 1 : PWM Buzzer,250,1
WRITE 1, OnTime
ENDIF
IF Increase_OffTime_Push_Button = Is_Pressed THEN
OffTime = OffTime + 1 : PWM Buzzer,250,1
WRITE 101, OffTime
ENDIF
IF Decrease_OffTime_Push_Button = Is_Pressed THEN
OffTime = OffTime - 1 : PWM Buzzer,250,1
WRITE 101, OffTime
ENDIF
IF Change_On_Off_Time_Push_Button = Is_Pressed THEN
PWM Buzzer,250,1
WHILE Change_On_Off_Time_Push_Button = Is_Pressed : PAUSE 100 : WEND
RETURN
ENDIF
LCDOUT $fe,1,"OnTime = ",dec Ontime
LCDOUT $fe, $c0,"OffTime = ",dec OffTime
PAUSE 100
goto Loop
MainLoop:
IF Change_On_Off_Time_Push_Button = Is_Pressed THEN GOSUB Change_On_Off_Time
'Hour variable gets its value here......
IF Increase_OnTime_Push_Button = Is_Pressed THEN
Hour = Hour + 1 : PWM Buzzer,250,1
ENDIF
'Hour variable gets its value here......
IF Decrease_OnTime_Push_Button = Is_Pressed THEN
Hour = Hour - 1 : PWM Buzzer,250,1
ENDIF
LCDOUT $fe,1,"Hr=",dec Hour," OnTime=",dec Ontime
LCDOUT $fe, $c0,"OffTime = ",dec OffTime
PAUSE 100
FOR Index = 1 to 10
READ Index , OnTime ' Read stored ON time.
READ Index +100, OffTime ' Read stored OFF time.
IF Hour = Ontime THEN Led = 1 ' If yes, turn ON the relay.
IF Hour = Offtime THEN Led = 0 ' If yes, turn OFF the relay.
NEXT Index
GOTO MainLoop
END
1 Attachment(s)
Thanks Dave, could you explain
Hi Dave,
I'm not familiar with "var byte[13]" or how it works but I'd really like to understand it as I would Sayzer's code example, I have a real thirst to learn PBP and this forum is a great opportunity for me.
The attachment shows all of the variables for one timer and all the necessary subroutines that are shared by all of the 12 timers except for some sub's that are used to select prints to show to the Lcd and a repeat On/Off timer. The Set_Timer_1: subroutine is repeated 11 more times and they all share the same sub's in the attachment, that'll give you a good idea of what I'm working on. If you have the time to explain the process using "var byte[13]", maybe something simple that'll flash an Led or just some theory then I'd love to see it.
Thanks
jessey