0% found this document useful (0 votes)
120 views43 pages

02 - Uc PIC16F87x 2020 PDF

Uploaded by

RafaelDiscky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views43 pages

02 - Uc PIC16F87x 2020 PDF

Uploaded by

RafaelDiscky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Mengenal

Mikrokontroler
PIC16F87x
Dr. Agfianto Eko Putra, M.Si.
Departemen Ilmu Komputer dan Elektronika
Fak. MIPA – Universitas Gadjah Mada
Versi PIC16F877, PIC16F877A, PIC16F887 - 2020
Keluarga produk Mikrokontroler PIC
• Mikrokontroler 8-bit • Mikrokontroler 32-bit
• PIC10 • PIC32
• PIC12 • 16-bit digital signal
• PIC14 controllers
• PIC16 • dsPIC30
• PIC17 • dsPIC33F
• PIC18
• Mikrokontroler 16-bit
• PIC24F
• PIC24H
Keluarga produk Mikrokontroler PIC
• Huruf F pada nama menunjukkan bahwa PIC
menggunakan memori flash dan dapat dihapus
secara elektrik.
• Huruf C pada nama berarti memori program hanya
dapat dihapus menggunakan sinar ultraviolet.
• Kecuali jenis PIC16C84 yang menggunakan EEPROM dan
dapat dihapus secara elektrik
Keluarga produk Mikrokontroler PIC
• Mengapa PIC16F877A sangat populer?
• Ya karena PIC16F877A sangat murah.
• Mudah membuat rangkaian minimalnya.
• Komponen tambahan yang dibutuhkan hanyalah sumber
tegangan 5V, osilator kristal 20MHz dan 2 unit kapasitor 22pF
capacitors.
• Apa kelebihan uC PIC16F877A?
• IC dapat deprogram berkali-kali hingga 10.000 kali. Sangat
baik dalam proses pengembangan suatu desain.
• Apa kelemahan uC PIC16F877A?
• Tidak memiliki osilator internal, so harus menyiapkan sumber
detak secara eksternal!
The PIC16F87X Microcontroller
Core Features
• High performance RISC CPU • Pinout compatible to the
• Only 35 single word instructions PIC16C73B/74B/76/77
to learn • Interrupt capability (up to 14
sources)
• All single cycle instructions
except for program branches • Power-on Reset (POR)
which are two cycle • Power-up Timer (PWRT) and
• Operating speed: DC - 20 MHz Oscillator Start-up Timer (OST)
clock input, DC - 200 ns • Watchdog Timer (WDT) with its
instruction cycle own on-chip RC oscillator for
• Up to 8K x 14 words of FLASH reliable operation
Program Memory,
• Up to 368 x 8 bytes of Data
Memory (RAM)
• Up to 256 x 8 bytes of EEPROM
Data Memory
Fitur2 peripheral mikrokontroler
PIC16F87X (1/2)
• 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
Fitur2 peripheral mikrokontroler
PIC16F87X (2/2)
• 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)
Diagram Blok Internal PIC16F877
• Arsitektur dasar PIC16F877 terdiri dari Memori
Program, file registers dan RAM, ALU dan register
CPU.
Memori PIC16F877
1. Program Memory – A memory that contains the program
(which we had written), after we've burned it.
• As a reminder, Program Counter executes commands stored in the
program memory, one after the other.
2. Data Memory – This is RAM memory type, which contains
a special registers like SFR (Special Function Register) and
GPR (General Purpose Register).
• The variables that we store in the Data Memory during the program
are deleted after we turn off the micro.
• These two memories have separated data buses, which makes the
access to each one of them very easy.
3. Data EEPROM (Electrically Erasable Programmable
ReadOnly Memory) – A memory that allows storing the
variables as a result of burning the written program.
Memori PIC16F877
• Program Memory and Data Memory two memories
that are needed to build a program, and Data
EEPROM is used to save data after the
microcontroller is turn off.
Memori Data (RAM) PIC16F877
• Media penyimpan untuk variable-variabel
• Memori Data biasa dikenal sebagai Register File dan terdiri
dari dua komponen
• General purpose register file (sama seperti RAM).
• Special purpose register file (sama seperti SFR pada uC 8051).
• Jangkauan alamat dari 0 hingga 511 dan dipartisi menjadi 4
banks → tiap bank diperluas hingga 7Fh (atau 128 bytes).
• Pengguna hanya dapat mengakses sebuah bute RAM di
dalam salah satu 4 bank memori dan hanya satu bank saja
pada saat bersamaan. Default bank-nya adalah BANK0.
• Untuk mengakses suatu register di bank lainnya, haris
dilakukan melalui program. Terdapat register khusus yang
bias diakses dari semabarang bank, contohnya register
STATUS.
Register2 pada PIC16F877A
• Some CPU Registers:
• WREG – Working register
• PC – Program Counter
• FSR – File Selection Register
• IDF – INDirect through FSR
• PCL – Program Counter Low Byte
• PCLATH – Program Counter LATcH
• Memory map registers
• STATUS register – changes/moves from/between the banks.
• PORT registers – assigns logic values (“0”/”1”) to the ports
• TRIS registers – data direction register (input/output)
Register WREG

• Register 8-bit;
• Digunakan untuk semua
operasi aritmetika dan
logika;
• Digunakan dalam banyak
instruksi:
• Sumber suatu
operan;
• Destinasi hasil dari
instruksi yang
dijalankan
Program Counter
• Program Counter (PC) is 13 bit and capable of addressing an
8K word x 14 bit program memory space.
• PC keeps track of the program execution by holding the
address of the current instruction.
• It is automatically incremented to the next instruction
during the current instruction execution.
• Program Counter Stack
• An independent 8-level stack is used for the program counter.
• As the PC is 13-bit, the stack is organized as 8x13bit registers.
• When an interrupt occurs, the PC is pushed onto the stack. When
the interrupt is being served, other interrupts remain disabled.
Hence, other 7 registers of the stack can be used for subroutine
calls within an interrupt service routine or within the mainline
program.
FSR & INDF
• FSR Register
• (File Selection Register, address = 04H, 84H) is an 8-bit
register used as data memory address pointer. This is
used in indirect addressing mode.
• INDF Register
• (INDirect through FSR, address = 00H, 80H) INDF is not a
physical register. Accessing INDF is actually access the
location pointed to by FSR in indirect addressing mode.
PCL & PCLATH
• PCL Register
• (Program Counter Low Byte, address =02H, 82H)
• PCL is actually the lower 8-bits of the 13-bit Program Counter.
This is a both readable and writable register.
• PCLATH Register
• (Program Counter LATcH, address = 0AH, 8AH)
• PCLATH is a 8-bit register which can be used to decide the
upper 5-bits of the PC. PCLATH is not the upper 5bits of the
PC. PCLATH can be read from or written to without affecting
the PC.
• The upper 3 bits of PCLATH remain zero and they serve no
purpose. When PCL is written to, the lower 5bits of PCLATH
are automatically loaded to the upper 5bits of the PC.
Register STATUS
• Is an 8-bit register that stores the status of the processor.
• In most cases, this register is used to switch between the
banks (Register Bank Select), but also has other capabilities.
Fitur Periferal PIC16F877 (1/6)
• PIC16F877 has 5 I/O ports:
• PORT A has 6 bit wide, Bidirectional
• PORT B, C, D have 8 bit wide, Bidirectional
• PORT E has 3 bit wide, Bidirectional
• Each port has 2 control registers:
• TRISx sets whether each pin is an input(1) or output(0)
• PORTx sets their output bit levels or contain their input bit
levels.
• Most pins have 25mA source/sink thus it can drive LEDs
directly.
Fitur Periferal PIC16F877 (2/6)
Fitur Periferal PIC16F877 (3/6)
• Analog to Digital Converter (ADC)
• Only available in 14-bit and 16-bit cores
• Fs (sample rate) < 54KHz
• The result is a 10 bit digital number
• Can generate an interrupt when ADC conversion is done
• The A/D module has 4 registers:
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register0 (ADCON0)
• A/D Control Register1 (ADCON1)
• Multiplexed 8 channel inputs
• Must wait 𝑇𝑎𝑐𝑞 to change up sampling capacitor.
• Can take a reference voltage different from that of the
controller
Fitur Periferal PIC16F877 (4/6)
• Timer/counter modules
• Generate interrupts on timer overflow
• Can use external pins as clock in/ clock out (ie. for
counting events or using a different Fosc)
• There are 3 Timer/counter modules:
• Timer0: 8-bit timer/counter with 8-bit pre-scaler
• Timer1: 16-bit timer/counter with 8-bit pre-scaler, can be
incremented during SLEEP via external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, pre-
scaler and post-scaler.
Fitur Periferal PIC16F877 (5/6)
• Universal Synchronous Asynchronous Receiver Transmitter
(USART/SCI) with 9-bit address detection.
• Asynchronous communication: UART (RS 232 serial)
• Can do 300bps – 115kbps
• 8 or 9 bits, parity, start and stop bits, etc.
• Outputs 5V → needs a RS232 level converter (e.g MAX232)
• Synchronous communication: i.e with clock signal
• SPI = Serial Peripheral Interface
• 3 wire: Data in, Data out, Clock
• Master/Slave (can have multiple masters)
• Very high speed (1.6Mbps)
• Full speed simultaneous send and receive (Full duplex)
• I2C = Inter IC
• 2 wire: Data and Clock
• Master/Slave (Single master only)
• Lots of cheap I2C chips available; typically < 100kbps
Fitur Periferal PIC16F877 (6/6)
• 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
• Parallel Slave Port (PSP) 8-bits wide, with external
RD, WR and CS controls
Rangkaian dasar PIC16F87x (1/2)
• Each PIC Microcontroller has a basic circuit and if you won’t
design the basic circuit then it won’t work.
• It’s just like providing power to your PIC Microcontroller and
it works on +5V level.
• If you want to turn ON fan then what will you do? You will
simply provide it power and that’s what we are gonna do
with PIC but in PIC case we also need to provide the
frequency at which it will work.
• So, now we know that we need to design the basic circuit
and this basic circuit contains power as well as the
frequency at which it will work.
• In order to provide frequency to PIC Microcontroller, we use
crystal oscillator and for PIC 16F877a, you can use crystal
oscillator of frequency range from 4MHz to 40MHz.
Rangkaian dasar PIC16F87x (2/2)
• Pin # 1: This Pin is called MCLR (Master Clear) and we need
to provide 5V to this pin through a 10k-ohm resistance.
• Pin # 11 & Pin # 32: These Pins are labelled as Vdd so we
also need to provide it +5V and you can see these lines are
in red color in above figure.
• Pin # 12 & Pin # 31: These Pins are Vss, so we have
provided GND (Ground) at this pin and its lines are in black
color.
• Pin # 13 & 14: These Pins are named as OSC1 (Oscillator
1) and OSC2 (Oscillator 2), now we have to attach
our Crystal Oscillator (16MHz) at these pins which I have
lined in Orange color. After the Crystal Oscillator, we have
33pF capacitors and then they are grounded.
Lima Port I/O pada PIC16F87x
• Port A: It has 6 Pins in total starting from Pin # 2 to Pin # 7. Port A
Pins are labelled from RA0 to RA5 where RA0 is the label of first
Pin of Port A.
• Port B: It has 8 Pins in total starting from Pin # 33 to Pin # 40.
Port B Pins are labelled from RB0 to RB7 where RB0 is the label of
first Pin of Port B.
• Port C: It has 8 Pins in total. It’s pins are not aligned together. First
four Pins of Port C are located at Pin # 15 – Pin # 18, while the last
four are located at Pin # 23 – Pin # 26.
• Port D: It has 8 Pins in total. It’s pins are also not aligned together.
First four Pins of Port D are located at Pin # 19 – Pin # 22, while
the last four are located at Pin # 27 – Pin # 30.
• Port E: It has 3 Pins in total starting from Pin # 8 to Pin # 10. Port
E Pins are labelled from RE0 to RE2 where RE0 is the label of first
Pin of Port E.
Fasilitas Interupsi pada PIC16F87x
• PIC16F877a has total 8 1. External Interrupts.
interrupt sources in it. 2. Timer Interrupts (
• An interrupt source is Timer0 / Timer1).
some event which 3. Port B State Change.
generates interrupt, this
source could be a timer 4. Parallel Slave Port
like interrupts are Read/Write.
generate after every 1 5. A/D Converter.
sec, or it could also be pin
state change event, like if 6. Serial Receive /
pin state is changed then Transmit.
interrupt will be 7. PWM (CCP1 / CCP2).
generated.
8. EEPROM Write
Operation.
Pemrograman
Mikrokontroler
PIC16F87x
Dr. Agfianto Eko Putra, M.Si.
Departemen Ilmu Komputer dan Elektronika
Fak. MIPA – Universitas Gadjah Mada
Versi PIC16F877, PIC16F877A, PIC16F887 - 2020
Pemrograman Mikrokontroler
Pemrograman Mikrokontroler
Pemrograman Mikrokontroler
Pemrograman Mikrokontroler
Kelebihan Bahasa Tingkat Tinggi
Top 3 PIC C Compiler
• MPLAB® X Integrated Development Environment
(IDE)
• https://www.microchip.com/mplab/mplab-x-ide
• MikroC Pro for PIC
• https://www.mikroe.com/mikroc-pic
• CCS Compiler
• http://www.ccsinfo.com/content.php?page=compilers
Terima Kasih!
[email protected]
http://agfi.staff.ugm.ac.id
http://pintarembeddedsystem.wordpress.com

You might also like