Next we must choose a microcontroller. We decided earlier that we would be using a PIC16F876, so choose Settings -> Microcontroller -> Microchip PIC16F876 28-PDIP or 28-SOIC. We also have to tell LDmicro what kind of crystal we will be using, and what the cycle time will be. Choose Settings -> MCU Parameters, and fill in our clock speed of 20 MHz. Leave the cycle time at 10 ms; that will usually be a good value.
Now we can assign pins to our inputs and outputs. Double-click `Xbutton' in the list at the bottom of the screen, and choose pin 14 of the PIC, which corresponds to MCU port RC3. (There is usually no reason for you to care which port you are using; just look at the pin number.)
Click `OK,' and then repeat the process for `Yled', which you can see from the schematic should go to pin 15. The other elements in the list are internal variables and bits in memory, so there is no need to assign pins to them. LDmicro will allocate memory for them when you compile.
So now you are ready to compile. Choose Compile -> Compile, and specify where you want to put the IHEX file. Then use whatever PIC programming equipment you have available to load that into your device, and you are ready to try it out.
This completes my tutorial. It is possible to write much more complex programs than that, of course. A program this simple uses only a very small fraction of your processor's memory, so there is room for many more rungs of logic. LDmicro also offers specialised instructions, for things like arithmetic, analog (A/D) inputs, PWM, and even text output to a character-based LCD. Consult the manual for details
No comments:
Post a Comment