PDA

View Full Version : Initialize variables



bmoe79
- 19th February 2015, 11:55
Hi.
I use a PIC18F45K80 @ 64MHz.
I have a seperate pbp file with my LCD menu code, witch I include at the end of my main code.
In my menu file I declare some variables and initialize them.
The strange thing is that not all of the variables get initialized so I have to initialize them again.
Is there anything wrong with the way I initialize the variables?
For example the variable go_back doesnt get set to 0 the first time.


'************************ VARIABLES *****************************


btn_debounce var byte : btn_debounce = 50
btn_rpt_start_time var word : btn_rpt_start_time = 300
btn_rpt_time var byte : btn_rpt_time = 100
show_menu var byte : show_menu = 0
menu_var var word : menu_var = 0
menu_var_min var word : menu_var_min = 0
menu_var_max var word : menu_var_max = 0
btn_repeat var bit : btn_repeat = 0
btn_repeat_quick var bit : btn_repeat_quick = 0
btn_released var bit : btn_released = 0
go_back var bit : go_back = 0 'THIS INITIALAZATION DOESNT WORK, IT'S INITIALIZED AS 1




'************************************************* ***************
'***************** MENU SUB ROUTINE ********************
'************************************************* ***************
'menu
menu:
go_back = 0 'BUT THIS DO
while go_back = 0
select case show_menu
case 0
.......
.......

Regards
/Matias

towlerg
- 19th February 2015, 13:11
Wild guess, something is writing to the byte/word/whatever this bit is apart of.

George

Acetronics2
- 19th February 2015, 13:31
oh oh ...

that looks Basic " C style" written ...

@first ... try not to initialize variables on the same line as you declare them ... ( one declaration block and further, one initialization block )

we could suspect the compiler to consider those are not initialization but directives ! let's say it could be a little bug ( not sure at all ... )

did you try MPLAB SIM to track your initialization sequence ??? ( excellent debugging tool, BTW ... )

Alain