retrobrad
PIC Microcontroller tutorial #1

 
Post new topic   Reply to topic    retrobrad Forum Index -> Work in progress...
View previous topic :: View next topic  
Author Message
retrobrad
Administrator
Administrator


Joined: 08 Jun 2007
Posts: 1039
Location: NSW, Australia

PostPosted: Tue Dec 25, 2007 1:04 pm    Post subject: PIC Microcontroller tutorial #1 Reply with quote

Hi guys, i thought id give you a few little tutorials on these great little microcontrollers! if you have never seen one then heres a picture of the ones ive been using lately:



so as you can see it has 18 legs or pins (9 on each side) this particular part number has 2kbytes of program memory (which doesnt sound like much, but you can do alot with 2k believe me!) it has 16 input / output pins (2 ports, PORTA and PORTB each with 8bits) it has an internal clock of 4Mhz and a few other neat features too.

Basically these can be used in loads and loads of applications, lets use a very simple example of flashing an LED.

you would write a code to your microcontroller to tell it to do various things - heres a run through.

firstly you would connect the anode (or positive) leg of the LED to one pin of either PORTA or PORTB (remember, each port has 8 pins) so for this example lets connect it to PORTA pin 0 (which is the very first pin of PORTA) we then connect the cathode (or negative) leg of the LED to a resistor and then to ground (or 0 volts) - we need the resistor to limit the current so we dont destroy the pic or the LED.

now we connect up power to the pic (but dont turn it on - we havent programmed anything!) connect +5volts to the power leg of the pic chip and also GND or 0v to the ground leg of the PIC.

now that our circuit is made we need to write our program - I use MPLAB to do this which is free from the microchip website.

firstly we need to tell the microcontroller that we want PORTA pin, 0 to be an output (because we are making an external thing turn on and off) it wouldnt work if we told the microcontroller to be an input!

now that it knows its an output, we would output a logic 1 or high or +5v or whatever you like to call it, to PORTA, pin 0 this will turn on the led, we then tell the microcontroller to wait a while - lets say 1 second,and then once its waited, we tell it to output a logic '0' or low or 0v to PORTA pin, 0 - this will turn the led off, we then tell it to wait 1 second again and then go back to the start of the program.

this way when we put the pic into the circuit and turn it on, it will do a continuous loop of turning the led on then off etc...

heres the pinout for reference:
NOTE vdd means +5v or the positive power connection and VSS means 0v or ground.




when i get time, or if anyone is interested - ill write up the source code for making the led flash - and again, if people are interested i can go into more programming examples and show how you can make a microcontroller do whatever you want!

and heres a really cool project someone made with a microcontroller - it uses only 32 RGB LEDS placed in a line and then spun around really fast!
(RGB leds are leds that can display all three primary colours and therefor can produce any colour depending on voltage levels....)

you will be impressed with this!
http://www.youtube.com/watch?v=93HcgS4W_8g
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    retrobrad Forum Index -> Work in progress... All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
Style Distributed by Olate