Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/07/04 21:29
Read: times


 
#69996 - RE: need some ideas..
Responding to: ???'s previous message
You could use some of your idea.

The first thing you need is a stable TIME BASE. The best, and frankly only right, way to do this is to use a timer interrupt. Timer interrupts can not be so slow as 1 time per second, but 50 times a second is realistic. Inside the timer interrupt service routine, you can have a counter which then counts back from 50 once every timer interrupt, and when it reaches 0, it sets a bit -let's call it "tick" and reloads itself with 50 again. So now you have a bit which goes high every second. Automatically. Punctually.

Your initialization would reset "tick" and set up the timer for periodic interrupt.

The main loop of your program would first check if "tick" goes high with every pass, and if it does, it should
- reset "second" again immediately
- Decrement the memory location you use to store the low digit second count -let's call it seclo-.
- If the low digit second count underflows, set it to 9, and decrement high second count.
- If high second count underflows, set it to 5, and decrement minutes. etc. for minutes and hours

Then, your main loop would take seclo, and use a lookup table to convert the value to another value which says which LEDs on seven segment digit for low seconds should light up and if you want to show that number, and store that information in another RAM location -lets call it sec7lo- . Same for all the other second, minute and hour data.

now the main loop would repeat.

Oh yes, the display! Well, you have a timer interrupt, havent you? It's ideal for multiplexing the sec7lo and all the other already conveniently decoded info to the display. Every time the timer isr runs, you take the next digit and output it to the segment port, while activating the appropriate anode driver.

Note that I don't blame you if you are still unable to build your project from this description immediately. It would take an amount of information sufficient to fill a small book to do that, and there you have it: you can't get a complete answer to your question from a reply on a message board, but you will need to read books, and search the internet. (If I were you, I'd trust books a whole lot more.) You will need to familiarize yourself with these topics:
- Timer interrupts. How to set up timers and interrupts
- Typical structure of a microcontroller program. Main loop and interrupt service routines (ISR's). Why it is not a good idea to wait using a delay loop, or wait for a bit to change with a non-technique like jnb tick,$
- Lookup tables. How to translate one value to another using a table inside a CPU.
- Multiplexing, especially applied to 7-segment LED displays. How to control lots of hardware with limited I/O.

Note also that this approach does not apply specifically to the 8052. A countdown clock could work very much like this on any controller/microcomputer.


List of 11 messages in thread
TopicAuthorDate
need some ideas..            01/01/70 00:00      
   RE: need some ideas..            01/01/70 00:00      
   RE: need some ideas..            01/01/70 00:00      
      RE: need some ideas..            01/01/70 00:00      
      RE: need some ideas..            01/01/70 00:00      
         RE: need some ideas..            01/01/70 00:00      
   RE: need some ideas..            01/01/70 00:00      
      RE: need some ideas..            01/01/70 00:00      
         RE: need some ideas..            01/01/70 00:00      
   First things first            01/01/70 00:00      
   RE: need some ideas..            01/01/70 00:00      

Back to Subject List