Re: Clock question
lennyG,
I think this is a very difficult question you have asked.
I have never studied programming or programming language, at least not in a formal classroom. Yet I have spent countless hours (hundreds of hours) blinking an LED, studying code snippets, writing to an LCD, trying different methods to detect a pushbutton, learning to use a subroutine, learning interrupts, studying more code examples, etc. etc.
I am just an electronics and microcontroller enthusiast. Yet I have done just what you describe.
For me it was really a process of building blocks... I started by learning how to read the time from an RTC module. Then I displayed that time on a given display (LCD or LED matrix, etc)
Then I learned how to set that time in the RTC. First as you said, from the program each time I loaded the code into the micro.
Then later by detecting a push button to cause the code to go to a separate "set time" routine.
Now this is what I think you are asking. How do I jump into this set time routine??
Well one way is for your main code to watch for a given button to be pressed. This is done periodically in your main code. When you want to set or adjust the time you would press this button and then the code jumps to the set time routine. Then in that routine it allows you to up/down the given value HH:MM:SS. You will want to be able to display that new value on your display so you can see when you get to the right number. Then you will want a different button (or a time out period) to automatically tell the micro to advance to the next thing to be adjusted HH>>MM>>SS (But usually you would skip SS and have the code set SS to zero).
I believe this is the heart of programming. You have to be able to DREAM up a way to literally direct the microcontroller to do what you want it to do.
There is no correct way to set the time. That is for you to imagine, code, test, debug, etc.
There are certainly good programming practices. There is elegant code and ugly code. Easy to understand and "what the hell was this guy thinking" kind of code, even though the ugly code may work correctly and never fail.
The set time routine must match and work with the rest of your code. The number of buttons required is dependent on your ability to dream up ways to signal different conditions to the micro. ie. short press, long press, double press within a time period, holding two buttons at once, only looking for a button press on powerup, etc, etc.
How do you tell someone to get to your house??? would someone else in that house use the EXACT same directions??? yet those two different set of directions would still result in arriving at your house. Although one may take longer, or drive a longer distance, etc.
To me (an untrained programmer) that is the beauty and the challenge of writing code.
Sorry for the non answer. But if someone provided you with an example it would likely take a considerable amount of effort to understand what and how they accomplished the given task. Would not likely work with your existing hardware. And they no-doubt did not write the code in one sitting. It likely evolved over several steps and testing phases.
If you are new at programming (guessing by your number of posts) then just start by doing simple things and adding bit by bit (no pun intended) to your code to make it do something else or blink an led faster/slower based on button press or up/down, etc. etc.
ask detailed questions, provide your coding examples when you ask, and you will get help here, world class programmers are lurking here and are very willing to help.
Last edited by Heckler; - 28th October 2015 at 19:12.
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Bookmarks