Published on

Detailed view of PIC 16F877A...

Published in: Education, Technology
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. PIC 16F877A06/08/13S. PARTHIBAN, M. TECH.1
  2. 2. The term PIC or Peripheral Interface Controller,has been coined by Microchip Technology Inc.Low-end range, mid-range and high end range ofcontrollers.What is PIC?06/08/13S. PARTHIBAN, M. TECH.2
  3. 3. We’re used to the Von-Neuman ArchitectureUsed in: 80X86 (PCs), 8051, 68HC11, etc.)Only one bus between CPU and memoryRAM and program memory share the same bus andthe same memory, and so must have the same bitwidthBottleneck: Getting instructions interferes withaccessing RAMCPU8Memory(& Data)PIC Architecture: Background06/08/13S. PARTHIBAN, M. TECH.3
  4. 4. PICs use the Harvard ArchitectureUsed mostly in RISC CPUs (we’ll get there)Separate program bus and data bus: can bedifferent widths!For example, PICs use:Data memory (RAM): a small number of 8bitregistersProgram memory (ROM): 12bit, 14bit or 16bitwide (in EPROM, FLASH, or ROM)CPU121416Memory(Data)8Memory(Program)PIC Architecture: Background06/08/13S. PARTHIBAN, M. TECH.4
  5. 5. Traditionally, CPUs are “CISC”Complex Instruction Set Computer (CISC)Used in: 80X86, 8051, 68HC11, etc.Many instructions (usually > 100)Many, many addressing modesUsually takes more than 1 internal clock cycle(T cycle) to executeExample:MC68HC05: LDAA 0x55010101011000 11002 bytes, 2 cyclesCISC06/08/13S. PARTHIBAN, M. TECH.5
  6. 6. PICs and most Harvard chips are “RISC”Reduced Instruction Set Computer (RISC)Used in: SPARC, ALPHA, Atmel AVR, etc.Few instructions (usually < 50)Only a few addressing modesExecutes 1 instruction in 1 internal clock cycle(Tcyc)Example:PIC16CXXX: MOVLW 0x551 word, 1 cycle1100XX 01010101RISC06/08/13S. PARTHIBAN, M. TECH.6
  7. 7. High performance RISC CPU with 35 no. ofinstruction set onlyHarvard ArchitecturePipelined InstructionsAnd a large number of Peripherals In-builtWhat is New in PIC?06/08/13S. PARTHIBAN, M. TECH.7
  8. 8. Pin Diagram06/08/13S. PARTHIBAN, M. TECH.8
  9. 9. 8kB of flash programmemory368bytes of Datamemory256-EEPROM datamemory15 InterruptsIn-circuit programming3 internal hardwaretimersCapture/Compare/PWM modulesUp to 8 channels of 10-Bit A/DBuilt-in USART forserial communication5 digital I/O ports (Upto 22 lines)Features06/08/13S. PARTHIBAN, M. TECH.9
  10. 10. PIC 16F877A has FIVE I/O PortsA total of 33 pins are used for I/O operations.PORT APort A is 6 bit wide and bi-directional.Its corresponding data direction register is TRISA.If TRISA port pin is set to 1,corresponding port A pinwill act as an input pin and vice versa.Port A is used for analog inputs.I/O Ports06/08/13S. PARTHIBAN, M. TECH.10
  11. 11. Port B is 8 bit wide and bi-directional.Its corresponding data direction register is TRISB.If TRISB port pin is set to 1,corresponding port Bpin will act as an input pin and vice versa.Port B is used for Data Transmission.Port B06/08/13S. PARTHIBAN, M. TECH.11
  12. 12. Port C is 8 bit wide and bi-directional.Its corresponding data direction register is TRISC.If TRISC port pin is set to 1,corresponding port Cpin will act as an input pin and vice versa.Port C is used for control registers(serialcommunication, I2C functions,serial data transfer).Port C06/08/13S. PARTHIBAN, M. TECH.12
  13. 13. Port D is 8 bit wide and bi-directional.Its corresponding data direction register isTRISD.If TRISD port pin is set to 1,corresponding port Dpin will act as an input pin and vice versa.Port D is used as Data portPort D06/08/13S. PARTHIBAN, M. TECH.13
  14. 14. Port E is 3 bit wide . They are for read, write andchip select operation.Each pin is individually configurable as inputsand outputs.Port E is generally used for controlling purposes.Port E06/08/13S. PARTHIBAN, M. TECH.14
  15. 15. 4 cycles per4 cycles per instruction on the PIC16F87xmicro controllers. instruction on the PIC16F87x microcontrollers.ClockReadInstructionDecodeInstructionExecuteInstructionStore ResultT1 T2 T3 T4Oscillator circuits generate a clock signal.Machine Cycle06/08/13S. PARTHIBAN, M. TECH.15
  16. 16. A Machine cycle is the time taken for a datatransfer from or to memory/ I/O Ports.Machine cycle is calculated using the formula:Clock Frequency=6.144MHzMachine cycle frequency= 6.144 MHz /4Hence 1 Machine cycle(Time taken for a datatransfer)= 1/T= 4/ 6.144 MHz= 0.651 µsCalculations06/08/13S. PARTHIBAN, M. TECH.16
  17. 17. An instruction cycle is the time taken to completean instruction.All instructions in 16F877A are single cycleinstructions except for Branching instruction. Theytake two machine cycles to complete aninstruction.Instruction Cycle06/08/13S. PARTHIBAN, M. TECH.17
  18. 18. Different PICs have different on-board peripherals somecommon peripherals are:3 Timers (0 & 2- 8bits, 1-16 bits)2 Compare/Capture/PWM ModulesAnalog to Digital Converters (ADC) (8, 10 and 12bit,50ksps)Serial communications: UART (RS-232C), SPI, I2C,CANPulse Width Modulation (PWM) (10bit)Voltage ComparatorsVoltage Reference ModulesMSSP – Master Synchronous Serial PortI2C (Master and Slave)SPI (Master and Slave)Watchdog timers, Brown out detect, LCD driversPIC overview06/08/13S. PARTHIBAN, M. TECH.18
  19. 19. InstructionsMemory OrganisationOverview06/08/13S. PARTHIBAN, M. TECH.19
  20. 20. 06/08/13S. PARTHIBAN, M. TECH.20
  21. 21. The data memory partitioned into General Purposeregisters and Special Function Registers.Bits RP1 and RP0 are the bank select bits.RP1 RP0 Bank0 0 00 1 11 0 21 1 3Data Memory Organisation06/08/13S. PARTHIBAN, M. TECH.21
  22. 22. 06/08/13S. PARTHIBAN, M. TECH.22
  23. 23. PIC16F877A has 3 TimersTimer 0 - 8 bitcan be used as a Timer/counterTimer 1 – 16 bitcan be used as a Timer/counterTimer 2 – 8 bit Timercan be used as the PWM time-base for the PWMmode of the CCP module.Timers06/08/13S. PARTHIBAN, M. TECH.23
  24. 24. 06/08/13S. PARTHIBAN, M. TECH.24
  25. 25. The data registers of Timer 1 are TMR1H andTMR1L.The 16 bit value to be loaded in the timer is given toData registersThe Control register is T1CON.The timer ON and oscillator enable operations arecontrolled through the control register.To determine if the timer has completed its operation,the timer overflow bit TMR1IF of the PIR1 register ischecked continuously.Timer 106/08/13S. PARTHIBAN, M. TECH.25
  26. 26. Universal synchronous asynchronous receivertransmitter is also known as a serialcommunication interface.USART can be configured in the followingmodes:Asynchronous - FULL DUPLEXsynchronous - HALF DUPLEXUSART06/08/13S. PARTHIBAN, M. TECH.26
  27. 27. For serial Communication, the SFR involved areTXSTA, TXREG, RCSTA,,RCREG and SPBRG.SPBRG is used to set the required baud rate.In TXSTA,TXEN is set high to enabletransmission.The transmitted data is stored in a temporarybuffer,TXREG.In RCSTA, SPEN and CREN are set high to enablereception.The received data is stored in a temporary buffer,RCREG.Serial Communication06/08/13S. PARTHIBAN, M. TECH.27
  28. 28. 06/08/13S. PARTHIBAN, M. TECH.28
  29. 29. 06/08/13S. PARTHIBAN, M. TECH.29
  30. 30. 06/08/13S. PARTHIBAN, M. TECH.30
  31. 31. FOR BAUD RATE:For asynchronous mode,Baud rate=Fosc / 64(x+1)For synchronous mode,Baud rate=Fosc / 4(x+1)FOR RECEPTION:Check RCIF flag till it is set. This indicates that the data iscompletely received in the RCREG. Move this value to workingregister for further manipulation.FOR TRANSMISSION:To transmit the calculated data, move the value to TXREG. Checkthe TXIF flag till it is set. This indicates that the data is completelytransmitted out.06/08/13S. PARTHIBAN, M. TECH.31
  32. 32. 06/08/13S. PARTHIBAN, M. TECH.32
  33. 33. PIC16F877A has 15 sources of interrupts.Only one vector location is allocated for theinterrupts.The Global interrupt enable bit is set, so that anyinterrupt can be acknowledged.Regardless of the Global enable bit, the usershould ensure,the appropriate interrupt flag bitsthat needs to be executed, is also set.Interrupts06/08/13S. PARTHIBAN, M. TECH.33
  34. 34. 06/08/13S. PARTHIBAN, M. TECH.34
  35. 35. Thank You06/08/13S. PARTHIBAN, M. TECH.35