Making Magnificent Moonlights
- PetPirate
- Gone Today, Here Tomorrow
- Posts: 1230
- Joined: Mon Jun 27, 2005 5:41 am
- My Puffers: 3x Tetraodon Nigroviridis in full marine
- Location: Shanghai, China
- Contact:
Alright, you 'orrible dissenting lot!
Still warm in the knowledge that our circuit is working, it's time to complete it!
First of all, we need some...
user input
By that, do I mean you all get to have you two bobs' worth
Certainly not. I mean we need a way for us to do stuff - like set the time, set the brightness, and order pizza.
Yes, we need a button! Or, more appropriately, a push-switch.
Switches are simple, right? Push to close a circuit. If you intuitively wanted to add a switch to our project, most people would probably try to do something like this:

But that ain't gonna work! In this case, what happens when the switch is pushed is that the MCU sees 5V. That's good... 5V is "1". But when the switch is open, the MCU doesn't see a "0", or 0V. Instead it sees "nothing" - neither 5V or 0V... the input is floating between the two, and could be either a "1" or a " 0 ".
That's not much good, is it? Fortunately we can fix it with a bit of ingenuity. Like so:
There. Now, when the switch is *open*, the chip sees 5V, or "1". When the switch is closed, current flows down to ground, and the MCU will see 0V. The resistor is fairly large - say, 10K, to ensure that not much current flows, but it is still small enough for the MCU to clearly see 0V.
There! Done! That's our switch.
Here it is incorporated into our circuit:

Right, now we need something else..... we need....
A display
Yup, no use having a button if we have no indication what it does. So here's where a nice, swanky LCD display comes in.
Picbasic.. and MikroBasic have built-in support for "intelligent" LCD displays based on or compatible with the Hitachi HD44780. Sounds complicated? Well, I'll admit, they do need a few wires to wire them up.... but controlling them is a breeeeeze.
Here are some standard LCDs I have in my rather dull collection:

They come with a varying number of connection pins, but the first 14 are always the same:

Now, if you're anything like me the first time I saw that, you'll be thinking .... FOURTEEN connections!!!!!!!! You're kidding, right?
Well, no... I'm not. The good news is, we don't have to use all of them. The first three are just power settings (a potentiometer is strung between +5V and ground, with the variying resistance going to the contrast pin, to allow us to fine-tune contrast). The MCU knows what to do with RS and E, and because we're not using RW, we just tie it to ground.
What's more we don't need to use all eight data pins. Our MCU is Sooooo clever, that it only needs to use 4. A bit like riding a bike without holding the handlebars. Except safer. So, we only use D4 ~ D7, and leave the others unconnected.

See, only SIX connections to our MCU now..... not too bad.
For more infor on LCD displays and PIC microcontrollers, see this
Here's our trusty old circuit diagram, with our LCD display in place:

Still warm in the knowledge that our circuit is working, it's time to complete it!
First of all, we need some...
user input
By that, do I mean you all get to have you two bobs' worth
Yes, we need a button! Or, more appropriately, a push-switch.
Switches are simple, right? Push to close a circuit. If you intuitively wanted to add a switch to our project, most people would probably try to do something like this:

But that ain't gonna work! In this case, what happens when the switch is pushed is that the MCU sees 5V. That's good... 5V is "1". But when the switch is open, the MCU doesn't see a "0", or 0V. Instead it sees "nothing" - neither 5V or 0V... the input is floating between the two, and could be either a "1" or a " 0 ".
That's not much good, is it? Fortunately we can fix it with a bit of ingenuity. Like so:
There. Now, when the switch is *open*, the chip sees 5V, or "1". When the switch is closed, current flows down to ground, and the MCU will see 0V. The resistor is fairly large - say, 10K, to ensure that not much current flows, but it is still small enough for the MCU to clearly see 0V.
There! Done! That's our switch.
Here it is incorporated into our circuit:

Right, now we need something else..... we need....
A display
Yup, no use having a button if we have no indication what it does. So here's where a nice, swanky LCD display comes in.
Picbasic.. and MikroBasic have built-in support for "intelligent" LCD displays based on or compatible with the Hitachi HD44780. Sounds complicated? Well, I'll admit, they do need a few wires to wire them up.... but controlling them is a breeeeeze.
Here are some standard LCDs I have in my rather dull collection:

They come with a varying number of connection pins, but the first 14 are always the same:

Now, if you're anything like me the first time I saw that, you'll be thinking .... FOURTEEN connections!!!!!!!! You're kidding, right?
Well, no... I'm not. The good news is, we don't have to use all of them. The first three are just power settings (a potentiometer is strung between +5V and ground, with the variying resistance going to the contrast pin, to allow us to fine-tune contrast). The MCU knows what to do with RS and E, and because we're not using RW, we just tie it to ground.
What's more we don't need to use all eight data pins. Our MCU is Sooooo clever, that it only needs to use 4. A bit like riding a bike without holding the handlebars. Except safer. So, we only use D4 ~ D7, and leave the others unconnected.

See, only SIX connections to our MCU now..... not too bad.
For more infor on LCD displays and PIC microcontrollers, see this
Here's our trusty old circuit diagram, with our LCD display in place:

Last edited by PetPirate on Sun Nov 20, 2005 12:43 am, edited 2 times in total.
- PetPirate
- Gone Today, Here Tomorrow
- Posts: 1230
- Joined: Mon Jun 27, 2005 5:41 am
- My Puffers: 3x Tetraodon Nigroviridis in full marine
- Location: Shanghai, China
- Contact:
WAIDDDDAMINNIT...... What do you mean "Nearly done"? What now?
Sorry, just one more thing. In order to include a timer, and to know which day it is, we need to include... well... a clock
but can't the MCU do that???
Not really... not very well. It's so busy doing other things that it would be difficult to ge t it to accurately count the time as well. Plus, trying to do so would be a pain. It's easier to tack another bit of hardware on, and just ask it what the time is every so often. Just as in real life - it's easier (and cheaper) to ask the time than buy a watch. Or something.
Anyway, that piece of hardware is called a "REAL TIME CLOCK", or RTC.
Here's the one we'll be using -- the DS1302 from Dallas:

As you can see, there are a few things this chip needs to live... again, a capacitor to smooth the power supply. Again, a crystal. This crystal is a bit diffrerent from the one we're using for our MCU though --- this crystal is tiiiiiiiinnnnny and accurate. 32.768Khz. Don't ask me why -- but 32,768 is always what we use for keeping time. The crystal doesn't need any added capacitors, if you get one with the right capacitance rating.
The only other thing we need is a backup battery. Then, when the power goes off, the RTC can remember the time. A non-rechargeable lithium coin cell should last up to TEN YEARS or so..... so I've added in one of them!
Here is Ms. Dallas added into our circuit diagram.

WHAAA... THERE'S MORE??
Yep. Simple though. One button isn't going to cut it for setting the time, is it? Most digital clocks use one button for "Mode", and then a couple for "Select", don't they? Let's do the same:

*DONE. 100% FINISHED. ALL THAT's LEFT IS TO FINISH BUILDING. And that's just a matter of plonking the components down on the board, isn't it? Watch this space!!!

Sorry, just one more thing. In order to include a timer, and to know which day it is, we need to include... well... a clock
but can't the MCU do that???
Not really... not very well. It's so busy doing other things that it would be difficult to ge t it to accurately count the time as well. Plus, trying to do so would be a pain. It's easier to tack another bit of hardware on, and just ask it what the time is every so often. Just as in real life - it's easier (and cheaper) to ask the time than buy a watch. Or something.
Anyway, that piece of hardware is called a "REAL TIME CLOCK", or RTC.
Here's the one we'll be using -- the DS1302 from Dallas:

As you can see, there are a few things this chip needs to live... again, a capacitor to smooth the power supply. Again, a crystal. This crystal is a bit diffrerent from the one we're using for our MCU though --- this crystal is tiiiiiiiinnnnny and accurate. 32.768Khz. Don't ask me why -- but 32,768 is always what we use for keeping time. The crystal doesn't need any added capacitors, if you get one with the right capacitance rating.
The only other thing we need is a backup battery. Then, when the power goes off, the RTC can remember the time. A non-rechargeable lithium coin cell should last up to TEN YEARS or so..... so I've added in one of them!
Here is Ms. Dallas added into our circuit diagram.

WHAAA... THERE'S MORE??
Yep. Simple though. One button isn't going to cut it for setting the time, is it? Most digital clocks use one button for "Mode", and then a couple for "Select", don't they? Let's do the same:

*DONE. 100% FINISHED. ALL THAT's LEFT IS TO FINISH BUILDING. And that's just a matter of plonking the components down on the board, isn't it? Watch this space!!!
Last edited by PetPirate on Sun Nov 20, 2005 12:55 am, edited 5 times in total.
-
puffermama
- Figure 8 Puffer
- Posts: 126
- Joined: Mon Oct 24, 2005 12:18 pm
-
Jager
-
puffermama
- Figure 8 Puffer
- Posts: 126
- Joined: Mon Oct 24, 2005 12:18 pm
-
Bred
- Former Staff Member
- Posts: 364
- Joined: Sat Jun 04, 2005 10:42 am
- Location: Toronto, Canada
- Contact:
Jhong wrote:32.768Khz. Don't ask me why -- but 32,768 is always what we use for keeping time.
32768Hz is the frequency at which common quartz crystals vibrate when a current is passed through them, that's why.
Nice one - LED display... I honestly didn't see that one coming!
You've left me behind in the dust. I'll probably never make it this far, but it is a very interesting read!
- PetPirate
- Gone Today, Here Tomorrow
- Posts: 1230
- Joined: Mon Jun 27, 2005 5:41 am
- My Puffers: 3x Tetraodon Nigroviridis in full marine
- Location: Shanghai, China
- Contact:
LOL! At least you enjoy the read. It's hard to judge if I'm posting interesting info, or just waaay to many words sometimes.
I didn't realise 32.768 was the standard resonant frequency... since you can purchase crystals of almost any speed (4MHz, 10MHz, 20MHz... or 100's of MHz for the crystals on PC mainboards).
Ah well... I've already got the thing hooked up and am playing with the software to check it is all possible before I post.... my clock is about 30 secs per hour too slow! Not really an acceptable error. I expect it is induced capacitance from the stripboard, so I'm fiddling around with strips of aluminium foil trying to improve the accuracy!
j
I didn't realise 32.768 was the standard resonant frequency... since you can purchase crystals of almost any speed (4MHz, 10MHz, 20MHz... or 100's of MHz for the crystals on PC mainboards).
Ah well... I've already got the thing hooked up and am playing with the software to check it is all possible before I post.... my clock is about 30 secs per hour too slow! Not really an acceptable error. I expect it is induced capacitance from the stripboard, so I'm fiddling around with strips of aluminium foil trying to improve the accuracy!
j
