Top.Mail.Ru
? ?
entries friends calendar profile Previous Previous Next Next
The diaries of two evil geniuses
wee_scot
themeadows
wee_scot
Your're ready to go ...
Your work area is set up. You've followed the last post through to make your ICSP adaptor. You've read both parts of the LED tutorial and now you're ready to make it all work :)

We're going to play with some LED's now. They're a great way to get into the swing of this whole microcontroller business.

Materials:
1 x PIC16F84A
1 x Crystal (4~20MHz)
2 x 15~33pF Ceramic Capacitors. What ever you choose, just make sure they are both the same.
1 x 0.1uF Capacitor (one of those little blue mono types is fine)
1 x 4K7 Resistor
8 x 5mm LEDs (your choice of colours)
8 x 220R Resistors
Jumper wire for your breadboard


Schematic:



Construction:
Build project on breadboard as per schematic. Try to line your LEDs up in a row with even spacing between them. Keep the 22pF caps as close to the crystal as possible. Double check EVERYTHING!


Code:
DEFINE OSC 4			' Set up timing to match the 4Mhz crystal

x	VAR	BYTE		' Declare a variable named "x"

Start:
	Pause  500		' Wait 500 milliseconds before continuing code execution
	High   PORTB.0		' Set pin RB0 to HIGH (+5V). This will be the power indicator to show the code is running
	Pause  1000		' Wait another second before continuing.
	
	For x = 1 TO 7		' Loop 7 times, once for each LED in our chain
		High PORTB.x	' Turn each LED on in turn
		Pause 150	' Leaving it on for 150 milliseconds
		Low PORTB.x	' Then turning it off before looping with almost no delay before the next one is lit
	Next
	
	GoTo Start		' Do it forever



Use CodeDesigner Lite to enter the code above and save it with a .pbp extension in the folder where your PicBasic Pro executable is. Compile the code by pressing F5. You'll now have a .hex file in the same directory that can be loaded into your programmer. Make sure you use the XT setting for a 4MHz crystal, and the HS setting for anything faster. Check, double check, and then check again ... Breadboard power is OFF. ICSP adaptor is plugged in. Programme the chip. Disconnect the adaptor. Check your wiring again. Fire up the breadboard. The power LED should come on after a short delay, then the other LEDs should start chasing each other.

Tags:

Leave a comment