If you know about Microcontoller keep read it, if don’t please read my Introduction to Microcontroller first (click here or click here, all in Indonesian language, sorry).

Do you know that not only Atmel AVR is the microcontroller. The other is PIC16F877 (or PIC16F87X: PIC16F873, PIC16F874, PIC16F876 and PIC16F877), one of the microcontoller made by Microchip Inc.. There are many families for the PIC microcontroller, the PIC16F877 is the PIC16 family. PIC16F877 is one of the most commonly used microcontroller especially in automotive, industrial, appliances and consumer applications. Take a look at the picture below… (and click it if you want more information at Microchip Inc.)

The PIC16F877 is a RISC (Reduced Instruction Set Computer) Microcontoller, which gives two great advantages:

  • The CPU only recognizes 35 simple instructions. Just to mention that in order to program other microcontrollers in assembly language it is necessary to know more than 200 instructions by heart.
  • The execution time is the same for almost all instructions, and lasts for 4 clock cycles. The oscillator frequency is stabilized by a quartz crystal. The execution time of jump and branch instructions is 2 clock cycles. It means that if the microcontroller’s operating speed is 20MHz, the execution time of each instruction will be 200nS, i.e. the program will execute 5 million instructions per second!

The PIC16F87X Microcontroller 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
  • Pinout compatible to the PIC16C73B/74B/76/77
  • Interrupt capability (up to 14 sources)
  • 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 FLASH/EEPROM technology
  • Fully static design
  • In-Circuit Serial Programming (ICSP) via two pins
  • Single 5V In-Circuit Serial Programming capability
  • In-Circuit Debugging via two pins
  • Processor read/write access to program memory
  • Wide operating voltage range: 2.0V to 5.5V
  • High Sink/Source Current: 25 mA
  • Commercial, Industrial and Extended temperature ranges
  • Low-power consumption:
    - < 0.6 mA typical @ 3V, 4 MHz
    - 20 μA typical @ 3V, 32 kHz
    - < 1 μA typical standby current

The PIC16F87X Microcontroller 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 (ADC)
  • Synchronous Serial Port (SSP) with SPI (Master mode) and I2C (Master/Slave)
  • Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection
  • Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only)
  • Brown-out detection circuitry for Brown-out Reset (BOR)

The PIC16F874/PIC16F877 Chip

Just like I mentioned before, there are four devices (PIC16F873, PIC16F874, PIC16F876 and PIC16F877). The PIC16F876/873 devices come in 28-pin packages and the PIC16F877/874 devices come in 40-pin packages. The Parallel Slave Port is not implemented on the 28-pin devices. Fot more information referred to the datasheet.

The PIC16F874/PIC16F877 Block Diagram

How to Program?

  • You need Hardware (minimum system) and Software for write your program to the flash rom of PIC (program downloader);
  • You can use assembly language using the default software from Microchip Inc.: MPLAB IDE (click here for more information). You can download it and its free!
  • You can use C Language:
    • CCS C Compiler from Custom Computer Services, you can try the demo version for 45 days (click here)
    • HI-TECH C for the PIC10/12/16 MCU Family, please find the information provided here. You can download and try the free lite mode.
  • You can use BASIC Language:
    • PIC Basic Pro Compiler is the industry standard BASIC programming language for Microchip’s PIC microcontrollers, click here for more information.
    • PIC Simulator IDE is powerful application that supplies PIC developers with user-friendly graphical development environment for Windows with integrated simulator (emulator), Basic compiler, assembler, disassembler and debugger. Click here for more information.
  • For downloader, I recommend use PICKit 2 from microchip, its easy to use and very portable!

Why Use C Language?!

The C language was development at Bell Labs in the early 1970’s by Dennis Ritchie and Brian Kernighan. One of the first platforms for implementation was the PDP-11 running under a UNIX environment.

Since its introduction, it has evolved and been standardized throughout the computing industry as an established development language. The PC has become a cost effective development platform using C++ or other favored versions of the ANSI standard.

C is a portable language intended to have minimal modification when transferring programs from one computer to another. This is fine when working with PC’s and mainframes, but Microcontrollers and Microprocessors are different breed. The main program flow will basically remain unchanged, while the various setup and port/peripheral control will be micro specific. An example of this is the port direction registers on a PICmicro®MCU are set 1=Input 0=Output, whereas the H8 is 0=Input and 1=Output.

The use of C in Microcontroller applications has been brought about by manufacturers providing larger program and RAM memory areas in addition to faster operating speeds.

An example quoted to me - as a non believer - was: to create a stopclock function would take 2/3 days in C or 2 weeks in assembler. ‘Ah’ I hear you say as you rush to buy a C compiler - why do we bother to write in assembler? It comes down to code efficiency - a program written in assembler is typically 80% the size of a C version. Fine on the larger program memory sized devices but not so efficient on smaller devices. You pay the money and take you PIC!!

[taken from PICmicro MCU C®: An introduction to programming The Microchip PIC in CCS C By Nigel Gardner]

The CCS PIC-C compiler

The CCS PCW compiler is specially designed to meet the special needs of the PICmicro MCU controllers. These tools allow developers to quickly design application software for these controllers in a highly readable, high-level language.

The compilers has some limitations when compared to a more traditional C compiler. The hardware limitations make many traditional C compilers ineffective. As an example of the limitations, the compilers will not permit pointers to constant arrays. This is due to the separate code/data segments in the PICmicro MCU hardware and the inability to treat ROM areas as data. On the other hand, the compilers have knowledge about the hardware limitations and do the work of deciding how to best implement your algorithms. The compilers can efficiently implement normal C constructs, input/output operations and bit twiddling operations.

The compiler can output 8 bit hex, 16 bit hex, and binary files. Two listing formats are available. Standard format resembles the Microchip tools and may be required by some third-party tools. The simple format is easier to read. The debug file may either be a Microchip .COD file or Advanced Transdata .MAP file. All file formats and extensions are selected via the Options|File Formats menu option in the Windows IDE.

What’s Next?

The detail of the Introduction to PIC16F877, including how many and what kind of registers, etcs, please datasheet, or you can visit MIKROE website here.

Thank you..

Tags: , , ,

11 Responses to “PIC16F877 Microcontrollers - Introduction”

  1. Wah saya belum kesampaian untuk belajar Mikro ini.

    Salam

  2. terkait dengan microcontrollers, bisa diunduh artikel-artikel berikut: http://repository.gunadarma.ac.....56789/2797

  3. Cek blog ini http://www.rudolfworotikan.com.

    Beberapa contoh kode sederhana yang dapat di gunakan, saya sudah coba menggunakan kode dari blog tersebut dan okay.

  4. sangat menambah wawasan

  5. terima kasih pak atas sharenya

  6. thank you for sharing it’s so helpful

  7. i like this article, thank you for sharing.

Trackbacks/Pingbacks

  1. Counter prescaler | Firstquantumre
  2. Aplikasi PIC16F877 untuk LED dan tombol | DSP & Embedded Electronics
  3. Memanfaatkan ADC Internal Mikrokontroler PIC16F877 | DSP & Embedded Electronics
  4. Memanfaatkan EEPROM internal Mikrokontroler PIC16F877 | DSP & Embedded Electronics

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>