Get Started With PIC

Here i am going to Share Tutorials for the PIC


Introduction​Welcome to the start of the PIC Tutorial. These pages will take you form the basic structure of the device, right through to programming methods and techniques. Also, there will be suggestions on how to modify the code so that you can adapt the PIC to suit your applications within Cybot. I will not be including any internal architecture diagrams, as this may only lead to confusion. If you want to look at the datasheet, then this can be downloaded from Microchips' web site.
To start, let us take a look at the PIC.

Microchip PIC 16F84 Microcontroller​Microchip manufacture a series of microcontrollers called PIC. You can see the range of their microcontrollers <a href="https://www.microchip.com/" target="_blank" rel="nofollow noopener noreferrer">Smart | Connected | Secure | Microchip Technology</a>. There are many different flavours available, some basic low memory types, going right up through to ones that have Analogue - To- Digital converters and even PWM built in. I am going to concentrate on the 16F84 PIC. Once you have learnt how to program one type of PIC, learning the rest is easy.
There are several ways of programming the PIC - using BASIC, C, or Assembly Language. I am going to show you the Assembly Language. Don't be put off by this. There are only 35 instructions to learn, and it is the cheapest way to program the PICs, as you do not need any extra software other than the freebies.
​
The 16F84 Pins
Below is a diagram showing the pin-outs of the PIC 16F84. I will go through each pin, explaining what each is used for.
[​IMG]

RA0 To RA4
RA is a bidirectional port. That is, it can be configured as an input or an output. The number following RA is the bit number (0 to 4). So, we have one 5-bit directional port where each bit can be configured as Input or Output.

RB0 To RB7
RB is a second bidirectional port. It behaves in exactly the same way as RA, except there are 8 - bits involved.
VSS And VDD
These are the power supply pins. VDD is the positive supply, and VSS is the negative supply, or 0V. The maximum supply voltage that you can use is 6V, and the minimum is 2V​OSC1/CLK IN And OSC2/CLKOUT
These pins is where we connect an external clock, so that the microcontroller has some kind of timing.

MCLR
This pin is used to erase the memory locations inside the PIC (i.e. when we want to re-program it). In normal use it is connected to the positive supply rail.

INT
This is an input pin which can be monitored. If the pin goes high, we can cause the program to restart, stop or any other single function we desire. We won't be using this one much.

T0CK1
This is another clock input, which operates an internal timer. It operates in isolation to the main clock. Again, we won't be using this one much either.

​

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    @harshad-ukH5ww • Apr 25, 2009

    In Next Section i will put the tutorial for programming of PIC

  • Rifaa

    @rifaa-NaWZZ4 • Apr 25, 2009

    Nice intro about PIC's.
    Umm! I like to know more ASAP.

  • debu

    @debu-62iszV • Apr 25, 2009

    @godfather: Good Job!

    As an addition to what godfather has written, #-Link-Snipped-# should be useful for anyone learning how to use PIC's (and microcontrollers in general).

    Regards,

    Debu 😀
    #-Link-Snipped-#

  • Ashraf HZ

    @Ash • Apr 26, 2009

    Good start, dude! I really need to brush up on using assembly on a PIC for sure. I'm being too reliant on C alone 😔

  • silverscorpion

    @silverscorpion-iJKtdQ • Apr 26, 2009

    Good job done.
    I'm very much familiar with 8051 series. But I've been very much in need of learning about PIC.
    I'm glad you help me learn PIC. And sure enough, the start is damn good.

    keep up the good work!!

  • Harshad Italiya

    @harshad-ukH5ww • Apr 26, 2009

    ashGood start, dude! I really need to brush up on using assembly on a PIC for sure. I'm being too reliant on C alone 😔
    silverscorpionGood job done.
    I'm very much familiar with 8051 series. But I've been very much in need of learning about PIC.
    I'm glad you help me learn PIC. And sure enough, the start is damn good.

    keep up the good work!!

    Guys me also working on 8051 only and i am also trying to learn PIC and one more thing if you want to learn NXP's LPC series then i can help you very well cause i had done a lot of work on this..

  • Harshad Italiya

    @harshad-ukH5ww • Apr 26, 2009

    Guys let us make a Programmer for PIC !!?

    There are so many Programmer available but let us make our Own..
    will post the Schametic Circuit Diagram here and from that we will design PCB layout.

    Feel Free to Post Comments.

  • Ashraf HZ

    @Ash • Apr 27, 2009

    Yeah, thats a good idea! Though I already have a programmer.. making another one might be useful.

    Also, a PCB layout for the basic PIC circuit (inc oscillator, caps, RS232, etc.. ) is also another good idea =) In fact, we could use that for our CE Bot project if xhx wont mind.

  • Harshad Italiya

    @harshad-ukH5ww • Apr 27, 2009

    I have circuit diagram and PCB layout made by me... its for 16F877... lets make its programmer and Also one Dev. board that may be useful for beginners...

  • Rifaa

    @rifaa-NaWZZ4 • Apr 27, 2009

    Godfather !!! where's the rest ot the tut.. hurry , pleeeeeeeeeeeeeeeeeeeeeeeese

  • Harshad Italiya

    @harshad-ukH5ww • Apr 27, 2009

    RifaaGodfather !!! where's the rest ot the tut.. hurry , pleeeeeeeeeeeeeeeeeeeeeeeese


    Dear Rifaa,

    I will post a tutorial also.... but there is one more idea that we will make a programmer plus Test board for PIC so we can Test our Module on that Testboard.. like LED blinking and etc module.....

    so i am working on that Programmer right now and yes Posting new Section soon

  • Harshad Italiya

    @harshad-ukH5ww • Apr 29, 2009

    Dear Friends,

    i Just Received the PCB which was Designed by me for PIC 16F877... if you guys want it then i will share with you...

    @ Ash... We can use this as CE Project also!!

    PS: i am working on that PCB hop it will Function properly

  • Ashraf HZ

    @Ash • Apr 29, 2009

    Well, it seems we are going to use an Atmel chip for the CE Bot. However, we can still pursue with the PIC as a back up. (robot is modular, after all).

    .. and, this can be a basis for other projects in the future =) Yeah, please do share the PCB layout.

    I've run out of PIC16F's.. gotta buy some more next week 😔 I still got one PIC18F left. Its able to use a USB connection.. might be useful 😉

  • Harshad Italiya

    @harshad-ukH5ww • Apr 29, 2009

    Sure Ash i will post the Layout here...

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Here is the Circuit Diagram for PIC.
    #-Link-Snipped-#

    please take a look at that and suggest the modification...

    i had completed the Layout also.

  • Ashraf HZ

    @Ash • May 1, 2009

    Good work, though we could also have a basic diagram without the DG411DJ & MC34063. Are you using them for a specific project?

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Nop Not for Specific Project but with this We can Vary the Vcc. in my case i am using for 5V Vcc.


    So is this OK?

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Actually i Got the Fabricated PCB and right now Working on it.. to Make it Run properly

  • Ashraf HZ

    @Ash • May 1, 2009

    Yeah, I guess thats fine. Good luck!

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Ok so In two to Three Days i will post the Layout cause i want to do some changes...

    I am Using Protel For PCB Designing any one aware by this Tool?

  • Ashraf HZ

    @Ash • May 1, 2009

    Yeah, heard of it.

    Though, Eagle Lite has been very sufficient for me so far. Pretty damn good for a free software 😀

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Yep its also nice to use crack software. 😉
    Well i will upload "gerber" file so its easy to fabricate.

    Cheers.

  • Ashraf HZ

    @Ash • May 1, 2009

    GF, you know CrazyEngineers is against the promotion of pirated software. I suggest you keep it to yourself next time 😀

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Buddy i was Jocking actually i got training on PROTEL thats why i know how to use it and i am using a Copyright Version already.

    and yes as i am CEan now i will never use pirated tools.

  • Rifaa

    @rifaa-NaWZZ4 • May 1, 2009

    OK GF, Here's what's bothering me about CE's in here. Pls don't take me personally, and I am not disappointed in any way but I just thought I'll let you all know.
    Some where in another thread some one discussed about electronic simulating software's and it's level of functionality. So then I asked about the best of the best there is, cause I like to get my hands on one and touch up What I lost and secondly I was dealing with a job tht uses PIC's and also I want to learn about schematic and PCB layout and all, and guess what, no one answered, and I was rather dissented then. 😔
    But I got over it since I did a lot of research, why I asked CE's was to save time but now I have gone through this all, LT Spice, P spice, protel, and NI Multisim.
    What worked for me best was Cadence, Pretty powerful and free too, but still I can only make a shcema and to transfer the layout is still Greek to me, and am working on it ( I will be grateful if some one point me the right way ).
    Now I found out most of you is using one software at least and why I though none of you just took some time to give a suggestion.
    Well, what's done is done, and I don't drag it behind me.

    So, concerning the schematic GF had posted, I just want to know what it is and how CE's like us that has no way of fabricating a PCB soon for the time being are gonna do with it.
    And having a PIC in it concerns me considering other CE's.

    I do have a programmer and that PIC you have it in the schematic. But I don't have the HEX file or what ever is used to program.
    Or am going too quickly on this. Just let me know.

    Taking about piracy, I think I know more about them than any of you, cause when a CE talks about pirated soft's in case of schematic capture software's, most of them are free, even the good ones, so any one of you can download them and use it, don't believe me then you can check it out. 😉

  • Ashraf HZ

    @Ash • May 1, 2009

    Alright rifaa, I got the hint 😛 Sorry, I forgot about replying to that thread since I had exams and project submissions.

    lets try to stick on topic here 😀

    Regarding the hex file, GF will hopefully explain about the basics of programming first.

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Sorry Rifaa,

    Ok you want to Make Your Own PIC Programmer i am giving you the PCB layout gerber file so you can give it to PCB manufacturer and about HEX file..

    That Hex file which we have to Load is available online i will send it to you also. yes you need one ICD2 which will load that file to PIC16F877A and mount that chip on our programmer. After that Connect it to MPLAB it will Load the Software for ICD2 automatically.

    I had posted Everything which i know may be i am wrong in case then let me know i will improve it..

    PS:- About PCB software.. if know how to USE PROTEL if you want to learn that then i can help you please post your Doubts regarding Protel i will try my best to answer you.

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    [FONT=Arial, Arial, Helvetica]Good Programming Techniques.[/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica] [/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]Before we get to the nitty gritty of programming the PIC, I think now is a good time to explain some good programming techniques.[/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]If you type a ; (semicolon) anywhere in your program, the compiler will ignore anything after it until the carriage return. This means we can add comments in our program to remind us of what on earth we were doing in the first place. This is good practice, even for the simplest programs. You may well fully understand how your program works now, but in a few months time, you may be scratching your head. So, use comments wherever you can – there is no limit.[/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]Secondly, you can assign names to constants via registers (more about these later). It makes it far easier to read in English what you are writing to, or what the value is, rather than trying to think of what all these numbers mean. So, use real names, such as COUNT. Notice that I have put the name in capitals. This makes it stand out, and also means that (by convention) it is a constant value.[/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica] [/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]Thirdly, put some kind of header on your programs by using the semi-colons. An example is below:[/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Author : ;
    ; Date : ;
    ; Version: ;
    ; Title: ;
    ; ;
    ; Description: ;
    ; ;
    ; ;
    ; ;
    ; ;
    ; ;
    ; ;
    ; ;
    ; ;
    ; ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica] [/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]Notice that I have made a kind of box by using the semi-colons. This just makes it look neat.[/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT]​ [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica] [/FONT]
    [FONT=Arial, Arial, Helvetica] [/FONT] [FONT=Arial, Arial, Helvetica] [/FONT][FONT=Arial, Arial, Helvetica]Finally, try and document the program on paper as well. You can either use flow charts or algorithms or anything else you want. This will help you in writing your program, step by step.[/FONT]

  • Harshad Italiya

    @harshad-ukH5ww • May 1, 2009

    Just Got one good mini tutorial for 16F87X
    #-Link-Snipped-# it

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    Hello Ceans,

    before i post the Layout of ICD2 here i am stuck with one problem.
    MPLAB is not installing the bootloader file in 16F877A.
    i am using bl010101.hex as a bootloader... ICD661.hex is also suitable for same chip

    Godfather

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    i have to make this Urgent so need to find the Alternative of this Programmer

    😔

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    I can Replace my Circuit with This one? !!

    [​IMG]

  • Ashraf HZ

    @Ash • May 2, 2009

    GF, can you try WinPic800 to bootload the 16F?

  • Rifaa

    @rifaa-NaWZZ4 • May 2, 2009

    OK GF and ash ..seriously. I really donno what in god's name you two are talking about.
    I mean I can repair TV's ..hi fi's, DVD players and anything concerning power electronics, but i really have no idea when it comes to PIC's and boot load,ICD2 or what ever.
    So you have to be very specific if you are telling me about PIC's.
    And about the schema, do you want me to make a PCB from it or what. I mean I can vero board it, no biggie.
    As for the PIC I have a 16F628-041/P and max 232 ..no problem. So I am good to go with tht schema.
    Cheers
    Ps I comment on programmer I have on the other tread

  • Ashraf HZ

    @Ash • May 2, 2009

    Yeah, you can solder all the components together with the vero board. Don't forget to get a DB-9 connector and a serial cable for communicating between the PIC and computer.

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    ashGF, can you try WinPic800 to bootload the 16F?

    Nop I had not tried on that i had tried on MPLAB only. and now Shifted to The new circuit cause this is very urgent for me. i will work on older circuit later but i am sure i will run that PCB also..

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    RifaaOK GF and ash ..seriously. I really donno what in god's name you two are talking about.
    I mean I can repair TV's ..hi fi's, DVD players and anything concerning power electronics, but i really have no idea when it comes to PIC's and boot load,ICD2 or what ever.
    So you have to be very specific if you are telling me about PIC's.
    And about the schema, do you want me to make a PCB from it or what. I mean I can vero board it, no biggie.
    As for the PIC I have a 16F628-041/P and max 232 ..no problem. So I am good to go with tht schema.
    Cheers
    Ps I comment on programmer I have on the other tread


    So Rifaa you are also going to Make One?

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    @ ASH.. winpic800 compitible with 16F? on its Site there in no 16F in that List.!!

  • Ashraf HZ

    @Ash • May 2, 2009

    godfather@ ASH.. winpic800 compitible with 16F? on its Site there in no 16F in that List.!!

    I think you were looking at recently supported devices. The full list is here:

    #-Link-Snipped-#

    Don't worry, I've used it before. Works fine 😀

  • Harshad Italiya

    @harshad-ukH5ww • May 2, 2009

    Oh yes you are right.
    thanks for this link Ash.

    i am using ICD2 clone to load the bootloader in 16F877A.. so this winpic800 is compitible with that hardware or there is any specific Hardware required?

  • Ashraf HZ

    @Ash • May 3, 2009

    Ah, that I'm not sure. Give it a shot.

  • Rifaa

    @rifaa-NaWZZ4 • May 3, 2009

    Yeah GF. If I make one, then only I am improving my knowledge about the basic concepts of how it works.
    I would rather make one than buy one.
    I bought one because I cannot get help on this topic.
    I owe a lot to CE. I'll do my part to this community, and U can count on it CE's
    Thanks again to all

  • Rifaa

    @rifaa-NaWZZ4 • May 3, 2009

    One more Q? GF.
    Do I have to solder the PIC. Or can I use a ZIF socket.

  • Harshad Italiya

    @harshad-ukH5ww • May 3, 2009

    you can use ZIF socket buddy.. i am going for Lunch...i will answer your Question soon.

  • Rifaa

    @rifaa-NaWZZ4 • May 3, 2009

    So which means that we can replace with another PIC to programmer something else, if the ZIF socket is there.
    Still, I've been thinking, doesn't the programmer have a PIC to do all the work.
    See, this is what confuses me...
    At first ( few years back )when I thought of learning programing I researched a lot and found some shema's of programmers. I wanted to build one then, but the thing is every damn programmer has a PIC in it and what I have leaned is that, if a PIC is used, then it should be programmed to do whatever one want's.

    So the point is how the heck am I going to program the programmer in the first place, if I don't have a programmer. get my point....😕
    I mean, I need to have a programmer to built a programmer so that I can program the programmer in order to program other PIC's 😕
    Confused HUH!!!.

    This was my predicament.. and I cannot get any help from any one, my colleges who I used to work with are too proud to teach me anything, cause they have their Masters and PhD's and all, and I am just certificate holder...so they hesitated to tell me any thing, cause when it comes to field work and trouble shooting, none of them could beat me even slightly.
    My knowledge and skills on repairing consumer electronics and power electronics are far better than they ever hope to be, so they did not want me to know anything about programming and they call themselves my friends. the #@$@2 lot. Still I am proud of what I am, I have worked hard to earn my reputation here and I deserved more, but fate has a funny sense of irony. Well..that's that. past is history. I'm moving on, on my terms now, and I will learn one way or the other. Someday they will see too. and I guess I'll have CE to thank for this. hmmmm.

    So...without a programmer I was getting no where, until you gf, started this thread, and the best part was, it started when I got my hands on my very first programmer. The Willem PRO...😁. I am sooooooooooooo happy.

    Now what I thought was the PIC is the brain of the programmer.. well something like tht.
    I was wondering where is the brain of the programmer you showed GF

  • Ashraf HZ

    @Ash • May 3, 2009

    That was also a confusion I faced when I first started out with PICs. There are different types of programmers out there with multiple features and electrical characteristics. Some directly load the firmware (or bootloader) without additional frills, while others provide debugging options. Keeping that in mind, they also have different types of software that can be used. Some programmers use low voltages, while others use high (like 13V).

    One of the most simplest types of programmers is the JDM one. This is what I started out with anyway. Theres no PIC component in there (except the one you are trying to program). Below is a very popular one:
    #-Link-Snipped-#

    Then I moved on and bought a PicKit2 clone. So far its okay.

    The one GF is attempting to do is another type called ICD2. It is more reliable and stable compared to cheaper programmers (like JDM), I believe. And has a debugging feature 😀

    Once you have loaded the firmware on the PIC, you do not have to use the programmer again. You can directly load the HEX files via the TX/RX pins of the PIC, using RS232.

  • Harshad Italiya

    @harshad-ukH5ww • May 3, 2009

    Well first of sorry Rifaa that you are not getting much help from my side...

    See here i am going to share my knowledge about this Programmer may be i am wrong in some cases but here it is...

    The programmer which i am going to make is a ICD2.... and its heart is PIC16F876. yes you need one programmer first to load the bootloader in the PIC16F876. after that you have to connect that ICD2 clone with MPLAB via RS232 Cable that MPLAB will automatically Load the Operting System file in the 16F876 and after that your ICD2 Clone is ready and by using that you can programm the other PIC controller with 5 programming lines. MCLR,PGD,PGC,Vcc,GND...

    i hop you get the overview and functionality of the programmer which i am going to make..

    i had studied about your programmer it sounds good and universal also will get knowledge of that more when got some time.

    @ash... Thanks for your help

  • Harshad Italiya

    @harshad-ukH5ww • May 3, 2009

    as said by ASH some controller available which loads OS automatically with RX TX but here in our case first of all we have to load bootloader file must.

  • Rifaa

    @rifaa-NaWZZ4 • May 4, 2009

    Oh goody.. my willem is quite good u say, now that's nice to know.
    So I was right huh!.. I need a programmer to make a programmer to program programmable IC'S. ..KEEKKE here we go again.
    SO GF , do you suggest that I use a ZIF socket where the PIC should be, Just like to be sure of what I am doing. only that needs to be detachable. Any other pointers I should no about, cause I am done with the LCD's ( almost , I'll put a thread on it, it will be quite interesting ), and after that I'll just vero board the schema u gave.
    Thanks to you all for this opportunity

  • Harshad Italiya

    @harshad-ukH5ww • May 5, 2009

    Rifaa... the PIC16F876 shown here in Circuit diagram is Fixed if you place it in ZIF or Solder it no problem this is the Via IC means the Code which you want to load in your Target IC is connected at the target side and this 16F876 works as ICD2 and transfers that code to Target side so if you want to program other IC then just connect that at Connector... means here 16F876 is Fixed in which there is a ICD2 Clone Operating System.