Docsity

PIC16F84A Microcontroller, Summaries of Microcontrollers

Toggle sidebar
bg1
1
PIC16F84 Microcontroller Reviewer
Chapter I (Intro to Microcontrollers) and Chapter II (PIC16F84), based on Nebojsa Matic's "PIC Microcontrollers
for Beginners Too"
Chapter I: Intro to Microcontrollers
Block What it does
Memory Stores data. You select a location (addressing), and the R/W line decides whether you read
or write.
CPU The brain of the chip. Its memory locations are called registers.
Bus Wires that connect the blocks. The address bus picks a location; the data bus carries the
data (8 bits here).
I/O ports Connect the chip to the outside world through its pins. Can be input, output, or bidirectional.
Serial communication Sends data one bit at a time over fewer lines (NRZ protocol). It is full-duplex: it can send
and receive at the same time.
Timer A free-run counter, used to measure time.
Watchdog Another free-run counter. If the program gets stuck and stops clearing it (CLRWDT), it
resets the chip.
ADC Converts an analog signal into a binary number.
Chapter II: PIC16F84
1. Basics
•RISC architecture with Harvard design: program and data have separate buses and memory, which makes
it faster.
•18 pins (DIP18 or SMD).
• One instruction cycle = 4 clock cycles (Q1 to Q4), so the oscillator clock is divided by 4.
•Pipelining: most instructions take 1 cycle. Jumps and calls take 2 cycles.
2. Oscillator
•XT: crystal plus two 30 pF capacitors to ground.
•RC: resistor (3k to 100k) plus a capacitor (above 20 pF). Cheaper, but less precise.
3. Reset
•Sources: power-on, MCLR pin, watchdog overflow, and during SLEEP.
•MCLR is active low. Connect it to the supply through a 5 to 10K pull-up resistor.
• After a reset: PC = 0000h, SFR registers are reset, RAM is not reset.
• The PWRT timer gives 72 ms for the oscillator to stabilize.
•Brown-out: the supply drops but not to zero. You need external parts to hold the chip in reset until voltage is
back in range.
4. CPU
• 8-bit ALU and the W (work) register.
pf3
pf4

Partial preview of the text

Download PIC16F84A Microcontroller and more Summaries Microcontrollers in PDF only on Docsity!

PIC16F84 Microcontroller Reviewer

Chapter I (Intro to Microcontrollers) and Chapter II (PIC16F84), based on Nebojsa Matic's "PIC Microcontrollers for Beginners Too"

Chapter I: Intro to Microcontrollers

Block What it does

Memory Stores data. You select a location (addressing), and the R/W line decides whether you read or write.

CPU The brain of the chip. Its memory locations are called registers.

Bus Wires that connect the blocks. The address bus picks a location; the data bus carries the data (8 bits here).

I/O ports Connect the chip to the outside world through its pins. Can be input, output, or bidirectional.

Serial communication Sends data one bit at a time over fewer lines (NRZ protocol). It is full-duplex : it can send and receive at the same time.

Timer A free-run counter, used to measure time.

Watchdog Another free-run counter. If the program gets stuck and stops clearing it ( CLRWDT ), it resets the chip.

ADC Converts an analog signal into a binary number.

Chapter II: PIC16F

1. Basics

  • RISC architecture with Harvard design: program and data have separate buses and memory, which makes it faster.
  • 18 pins (DIP18 or SMD).
  • One instruction cycle = 4 clock cycles (Q1 to Q4), so the oscillator clock is divided by 4.
  • Pipelining: most instructions take 1 cycle. Jumps and calls take 2 cycles.

2. Oscillator

  • XT: crystal plus two 30 pF capacitors to ground.
  • RC: resistor (3k to 100k) plus a capacitor (above 20 pF). Cheaper, but less precise.

3. Reset

  • Sources: power-on, MCLR pin, watchdog overflow, and during SLEEP.
  • MCLR is active low. Connect it to the supply through a 5 to 10K pull-up resistor.
  • After a reset: PC = 0000h , SFR registers are reset, RAM is not reset.
  • The PWRT timer gives 72 ms for the oscillator to stabilize.
  • Brown-out: the supply drops but not to zero. You need external parts to hold the chip in reset until voltage is back in range.

4. CPU

  • 8-bit ALU and the W (work) register.
  • STATUS register bits: C (Carry), DC (Digit Carry), Z (Zero), RP0 (bank select), IRP (indirect addressing).

5. Ports

PORTA PORTB

Pins 5 (RA0 to RA4) 8 (RB0 to RB7)

Direction register TRISA TRISB

Special RA4 is input only (it is also the T0CKI pin).

Internal pull-ups (RBPU bit). RB4 to RB interrupt on change. RB0 is the external interrupt pin (INT).

Rule: in the TRIS registers, 1 = input, 0 = output.

6. Memory

  • Program memory: FLASH, 1024 x 14 bits. Address 0 is the reset vector, address 4 is the interrupt vector.
  • Data memory: RAM (SFR and GPR registers) plus 64 bytes of EEPROM.
  • Two banks , chosen with the RP0 bit in STATUS:
    • bcf STATUS, RP0 selects Bank 0.
    • bsf STATUS, RP0 selects Bank 1.
  • GPR (general purpose RAM) is at 0Ch to 4Fh and is the same in both banks.
  • Program counter: 13 bits (PCLATH and PCL).
  • Stack: 8 levels, 13 bits wide. Saves the return address (CALL pushes it, RETURN pops it).
  • In-system programming: MCLR at 13.5 V, Vdd at 4.5 to 5.5 V.

7. Addressing Modes

  • Direct: the address comes from the instruction plus the RP bits.
  • Indirect: uses FSR (holds the address) and INDF (accesses the data at that address). Good for arrays and loops.

8. Interrupts

  • Let the chip react to an event the moment it happens.
  • INTCON is the control register. GIE (bit 7) turns all interrupts on or off.
  • 4 sources:
    1. EEPROM write complete
    2. TMR0 overflow
    3. Change on RB4 to RB
    4. External interrupt on RB0/INT
  • What happens when an interrupt occurs:
    1. GIE is cleared.
    2. The return address is pushed to the stack.
    3. PC jumps to 0004h.
  • Inside the ISR:
    • Clear the interrupt flag, or the ISR will run again.
    • Save and restore W and STATUS (PUSH and POP). Use SWAPF , because it does not change STATUS bits.
    • Finish with RETFIE , which sets GIE again.

Things to Remember

Item Answer

TRIS bit values 1 = input, 0 = output

Reset vector / interrupt vector 0000h / 0004h

Cycles per instruction 1 normally, 2 for jumps and calls

EEPROM write keys 55h, then AAh (to EECON2)

End of an ISR Clear the flag, then RETFIE