Pic Microcontroller

What Is A Microcontroller

A microcontroller is an all in one electronic integrated circuit with built in processor memory and peripherals that is also re-programmable.

You may not be able to recognize the microcontroller as for cost savings its cheaper to build an ASIC (Application Specific Integrated Circuit). This is a custom chip designed only for the product which is mass produced in milliions making the cost of the device far cheaper than using an individual microcontroller.

Nevertheless each system is based on a microcontroller.

Electronic Circuit design has progressed from individual transistors which are based on silicon to placing thousands and then millions of transistors on a single silicon wafer. The transistors, arranged in the correct configuration, perform different functions such as time delays, boolean logic, memory etc.

7400 series logic

Still available today are the older 74 series devices. These are ICs encased in plastic with connection pins on the outside and each one performs a different well defined function.

By grouping these devices together you can make up circuits by connecting the pins of the device to pins of other devices. About 20 years ago this was the only way of making digital electronic systems and you would typically have racks of circuit boards each with 50 of these devices wired up.

More transistors

Of course the disadvantage of these racks of circuit boards is that once you have designed the board you can not change it so you had to be absolutely sure that the design was perfect. If it was not then you had to start over - and for a complex system that means spending money on a new circuit board and spending time re-designing it.

With the advance of manufacturing techniques more transistors can be put on the silicon wafer - and if you can get more transistors on a wafer there are two advantages.


Increased functionalty.
Higher speed.

Smaller transistors means smaller physical problems (capacitance slows down a devcie - so a smaller device has less) and they also use less current. Less current means less power and less power means less heat and less heat means that the device can operate faster.

Given enough transistors you can design a circuit (or Integrated Circuit - ICs) to perform virtually any function you can think and using a special form of transistor (flash memory) means that the device can store information for years - this memory is also re-programmable.

Processor

The next stage in development was creating the processor which is a specialised circuit in which the function of the device is not set at all. Instead the device is capable of performing different functions when it is given different inputs and not only that - it has a small amount of ram inside used for internal temporary storage (registers) - and this lets it remember a sequence of events.

When you combine this device with two types external memory (other ICs) you can make a system that can follow a defined sequence of events. By reading instructions from the memory (ROM) the processor knows what it should be doing as its next event sequence and it can store data in external RAM memory.


ROM - Read Only Memory (permament)
RAM - Random access memory (temporary - when power goes info is lost).

In addition the processor can read the state of input pins and set the state of output pins so it can react to the outside world e.g. turn on a light or read a key press.

You can see where this is going - it's a device that has re-programmable memory and has many of the building blocks (7400 series) although now greatly refined and adapted inside the device - it's the microcontroller.

Microcontrollers

A microcontroller is a specialized integrated circuit which combines a processor and external memory inside the silicon wafer itself. You now have a customizable device that you can change its function just by re-programming it.

In addition as microcontrollers have been refiined you will find devices that have many other peripherals inside them. Where once you had to buy a UART IC (an RS232 communication device - to talk to a PC) and place it on the processor bus in addition to the RAM and the ROM; this device is now part of the microcontroller itself.

Here are the internal peripherals of the 16F88 a modern PIC microcontroller - this is just an example there are many more microcontroller manufacturers e.g. Atmel, Motorola, Zilog.


RAM 386 Bytes.
ROM 4096 words.
EEPROM 256 Bytes.
I/O 16 pins.
Internal oscillator.
Timer 1.
Timer 2.
Timer 3.
USART. SSP - Synchronous Serial port I2C, SPI protocols.
CCP - Capture Compare PWM.
Analogue comparator 1.
Analogue comparator 2.
ADC multiplexed inputs from 7 pins.

This an 18 pin IC which is as big as some of the original 7400 devices but it can do much more that those single chips. For instance you can make the following types of projects using it:

Universal Infrared decoder/encoder.
Ultrasonic tape measure.
Frequency counter.
Metal detector.

PIC Microcontroller - PIC16F877A 

 The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction execution, 256 bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port.


Microchip PIC16F877A Microcontroller Features

High-Performance RISC CPULead-free; RoHS-compliantOperating speed: 20 MHz, 200 ns instruction cycleOperating voltage: 4.0-5.5VIndustrial temperature range (-40° to +85°C)15 Interrupt Sources35 single-word instructionsAll single-cycle instructions except for program branches (two-cycle)Special Microcontroller FeaturesFlash Memory: 14.3 Kbytes (8192 words)Data SRAM: 368 bytesData EEPROM: 256 bytesSelf-reprogrammable under software controlIn-Circuit Serial Programming via two pins (5V)Watchdog Timer with on-chip RC oscillatorProgrammable code protectionPower-saving Sleep modeSelectable oscillator optionsIn-Circuit Debug via two pins


Peripheral Features

33 I/O pins; 5 I/O portsTimer0: 8-bit timer/counter with 8-bit prescalerTimer1: 16-bit timer/counter with prescalerCan be incremented during Sleep via external crystal/clockTimer2: 8-bit timer/counter with 8-bit period register, prescaler and postscalerTwo Capture, Compare, PWM modules16-bit Capture input; max resolution 12.5 ns16-bit Compare; max resolution 200 ns10-bit PWMSynchronous Serial Port with two modes:SPI MasterI2C Master and SlaveUSART/SCI with 9-bit address detectionParallel Slave Port (PSP)8 bits wide with external RD, WR and CS controlsBrown-out detection circuitry for Brown-Out Reset
Analog Features10-bit, 8-channel A/D ConverterBrown-Out ResetAnalog Comparator module2 analog comparatorsProgrammable on-chip voltage reference moduleProgrammable input multiplexing from device inputs and internal VREFComparator outputs are externally accessible


Many times we have to write the code for handling interrupts in PIC microcontrollers (e-g when you need to control servo motor which has position encoder, with your PIC microcontroller). This post is a guide on this issue. I am going to explain interrupt handling with the example of 'Capturing external interrupts on RB0/INT pin'. You can download complete code and simulation in Proteus from the 'Downloads' section in the end of this post. The following circuit diagram made on Proteus7.6 shows the setup used to capture interrupt on RB0/INT pin.
Figure 1.   Posedge Interrupt Capturing on PIC16F877
In the figure above push button was pressed five times, that is why pin 19 and pin 21 are high ( PORTD displays how many interrupts have been captured). Whenever push button is pressed then an interrupt is triggered on the posedge of the signal (on pin RB0/INT). This interrupt is processed and PORTD output is incremented by one.

Here is the code to enable external posedge triggered interrupts on the RB0/INT pin.

Figure 2.   InitExternal_INT function code
You will need to call InitExternal_INT() from your main. When the interrupt occurs then ISR is executed, which is shown below.
 
Figure 3.   ISR code for external interrupt handling in PIC
Many PIC microcontrollers have the same interrupt handling function defined with the key word 'interrupt' for all the interrupt sources. That is why it is necessary to check the particular interrupt flag in the ISR to find out the actual source of the interrupt. For example in the code above a function named 'ISR' (stands for Interrupt Service Routine) is defined to handle all the interrupts. In this function firstly INTF flag is checked, (which is one if the external interrupt was triggered) if external interrupt was trigerred then PORTD value is incremented by one and interrupt is cleared.

The main function code is shown below.
Figure 4.   Main function for external interrupt capturing
Main function just enables the external interrupts on RB0/INT pin and then PORTD value is cleared to zero after setting PORTD direction to be output. After that main function just sits in the while loop for ever.

Using the code given in this post you will be able to easily handle interrupts in the PIC microcontroller. As an example, when you need to control servo motor (which has position encoder), then you can attach the output of position encoder on your PIC RB0/INT pin and capture interrupts on it. Whenever servo motor moves one position, then you will receive one interrupt. By incrementing a variable on each interrupt you can always keep track of servo motor position in real time.

You can leave your comments in the comment section below.

Downloads

The code was compiled in MPLAB v8.76 with HI-TECH C and simulation was made in Proteus v7.6.
To download code click here.
To download proteus simulation click here.

Comments

  1. Heya i'm for the first time here. I found this board and I find It really helpful & it helped me out much. I hope to provide something again and help others like you helped me.

    my blog post ... casino bonus

    ReplyDelete
  2. I'm not sure where you are getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this information for my mission.

    Review my web page ... casino bonuses no deposit

    ReplyDelete
  3. Nice blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make
    my blog shine. Please let me know where you got your design.
    Bless you

    Also visit my blog post :: sound system ()

    ReplyDelete
  4. Hi to every one, as I am in fact keen of reading this webpage's post to be updated regularly. It carries fastidious data.

    Feel free to surf to my web blog - car town trainer

    ReplyDelete
  5. Your website appears to be having some compatibilty issues in my internet explorer browser.
    The content seems to be running off the webpage pretty bad.
    If you want you can contact me at: christopher_post@inbox.

    com and I'll shoot you over a screenshot of the problem.

    Also visit my blog: appliance repairs [www.picowiki.com]

    ReplyDelete
  6. Hi! My name is Vanessa and I just desired to say your blog website is awesome!
    It's hilarious because I use to have a blogging site that virtually had an identical web address: http://www.blogger.com/comment.g?blogID=86324850310242427&postID=5197033507738150841 mine was only a few characters different. Nonetheless, I am a big fan of your web site and if you ever would like a guest post please make sure to email me at: vanessa.garnett@inbox.com. I love writing!

    Visit my webpage: emergency refrigerator repairs

    ReplyDelete
  7. Its not my first tіme to pay a νіsіt thiѕ ωeb sitе, i
    am broωsіng this web рage dailly and takе nicе infοгmatiоn fгοm
    here daily.

    Fеel freе to suгf to my sіte ::
    remedios para la impotencia

    ReplyDelete
  8. Hey there! I'm at work browsing your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the excellent work!

    Here is my web site; emergency refrigerator repairs

    ReplyDelete
  9. Hi there just happened upon your website from
    Google after I typed in, "Blogger: Tayyab Siddiqui" or perhaps something similar (can't quite remember exactly). Anyways, I'm
    grateful I found it because your content is exactly what
    I'm searching for (writing a college paper) and I hope you don't mind if I gather some material from here and I
    will of course credit you as the reference. Thank you very
    much.

    Here is my web page refrigerator parts and repair

    ReplyDelete
  10. Hey there! I realize this is somewhat off-topic
    however I needed to ask. Does running a well-established website
    like yours require a large amount of work? I'm completely new to running a blog but I do write in my diary daily. I'd like to start a blog so I can easily share my personal experience and thoughts online.
    Please let me know if you have any kind of suggestions or tips for new aspiring blog owners.
    Thankyou!

    Visit my page: emergency appliance repairs **

    ReplyDelete
  11. Whаt's up to every body, it's mу fігѕt ρаy а vіsit of thіѕ ωeb site;
    this weblog incluԁеs гemarκable аnd in fаct gοod infоrmatiоn іn fаѵoг οf reаdeгs.


    Αlso visit my web-site: voltage dependent resistor

    ReplyDelete
  12. Hello there! I know this is somewhat off topic but I was wondering which blog platform are you using for this site?
    I'm getting tired of Wordpress because I've had issues
    with hackers and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

    Here is my blog post: loan modification company ()

    ReplyDelete
  13. Usually I do not read article on blogs, but I would like to say that
    this write-up very forced me to take a look at and do
    so! Your writing style has been amazed me. Thank you,
    quite great post.

    Feel free to visit my webpage; casino bonus (exteen.com)

    ReplyDelete
  14. Your means of describing all in this piece of writing is in fact good, every
    one can without difficulty understand it, Thanks a
    lot.

    Feel free to visit my homepage bicycle computer (http://www.cemevi.net/)

    ReplyDelete
  15. Mу coder is trying to perѕuade me to move to .
    nеt from PHP. I havе always ԁisliked the іdea because of the сosts.
    But he's tryiong none the less. I've been using WordPress
    on numerous ωebsіtes for abοut a year and
    am nеrvous about swіtching to another platform.

    I have hеard excellent things abоut blogengine.
    nеt. Is there a way I cаn impoгt all my ωοrdpreѕѕ posts
    into іt? Any helρ would bе rеаlly aρpreсiated!


    my weblog; cheаp saіlboat onlinе ()

    ReplyDelete
  16. Hey there! Do you know if they make any plugins to help with SEO?
    I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good results.
    If you know of any please share. Appreciate it!

    Here is my web site jackpot 6000 (http://marshakec.momaroo.com/773080129/problems-at-the-reef-club-casino/)

    ReplyDelete
  17. My brother recommended I might like this web site. He used to be totally right.
    This submit actually made my day. You can not believe simply how much time I had spent for this information!
    Thank you!

    Feel free to surf to my web site; Las vegas Dentist

    ReplyDelete
  18. Simply desire to say your article is as amazing.
    The clearness on your submit is just nice and i
    can suppose you're an expert on this subject. Well with your permission allow me to take hold of your feed to keep up to date with imminent post. Thanks 1,000,000 and please continue the gratifying work.

    Here is my web site: jackpot 6000 (http://profitbusinessathome.net/NicholqvWillsonau)

    ReplyDelete
  19. I think this is one of the most vital info for me.
    And i'm glad reading your article. But want to remark on some general things, The site style is great, the articles is really great : D. Good job, cheers

    Visit my website :: mobile casino

    ReplyDelete
  20. If some one wants to be updated with most recent
    technologies then he must be pay a visit this web page and
    be up to date daily.

    Here is my site :: fullerton montessori school

    ReplyDelete
  21. WOW just what I was searching for. Came
    here by searching for master cleanse insider


    http://www.wildgrown.com/index.php/Ginseng-Forum/?
    do=profileinfo&func=myprofile

    my page http://nuvocleanseblog.com

    ReplyDelete
  22. Doh! I was domain shopping at namecheap.com and
    went to type in the domain name: http://www.
    blogger.com/comment.g?postID=5197033507738150841&blogID=86324850310242427 and guess who
    already acquired it? You did! lol j/k. I was about to buy this domain name but realized it was taken so I figured
    I'd come check it out. Good blog!

    my site :: refrigerator repair

    ReplyDelete
  23. Nice publish, that is specifically the data I was looking
    for. Are you currently likely to be masking this subject in greater depth quickly?

    Hope so! Thanks

    Also visit my page: weight loss before and after pictures women

    ReplyDelete
  24. Howdy! I am about to begin my own website and
    was wondering if you know where the best place to buy a blog url
    is? I am not even sure if that's what its called? (I'm new to this) I'm referring to "http://www.blogger.com/comment.g?postID=5197033507738150841&blogID=86324850310242427". Exactly how do I go about getting one of these for the website I'm creating?
    Thanks alot :)

    Here is my webpage 24 hour appliance repair ()

    ReplyDelete
  25. Hey! I was interested to know if setting up a blog
    website such your own: http://www.blogger.com/comment.g?

    postID=5197033507738150841&blogID=86324850310242427 is hard to do
    for unskilled people? I have been wanting to create my own blog for a while now but have been turned off mainly because I've always assumed it required tons of work. What do you think? Many thanks

    Also visit my blog post appliance repair company

    ReplyDelete
  26. Hey! This is my first visit to your blog!
    We are a team of volunteers and starting
    a new initiative in a community in the same niche. Your blog
    provided us useful information to work on.
    You have done a marvellous job!

    Also visit my web site ... appliance repairs

    ReplyDelete
  27. Hi there to all, the contents existing at this site are really
    remarkable for people knowledge, well, keep up the nice work fellows.


    Feel free to surf to my page - irvine kids dentist (benjaminharper.jimdo.com)

    ReplyDelete
  28. Hiya. I'm sorry to trouble you but I ran across your blog site and discovered you happen to be using the exact same template as me. The only issue is on my blog, I'm struggling to get the design and style looking like yours.
    Would you mind emailing me at: collette_sibley@web.de so I can get this figured out.

    By the way I've bookmarked your web-site: http://www.blogger.com/comment.g?postID=5197033507738150841&blogID=86324850310242427 and will certainly be visiting often. Thanks!!

    My weblog 24 hour appliance repair

    ReplyDelete
  29. Тhanks for finally talking abоut > "Pic Microcontroller" < Loved it!

    Review my website :: ρгoblema сon la ereccion

    ReplyDelete
  30. I blog often and I really appreciate your information.
    This great article has truly peaked my interest.

    I'm going to take a note of your website and keep checking for new details about once per week. I opted in for your RSS feed as well.

    my web page Extreme Gain ()

    ReplyDelete
  31. fantastic put up, very informative. I ponder why the
    opposite experts of this sector don't realize this. You must continue your writing. I am sure, you've a great readers' base already!

    Here is my page - cosmetic dentistry :: ::

    ReplyDelete
  32. I drop a leave a response whenever I especially enjoy a article on a website or I
    have something to valuable to contribute to the conversation.
    Usually it is triggered by the fire displayed in the article I looked at.

    And on this post "Pic Microcontroller". I was actually excited enough to post a thought ;-) I do have a couple of questions for
    you if you do not mind. Is it just me or do a few of these comments
    appear like they are written by brain dead visitors?
    :-P And, if you are writing at other online sites, I'd like to follow anything new you have to post. Would you make a list all of all your communal pages like your twitter feed, Facebook page or linkedin profile?

    Here is my site Jackpot 6000

    ReplyDelete

Post a Comment

Popular Posts