Lights!


Following on from the last post we'll set up the oscillator while we're in the configuration bits.

See this one, RSTOSC?




Notice how it has the Warning Sign next to it? It means we can't just change it. So what we need to do is to click the button "Generate Source Code to Output". Click it.

There will be a list of what are called compiler directives. These start with #pragma.

#pragma directives are not C. They are specific lines that tell a specific compiler to do a specific thing, in this case it is setting configuration bits.

There are two of these you'll need, one is the watchdog, the other is the oscillator. Don't worry too much about why, just copy them in. All will become clear later.

Here they are:

#pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)
#pragma config RSTOSC = LFINT // Power-up default value for COSC bits (LFINTOSC)

Then forget about them until a lot later. But don't leave them out!

Your code should look like this:



OK. You could get a real microprocessor now, and all the bits you need, and run this program, which will do absolutely nothing, forever.

Not a very exciting project though, is it?

Here's what I propose we do, between us. We'll light up an LED. We all know what an LED is, don't we? Light Emitting Diode. It's a quite low voltage piece of semiconductor technology which, when you pass a current through it, will make it emit light at a wavelength you can usually see.

Clear? Of course it is. If it isn't, it soon will be. But for now, we're pretending we've got an LED.

We can light up the LED by applying a voltage across it, through a resistor, to make it light up to its "proper" brightness (they come in all sorts of power ratings). We'll use something like a 10mA (milliamp) one, which will be quite bright but won't blow up your microproceor or USB connection. Then we'll make it go from off to on, slowly, repeatedly, so you can watch it and marvel at how you now understand how real microprocessors make LEDs do that. It's probably easier than you think, but probably not HOW you think.

Firstly, we'll do it the quick and dirty way. Just so you can see how the theory goes. Ready? Of course you are.

LEGS

Don't get excited. The microprocessor we're going to use has legs. These are called DIP packages (DIP stands for Dual Inline Package) and these have legs that go into the sockets on the breadboard.


Each "leg" has multiple functions, usually. They can be analogue or digital (among other things). Analogue (American spelling is analog because, well, it just is) means that it can take in or put out a voltage that is variable, maybe 1, maybe 2, maybe 3 volts, and digital means it can take in or put out a voltage that is either no volts or all the volts. No volts is 0, unsurprisingly, and all the volts is 1. It's called digital because the 0 or 1 represents a digit. In this case a binary digit.


Now have a quick read of this thing about binary and stuff. Then we'll get on.

Comments

Popular posts from this blog

Get the software

Your first test