21-10-2016, 11:54 AM
1460308586-PICMICROCONTROLLER.doc (Size: 296 KB / Downloads: 2)
PIC
The microcontroller that has been used for this project is from PIC series. PIC microcontroller is the first RISC based microcontroller fabricated in CMOS (complimentary metal oxide semiconductor) that uses separate bus for instruction and data allowing simultaneous access of program and data memory.
The main advantage of CMOS and RISC combination is low power consumption resulting in a very small chip size with a small pin count. The main advantage of CMOS is that it has immunity to noise than other fabrication techniques.
Various microcontrollers offer different kinds of memories. EEPROM, EPROM, FLASH etc. are some of the memories of which FLASH is the most recently developed. Technology that is used in pic16F877 is flash technology, so that data is retained even when the power is switched off. Easy Programming and Erasing are other features of PIC 16F877.
CORE FEATURES:
• High-performance RISC CPU
• Only 35 single word instructions to learn
• All single cycle instructions except for program branches which are two cycle
• Operating speed: DC - 20 MHz clock input
DC - 200 ns instruction cycle
• Up to 8K x 14 words of Flash Program Memory,
Up to 368 x 8 bytes of Data Memory (RAM)
Up to 256 x 8 bytes of EEPROM data memory
• Pin out compatible to the PIC16C73/74/76/77
• Interrupt capability (up to 14 internal/external
• Eight level deep hardware stack
• Direct, indirect, and relative addressing modes
• Power-on Reset (POR)
• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own on-chip RC Oscillator for reliable operation
• Programmable code-protection
• Power saving SLEEP mode
• Selectable oscillator options
• Low-power, high-speed CMOS EPROM/EEPROM technology
• Fully static design
• In-Circuit Serial Programming (ICSP) via two pins
• Only single 5V source needed for programming capability
• In-Circuit Debugging via two pins
• Processor read/write access to program memory
• Wide operating voltage range: 2.5V to 5.5V
• High Sink/Source Current: 25 mA
• Commercial and Industrial temperature ranges
• Low-power consumption:
< 2mA typical @ 5V, 4 MHz
20mA typical @ 3V, 32 kHz
< 1mA typical standby current
PERIPHERAL FEATURES:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler, can be incremented during sleep
Via external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
• Two Capture, Compare, PWM modules
Capture is 16-bit, max resolution is 12.5 ns,
Compare is 16-bit, max resolution is 200 ns,
PWM max. Resolution is 10-bit
• 10-bit multi-channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI. (Master Mode) and I2C. (Master/Slave)
• Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with
9- Bit addresses detection.
• Brown-out detection circuitry for Brown-out Reset (BOR)
ARCHITECTURE OF PIC 16F877:
The complete architecture of PIC 16F877 is shown in the fig 2.1. Table 2.1 gives details about the specifications of PIC 16F877. Fig 2.2 shows the complete pin diagram of the IC PIC 16F877.
Note :
1. This buffer is a Schmitt Trigger input when configured as an external interrupt.
2. This buffer is a Schmitt Trigger input when used in serial programming mode.
3. This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing to a microprocessor bus).
4. This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a
CMOS input otherwise.
I/O PORTS:
Some pins for these I/O ports are multiplexed with an alternate function for the peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin.
Additional Information on I/O ports may be found in the IC micro™ Mid-Range Reference Manual,
PORTA AND THE TRISA REGISTER:
PORTA is a 6-bit wide bi-directional port. The corresponding data direction register is TRISA. Setting a TRISA bit (=1) will make the corresponding PORTA pin an input, i.e., put the corresponding output driver in a Hi-impedance mode. Clearing a TRISA bit (=0) will make the corresponding PORTA pin an output, i.e., put the contents of the output latch on the selected pin.
PORTB AND TRISB REGISTER:
PORTB is an 8-bit wide bi-directional port. The corresponding data direction register is TRISB. Setting a TRISB bit (=1) will make the corresponding PORTB pin an input, i.e., put the corresponding output driver in a hi-impedance mode. Clearing a TRISB bit (=0) will make the corresponding PORTB pin an output, i.e., put the contents of the output latch on the selected pin. Three pins of PORTB are multiplexed with the Low Voltage Programming function; RB3/PGM, RB6/PGC and RB7/PGD. The alternate functions of these pins are described in the Special Features Section. Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on all the pull-ups.
This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are disabled on a Power-on Reset.
PORTC AND THE TRISC REGISTER:
PORTC is an 8-bit wide bi-directional port. The corresponding data direction register is TRISC. Setting a TRISC bit (=1) will make the corresponding PORTC pin an input, i.e., put the corresponding output driver in a hi-impedance mode. Clearing a TRISC bit (=0) will make the corresponding PORTC pin an output, i.e., put the contents of the output latch on the selected pin. PORTC is multiplexed with several peripheral functions. PORTC pins have Schmitt Trigger input buffers.
PORTD AND TRISD REGISTERS:
This section is not applicable to the 28-pin devices. PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. PORTD can be configured as an 8-bit wide microprocessor Port (parallel slave port) by setting control bit PSPMODE (TRISE<4>). In this mode, the input buffers are TTL.
PORTE AND TRISE REGISTER:
PORTE has three pins RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7, which are individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers.
The PORTE pins become control inputs for the microprocessor port when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make sure that the TRISE<2:0> bits are set (pins are configured as digital inputs). Ensure ADCON1 is configured for digital I/O. In this mode the input buffers are TTL.
PORTE pins are multiplexed with analog inputs. When selected as an analog input, these pins will read as '0's. TRISE controls the direction of the RE pins, even when they are being used as analog inputs. The user must make sure to keep the pins configured as inputs when using them as analog inputs.
MEMORY ORGANISATION:
There are three memory blocks in each of the PIC16F877 MUC’s. The program memory and Data Memory have separate buses so that concurrent access can occur.
PROGRAM MEMORY ORGANISATION:
The PIC16f877 devices have a 13-bit program counter capable of addressing 8K *14 words of FLASH program memory. 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.
DATA MEMORY ORGANISTION:
The data memory is partitioned into multiple banks which contain the General Purpose Registers and the special functions Registers. Bits RP1 (STATUS<6) and RP0 (STATUS<5>) are the bank selected bits.
Each bank extends up to 7Fh (1238 bytes). 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.
EEPROM:
EEPROM (electrically erasable, programmable read only memory) technology supplies
Nonvolatile storage of variables to a PIC-controlled device or instrument. That is variables stored in an EEPROM will remain there even after power has been turned off and then on again. Some instruments use an EEPROM to store calibration data during manufacture. In this way, each instrument is actually custom built, with customization that can be easily automated. Other instruments use and EEPROM to allow a user to store several sets of setup information. For an instrument requiring a complicated setup procedure, this permits a user to retrieve the setup required for any one of several very
Different measurements. Still other devices use an EEPROM in a way that is transparent
To a user, providing backup of setup parameters and thereby bridging over power outages
The data EEPROM and flash program memory are readable and writable during normal operation over the entire VDD range. A bulk erase operation may not be issued from user code (which includes removing code protection. The data memory is not directly mapped in the register file space. Instead it is indirectly addressed through the special function registers (SFR).
There are six SFRS used to read and write the program and data EEPROM memory.
These registers are:
EECON1
EECON2
EEDATA
EEDATH
EEADR
EEADRH
EEDATA holds the 8-bit data for read/write and EEADRR holds the address of the EEPROM location being accessed. The 8-bit EEADR register can access up to 256 locations of data EEPROM. The EEADR register can be thought of as the indirect addressing register of the data EEPROM. EEcon1 contains the control bits, while eecon2 is the register used to initiate the read/write. The EEPROM data memory allows bytes read and write. A byte write automatically erases the location and writes the new data. The write time is controlled by timer in-built.
TIMERS
There are three timers used Timer 0, Timer1 and Timer2
Timer 0
8-bit timer/counter
Software programmable prescaler
Internal or external clock select
Readable writable
Interrupt on overflow
Edge selects for external clock
Timer 1
Timer 1 can be used as timer or counter
It is 16-bit register
Software programmable prescaler
Interrupt on overflow
Readable and writable
The timer-1 module is a 16-bit timer/counter consisting two 8-bit register (TMR1H) and
TMR1L), which are readable and writable. The TMR1 register pair (TMR1H:TMR1L)
Increments from 0000h to FFH and rolls over to 0000h. The tmr1 interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit tmr1IF. This interrupt can be enabled/disabled by setting/clearing tmr1 interrupt enable bit tmr1IE.
Timer-2
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.
The timer2 module has an 8-bit period register PR2. Timer2 increments from 00h until it match 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
Timer 2 can be shut off by clearing control bit tmr2on to minimize power consumption.
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
An any device reset
Tmr2 is not cleared when t2con is written
ANALOG TO DIGITAL CONVERTER (ADC)
There are two types of analog to digital converter is present in this IC. We use 10-bit ADC. The ADC module can have up to eight analog inputs for a device. The analog input charges a sample and hold capacitor. The output of sample and hold capacitor is the input into the converter. The converter then generates a digital result of this analog level via successive approximation. The A/D conversion of the analog input signal results in a
Corresponding10-bit digital number. The A/D module has high and low voltage reference input that is software selectable to some combination of VDD, VSS, and RA2
Or RA3.
The A/D module has four registers. These registers are
A/D result high register (ADRESH)
A/D RESULT LOW REGISTER (ADRESL)
A/D CONTROL REGISTER 0 (ADCON0)
A/D CONTROL REGISTER 1 (ADCON1)
INTERRUPTS
The PIC16F87X FAMILY HAS UPTO 14 SOURCES OF INTERRUPT. The interrupt control register (INTCON) records individual interrupt requests in flag bits. IT also has individual interrupt requests in flag bits. IT also has individual and global interrupt enables bits.
Though some modules may generate multiple interrupts such as (USART) They have 14 sources. There is a minimum of one register used in the control and status of the interrupts.
INTCON
Additionally if the device has peripheral interrupts, then it will have registers to enable the peripheral interrupts and registers to hold the interrupt flag bits
ADDRESSING MODES:
DIRECT ADDRESSING:
In direct addressing, the operand specified by an 8-bit address field in the instruction. Only internal data RAM and SFR’s can be directly addressed.
INDIRECT ADDRESSING:
In Indirect addressing, the instruction specifies a register that contains the address of the operand. Both internal and external RAM can indirectly address.
The address register for 8-bit addresses can be either the Stack Pointer or R0 or R1 of the selected register Bank. The address register for 16-bit addresses can be only the 16-bit data pointer register, DPTR.
INDEXED ADDRESSING:
Program memory can only be accessed via indexed addressing this addressing mode is intended for reading look-up tables in program memory. A 16 bit base register (Either DPTR or the Program Counter) points to the base of the table, and the accumulator is set up with the table entry number. Adding the Accumulator data to the base pointer forms the address of the table entry in program memory.
Another type of indexed addressing is used in the“ case jump ” instructions. In this case the destination address of a jump instruction is computed as the sum of the base pointer and the Accumulator data.
REGISTER INSTRUCTION:
The register banks, which contains registers R0 through R7, can be accessed by instructions whose opcodes carry a 3-bit register specification. Instructions that access the registers this way make efficient use of code, since this mode eliminates an address byte. When the instruction is executed, one of four banks is selected at execution time by the row bank select bits in PSW.
REGISTER - SPECIFIC INSTRUCTION:
Some Instructions are specific to a certain register. For example some instruction always operates on the Accumulator, so no address byte is needed to point OT ir. In these cases, the opcode itself points to the correct register. Instruction that register to Accumulator as A assemble as Accumulator - specific Opcodes.
IMMEDIATE CONSTANTS:
The value of a constant can follow the opcode in program memory For example. MOV A, #100 loads the Accumulator with the decimal number 100. The same number could be specified in hex digit as 64h.
OSCILLATOR AND CLOCK CIRCUIT:
XTAL1 and XTAL2 are the input and output respectively of an inverting amplifier which is intended for use as a crystal oscillator in the pioerce configuration, in the frequency range of 1.2 Mhz to 12 Mhz. XTAL2 also the input to the internal clock generator.
To drive the chip with an internal oscillator, one would ground XTAL1 and XTAL2. Since the input to the clock generator is divide by two filip flop there are no requirements on the duty cycle of the external oscillator signal. However, minimum high and low times must be observed.
The clock generator divides the oscillator frequency by 2 and provides a tow phase clock signal to the chip. The phase 1 signal is active during the first half to each clock period and the phase 2 signals are active during the second half of each clock period.
CPU TIMING:
A machine cycle consists of 6 states. Each stare is divided into a phase / half, during which the phase 1 clock is active and phase 2 half. Arithmetic and Logical operations take place during phase1 and internal register - to register transfer take place during phase 2
TRENDS AND DEVELOPMENTS IN MICRO CONTROLLER
The manner in which the use of micro controllers is shaping our lives is breathtaking. Today, this versatile device can be found in a variety of control applications. CVTs, VCRs, CD players, microwave ovens, and automotive engine systems are some of these.
A micro controller unit (MCU) uses the microprocessor as its central processing unit (CPU) and incorporates memory, timing reference, I/O peripherals, etc on the same chip. Limited computational capabilities and enhanced I/O are special features.
The micro controller is the most essential IC for continuous process- based applications in industries like chemical, refinery, pharmaceutical automobile, steel, and electrical, employing programmable logic systems (DCS). PLC and DCS thrive on the programmability of an MCU.
There are many MCU manufacturers. To understand and apply general concepts, it is necessary to study one type in detail. This specific knowledge can be used to understand similar features of other MCUs.
Micro controller devices have many similarities. When you look at the differences, they are not so great either. Most common and popular MCUs are considered to be mature and well-established products, which have their individual adherents and devotees. There are a number of variants within each family to satisfy most memory, I/O, data conversion, and timing needs of enduser applications.
The MCU is designed to operate on application-oriented sensor data-for example, temperature and pressure of a blast furnace in an industrial process that is fed through its serial or operated on under the control of software and stored in ROM. Appropriate signals are fed via output ports to control external devices and systems.
APPLICATIONS OF MICROCONTROLLERS
Microcontrollers are designed for use in sophisticated real time applications such as
1. Industrial Control
2. Instrumentation and
3. Intelligent computer peripherals
They are used in industrial applications to control
• Motor
• Robotics
• Discrete and continuous process control
• In missile guidance and control
• In medical instrumentation
• Oscilloscopes
• Telecommunication
• Automobiles
• For Scanning a keyboard
• Driving an LCD
• For Frequency measurements
• Period Measurements
4.2 LIQUID CRYSTAL DISPLAY (LCD)
Liquid crystal displays (LCD’s) have materials, which combine the properties of both liquids and crystals. Rather than having a melting point, they have a temperature range within which the molecules are almost as mobile as they would be in a liquid, but are grouped together in an ordered form similar to a crystal.
An LCD consists of two glass panels, with the liquid crystal material sand witched in between them. The inner surface of the glass plates are coated with transparent electrodes which define the character, symbols or patterns to be displayed polymeric layers are present in between the electrodes and the liquid crystal, which makes the liquid crystal molecules to maintain a defined orientation angle.
One each polarizes are pasted outside the two glass panels. These polarizes would rotate the light rays passing through them to a definite angle, in a particular direction. When the LCD is in the off state, light rays are rotated by the two polarizes and the liquid crystal, such that the light rays come out of the LCD without any orientation, and hence the LCD appears transparent.
When sufficient voltage is applied to the electrodes, the liquid crystal molecules would be aligned in a specific direction. The light rays passing through the LCD would be rotated by the polarizes, which would result in activating / highlighting the desired characters. The LCD’s are lightweight with only a few millimeters thickness. Since the LCD’s consume less power, they are compatible with low power electronic circuits, and can be powered for long durations.
The LCD does not generate light and so light is needed to read the display. By using backlighting, reading is possible in the dark. The LCD’s have long life and a wide operating temperature range. Changing the display size or the layout size is relatively simple which makes the LCD’s more customers friendly.
The LCDs used exclusively in watches, calculators and measuring instruments are the simple seven-segment displays, having a limited amount of numeric data. The recent advances in technology have resulted in better legibility, more information displaying capability and a wider temperature range. These have resulted in the LCDs being extensively used in telecommunications and entertainment electronics. The LCDs have even started replacing the cathode ray tubes (CRTs) used for the display of text and graphics, and also in small TV applications.
Crystalonics dot–matrix (alphanumeric) liquid crystal displays are available in TN, STN types, with or without backlight. The use of C-MOS LCD controller and driver ICs result in low power consumption. These modules can be interfaced with a 4-bit or 8-bit microprocessor /Micro controller.
• The built-in controller IC has the following features:
• Correspond to high speed MPU interface (2MHz)
• 80 x 8 bit display RAM (80 Characters max)
• 9,920-bit character generator ROM for a total of 240 character fonts. 208 character fonts (5 x 8 dots) 32 character fonts (5 x 10 dots)
• 64 x 8 bit character generator RAM 8 character generator RAM 8 character fonts (5 x 8 dots) 4 characters fonts (5 x 10 dots)
• Programmable duty cycles
• 1/8 – for one line of 5 x 8 dots with cursor
• 1/11 – for one line of 5 x 10 dots with cursor
• 1/16 – for one line of 5 x 8 dots with cursor
• Wide range of instruction functions display clear, cursor home, display on/off, cursor on/off, display character blink, cursor shift, display shift.
• Automatic reset circuit, which initializes the controller / driver ICs after power on.