pic micro controller

44
PIC 16F877 MICROCONTROLLER SUBMITTED BY ANAMIKA GUPTA ME REGULAR(E.C.E) PIC 16F877

Upload: anamika-gupta

Post on 26-Nov-2014

168 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Pic Micro Controller

PIC 16F877

PIC 16F877MICROCONTROLLER

SUBMITTED BYANAMIKA GUPTAME

REGULAR(E.C.E)

Page 2: Pic Micro Controller

What is a Microcontroller?

A single chip that contains Processor (the CPU) Non-volatile memory for the

program (ROM or flash) Volatile memory for input and output

(RAM) Clock An I/O control unit. Also called a "computer on a chip" Billions of microcontroller units

(MCUs) are embedded each year in a large number of products from toys to automobiles.

For example, a single vehicle can use 70 or more microcontrollers..

2 PIC 16F877

Page 3: Pic Micro Controller

3

Microcontrollers are designed for embedded applications, in contrast to the microprocessor used in personal computers or other general purpose applications.

PIC microcontroller chips from Microchip are the world's smallest microcontrollers.

PIC 16F877

Page 4: Pic Micro Controller

FLASH MicrocontrollersUsing microcontrollers with integrated FLASH memory modules provides

greater flexibility with regard to field programmability. FLASH EEPROMs are fundamentally different from One Time

Programmable devices, in that FLASH modules are electrically erasable.Add robustness to reprogramability.FLASH devices can be repeatedly erased and reprogrammed while installed

in the user application.Reduced programming time and reduce cost.

4 PIC 16F877

Page 5: Pic Micro Controller

PIC ArchitecturePeripheral interface controllers is a family of microcontrollers by Microchip

Technology.Programming a PIC processor is much easier ,have attractive features and

they are suitable for a wide range of applications.Harvard architecture.Use of separated program and data memories.Make data and address buses separate allowing increased data flow to and

from the CPU.Data and address busses can be different widths.

5

DataMemory CPU Program

Memory CPU

ProgramandData

Memory

Harvard von-Neumann

PIC 16F877

Page 6: Pic Micro Controller

Feature of 16F877 8 kbytes of FLASH Program Memory. 368 bytes of Data Memory (RAM). 256 bytes of EEPROM Data Memory. 33 input or output pins. 20 MHz operating speed(200 ns instruction cycle) High performance RISC CPU. Only 35 simple word instructions. All single cycle instructions except for program branches which are two

cycles.  Power on Reset (POR). Power-Up Timer (PWRT) and oscillator start-up timer. Low power- high speed CMOS 8-bit flash microcontroller.

6 PIC 16F877

Page 7: Pic Micro Controller

Feature of 16F866 ……. Wide operating voltage range (2.0 – 5.56)volts. Low power consumption . Synchronous Serial Port (SSP) with SPI (master code) and I2C

(master/slave). PICs have different on-board peripherals. Some common peripherals are:

Analog to Digital Converters (ADC) Serial communications: UART ,SPI, I2CTimers and counters (8 and 16bit)Watchdog timers, Brown out timers.

7 PIC 16F877

Page 8: Pic Micro Controller

Pin Diagram PIC 16F877

8 PIC 16F877

Page 9: Pic Micro Controller

PIC Block Diagram

9 PIC 16F877

Page 10: Pic Micro Controller

PIC 16F877 Block Diagram

10 PIC 16F877

Page 11: Pic Micro Controller

CPU

A PIC CPU consists of several sub units such as instruction decoder, ALU, accumulator, control unit, etc.

It normally supports Reduced Instruction Set Computer (RISC) architecture, a type of microprocessor that focuses on rapid and efficient processing of a relatively small set of instructions.

RISC design in which most of the instructions a computer decodes and executes are simple.

11 PIC 16F877

Page 12: Pic Micro Controller

These RISC structure gives the following advantages

• The RISC structure only has 35 simple instructions as compared to other. • The execution time is same for most of the instructions (except very few

numbers).• The execution time required is very less (5 million instructions/second

(approximately).

12 PIC 16F877

Page 13: Pic Micro Controller

Memory The memory in a PIC chip used to store the data and programs temporary or permanently. As like normal microcontrollers, the PIC chip also has certain amount of RAM, ROM,

EEPROM, other flash memory, etc. A PIC Chip normally contains a certain amount of flash memory.

ALU Perform operations on temporary working register and register file. 8 bit wide ALU. One of the operand is normally in W register and the other one is either a fine register on

an immediate constant. Effect various flags ,namely,carry,digit carry, zero in Status register..

13 PIC 16F877

Page 14: Pic Micro Controller

Bus BUS is the communication or data transmission/reception path in a

microcontroller unit. In a normal microcontroller chip, two types of  buses are normally available.

1)  Data bus Data bus is used for memory addressing. The function of data bus is

interfacing all the circuitry components inside the PIC chip.

2)AddressbusAddress bus mostly used for memory addressing. The function of address bus is to transmit the address from the CPU to memory locations.

14 PIC 16F877

Page 15: Pic Micro Controller

Power on resetThe task of POR is ensuring that the processor starts at known address

when power is first on.The reset function will set the program counter to the starting address.

Power up timerA special timer that delay the start of program execution after the PIC has

been reset on power.This time delay allows VDD to rise to the required level.

Brown out delayWhen the power supply drops below a certain voltage(4 v in case of PIC),it

causes PIC to reset.

PIC 16F877 15

Page 16: Pic Micro Controller

PIC 16F877 16

WDTA watch dog timer is a simple timer circuit that performs a specific

operation after a certain period of time if something goes wrong.Suppose we have written a program which is compiled successfully and

when we simulate it every time seems to work fine.Then we program the PIC.However after a long period of time the program gets stuck somewhere .What needs it this case is some kind of reset if the program is gets stuck.This is a purpose of a watchdog timer circuit.When the WDT is enable, a counter starts at 00 and increment by 1 unit

until it reaches FF.

Page 17: Pic Micro Controller

When it goes from FF to 00 the PIC will be reset, irrespective of what it is doing.

The only way we can stop the WDT, from resetting the WDT back to 00 throughout the program which is done by the processor.

Which indicates that the processor functioning is going on.Watchdog timer is thus increases the system reliability.

PIC 16F877 17

WDT…..

Page 18: Pic Micro Controller

ICD

One the great advantages of PIC 16F877 the In-Circuit Debugger (ICD). With the ICD we can watch our program run in the chip/module and find

any bugs or programming mistakes as they happen. It's like making everything happen in slow motion so you can see where the

error occurred. To use ICD we simply press the DEBUG button.Debug add a block of code to our program that is used by the ICD.The added ICD block of code sends variable values, internal register values

and other details to the PC through the programming cable. The ICD, will display that data ,by using the ICD debug tool.

18 PIC 16F877

Page 19: Pic Micro Controller

CPU Register

W or Working Resister(8-bits)STATUS Resister(8 bits)FSR(File Selection Register(8 bits)PCLATH(Program Counter Latch) (5 bits)PCL(Program Counter Byte)(8 bits)

19 PIC 16F877

Page 20: Pic Micro Controller

W or Working Resister

8 bits wideContains one of the source operands during the execution of instructions.Serve as the destination for the result of the operation.Only used for ALU operations..

20 PIC 16F877

Page 21: Pic Micro Controller

Status Register Status register is an eight bit register that contains the arithmetic status of the arithmetic logic unit

(ALU), the reset status and the bank select bits for the data memory. The detailed explanation of status register is given below.

Carry bit(C)

When two 8-bit operands are added ,a 9 bits result occurs,because the result of addition may exceeds 256(FFH).

The 9th bit is copied in the Carry bit.Bit 0 (C): Carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions) 1 = A carry-out from the Most Significant bit of the result occurred 0 = No carry-out from the Most Significant bit of the result occurred.

21 PIC 16F877

Page 22: Pic Micro Controller

Digit carry(DC)

This bit indicates a Carry from the lower 4 bits,during 8 bit addition. If set,it means there is a carry from the 3rd bit to 4th bit position. Bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions) (For borrow, the polarity is reversed) (1 = A carry-out from the 4th low order bit of the result occurred 0 = No carry-out from the 4th low order bit of the result.

22 PIC 16F877

Page 23: Pic Micro Controller

Zero(Z)

Many arithmetic and logic instructions affect the zero flag.Decf instruction can be used to decrement a variable in RAM, and if result is

zero,Zbit is set, otherwise cleared. Bit 2, (Z): Zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero.)

TO and PD(active low)

Used along with the SLEEP mode of PIC.During the sleep mode the microcontroller save lots of power. After coming out of this mode, the CPU can check these two status bits to

determine which kind of event is responsible to bring it out of the SLEEP mode.Bit 4, (TO): this is a time-out bit used for timing and counting, sleep and reset

functions. 1 = after power-up, CLRWDT instruction or SLEEP instruction 0 = A WDT time-out occurred

23 PIC 16F877

Page 24: Pic Micro Controller

Bit 3, (PD): Power-down bit1 = after power-up or by the CLRWDT instruction0 = by execution of the SLEEP instruction

RP0 and RP1There are four memory banks ,each of 128 bytes in size.For bank selection 2 bits are needed, making the effective address 9-bit

wide.

24 PIC 16F877

Page 25: Pic Micro Controller

Direct addressing mode Microchip has provided only direct addressing mode for the register file

with 7-bits address plus remaining 8th and 9th bits frozen in the STATUS REGISTER bits RP1:RP2.

11 = Bank 3 (180h-1FFh)10 = Bank 2 (100h-17Fh)01 = Bank 1 (80h-FFh)00 = Bank 0 (00h-7Fh) As shown in figure

25 PIC 16F877

Page 26: Pic Micro Controller

Use of RP1:RP0 bits in direct addressing mode

26 PIC 16F877

Page 27: Pic Micro Controller

Indirect addressing mode

IRP bit is used for indirect addressing.The IRP bit allows selecting either1= Bank 2 & bank 3 0= Bank 0 & bank 1 The IPR bit and FSR decide the effective 9 bit address. As shown in figure

27 PIC 16F877

Page 28: Pic Micro Controller

Use of IPR bits in indirect addressing mode

28 PIC 16F877

Page 29: Pic Micro Controller

FSR (File Selection Register)

FSR is the pointer used for indirect memory addressing in the whole register file.

In PIC every instruction that can be used for direct addressing may also be used in a different way for indirect addressing.

The only difference in indirect addressing mode is that one has to write the address byte in FSR .

29 PIC 16F877

Page 30: Pic Micro Controller

PCLATH (Program Counter Latch)Different from the program counter.Any write to PCL will cause the contents of PCLATH to be transferred to

the 13 bit PC higher locations.

30 PIC 16F877

Page 31: Pic Micro Controller

31

PCLProgram Counter byte.PCL is the lower byte of the PC.Cause PCLATH contents to be

transferred to the PC higher bit locations.

PC of PIC is associated with an 8-level stack.

PC always points to the next instruction to be executed.

In case of call to subroutines, the returned address is pushed onto the stack.

After the return from called subroutine, this return address is retrieved.

Stack width and PC width should be same. PIC 16F877

Page 32: Pic Micro Controller

Power Control RegisterContains the flags which can differentiate between the type of reset

occurred namelyPower on resetBrown out reset

32 PIC 16F877

Page 33: Pic Micro Controller

Option_Reg Register

Bit 7 (RBPU): This is a PORT B Pull-up Enable bit. 1 = PORTB pull-ups are disabled. 0 = PORTB pull-ups are enabled by individual port latch values.

Bit 6 (INTEDG): This is an Interrupt Edge Select bit. This bit decided if the interrupt is on either rising edge or falling edge. The function of this bit is given below.

1 = Interrupt on rising edge of RB0/INT pin. 0 = Interrupt on falling edge of RB0/INT pin.

33 PIC 16F877

Page 34: Pic Micro Controller

Bit 5 (T0CS): this is a timer-0(TMR0) Clock Source Select bit and its function is given below.

1 = Transition on RA4/T0CKI pin. 0 = Internal instruction cycle clock.Bit 4 (T0SE): TMR0 Source Edge Select bit which select the timer 0 source

edge. 1 = Increment on high-to-low transition on RA4/T0CKI pin. 0 = Increment on low-to-high transition on RA4/T0CKI pin.Bit 3 (PSA): Prescaler Assignment bit. 1 = Prescaler is assigned to the Watch Dog Timer (WDT). 0 = Prescaler is assigned to the Timer0 module.)Bit 2-0 (PS2:PS0): Prescaler Rate Select bits

34 PIC 16F877

Page 35: Pic Micro Controller

Stack The entire PIC chip has an area for storing the return addresses. This area or

unit called Stack is used in some Peripheral interface controllers. The hardware stack is not accessible by software. But  for most of the controllers, it can be easily accessible.

35 PIC 16F877

Page 36: Pic Micro Controller

Input/output portsPIC 16F877 series normally has five input/output ports. They are used for the input/output interfacing with other devices/circuits.Most of these port pins are multiplexed for handling alternate function for

peripheral features on the devices.The PIC 16F877 chip basically has 5 input/output ports. PORT A PORT B PORT C PORT D PORT E

36 PIC 16F877

Page 37: Pic Micro Controller

Memory Organization of PIC16F877PIC microcontrollers have separated memory and data memory with

separated address and data buses.The memory of a PIC 16F877 chip is divided into 2 sections. They areProgram memoryData memory

37 PIC 16F877

Page 38: Pic Micro Controller

Program memoryProgram memory contains the programs that are written by the user. The

program counter (PC) executes these stored commands one by one. Usually PIC16F877 devices have a 13 bit wide program counter that is capable of addressing 8K×14 bit wide flash program memory space.

That can be electrically erasable /reprogrammed.  This memory is primarily used for storing the programs that are written

(burned) to be used by the PIC.

38 PIC 16F877

Page 39: Pic Micro Controller

Program memory map of 16F877

39 PIC 16F877

Page 40: Pic Micro Controller

Program memory……Program counters (PC) is used to keep the track of the program execution

by holding the address of the current instruction. The counter is automatically incremented to the next instruction during the current instruction execution.

Each time the main program execution starts at address 0000 – Reset Vector. The address 0004 is “reserved” for the “interrupt service routine” (ISR).

40 PIC 16F877

Page 41: Pic Micro Controller

PIC16F87XA Data Memory Organization

Data memory is divided in two four banks, Each bank holds 128 bytes of addressable memory.

Contain GPR and SPR.The banked arrangement is necessary because there are only 7 bits are

available in the instruction word for the addressing of a register, which gives only 128 addresses.

The selection of the banks are determined by control bits RP1, RP0 in the STATUS registers

Together the RP1, RP0 and the specified 7 bits effectively form a 9 bit address.

41 PIC 16F877

Page 42: Pic Micro Controller

PIC 16F877 42

Page 43: Pic Micro Controller

Advantages of PIC Controlled System Reliability

The PIC controlled system often resides machines that are expected to run continuously for many years without any error and in some cases recover by themselves if an error occurs.

PerformanceMany of the PIC based embedded system use a simple pipelined RISC processor for computation

Power consumptionA PIC controlled system operates with minimal power consumption without sacrificing performance..

MemoryMost of the PIC based systems are memory expandable and will help of this we can easily adding more and more memory according to the usage and type of application.

43 PIC 16F877

Page 44: Pic Micro Controller

PIC 16F877

THANK YOU