5.4 Microcontrollers II:
PIC16F84 Microcontroller
Dr. Tarek A. TutunjiMechatronics Engineering Department
Philadelphia University, Jordan
PIC Microcontroller
In the previous sequence, general microcontrollers and PIC architecture were introduced
In this presentation, PIC 16F84 will be used to elaborate microcontrollers. This will include• Pins description• Registers• Instruction set• Design & programming examples
PIC 16F84 Pins
General Specifications• Runs at 10 MHz• 8-bit data• 14-bit instruction• 1K Flash memory• One working register (W)
18 pins• VDD (+5V), VSS (gnd)• 13 I/O pins through two ports• Port A: 5-pins RA0 RA5
RA4 dual purpose (timer)
• Port B: 8-pins RB0RB7 RB0 dual purpose (Interrupt)
• !MCLR master clear (active low)• CLKIN (RC clock input)
PIC 16F84 Registers
All file registers are 8-bits
They are divided into: • SPR, specific purpose
• GPR, general purpose
The main specific registers are• PORTA: has 5 I/O bits
• TRISA: specifies the direction of port pins ‘1’ for Input & ‘0’ for Output
• PORTB: has 8 I/O bits
• TRISB: specifies the direction of port pins
• STATUS: bit 5 = 0 (1) page 0 (1)
• TMR0: 8-bit timer
• INTCON: Interrupt Control register
35 Instructions
Instructions used in next examples
MOVLW k move literal ‘k’ to W
MOVWF f move W contents to f
CLRF f clear f
INCF f increment f
BCF f,b clear bit ‘b’ in register ‘f’
BSF f,b set bit in f
BTFSS f,b bit test, skip if set
BTFSC f,b bit test, skip if clear
GOTO k go to address k
LED : circuit diagram
Writing to port (LED):
assembly program; This program is used to flash LED connected to pin RA1
STATUS equ 03h ; ‘equ’ is not an instructionTRISA equ 85h ; it is used by the assemblerPORTA equ 05h ; gives name to address value
bsf STATUS,5 ; Set bit 5 in Status register go to page 1movlw 00h ; Move ’00’ to W (working register)movwf TRISA ; Move contents of W to TRISA all outputbcf STATUS,5 ; Clear bit 5 in Status register go to page 0
Start movlw 02h ; Move ’02’ to Wmovwf PORTA ; Port A = ‘0000 0010’ RA1 ‘high’movlw 00h ; Move ’00; to Wmovwf PORTA ; Port A = ‘0000 0000’ RA1 ‘low’goto Start ; loop back to Start
Switches and LEDs:
circuit diagram
PIC16F84
+5V
Sw1clear
Sw2count
C
RA0
RA1
Vdd!MCLR
Vss
RB0
RB1
RB2
RB3
RB4
RB5
RB6
RB7
CLKIN
R
Reading & Writing; This program outputs binary count to LEDs connected at RB0 to RB7; Input switches connected to RA0 and Ra1 stops, starts, and resets the count
STATUS equ 03 ; assigns names to register addressesPORTA equ 05TRISA equ 85PORTB equ 06TRISB equ 86
bsf status, 5 ; go to page 1movwf 00 ; W = ‘0000 0000’movlw PORTB ; makes PORTB output (connected to LEDs)movwf ff ; W = ‘1111 1111’movlw PORTA ; makes PORTA input (connected to switches)bcf status,5 ; go back to page 0
Reset clrf portb ; PORTB = ‘0000 0000’ All LEDs off
Start btfss PORTA,0 ; Read RA0 (SW1), test RA0 value and skip if ‘1’goto Reset ; go back to Resetbtfsc PORTA,1 ; Read RA1 (SW2), test RA1 value and skip if ‘0’incf PORTB ; Increment PORTB PORTB = PORTB+1
goto Start
Summary
PIC 16F84 microcontroller runs at maximum frequency of 10 MHz
The input clock can either be RC circuit or oscillator
PIC 16F84 has 13 I/0 ports divided into 2 ports (A and B)
The main registers are: PORTA, PORTB, TRISA, TRISB, and STATUS
There are 35 instructions
Examples for simple I/O circuits (LEDs and Switches) were given