Hello all,
I'm taking a course on microcontroller interfacing, and we are programming PIC16F877A's with CCS C.
I want to make a program slightly more advanced than the lab topics, but I have been pondering how to structure it for days, and I would like some tips or advice.
I have an LCD, and 3 buttons: up, down, and select. There is a temperature sensor, which I have interfaced successfully. The LCD has a backlight. I want to have a menu system where by pressing the select button, it changes menus, and pressing up/down alters the values on the current menu. Through the menu one could enable/disable the backlight, and change the displayed temperature to C or F, and a few other things.
I am thinking that each press of the "select" button increments a "selected_menu" variable, and each time the main loop runs, it checks (through a SWITCH statement) which menu it's in, and displays the appropriate information. Also in this loop, it would check the state of various flags, like BACKLIGHT_ON and UNIT and take the appropriate course of action.
I know my question sounds sort of vague, it is because I am a beginner programmer. But what sort of structure should I use for this? Am I on the right track by using the menu to set variables, and then checking these variables in a loop?
I have heard people mention "finite state machines" for menus, but I am not sure if this would work for me, as I think there would have to be many "modes" (eg a mode where backlight=off AND unit=C, basically you'd need a mode for each possible combination of these settings).
So, to recap, what advice can you offer? I will do my own investigation if you can give me some clues.
Thanks for your time.
I'm taking a course on microcontroller interfacing, and we are programming PIC16F877A's with CCS C.
I want to make a program slightly more advanced than the lab topics, but I have been pondering how to structure it for days, and I would like some tips or advice.
I have an LCD, and 3 buttons: up, down, and select. There is a temperature sensor, which I have interfaced successfully. The LCD has a backlight. I want to have a menu system where by pressing the select button, it changes menus, and pressing up/down alters the values on the current menu. Through the menu one could enable/disable the backlight, and change the displayed temperature to C or F, and a few other things.
I am thinking that each press of the "select" button increments a "selected_menu" variable, and each time the main loop runs, it checks (through a SWITCH statement) which menu it's in, and displays the appropriate information. Also in this loop, it would check the state of various flags, like BACKLIGHT_ON and UNIT and take the appropriate course of action.
I know my question sounds sort of vague, it is because I am a beginner programmer. But what sort of structure should I use for this? Am I on the right track by using the menu to set variables, and then checking these variables in a loop?
I have heard people mention "finite state machines" for menus, but I am not sure if this would work for me, as I think there would have to be many "modes" (eg a mode where backlight=off AND unit=C, basically you'd need a mode for each possible combination of these settings).
So, to recap, what advice can you offer? I will do my own investigation if you can give me some clues.
Thanks for your time.