Saturday, June 6, 2009
How Microcontrollers Work
Microcontrollers are hidden inside a surprising number of products these days. If your microwave oven has an LED or LCD screen and a keypad, it contains a microcontroller. All modern automobiles contain at least one microcontroller, and can have as many as six or seven: The engine is controlled by a microcontroller, as are the anti-lock brakes, the cruise control and so on. Any device that has a remote control almost certainly contains a microcontroller: TVs, VCRs and high-end stereo systems all fall into this category. Nice SLR and digital cameras, cell phones, camcorders, answering machines, laser printers, telephones (the ones with caller ID, 20-number memory, etc.), pagers, and feature-laden refrigerators, dishwashers, washers and dryers (the ones with displays and keypads)... You get the idea. Basically, any product or device that interacts with its user has a microcontroller buried inside.
In this article, we will look at microcontrollers so that you can understand what they are and how they work. Then we will go one step further and discuss how you can start working with microcontrollers yourself -- we will create a digital clock with a microcontroller! We will also build a digital thermometer. In the process, you will learn an awful lot about how microcontrollers are
PIC Programming With the Basics - Article 2
This is the second article of this tutorial series. Up to now, we have already finished basic arrangements of the project, as well as the coding. (We will be dealing about the coding in a separate article more deeply. Until we will use the previous coding part) now we have to do the compiling pert and the simulating part.
Step 1: After you have finished the coding part, we have to compile and see whether there are errors or not. For that you have to press the build project button (ctrl+F9).
The button is displayed in the picture. It will be compiled automatically when you press the button.
Build the Project
Then you have to wait until you get the result.
Step2: If the project compiled successfully, it will be displayed as in the above picture. If it wasn't there should be a problem some where of your project. Most probably in the coding. As you may have forgotten to put a semicolon or may be a wrong code. (We will discuss about these things later.)
If so you have to correct those errors until you are getting the successfully compiled programme. If so, now we have finished our first project. All we have to do is, run the project & get the out put.
Step3: We are going to use the Proteus 7 Software for this task. Just open the software. You will be given an interface as below.
Now you need to pick the devices to run the pragramme. Just click the pick button there and get the needed devices.
Step4: Pick a pic16f84, LogicProbe (Active) to see the out put. You can just type the devices you need to get, and then they will be appearing. Then just double click on top of them to get them in to your devices list. Finally just click "ok".
Step5: Now you have to arrange the devices as a circuit. Just click on the top of the name of the device (Example: pic16f84), and then place it on the right hand side area. Finally it should look like this.
Step6: Finally you need to load the ".hex" file in to your pic-microcontroller. For that, just double click on the top of the pic. Then a dialog box will be appearing.
Loading the ".hex" file
Set the clock frequency as 4MHz.As we made it to 4, when we were starting our programme.
Ok, that's all. Just click the OK button. Then our target is achieved. Just click the Play button at the bottom of the page. Then you can see the whole PortB of the pic is blinking. Although we have used only one logic state, whole the port should blink.
Anyway that's the end of the first task. Follow the other articles, if you wish to follow the other techniques too.
Thanks. Your Comments are highly appreciated. So please don't hesitate to post your comments.
Visit http://www.picbestsite.com for more details.Learn PIC programming from the basics.Figures were used frequently to demonstrate the facts easily.Download the needed software, materials freely. visit http://www.picbestsite.com
Article Source: http://EzineArticles.com/?expert=Kamal_Warna_Dayananda
PIC Programming With the Basics - Article 1 (Assembly)
This article will helps you to develop the knowledge of your Assembly language, which is used to programme a pic. Example programmes, projects would be covered in the next articles.
PIC (16f) has only 35 instructions.35 means not that much. Every specific instruction would be done a specific task. The whole article is reserved to understand the tasks of the each and every instruction.
Notes!
Some PICs have slightly different instruction sets, but if you know the basics, you'll be able to handle the differences with just a little study.
Here there are some of the instruction were discriped. Take a look at them. We will use these instructions little later when we get in to, tutorials of Assembly language.
MOVLW
Example: MOVLW 07
Side effects: none
The W register is central to most programs. This instruction moves a constant into the W register.
MOVF, MOVWF
Examples:
MOVF temp,W
MOVF temp,F
MOVWF temp
Side effects: Sets or clears Z flag (MOVF); none (MOVWF)
These instructions allow you to move data between registers and the W register. The first example moves the value in register temp into W. The third example moves W into temp. The second example moves the value of temp into temp. At first, that seems pointless, but it sets the Z condition flags without disturbing anything else, so it is useful for conditional jumps. If the number moved is 0, the Z flag is set. Otherwise it is cleared.
While you can use a number for a register is more common & easy to name them using EQU.
For example:
temp equ 0×70
movlw 0×10
movwf temp
ADDWF, ANDWF, IORWF, SUBWF, XORWF
Example:
ADDWF temp,W
XORWF x,F
These instructions do the specified operation on the W register and another register of your choice. Add and subtract work as you'd expect. The logical AND, IOR (inclusive OR) and XOR functions are the classic boolean logic primitives.
The result can be placed in the W register or back in the original register as you wish. For example:
MOVLW 1 ; put 1 in W
ADDWF temp,F ; add 1 to temp, store in temp
; w still equals 1 here
ADDWF x,W ; W=x+W, x is unchanged
The subtraction operation always computes F-W, so be careful that you don't mean W-F. So if W contains 3 and x contains 10, performing a subtraction will result in 7.
To compute the two's compliment of a negative number, write the magnitude as a binary number. So for 7, we have 00000111. Then invert all the bits (11111000) and add 1 (11111001). You can easily reverse the process, so if I tell you the subtraction yields 0xF9, you can write it as binary (11111001), subtract 1 (11111000) and then invert the bits (00000111) to know that it means -7.
All the instructions in this section set the Z flag if their result is zero. Otherwise, the Z flag is cleared.
ADDLW, ANDLW, IORLW, SUBLW, XORLW
Example:
ADDLW .30
XORLW 0x80
These instruction act just like the normal add, subtract, and, inclusive or, and exclusive or instructions except they operate on a literal.
So:
ADDLW 2
adds 2 to W (and, of course, leaves the result in W). All the flags are modified just as they are in the register-based versions of these instructions (see above). The subtract instruction computes literal-W which is often confusing. So instead of writing:
SUBLW 2 ; computes 2-W
You probably meant to write:
ADDLW -2 ; This is probably what you really want
CLRF, CLRW
Example:
CLRF temp
CLRW
Side effect: Sets the Z flag to 1
It is a very common operation to load a zero into a register and this instruction can do that in one step. The CLRW instruction clears W, which is odd since MOVLW 0 will do this also
INCF, DECF
Example:
INCF temp,W
DECF x,F
Another common operation is to add or subtract 1 from a register. These instructions do that (INCF is +1; DECF is -1).
INCFSZ, DECFSZ
Example:
INCFSZ temp,W
DECFSZ x,F
These instructions are similar to INCF and DECF. They add or subtract one from the indicated register and store the result as directed. However, these instructions don't set the Z flag. Instead, if the result is zero, they skip the next instruction. This is useful, of course, for loops. Here's an example:
CLRF y
MOVLW .10 ;
MOVWF i ; i=10
MOVF x,W ; W=X
LOOP: ADDWF y,F ; Y=Y+X
DECFSZ i,F
GOTO LOOP
; Leave here with the answer in y
RLF, RRF
Example:
RLF temp,F
These instructions move the bits in the register left by one bit (RLF) or right (RRF).
This is often useful to manipulate bits, but there is another interesting property: shifting left multiplies a number by 2 and shifting right divides by 2! You can often combine this with adding to get easy multiplications. For example, suppose you want to compute y=10*x. Well, that is the same as y=8*x+2*x, right? So try this:
BCF status,C ; C=0
RLF x,F ; X=2*X
BCF status,C
RLF x,W ; W=2*X (so 4*X)
MOVWF temp
BCF status,C
RLF temp,W ; W=2*X (so 8*X)
ADDWF x,W ; W=8X+2X = 10X
MOVWF y
BCF, BSF
Example:
BCF status,Z
These instructions clear (BCF) or set (BSF) the indicated bit in a register. The bit may have a name (like Z) or you can use a number from 0 to 7 (0 is the least significant bit and 7 is the most significant). Sometimes you can use these to save a few instructions. For example, suppose you had written:
MOVLW 0x7F
ANDWF temp,F
You could replace this with a single BCF temp,7 instruction. Not only is this faster and takes less space, but it doesn't destroy the W register either!
GOTO
Example:
GOTO main
As you'd expect, the GOTO instruction forces your program to resume execution at the label you indicate. The instruction only holds an 11 bit address, so the top bits of the new program counter come from the PCLATH register.
RETLW
Example:
RETLW .99
RETLW is exactly like RETURN except that it loads a literal value into the W register before it returns.
RETFIE
Example:
RETFIE
This will Sets GIE
RETFIE is exactly like a return, but it also sets the global interrupt enable (GIE). When a hardware interrupt occurs, it clears GIE and executes what amounts to a CALL instruction. Using RETFIE allows you to enable interrupts and return to the main program all in one step. If you don't want interrupts enabled again, just execute a RETURN instead.
BTFSC, BTFSS
Example:
BTFSS temp,7
When you want to perform a conditional jump, you need one of these instructions. They test a bit and skip the next instruction if the bit is set (BTFSS) or clear (BTFSC). Most often the next instruction is a GOTO or a CALL, but it could be any single instruction. For example, this code tests temp to see if it is zero. If it is, it loads temp with 0×80. Otherwise, temp is unchanged:
MOVF temp,F ; set Z flag, no data really moved
BTFSC status,Z ; skip if not zero
BSF temp,7 ; since temp was 0, now it is 0x80!
CLRWDT
Example:
CLRWDT
This instruction informs the watchdog timer that your program is still executing.
***********************************************************
I know that the above description will not be helpful to you to carry on. We have to have the practical experience. So we will do some tutorials, based on Assembly language in future. Stay with us.
If there are any questions, feel free to ask.
Thanks (Admin).
Visit http://www.picbestsite.com for more details. Learn PIC programming from the basics.Figures were used frequently to demonstrate the facts easily. Download the needed software, materials freely. visit http://www.picbestsite.com
Article Source: http://EzineArticles.com/?expert=Kamal_Warna_Dayananda
Is the PIC 16F84 Dead? - The Most Popular Microcontroller Of All Time
Is the 16F84 too old for your electronic projects?
If you don't know what a 16F84 is then you have never heard of Microchip(R) - a company that creates powerful stand alone microcontrollers. A microcontroller is simply a very small computer but unlike standard computing systems everything is contained within the device itself. There are no external peripherals such as RAM, EPROM, I/O devices.
If you are looking for an easy way to create your own projects then microcontrollers fit the bill because they:
- Are very Small (some have 8 pins and even smaller have 5).
- Have many internal peripherals.
- Are based on reprogrammable internal memory
- Have built in timers.
- Have internal RAM.
In short they are ideal for controlling your projects -- all you have to do is program them.
This is one of the spectacular advantages over doing discrete designs since if you make a mistake in a discrete design you will have to debug and re-wire. With a microcontroller you can just re-program the device in circuit (having simulated the code to figure out the mistake first).
Even better is the fact that you can make advanced projects, because internally the peripherals operate quite fast e.g. you could create a 50MHz frequency counter using no external components (except a display).
Languages
In fact you can program them in many different languages but the most popular is machine code. The reason for it's popularity is the fact that MicroChip(R) created all the tools necessary for development of a machine code program for free so you will find many many examples of assembler code on the internet.
Personally I don't like machine coding in assembler (although I can use it if needed e.g. for speed) because it takes a huge amount of time compared to using a high level language. In fact I would say it takes 10 times as long with assembler. Also assembler is a totally unstructured language; meaning that it is very hard to maintain i.e. if you want to add a module then you probably have to review the whole of the code whereas with a high level language areas of code are protected saving you from making mistakes.
Microchip has released many hundreds of different devices (now vastly improved over the 16F84) but the fundamental operation of each one is based on the original design and even if you only studied the original 16F84 (OK there was a 16C84) you would have a pretty good idea of how all of the range of devices work.
That is the great power of the MicroChip(R) devices i.e. you learn something using one device and you are adding to your knowledge for the whole range - for instance to program a 12F675, 16F84, 16F88 or 16F877 you need to know only about ICSP because that interface is shared across the whole range. This means your learning curve is greatly reduced.
Of course there are some specialized peripherals that are for professional developers such as driving the pins of a dedicated LCD but you only need to concentrate on the standard peripherals (good examples are in the 12F675, 16F88, 16F628 and 16F877).
Peripherals
In fact there are about 15 standard internal peripherals for the modern (16F range) device whereas the 16F84 has only one.
This is why I believe that the 16F84 has had a good running but it's now time to say goodbye to it. Other reasons for this are that it has a quarter the memory size of a 16F88 and now costs about 5 times as much.
Note The 16F88 and 16F628 borrow heavily from the 16F84 even having the same pinout so you won't have any trouble if you are already used to a 16F84.
Summary
The 16F84 is probably too old for serious design because there are newer (backwards compatible) devices that will allow you to create far more capable projects.
John Main's website provides microcontroller resources and free projects which are fully documented and include schematics and source code.
You can find example of a 50MHz Seven segment here: Frequency counter circuit. This uses a 16F877 as the microcontroller.
Vist this site for more: http://www.best-microcontroller-projects.com
Article Source: http://EzineArticles.com/?expert=John_Main
What Is A Microcontroller
Each of these systems will use a microcontroller as their main control unit:
- Car lock remote key fob.
- TV Remote control.
- Security system.
- Electronic safe.
- Car anti lock braking system.
- Satelite decoder.
- DVD player.
- Toaster.
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.
Note: All of these projects can be made using the same device because you can re-program the microcontroller to do a different job.
You can find more information here: microcontroller information and how to build a website that gets the click.
Copyright © John Main 2006 Free to distribute if the article is kept complete. http://www.best-microcontroller-projects.com Article Source: http://EzineArticles.com/?expert=John_Main |