Beruflich Dokumente
Kultur Dokumente
ON MICRO CONTROLER
SUBMITTED IN THE PARTIAL FULFILLMENT FOR THE AWARD OF THE DEGREE OF BACHELOR OF TECHNOLOGY IN ELECTRONICS & COMMUNICATION
Submitted by: Payal Mittal (1808220) Submitted to: Electronics & Communication Department
(BATCH 2008-2010)
CERTIFICATE
ACKNOWLEDGEMENT
Perseverance, inspiration and motivation have always played a key role in any venture. It is not just the brain that matters most, but that which guides them: The character, the heart, generous qualities and progressive forces. What was conceived just as an idea materialized slowly into concrete facts? The metamorphosis took endless hours of toil, had its moments of frustration, but in the end everything seemed to have sense. At this level of understanding it is often difficult to understand the wide spectrum of knowledge without proper guidance & advice. Hence, I take this opportunity to express my heartfelt gratitude to respected Er. Anurag Goyal who had faith in me and allowed me to work on the PIC controller. And for his kind co-operation throughout the period of work undertaken, which has been instrumented in the success of my project and for providing me the technical knowledge and moral support to complete the work. I would also like to pay my sincere gratitude to respected Er. Parveen, Head of the department of Electronics, Haryana Engineering college, Jagadhri for providing me opportunity to move with such a big corporation. Last but not the least; I extend my gratitude to the Microsoft. It is only when you make a presentation, realize the importance of Microsoft Power Point and only when you put matter in order know the importance of Microsoft Word.
INDEX
Chapter 1 : Chapter 2 : Chapter 3 : Chapter 4 :
Introduction to Microcontroller Embedded System Microcontroller Microcontroller v/s Microprocessor Introduction to 16F877A PIC Microcontroller Architecture of 16F877A Special function registers Option registers Intcon Memory Memory organization Data Memory organization Data EEPROM and Flash Memory Circuit Implementation Counters Interrupts Power Supply MCLR Timers Timer 0 Module Timer 2 Module Light Emitting Diode Introducing the LED Resistor Seven segment display
LIST OF FIGURES
FIG. NO. 1. 2. 3. 4. 5. 6. 7. DESCRIPTION Pin diagram Memory organization Timer 0 module Timer 2 module LED Resistor Seven Segment Display
CHAPTER 1 INTRODUCTION
1.1
EMBEDDED SYSTEM
An Embedded System is a combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a specific function. A good example is the microwave oven. Almost every household has one, and tens of millions of them are used every day, but very few people realize that a processor and software are involved in the preparation of their lunch or dinner. This is in direct contrast to the personal computer in the family room. It too is comprised of computer hardware and software and mechanical components (disk drives, for example). However, a personal computer is not designed to perform a specific function. Rather, it is able to do many different things. Many people use the term general-purpose computer to make this distinction clear. As shipped, a general-purpose computer is a blank slate; the manufacturer does not know what the customer will do with it. One customer may use it for a network file server, another may use it exclusively for playing games, and a third may use it to write the next great American novel. Frequently, an embedded system is a component within some larger system. For example, modern cars and trucks contain many embedded systems. One embedded system controls the anti-lock brakes, another monitors and controls the vehicle's emissions, and a third displays information on the dashboard. In some cases, these embedded systems are connected by some sort of a communications network, but that is certainly not a requirement. At the possible risk of confusing you, it is important to point out that a general-purpose computer is itself made up of numerous embedded systems. For example, my computer consists of a keyboard, mouse, video card, modem, hard drive, floppy drive, and sound cardeach of which is an embedded system. Each of these devices contains a processor and software and is designed to perform a specific function. For example, the modem is designed to send and receive digital data over an analog telephone line. That's it. And all of the other devices can be summarized in a single sentence as well. If an embedded system is designed well, the existence of the processor and software could be completely unnoticed by a user of the device. Such is the case for a microwave oven, VCR, or alarm clock. In some cases, it would even be possible to build an equivalent device that does not contain the processor and software. This could be done by
replacing the combination with a custom integrated circuit that performs the same functions in hardware. However, a lot of flexibility is lost when a design is hard-coded in this way. It is much easier, and cheaper, to change a few lines of software than to redesign a piece of custom hardware.
1.2 MICROCONTROLLER
A microcontroller (or MCU) is a computer-on-a-chip used to control electronic devices. It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). A typical microcontroller contains all the memory and nterfaces needed for a simple application, whereas a general purpose microprocessor requires additional chips to provide these functions.
1.2.1 INTRODUCTION
Circumstances that we find ourselves in today in the field of microcontrollers had their beginnings in the development of technology of integrated circuits. This development has made it possible to store hundreds of thousands of transistors into one chip. That was a prerequisite for production of microprocessors , and the first computers were made by adding external peripherals such as memory, input-output lines, timers and other. Further increasing of the volume of the package resulted in creation of integrated circuits. These integrated circuits contained both processor and peripherals. That is how the first chip
1.2.2 HISTORY
it was year 1969, and a team of japanese engineers from the busicom company arrived to united states with a request that a few integrated circuits for calculators be made using their projects. the proposition was set to intel, and marcian hoff was responsible for the project. since he was the one who has had experience in working with a computer (pc) pdp8, it occured to him to suggest a fundamentally different solution instead of the suggested construction. this solution presumed that the function of the integrated circuit is determined by a program stored in it. that meant that configuration would be more simple, but that it would require far more memory than the project that was proposed by japanese engineers would require. after a while, though japanese engineers tried finding an easier solution, marcian's idea won, and the first microprocessor was born. in transforming an idea into a ready made product , frederico faggin was a major help to intel. he transferred to intel, and in only 9 months had succeeded in making a product from its first conception. intel obtained the rights to sell this integral block in 1971. First, they bought the license from the busicom company who had no idea what treasure they had. During that year, there appeared on the market a microprocessor called 4004. That was the first 4-bit microprocessor with the speed of 6 000 operations per second. Not long after that, American company CTC requested from INTEL and Texas Instruments to make an 8-bit microprocessor for use in terminals. Even though CTC gave up this idea in the end, Intel and Texas Instruments kept working on the microprocessor and in April of 1972, first 8-bit microprocessor appeard on the market under a name 8008. It was able to address 16Kb of memory, and it had 45 instructions and the speed of 300 000 operations per second. That microprocessor was the predecessor of all today's microprocessors. Intel kept their developments up in April of 1974, and they put on the market the 8-bit processor under a name 8080 which was able to address 64Kb of memory, and which had 75 instructions, and the price began at $360 microprocessors.
At the WESCON exhibit in United States in 1975, a critical event took place in the history of microprocessors. The MOS Technology announced it was marketing microprocessors 6501 and 6502 at $25 each, which buyers could purchase immediately. This was so sensational that many thought it was some kind of a scam, considering that competitors were selling 8080 and 6800 at $179 each. As an answer to its competitor, both Intel and Motorola lowered their prices on the first day of the exhibit down to $69.95 per microprocessor. Motorola quickly brought suit against MOS Technology and Chuck Peddle for copying the protected 6800. MOS Technology stopped making 6501, but kept producing 6502. The 6502 was a 8-bit microprocessor with 56 instructions and a capability of directly addressing 64Kb of memory. Due to low cost , 6502 becomes very popular, so it was installed into computers such as: KIM-1, Apple I, Apple II, Atari, Comodore, Acorn, Oric, Galeb, Orao, Ultra, and many others. Soon appeared several makers of 6502 (Rockwell, Sznertek, GTE, NCR, Ricoh, and Comodore takes over MOS Technology) which was at the time of its prosperity sold at a rate of 15 million processors a year!Others were not giving up though. Frederico Faggin leaves Intel, and starts his own Zilog Inc.In 1976 Zilog announced the Z80. During the making of this microprocessor, Faggin made a pivotal decision. Knowing that a great deal of programs have been already developed for 8080, Faggin realized that many would stay faithful to that microprocessor because of great expenditure which redoing of all of the programs would result in. Thus he decided that a new processor had to be compatible with 8080, or that it had to be capable of performing all of the programs which had already been written for 8080. Beside these characteristics, many new ones have been added, so that Z80 was a very powerful microprocessor in its time. It was able to address directly 64 Kb of memory, it had 176 instructions, a large number of registers, a built in option for refreshing the dynamic RAM memory, single-supply, greater speed of work etc. Z80 was a great success and everybody converted from 8080 to Z80. It could be said that Z80 was without a doubt commercially most successful 8-bit microprocessor of that time. Besides Zilog, other new manufacturers like Mostek, NEC, SHARP, and SGS also appeared. Z80 was the heart of many computers like Spectrum, Partner, TRS703, Z-3 .
In 1976, Intel came up with an improved version of 8-bit microprocessor named 8085. However, Z80 was so much better that Intel soon lost the battle. Altough a few more processors appeared on the market (6809, 2650, SC/MP etc.), everything was actually already decided. There weren't any more great improvements to make manufacturers convert to something new, so 6502 and Z80 along with 6800 remained as main representatives of the 8-bit microprocessors of that time.
2.1
came in mid 1990' s. A company named Microchip made its first simple microcontroller, which they called PIC. Originally this was developed as a supporting device for POP computers to control its peripheral devices, and therefore' named as PIC, Peripheral Interface Controller. Thus all the chips developed by Microchip have been named as a class by themselves and called PIC. Microchip itself does not use this term anymore to describe their microcontrollers, however use PIC as part of product name. they call their products MCU's. A large number of microcontroller designs are available from microchip. Depending upon the architecture, memory layout and processing power. They have been classified as low range, mid range, high range and now digital signal processing microcontrollers. The beauty of these devices is their easy availability, low cost and easy programming and handling. This has made PIC microcontrollers as the apple of hobbyists and students eyes. We shall be talking about mid-range PIC microcontrollers, and use PIC16F877A rototype in this manual to explore them. Knowledge gained by learning and exploring one microcontroller is almost 90% applicable on other microcontrollers of the same family The only difference is in availability of resources on different chips. General organization of PIC Microcontrollers. Although we shall talk in detail on various aspect of these chips in relevant sections, here I would like to give a brief introduction on the overall business involved. Fig shows the pin out details of a very popular 40 pin In PIC microcontroller, PIC16F877, as you can see that each pin has been assigned a number of functions. Sometimes two and sometimes three. This situation is very common in microcontroller, as there is always more which your microcontroller
Can offer, yet the number of pins on a given package is limited. In a given circuit/application a pin is usually tied to a specific job, and all functionality q a pin is usually not required, however you make opt to use the specific pin your own way. The specific function of a pin is selected by configuring various bits of internal registers. The number and names of these special function registers (SFRs) vary from device to device as some devices have limited functionality while others have more. Nevertheless if we are talking about a function which is present in both devices, its SFR will be same. The selection and settings of these SFR's is the key to successful programming. It is therefore mandatory to go through the data sheets of the device before starting a project. Second important thing to know is that the devices with same number of R microchip), are all pin-compatible. Which means if you design a project four Pin PIC microcontrol1er, and later want to replace the chip with another 40 pin PIC microcontroller are all compatible. It is also good to know that a pin labeled as lets say RBO is plotted, on pin 33 of PIC l6F877, but the same pin is available on pin 6 in 18 pin PIC1F628 the pins are functionally same, as long as their names are same. So if you develop all a project while experimenting on. 18F452 using pin RBO, after successful testing you want to
transport the project to an 18 pm device, which also has RBO on It, apart form pin number on package, and recompiling the program, you don have to bother much about anything else.
known also as the prescaler), the external INT interrupt, TMR0 and the weak pull-ups on. PORTB.
CHAPTER 4 MEMORY
Fig.-
Memory organization
The PIC16F87XA devices have a 13-bit program counter capable of addressing an 8K word x 14 bit program memory space. The PIC16F876A/877A devices have 8K words x 14 bits of Flash program memory, while PIC16F873A/874A devices have 4K words x 14 bits. Accessing a location above the physically implemented address will cause a wraparound. The Reset vector is at 0000h and the interrupt vector is at 0004h.
The lower locations of each bank are reserved for the Special Function Registers. Above the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.
5.1 COUNTERS
If a timer is supplied with pulses over the microcontroller input pin then it turns into a counter, clearly, it is about the same electronic circuit. The only difference is that in this case pulses to be counted come through the ports and their duration (width) is mostly not defined. That is why they cannot be used for time measurement, but can be used to measure anything else: products on an assembly line, number of axis rotation, passengers etc. (depending on sensor in use).
Watchdog Timer
As name itself indicates a lot about its purpose. Watchdog Timer is a timer connected to a completely separate RC oscillator within the microcontroller. If the watchdog timer is enabled, every time it counts up to end, the microcontroller reset occurs and program execution starts from the first instruction. The point is to prevent this from happening by using a specific command. The whole idea is based on the fact that every program is executed in several longer or shorter loops.
If instructions which reset the watchdog timer are set on the appropriate program locations, besides commands being regularly executed, then the operation of watchdog timer will not affect program execution. If for any reason (usually electrical noises in industry), the program counter "gets stuck" on some memory location from which there is no return, the watchdog will .not be cleared and there registers value being constantly incremented will reach the maximum! Reset occurs .
5.2 INTERRUPTS
The subject of interrupts is probably' be the longest and most difficult to go through. There is no easy way of explaining interrupts, but hopefully by the end of this section you will be able to implement interrul1t into your own programs. We have split the section into two parts. This is to help break the subjects up, and to give you, a break. So what is an interrupt? Well, as the name suggest an interrupt is a process or a signal that stops a microprocessor/microcontroller. What it is doing so that something else can happen. Let me give you an every day example. at home, chatting to someone. Suddenly the telephone rings. You stop chatting and pick up the telephone to speak to the caller. When you have finished your telephone conversation, you go back to chatting to the person before telephone rang. You can think of the main routine as you chatting to person before the telephone ringing causes you to interrupt your chatting, and the interrupt routine is the process of talking on the telephone. When the telephone conversation has ended, you then back to your main routine of chatting. This example is exactly how an interrupt ca~ processor to act. The main program is running, performing some function in a circuit, but when an interrupt occurs the main program halts while another routine is carried out. When this routine finishes, the processor goes back to the main routine again. The PIC has 4 sources of interrupt. They can be split into two groups. Two are sources of interrupts that can be applied externally to the PIC, while the other two are internal processes. We are going to explain the two external ones here. The other two will be explained in timers and storing data. If you look at the pin-out of the PIC, you will see that pin 33 shows it is RBO/INT. Now, RBO is obviously Port B bit O. The INT symbolizes that it can also be configures as an external interrupt pin. Also, Port B bits 4 to 7 can also be used for interrupts. Before we can use the INT or other Port B pins, we need to do two things. First we need to tell the PIC that we are going to use interrupts. Secondly, we need to specify which port B pin we will be using as an interrupt and not as an I/O pin.
Inside the PIC there is a register called iNTCON, and is at address 0Bh. Within this register there are 8 bits that can be enabled or disabled. Bit 7 of INTCON is called GIE. This is the Global Interrupt Enable. Setting this to I tells the PIC that we are going to use an interrupt. Bit 4 of INTCON is called INTE, which means interrupt Enable. Setting this bit to I tells the PIC that RBO will be an interrupt pin. Setting bit 3, called RBIE, tells the PIC that we will be using Port B bits 4 to 7. Now the PIC knows when this pin goes high or low, it will need to stop what it's doing and get on with an interrupt routine. Now, we need to tell . IC whether the interrupt is going to be on the rising edge (OV to +5V) or the falling edge (+5Vto 0V) transition of the signal. In other words, do we want the PIC to interrupt when the signal goes from low to high, or from high to low. By default, this is set up to be on the rising edge. The edge 'triggering' is set up in another register called the OPTION register, at address 81 h. The bit we are interested in is bit 6, which is called INTEDG. Setting this to 1 will cause the PIC to interrupt on the rising edge (default state) and setting it because the PIC to interrupt on the falling edge. If you' want the PIC to trigger o~ the edge, then you don't need to do anything to this bit. Ok, so now we have told the PIC which pin is going to be the interrupt, and on which edge to trigger, what happens in the program and the PIC when interrupt occurs? Two things happen. First, a 'flag' is set. This tells the internal processor of the PIC that an interrupt has occurred. Secondly, the program counter which points to a particular address within the PIC. Let's quickly look at each of these separately.
Interrupt Flag
In our INTCON register, bit 1 is the interrupt flag, called INTF. Now when any interrupt occurs, this flag will be set to 1 while there isn't an interrupt, the flag is set to O. And that is all it does. Now you are probably thinking 'what is the point? Well, while this flag is set to the PIC cannot, and. will ~, pond to any other interrupt. So, let say that we use an interrupt. The flag will be 1, and the PIC will go to our routine for processing the interrupt. If this flag was not set to 1, and the PIC was allowed to keep responding to the interrupt, then continually pulsing the pin will keep the PIC going back to the start of our interruption routine will never finishing it. Going back to my example of telephone, it's like
picking up the telephone, and Just as soon as you start to speak It starts ringing again because someone else want to talk to you. It is far better to finish one conversation, then pick up the phone again to talk to the second person. There is a slight drawback to this flag. Although the PIC automatically sets this flag to 1; it doesn't set it back to 0! That ,task has to be done by the programmer - i.e. you. This is easily done, as We are sure you can guess, and has to be done after the PIC has executed the interrupt routine.
On every PIC microcontroller you will find a pin labeled as MCLR. This pin has two basic functions. It is used to reset the microcontroller, like soft boot. As well as to put the microcontroller into programming mode. The MCLR pin when connected to ground, will reset the microcontroller, and keep it in reset the microcontroller state, till the ground connection is released. After that the microcontroller will have all its RAM reset, and program execution will begin, just like the system has been just powered on. A 1OK pull up resistor is usually connected with the pin to keep it high when reset switch is released. The same pin will also work as program mode pin. When a new software is to be downloaded into the microchip by your programming device. This can be done right in your circuit, or by taking the IC out of circuit and putting it into the IC socket on your programmer. We shall talk more about this in section on programming.
CHAPTER 6 TIMERS
cleared in software by the Timer0 module Interrupt Service Routine before re-enabling this interrupt. The TMR0 interrupt cannot awaken the processor from Sleep since the timer is shut-off during Sleep.
6.2 TIMER2 MODULE Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the PWM time base for the PWM mode of the CCP module(s). The TMR2 register is readable and writable and is cleared on any device Reset. The input clock (FOSC/4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits T2CKPS1:T2CKPS0 (T2CON<1:0>). The Timer2 module has an 8-bit period register, PR2. Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next increment cycle. PR2 is a readable and writable register. The PR2 register is initialized to FFh upon Reset. The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2 interrupt (latched in flag bit, TMR2IF (PIR1<1>)). Timer2 can be shut-
off by clearing control bit, TMR2ON (T2CON<2>), to minimize power consumption. Register 7-1 shows the Timer2 Control register. Additional information on timer modules is available in the PICmicro Mid-Range MCU Family Reference Manual (DS33023).
The prescaler and postscaler counters are cleared when any of the following occurs: a write to the TMR2 register a write to the T2CON register any device Reset (POR, MCLR Reset, WDT Reset or BOR TMR2 is not cleared when T2CON is written. 7.2 Output of TMR2 The output of TMR2 (before the postscaler) is fed to the SSP module, which optionally uses it to generate the shift clock.
Fig. shows an LEDs schematic symbol and part drawing. An LED has two terminals. One is called the anode, and the other is called the cathode. In this activity, you will have to build the LED into a circuit, paying attention to make sure the leads connected to the anode and cathode are connected to the circuit properly. On the part drawing, the anode lead is labeled with the plus-sign (+). On the schematic symbol, the anode is the wide part of the triangle. In the part drawing, the cathode lead is the unlabeled pin, and on the schematic symbol, the cathode is the line across the point of the triangle.
each LED circuit to make sure it works, you can be more confident that it will work when you connect it to a BASIC Stamp.
Resistors like the ones we are using in this activity have colored stripes that tell you what their resistance values are. There is a different color combination for each resistance value. For example, the color code for the 470 resistor is yellow-violet-brown. There may be a fourth stripe that indicates the resistors tolerance. Tolerance is measured in percent, and it tells how far off the parts true resistance might be from the labeled resistance. The fourth stripe could be gold (5%), silver (10%) or no stripe (20%). For the activities in this book, a resistors tolerance does not matter, but its value does. Each color
bar that tells you the resistors value corresponds to a digit, and these colors/digits are listed in Table Figure shows how to use each color bar with the table to determine the value of a resistor.
Here is an example that shows how Table and Figure can be used to figure out a resistor value by proving that yellow-violet-brown is really 470 :
Figure shows a schematic of the LEDs inside the 7-segment LED display. Each LED anode is connected to an individual pin. All the cathodes are connected together by wire inside the part. Because all the cathodes share a common connection, the 7-segment LED display can be called a common cathode display. By connecting either pin 3 or pin 8 of the part to Vss, you will connect all the LED cathodes to Vss.
CONCLUSION
I Would Like To Say That I Was Given A Great Chance To Study, Understand And Learn About The Embedded Systems. and got a great opportunity to learn about a industrial controller (PIC ) ,which is massively used all over the world on an average of about 69 %.so , would like to thank my college to include this training as a part of studies, Apart from the great chance to develop it also act as a great source of inspiration and Motivation for all of us inside and out
REFERENCES