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.
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.
You will need to call InitExternal_INT() from your main. When the interrupt occurs then ISR is executed, which is shown below.
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.
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.
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
How to handle interrupts in PIC microcontroller ?
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 |
Here is the code to enable external posedge triggered interrupts on the RB0/INT pin.
Figure 2. InitExternal_INT function code |
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 |
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
To download code click here.
To download proteus simulation click here.
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.
ReplyDeletemy blog post ... casino bonus
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.
ReplyDeleteReview my web page ... casino bonuses no deposit
Nice blog! Is your theme custom made or did you download it from somewhere?
ReplyDeleteA 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 ()
Hi to every one, as I am in fact keen of reading this webpage's post to be updated regularly. It carries fastidious data.
ReplyDeleteFeel free to surf to my web blog - car town trainer
Your website appears to be having some compatibilty issues in my internet explorer browser.
ReplyDeleteThe 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]
Hi! My name is Vanessa and I just desired to say your blog website is awesome!
ReplyDeleteIt'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
Its not my first tіme to pay a νіsіt thiѕ ωeb sitе, i
ReplyDeleteam 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
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!
ReplyDeleteHere is my web site; emergency refrigerator repairs
Hi there just happened upon your website from
ReplyDeleteGoogle 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
Hey there! I realize this is somewhat off-topic
ReplyDeletehowever 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 **
Whаt's up to every body, it's mу fігѕt ρаy а vіsit of thіѕ ωeb site;
ReplyDeletethis 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
Hello there! I know this is somewhat off topic but I was wondering which blog platform are you using for this site?
ReplyDeleteI'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 ()
Usually I do not read article on blogs, but I would like to say that
ReplyDeletethis 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)
Your means of describing all in this piece of writing is in fact good, every
ReplyDeleteone can without difficulty understand it, Thanks a
lot.
Feel free to visit my homepage bicycle computer (http://www.cemevi.net/)
Mу coder is trying to perѕuade me to move to .
ReplyDeletenе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е ()
Hey there! Do you know if they make any plugins to help with SEO?
ReplyDeleteI'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/)
My brother recommended I might like this web site. He used to be totally right.
ReplyDeleteThis 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
Simply desire to say your article is as amazing.
ReplyDeleteThe 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)
I think this is one of the most vital info for me.
ReplyDeleteAnd 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
If some one wants to be updated with most recent
ReplyDeletetechnologies then he must be pay a visit this web page and
be up to date daily.
Here is my site :: fullerton montessori school
WOW just what I was searching for. Came
ReplyDeletehere by searching for master cleanse insider
http://www.wildgrown.com/index.php/Ginseng-Forum/?
do=profileinfo&func=myprofile
my page http://nuvocleanseblog.com
Doh! I was domain shopping at namecheap.com and
ReplyDeletewent 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
Nice publish, that is specifically the data I was looking
ReplyDeletefor. 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
Howdy! I am about to begin my own website and
ReplyDeletewas 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 ()
Hey! I was interested to know if setting up a blog
ReplyDeletewebsite 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
Hey! This is my first visit to your blog!
ReplyDeleteWe 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
Hi there to all, the contents existing at this site are really
ReplyDeleteremarkable for people knowledge, well, keep up the nice work fellows.
Feel free to surf to my page - irvine kids dentist (benjaminharper.jimdo.com)
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.
ReplyDeleteWould 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
Тhanks for finally talking abоut > "Pic Microcontroller" < Loved it!
ReplyDeleteReview my website :: ρгoblema сon la ereccion
I blog often and I really appreciate your information.
ReplyDeleteThis 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 ()
fantastic put up, very informative. I ponder why the
ReplyDeleteopposite 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 :: ::
I drop a leave a response whenever I especially enjoy a article on a website or I
ReplyDeletehave 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